blob: ff634315ec816a8419fb7fa23df2557a9b8e1a39 [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 */
Harpreet \"Eli\" Sangha714220e2019-09-27 19:01:25 +090016#ifndef ANDROID_HARDWARE_VIBRATOR_V1_x_VIBRATOR_H
17#define ANDROID_HARDWARE_VIBRATOR_V1_x_VIBRATOR_H
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090018
Harpreet \"Eli\" Sangha714220e2019-09-27 19:01:25 +090019#include <android/hardware/vibrator/1.4/IVibrator.h>
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090020#include <hidl/Status.h>
21
22namespace android {
23namespace hardware {
24namespace vibrator {
Harpreet \"Eli\" Sangha714220e2019-09-27 19:01:25 +090025namespace V1_4 {
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090026namespace implementation {
27
28using android::hardware::vibrator::V1_0::EffectStrength;
29using android::hardware::vibrator::V1_0::Status;
Harpreet \"Eli\" Sangha714220e2019-09-27 19:01:25 +090030using android::hardware::vibrator::V1_3::Effect;
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090031
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.
Michael Wrighta4c94fd2019-03-21 20:48:34 +000049 Return<void> perform_1_2(V1_2::Effect effect, EffectStrength strength,
50 perform_cb _hidl_cb) override;
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090051
52 // Methods from ::android::hardware::vibrator::V1_3::IVibrator follow.
53 Return<bool> supportsExternalControl() override;
54 Return<Status> setExternalControl(bool enabled) override;
Harpreet \"Eli\" Sangha714220e2019-09-27 19:01:25 +090055 Return<void> perform_1_3(V1_3::Effect effect, EffectStrength strength,
56 perform_cb _hidl_cb) override;
57
58 // Methods from ::android::hardware::vibrator::V1_4::IVibrator follow.
59 Return<hidl_bitfield<Capabilities>> getCapabilities() override;
60 Return<Status> on_1_4(uint32_t timeoutMs, const sp<IVibratorCallback>& callback) override;
61 Return<void> perform_1_4(V1_3::Effect effect, EffectStrength strength,
62 const sp<IVibratorCallback>& callback, perform_cb _hidl_cb) override;
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090063
64 private:
Harpreet "Eli" Sangha15d52022019-04-10 16:38:12 +090065 Return<void> perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb);
66 template <typename T>
67 Return<void> perform(T effect, EffectStrength strength, perform_cb _hidl_cb);
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090068 Status enable(bool enabled);
69 Status activate(uint32_t ms);
70 void timeout();
71
72 static void timerCallback(union sigval sigval);
Harpreet "Eli" Sanghaa2443212019-03-25 14:08:59 +090073 static const std::string effectToName(Effect effect);
Harpreet "Eli" Sangha79755bc2019-03-25 16:42:28 +090074 static uint32_t effectToMs(Effect effect, Status* status);
75 static uint8_t strengthToAmplitude(EffectStrength strength, Status* status);
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090076
77 private:
78 bool mEnabled{false};
79 uint8_t mAmplitude{UINT8_MAX};
80 bool mExternalControl{false};
81 std::mutex mMutex;
82 timer_t mTimer{nullptr};
Harpreet \"Eli\" Sangha714220e2019-09-27 19:01:25 +090083 sp<IVibratorCallback> mCallback{nullptr};
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090084};
85} // namespace implementation
Harpreet \"Eli\" Sangha714220e2019-09-27 19:01:25 +090086} // namespace V1_4
Harpreet "Eli" Sanghae8631242019-01-31 15:43:36 +090087} // namespace vibrator
88} // namespace hardware
89} // namespace android
90
Harpreet \"Eli\" Sangha714220e2019-09-27 19:01:25 +090091#endif // ANDROID_HARDWARE_VIBRATOR_V1_x_VIBRATOR_H