blob: 518077455235f97ee1553dc6ce59212a970200b7 [file] [log] [blame]
Steven Morelandcb5d1072019-11-10 17:44:56 -08001/*
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;
30
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.
48 Return<void> perform_1_2(V1_2::Effect effect, EffectStrength strength,
49 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 Return<void> perform_1_3(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override;
55
56 private:
57 Return<void> perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb);
58 template <typename T>
59 Return<void> perform(T effect, EffectStrength strength, perform_cb _hidl_cb);
60 Status enable(bool enabled);
61 Status activate(uint32_t ms);
62 void timeout();
63
64 static void timerCallback(union sigval sigval);
65 static const std::string effectToName(Effect effect);
66 static uint32_t effectToMs(Effect effect, Status* status);
67 static uint8_t strengthToAmplitude(EffectStrength strength, Status* status);
68
69 private:
70 bool mEnabled{false};
71 uint8_t mAmplitude{UINT8_MAX};
72 bool mExternalControl{false};
73 std::mutex mMutex;
74 timer_t mTimer{nullptr};
75};
76} // namespace implementation
77} // namespace V1_3
78} // namespace vibrator
79} // namespace hardware
80} // namespace android
81
82#endif // ANDROID_HARDWARE_VIBRATOR_V1_3_VIBRATOR_H