1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CROWN_TRANSFORM_PROCESSOR_H
17 #define CROWN_TRANSFORM_PROCESSOR_H
18 
19 #include <map>
20 #include <memory>
21 
22 #include "libinput.h"
23 #include "singleton.h"
24 
25 #include "pointer_event.h"
26 
27 namespace OHOS {
28 namespace MMI {
29 #ifdef OHOS_BUILD_ENABLE_CROWN
30 class CrownTransformProcessor final : public std::enable_shared_from_this<CrownTransformProcessor> {
31     DECLARE_DELAYED_SINGLETON(CrownTransformProcessor);
32 
33 public:
34     DISALLOW_COPY_AND_MOVE(CrownTransformProcessor);
35     std::shared_ptr<PointerEvent> GetPointerEvent() const;
36     bool IsCrownEvent(struct libinput_event *event);
37     int32_t NormalizeRotateEvent(struct libinput_event *event);
38     void Dump(int32_t fd, const std::vector<std::string> &args);
39 
40 private:
41     int32_t HandleCrownRotateBegin(struct libinput_event_pointer *rawPointerEvent);
42     int32_t HandleCrownRotateUpdate(struct libinput_event_pointer *rawPointerEvent);
43     int32_t HandleCrownRotateEnd();
44     int32_t HandleCrownRotateBeginAndUpdate(struct libinput_event_pointer *rawPointerEvent, int32_t action);
45     void HandleCrownRotatePostInner(double angularVelocity, double degree, int32_t action);
46     void DumpInner();
47 
48     std::shared_ptr<PointerEvent> pointerEvent_ { nullptr };
49     int32_t deviceId_ { -1 };
50     int32_t timerId_ { -1 };
51     uint64_t lastTime_ { 0 };
52 };
53 #define CROWN_EVENT_HDR ::OHOS::DelayedSingleton<CrownTransformProcessor>::GetInstance()
54 #endif // OHOS_BUILD_ENABLE_CROWN
55 } // namespace MMI
56 } // namespace OHOS
57 #endif // CROWN_TRANSFORM_PROCESSOR_H