blob: 04c2e394c82f78e57b02c318db420fb57561cb4f [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
Prabir Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000018
Chris Ye6393a262020-08-04 19:41:36 -070019#include <array>
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000020#include <chrono>
21#include <cstdint>
22#include <string>
Chris Ye87143712020-11-10 05:05:58 +000023#include <vector>
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000024
25namespace android {
26
Chris Ye6393a262020-08-04 19:41:36 -070027// evdev FF_RUMBLE effect only supports two channels of vibration.
28constexpr size_t CHANNEL_SIZE = 2;
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000029/*
30 * Describes a rumble effect
31 */
32struct VibrationElement {
33 std::chrono::milliseconds duration;
Chris Ye6393a262020-08-04 19:41:36 -070034 // Channel amplitude range 0-255.
Chris Ye87143712020-11-10 05:05:58 +000035 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. Lewiscacd69a2019-08-12 22:07:00 +000046
Chris Ye6393a262020-08-04 19:41:36 -070047 const std::string toString() const;
Chris Ye87143712020-11-10 05:05:58 +000048
49 uint16_t getMagnitude(int32_t vibratorId) const;
50
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000051 bool isOn() const;
52};
53
Chris Ye87143712020-11-10 05:05:58 +000054/*
55 * Describes a sequence of rumble effect
56 */
57struct 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. Lewiscacd69a2019-08-12 22:07:00 +000072} // namespace android