1 /*
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 
17 #pragma once
18 
19 #include "InputMapper.h"
20 
21 namespace android {
22 
23 class VibratorInputMapper : public InputMapper {
24 public:
25     template <class T, class... Args>
26     friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
27                                                 const InputReaderConfiguration& readerConfig,
28                                                 Args... args);
29     virtual ~VibratorInputMapper();
30 
31     virtual uint32_t getSources() const override;
32     virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo) override;
33     [[nodiscard]] std::list<NotifyArgs> process(const RawEvent& rawEvent) override;
34 
35     [[nodiscard]] std::list<NotifyArgs> vibrate(const VibrationSequence& sequence, ssize_t repeat,
36                                                 int32_t token) override;
37     [[nodiscard]] std::list<NotifyArgs> cancelVibrate(int32_t token) override;
38     virtual bool isVibrating() override;
39     virtual std::vector<int32_t> getVibratorIds() override;
40     [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when) override;
41     virtual void dump(std::string& dump) override;
42 
43 private:
44     bool mVibrating;
45     VibrationSequence mSequence;
46     ssize_t mRepeat;
47     int32_t mToken;
48     ssize_t mIndex;
49     nsecs_t mNextStepTime;
50 
51     explicit VibratorInputMapper(InputDeviceContext& deviceContext,
52                                  const InputReaderConfiguration& readerConfig);
53     [[nodiscard]] std::list<NotifyArgs> nextStep();
54     [[nodiscard]] NotifyVibratorStateArgs stopVibrating();
55 };
56 
57 } // namespace android
58