Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _VIBRATION_ELEMENT_H |
| 18 | #define _VIBRATION_ELEMENT_H |
| 19 | |
Chris Ye | 6393a26 | 2020-08-04 19:41:36 -0700 | [diff] [blame] | 20 | #include <array> |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 21 | #include <chrono> |
| 22 | #include <cstdint> |
| 23 | #include <string> |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame^] | 24 | #include <vector> |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | |
Chris Ye | 6393a26 | 2020-08-04 19:41:36 -0700 | [diff] [blame] | 28 | // evdev FF_RUMBLE effect only supports two channels of vibration. |
| 29 | constexpr size_t CHANNEL_SIZE = 2; |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 30 | /* |
| 31 | * Describes a rumble effect |
| 32 | */ |
| 33 | struct VibrationElement { |
| 34 | std::chrono::milliseconds duration; |
Chris Ye | 6393a26 | 2020-08-04 19:41:36 -0700 | [diff] [blame] | 35 | // Channel amplitude range 0-255. |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame^] | 36 | std::vector<std::pair<int32_t /*vibratorId*/, uint8_t /*amplitude*/>> channels; |
| 37 | |
| 38 | explicit VibrationElement(size_t channelNum); |
| 39 | |
| 40 | VibrationElement(const VibrationElement& other); |
| 41 | |
| 42 | bool operator==(const VibrationElement& other) const; |
| 43 | |
| 44 | bool operator!=(const VibrationElement& other) const; |
| 45 | |
| 46 | void addChannel(int32_t vibratorId, uint8_t amplitude); |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 47 | |
Chris Ye | 6393a26 | 2020-08-04 19:41:36 -0700 | [diff] [blame] | 48 | const std::string toString() const; |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame^] | 49 | |
| 50 | uint16_t getMagnitude(int32_t vibratorId) const; |
| 51 | |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 52 | bool isOn() const; |
| 53 | }; |
| 54 | |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame^] | 55 | /* |
| 56 | * Describes a sequence of rumble effect |
| 57 | */ |
| 58 | struct VibrationSequence { |
| 59 | // Pattern of vibration elements |
| 60 | std::vector<VibrationElement> pattern; |
| 61 | |
| 62 | explicit VibrationSequence(size_t length); |
| 63 | |
| 64 | void operator=(const VibrationSequence& other); |
| 65 | |
| 66 | bool operator==(const VibrationSequence& other) const; |
| 67 | |
| 68 | void addElement(VibrationElement element); |
| 69 | |
| 70 | const std::string toString() const; |
| 71 | }; |
| 72 | |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 73 | } // namespace android |
| 74 | |
| 75 | #endif // _VIBRATION_ELEMENT_H |