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 #pragma once 18 19 #include <array> 20 #include <chrono> 21 #include <cstdint> 22 #include <string> 23 #include <vector> 24 25 namespace android { 26 27 // evdev FF_RUMBLE effect only supports two channels of vibration. 28 constexpr size_t CHANNEL_SIZE = 2; 29 /* 30 * Describes a rumble effect 31 */ 32 struct VibrationElement { 33 std::chrono::milliseconds duration; 34 // Channel amplitude range 0-255. 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); 46 47 const std::string toString() const; 48 49 uint16_t getMagnitude(int32_t vibratorId) const; 50 51 bool isOn() const; 52 }; 53 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 72 } // namespace android 73