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> |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | |
Chris Ye | 6393a26 | 2020-08-04 19:41:36 -0700 | [diff] [blame] | 27 | // evdev FF_RUMBLE effect only supports two channels of vibration. |
| 28 | constexpr size_t CHANNEL_SIZE = 2; |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 29 | /* |
| 30 | * Describes a rumble effect |
| 31 | */ |
| 32 | struct VibrationElement { |
| 33 | std::chrono::milliseconds duration; |
Chris Ye | 6393a26 | 2020-08-04 19:41:36 -0700 | [diff] [blame] | 34 | // Channel amplitude range 0-255. |
| 35 | std::array<uint8_t, CHANNEL_SIZE> channels = {0, 0}; |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 36 | |
Chris Ye | 6393a26 | 2020-08-04 19:41:36 -0700 | [diff] [blame] | 37 | const std::string toString() const; |
| 38 | uint16_t getMagnitude(size_t channelIndex) const; |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 39 | bool isOn() const; |
| 40 | }; |
| 41 | |
| 42 | } // namespace android |
| 43 | |
| 44 | #endif // _VIBRATION_ELEMENT_H |