blob: a931b63b099e30a93bdfa3799e2a9b316ae71027 [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;
30using android::hardware::vibrator::V1_2::Effect;
31
32class Vibrator : public IVibrator {
33 public:
34 Vibrator();
35
36 // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow.
37 Return<Status> on(uint32_t timeoutMs) override;
38 Return<Status> off() override;
39 Return<bool> supportsAmplitudeControl() override;
40 Return<Status> setAmplitude(uint8_t amplitude) override;
41 Return<void> perform(V1_0::Effect effect, EffectStrength strength,
42 perform_cb _hidl_cb) override;
43
44 // Methods from ::android::hardware::vibrator::V1_1::IVibrator follow.
45 Return<void> perform_1_1(V1_1::Effect_1_1 effect, EffectStrength strength,
46 perform_cb _hidl_cb) override;
47
48 // Methods from ::android::hardware::vibrator::V1_2::IVibrator follow.
49 Return<void> perform_1_2(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override;
50
51 // Methods from ::android::hardware::vibrator::V1_3::IVibrator follow.
52 Return<bool> supportsExternalControl() override;
53 Return<Status> setExternalControl(bool enabled) override;
54
55 private:
56 Status enable(bool enabled);
57 Status activate(uint32_t ms);
58 void timeout();
59
60 static void timerCallback(union sigval sigval);
61 static const char* effectToName(Effect effect);
62 static uint32_t effectToMs(Effect effect);
63 static uint8_t strengthToAmplitude(EffectStrength strength);
64
65 private:
66 bool mEnabled{false};
67 uint8_t mAmplitude{UINT8_MAX};
68 bool mExternalControl{false};
69 std::mutex mMutex;
70 timer_t mTimer{nullptr};
71};
72} // namespace implementation
73} // namespace V1_3
74} // namespace vibrator
75} // namespace hardware
76} // namespace android
77
78#endif // ANDROID_HARDWARE_VIBRATOR_V1_3_VIBRATOR_H