1 /*
2 * Copyright (c) 2022 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 #include "sensor_system_js.h"
16
17 #include "async_callback_info.h"
18 #include "sensor_js.h"
19
20 namespace OHOS {
21 namespace Sensors {
SubscribeAccelerometer(napi_env env,napi_callback_info info)22 napi_value SubscribeAccelerometer(napi_env env, napi_callback_info info)
23 {
24 CALL_LOG_ENTER;
25 return Subscribe(env, info, SENSOR_TYPE_ID_ACCELEROMETER, SUBSCRIBE_CALLBACK);
26 }
27
UnsubscribeAccelerometer(napi_env env,napi_callback_info info)28 napi_value UnsubscribeAccelerometer(napi_env env, napi_callback_info info)
29 {
30 CALL_LOG_ENTER;
31 return Unsubscribe(env, info, SENSOR_TYPE_ID_ACCELEROMETER);
32 }
33
SubscribeCompass(napi_env env,napi_callback_info info)34 napi_value SubscribeCompass(napi_env env, napi_callback_info info)
35 {
36 CALL_LOG_ENTER;
37 return Subscribe(env, info, SENSOR_TYPE_ID_ORIENTATION, SUBSCRIBE_COMPASS);
38 }
39
UnsubscribeCompass(napi_env env,napi_callback_info info)40 napi_value UnsubscribeCompass(napi_env env, napi_callback_info info)
41 {
42 CALL_LOG_ENTER;
43 return Unsubscribe(env, info, SENSOR_TYPE_ID_ORIENTATION);
44 }
45
SubscribeProximity(napi_env env,napi_callback_info info)46 napi_value SubscribeProximity(napi_env env, napi_callback_info info)
47 {
48 CALL_LOG_ENTER;
49 return Subscribe(env, info, SENSOR_TYPE_ID_PROXIMITY, SUBSCRIBE_CALLBACK);
50 }
51
UnsubscribeProximity(napi_env env,napi_callback_info info)52 napi_value UnsubscribeProximity(napi_env env, napi_callback_info info)
53 {
54 CALL_LOG_ENTER;
55 return Unsubscribe(env, info, SENSOR_TYPE_ID_PROXIMITY);
56 }
57
SubscribeLight(napi_env env,napi_callback_info info)58 napi_value SubscribeLight(napi_env env, napi_callback_info info)
59 {
60 CALL_LOG_ENTER;
61 return Subscribe(env, info, SENSOR_TYPE_ID_AMBIENT_LIGHT, SUBSCRIBE_CALLBACK);
62 }
63
UnsubscribeLight(napi_env env,napi_callback_info info)64 napi_value UnsubscribeLight(napi_env env, napi_callback_info info)
65 {
66 CALL_LOG_ENTER;
67 return Unsubscribe(env, info, SENSOR_TYPE_ID_AMBIENT_LIGHT);
68 }
69
SubscribeStepCounter(napi_env env,napi_callback_info info)70 napi_value SubscribeStepCounter(napi_env env, napi_callback_info info)
71 {
72 CALL_LOG_ENTER;
73 return Subscribe(env, info, SENSOR_TYPE_ID_PEDOMETER, SUBSCRIBE_CALLBACK);
74 }
75
UnsubscribeStepCounter(napi_env env,napi_callback_info info)76 napi_value UnsubscribeStepCounter(napi_env env, napi_callback_info info)
77 {
78 CALL_LOG_ENTER;
79 return Unsubscribe(env, info, SENSOR_TYPE_ID_PEDOMETER);
80 }
81
SubscribeBarometer(napi_env env,napi_callback_info info)82 napi_value SubscribeBarometer(napi_env env, napi_callback_info info)
83 {
84 CALL_LOG_ENTER;
85 return Subscribe(env, info, SENSOR_TYPE_ID_BAROMETER, SUBSCRIBE_CALLBACK);
86 }
87
UnsubscribeBarometer(napi_env env,napi_callback_info info)88 napi_value UnsubscribeBarometer(napi_env env, napi_callback_info info)
89 {
90 CALL_LOG_ENTER;
91 return Unsubscribe(env, info, SENSOR_TYPE_ID_BAROMETER);
92 }
93
SubscribeHeartRate(napi_env env,napi_callback_info info)94 napi_value SubscribeHeartRate(napi_env env, napi_callback_info info)
95 {
96 CALL_LOG_ENTER;
97 return Subscribe(env, info, SENSOR_TYPE_ID_HEART_RATE, SUBSCRIBE_CALLBACK);
98 }
99
UnsubscribeHeartRate(napi_env env,napi_callback_info info)100 napi_value UnsubscribeHeartRate(napi_env env, napi_callback_info info)
101 {
102 CALL_LOG_ENTER;
103 return Unsubscribe(env, info, SENSOR_TYPE_ID_HEART_RATE);
104 }
105
SubscribeOnBodyState(napi_env env,napi_callback_info info)106 napi_value SubscribeOnBodyState(napi_env env, napi_callback_info info)
107 {
108 CALL_LOG_ENTER;
109 return Subscribe(env, info, SENSOR_TYPE_ID_WEAR_DETECTION, SUBSCRIBE_CALLBACK);
110 }
111
UnsubscribeOnBodyState(napi_env env,napi_callback_info info)112 napi_value UnsubscribeOnBodyState(napi_env env, napi_callback_info info)
113 {
114 CALL_LOG_ENTER;
115 return Unsubscribe(env, info, SENSOR_TYPE_ID_WEAR_DETECTION);
116 }
117
GetOnBodyState(napi_env env,napi_callback_info info)118 napi_value GetOnBodyState(napi_env env, napi_callback_info info)
119 {
120 CALL_LOG_ENTER;
121 return GetBodyState(env, info);
122 }
123
SubscribeDeviceOrientation(napi_env env,napi_callback_info info)124 napi_value SubscribeDeviceOrientation(napi_env env, napi_callback_info info)
125 {
126 CALL_LOG_ENTER;
127 return Subscribe(env, info, SENSOR_TYPE_ID_ORIENTATION, SUBSCRIBE_CALLBACK);
128 }
129
UnsubscribeDeviceOrientation(napi_env env,napi_callback_info info)130 napi_value UnsubscribeDeviceOrientation(napi_env env, napi_callback_info info)
131 {
132 CALL_LOG_ENTER;
133 return Unsubscribe(env, info, SENSOR_TYPE_ID_ORIENTATION);
134 }
135
SubscribeGyroscope(napi_env env,napi_callback_info info)136 napi_value SubscribeGyroscope(napi_env env, napi_callback_info info)
137 {
138 CALL_LOG_ENTER;
139 return Subscribe(env, info, SENSOR_TYPE_ID_GYROSCOPE, SUBSCRIBE_CALLBACK);
140 }
141
UnsubscribeGyroscope(napi_env env,napi_callback_info info)142 napi_value UnsubscribeGyroscope(napi_env env, napi_callback_info info)
143 {
144 CALL_LOG_ENTER;
145 return Unsubscribe(env, info, SENSOR_TYPE_ID_GYROSCOPE);
146 }
147
SubscribeGravity(napi_env env,napi_callback_info info)148 napi_value SubscribeGravity(napi_env env, napi_callback_info info)
149 {
150 CALL_LOG_ENTER;
151 return Subscribe(env, info, SENSOR_TYPE_ID_GRAVITY, SUBSCRIBE_CALLBACK);
152 }
153
UnsubscribeGravity(napi_env env,napi_callback_info info)154 napi_value UnsubscribeGravity(napi_env env, napi_callback_info info)
155 {
156 CALL_LOG_ENTER;
157 return Unsubscribe(env, info, SENSOR_TYPE_ID_GRAVITY);
158 }
159
SubscribeMagnetic(napi_env env,napi_callback_info info)160 napi_value SubscribeMagnetic(napi_env env, napi_callback_info info)
161 {
162 CALL_LOG_ENTER;
163 return Subscribe(env, info, SENSOR_TYPE_ID_MAGNETIC_FIELD, SUBSCRIBE_CALLBACK);
164 }
165
UnsubscribeMagnetic(napi_env env,napi_callback_info info)166 napi_value UnsubscribeMagnetic(napi_env env, napi_callback_info info)
167 {
168 CALL_LOG_ENTER;
169 return Unsubscribe(env, info, SENSOR_TYPE_ID_MAGNETIC_FIELD);
170 }
171
SubscribeHall(napi_env env,napi_callback_info info)172 napi_value SubscribeHall(napi_env env, napi_callback_info info)
173 {
174 CALL_LOG_ENTER;
175 return Subscribe(env, info, SENSOR_TYPE_ID_HALL, SUBSCRIBE_CALLBACK);
176 }
177
UnsubscribeHall(napi_env env,napi_callback_info info)178 napi_value UnsubscribeHall(napi_env env, napi_callback_info info)
179 {
180 CALL_LOG_ENTER;
181 return Unsubscribe(env, info, SENSOR_TYPE_ID_HALL);
182 }
183 } // namespace Sensors
184 } // namespace OHOS