• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 OHOS_ROSEN_FOLD_SCREEN_SENSOR_MANAGER_H
17 #define OHOS_ROSEN_FOLD_SCREEN_SENSOR_MANAGER_H
18 
19 #ifdef SENSOR_ENABLE
20 #include <functional>
21 #include <mutex>
22 #include <climits>
23 
24 #include "fold_screen_controller.h"
25 #include "fold_screen_controller/sensor_fold_state_manager/sensor_fold_state_manager.h"
26 #include "refbase.h"
27 #include "wm_single_instance.h"
28 #include "sensor_agent.h"
29 #include "sensor_agent_type.h"
30 
31 namespace OHOS {
32 namespace Rosen {
33 
34 class FoldScreenSensorManager : public RefBase {
35     WM_DECLARE_SINGLE_INSTANCE_BASE(FoldScreenSensorManager);
36 
37 public:
38     void RegisterPostureCallback();
39 
40     void RegisterApplicationStateObserver();
41 
42     void RegisterHallCallback();
43 
44     void UnRegisterPostureCallback();
45 
46     void UnRegisterHallCallback();
47 
48     void SetFoldScreenPolicy(sptr<FoldScreenPolicy> foldScreenPolicy);
49 
50     void SetSensorFoldStateManager(sptr<SensorFoldStateManager> sensorFoldStateManager);
51 
52     void HandlePostureData(const SensorEvent * const event);
53 
54     void HandleHallData(const SensorEvent * const event);
55 
56     void TriggerDisplaySwitch();
57 
58     bool GetSensorRegisterStatus(void);
59 
60     typedef struct EXTHALLData {
61         float flag = 0.0F;
62         float hall = 0.0F; // BC axis angle
63         float hallNfc = 0.0F;
64         float hallProtectiveCase = 0.0F;
65         float hallAb = 0.0F;
66     } ExtHallData;
67 
68     typedef struct PostureDataSecondary {
69         float postureAccxc = 0.0F;
70         float postureAccyc = 0.0F;
71         float postureAcczc = 0.0F;
72         float postureAccxb = 0.0F;
73         float postureAccyb = 0.0F;
74         float postureAcczb = 0.0F;
75         float postureBc = 0.0F;
76         float postureScreen = 0.0F;
77         float postureAccxx = 0.0F;
78         float postureAccyx = 0.0F;
79         float postureAcczx = 0.0F;
80         float postureAb = 0.0F;
81         float postureAbAnti = 0.0F;
82     } PostureDataSecondary;
83 
84     float GetGlobalAngle() const;
85     void SetGlobalAngle(float angle);
86     uint16_t GetGlobalHall() const;
87     void SetGlobalHall(uint16_t hall);
88 
89 protected:
90     FoldStatus GetCurrentState();
91 
92 private:
93     sptr<FoldScreenPolicy> foldScreenPolicy_;
94 
95     sptr<SensorFoldStateManager> sensorFoldStateManager_;
96 
97     std::recursive_mutex mutex_;
98 
99     FoldStatus mState_ = FoldStatus::UNKNOWN;
100 
101     SensorUser postureUser {};
102 
103     SensorUser hallUser {};
104 
105     void NotifyFoldAngleChanged(float foldAngle);
106 
107     FoldScreenSensorManager();
108 
109     ~FoldScreenSensorManager() = default;
110 
111     float globalAngle = -1.0F;
112 
113     uint16_t globalHall = USHRT_MAX;
114 
115     bool registerPosture_ = false;
116 
117     bool registerHall_ = false;
118 };
119 } // namespace Rosen
120 } // namespace OHOS
121 #endif
122 #endif