blob: 736041e7fd35cdd3ddbefcb3c8013b4d4fac93d7 [file] [log] [blame]
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +00001/*
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 Ye6393a262020-08-04 19:41:36 -070020#include <array>
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000021#include <chrono>
22#include <cstdint>
23#include <string>
Chris Ye87143712020-11-10 05:05:58 +000024#include <vector>
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000025
26namespace android {
27
Chris Ye6393a262020-08-04 19:41:36 -070028// evdev FF_RUMBLE effect only supports two channels of vibration.
29constexpr size_t CHANNEL_SIZE = 2;
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000030/*
31 * Describes a rumble effect
32 */
33struct VibrationElement {
34 std::chrono::milliseconds duration;
Chris Ye6393a262020-08-04 19:41:36 -070035 // Channel amplitude range 0-255.
Chris Ye87143712020-11-10 05:05:58 +000036 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. Lewiscacd69a2019-08-12 22:07:00 +000047
Chris Ye6393a262020-08-04 19:41:36 -070048 const std::string toString() const;
Chris Ye87143712020-11-10 05:05:58 +000049
50 uint16_t getMagnitude(int32_t vibratorId) const;
51
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000052 bool isOn() const;
53};
54
Chris Ye87143712020-11-10 05:05:58 +000055/*
56 * Describes a sequence of rumble effect
57 */
58struct 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. Lewiscacd69a2019-08-12 22:07:00 +000073} // namespace android
74
75#endif // _VIBRATION_ELEMENT_H