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