blob: c11806158fb8f4c9d6d96daffc9454057ba74a74 [file] [log] [blame]
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +09001/*
2 * Copyright (C) 2019 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#ifndef ANDROID_HARDWARE_VIBRATOR_V1_3_VIBRATOR_H
17#define ANDROID_HARDWARE_VIBRATOR_V1_3_VIBRATOR_H
18
19#include <android/hardware/vibrator/1.3/IVibrator.h>
20#include <hidl/Status.h>
21
22namespace android {
23namespace hardware {
24namespace vibrator {
25namespace V1_3 {
26namespace implementation {
27
28using android::hardware::vibrator::V1_0::EffectStrength;
29using android::hardware::vibrator::V1_0::Status;
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090030
31class Vibrator : public IVibrator {
32 public:
33 Vibrator();
34
35 // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow.
36 Return<Status> on(uint32_t timeoutMs) override;
37 Return<Status> off() override;
38 Return<bool> supportsAmplitudeControl() override;
39 Return<Status> setAmplitude(uint8_t amplitude) override;
40 Return<void> perform(V1_0::Effect effect, EffectStrength strength,
41 perform_cb _hidl_cb) override;
42
43 // Methods from ::android::hardware::vibrator::V1_1::IVibrator follow.
44 Return<void> perform_1_1(V1_1::Effect_1_1 effect, EffectStrength strength,
45 perform_cb _hidl_cb) override;
46
47 // Methods from ::android::hardware::vibrator::V1_2::IVibrator follow.
Michael Wrighta4c94fd2019-03-21 20:48:34 +000048 Return<void> perform_1_2(V1_2::Effect effect, EffectStrength strength,
49 perform_cb _hidl_cb) override;
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090050
51 // Methods from ::android::hardware::vibrator::V1_3::IVibrator follow.
52 Return<bool> supportsExternalControl() override;
53 Return<Status> setExternalControl(bool enabled) override;
Michael Wrighta4c94fd2019-03-21 20:48:34 +000054 Return<void> perform_1_3(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override;
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090055
56 private:
57 Status enable(bool enabled);
58 Status activate(uint32_t ms);
59 void timeout();
60
61 static void timerCallback(union sigval sigval);
Harpreet "Eli" Sanghaa2443212019-03-25 14:08:59 +090062 static const std::string effectToName(Effect effect);
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090063 static uint32_t effectToMs(Effect effect);
64 static uint8_t strengthToAmplitude(EffectStrength strength);
65
66 private:
67 bool mEnabled{false};
68 uint8_t mAmplitude{UINT8_MAX};
69 bool mExternalControl{false};
70 std::mutex mMutex;
71 timer_t mTimer{nullptr};
72};
73} // namespace implementation
74} // namespace V1_3
75} // namespace vibrator
76} // namespace hardware
77} // namespace android
78
79#endif // ANDROID_HARDWARE_VIBRATOR_V1_3_VIBRATOR_H