• 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     typedef struct EXTHALLData {
59         float flag = 0.0F;
60         float hall = 0.0F; // BC axis angle
61         float hallNfc = 0.0F;
62         float hallProtectiveCase = 0.0F;
63         float hallAb = 0.0F;
64     } ExtHallData;
65 
66     typedef struct PostureDataSecondary {
67         float postureAccxc = 0.0F;
68         float postureAccyc = 0.0F;
69         float postureAcczc = 0.0F;
70         float postureAccxb = 0.0F;
71         float postureAccyb = 0.0F;
72         float postureAcczb = 0.0F;
73         float postureBc = 0.0F;
74         float postureScreen = 0.0F;
75         float postureAccxx = 0.0F;
76         float postureAccyx = 0.0F;
77         float postureAcczx = 0.0F;
78         float postureAb = 0.0F;
79         float postureAbAnti = 0.0F;
80     } PostureDataSecondary;
81 
82 protected:
83     FoldStatus GetCurrentState();
84 
85 private:
86     sptr<FoldScreenPolicy> foldScreenPolicy_;
87 
88     sptr<SensorFoldStateManager> sensorFoldStateManager_;
89 
90     std::recursive_mutex mutex_;
91 
92     FoldStatus mState_ = FoldStatus::UNKNOWN;
93 
94     SensorUser postureUser {};
95 
96     SensorUser hallUser {};
97 
98     void NotifyFoldAngleChanged(float foldAngle);
99 
100     FoldScreenSensorManager();
101 
102     ~FoldScreenSensorManager() = default;
103 
104     float globalAngle = -1.0F;
105 
106     uint16_t globalHall = USHRT_MAX;
107 
108     bool registerPosture_ = false;
109 };
110 } // namespace Rosen
111 } // namespace OHOS
112 #endif
113 #endif