blob: b60fface44935073c7448dbec81ab2ff7d97a66a [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>
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.
35 std::array<uint8_t, CHANNEL_SIZE> channels = {0, 0};
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000036
Chris Ye6393a262020-08-04 19:41:36 -070037 const std::string toString() const;
38 uint16_t getMagnitude(size_t channelIndex) const;
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000039 bool isOn() const;
40};
41
42} // namespace android
43
44#endif // _VIBRATION_ELEMENT_H