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 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 18 | |
Chris Ye | 6393a26 | 2020-08-04 19:41:36 -0700 | [diff] [blame] | 19 | #include <array> |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 20 | #include <chrono> |
| 21 | #include <cstdint> |
| 22 | #include <string> |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 23 | #include <vector> |
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. |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 35 | std::vector<std::pair<int32_t /*vibratorId*/, uint8_t /*amplitude*/>> channels; |
| 36 | |
| 37 | explicit VibrationElement(size_t channelNum); |
| 38 | |
| 39 | VibrationElement(const VibrationElement& other); |
| 40 | |
| 41 | bool operator==(const VibrationElement& other) const; |
| 42 | |
| 43 | bool operator!=(const VibrationElement& other) const; |
| 44 | |
| 45 | void addChannel(int32_t vibratorId, uint8_t amplitude); |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 46 | |
Chris Ye | 6393a26 | 2020-08-04 19:41:36 -0700 | [diff] [blame] | 47 | const std::string toString() const; |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 48 | |
| 49 | uint16_t getMagnitude(int32_t vibratorId) const; |
| 50 | |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 51 | bool isOn() const; |
| 52 | }; |
| 53 | |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 54 | /* |
| 55 | * Describes a sequence of rumble effect |
| 56 | */ |
| 57 | struct VibrationSequence { |
| 58 | // Pattern of vibration elements |
| 59 | std::vector<VibrationElement> pattern; |
| 60 | |
| 61 | explicit VibrationSequence(size_t length); |
| 62 | |
| 63 | void operator=(const VibrationSequence& other); |
| 64 | |
| 65 | bool operator==(const VibrationSequence& other) const; |
| 66 | |
| 67 | void addElement(VibrationElement element); |
| 68 | |
| 69 | const std::string toString() const; |
| 70 | }; |
| 71 | |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 72 | } // namespace android |