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 <ui/Rotation.h>
20 
21 #include "CursorScrollAccumulator.h"
22 #include "InputMapper.h"
23 #include "SlopController.h"
24 
25 namespace android {
26 
27 class RotaryEncoderInputMapper : public InputMapper {
28 public:
29     template <class T, class... Args>
30     friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
31                                                 const InputReaderConfiguration& readerConfig,
32                                                 Args... args);
33     virtual ~RotaryEncoderInputMapper();
34 
35     virtual uint32_t getSources() const override;
36     virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo) override;
37     virtual void dump(std::string& dump) override;
38     [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when,
39                                                     const InputReaderConfiguration& config,
40                                                     ConfigurationChanges changes) override;
41     [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override;
42     [[nodiscard]] std::list<NotifyArgs> process(const RawEvent& rawEvent) override;
43 
44 private:
45     CursorScrollAccumulator mRotaryEncoderScrollAccumulator;
46 
47     int32_t mSource;
48     float mScalingFactor;
49     ui::Rotation mOrientation;
50     std::unique_ptr<SlopController> mSlopController;
51 
52     explicit RotaryEncoderInputMapper(InputDeviceContext& deviceContext,
53                                       const InputReaderConfiguration& readerConfig);
54     [[nodiscard]] std::list<NotifyArgs> sync(nsecs_t when, nsecs_t readTime);
55 };
56 
57 } // namespace android
58