• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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/**
17 * @syscap SystemCapability.Sensors.Sensor
18 * @import import sensor from '@system.sensor';
19 * @permission ohos.permission.ACCELEROMETER
20 * @since 3
21 * @deprecated since 8
22 */
23export interface AccelerometerResponse {
24  /**
25   * X-coordinate
26   * @since 3
27   */
28  x: number;
29
30  /**
31   * Y-coordinate
32   * @since 3
33   */
34  y: number;
35
36  /**
37   * Z-coordinate
38   * @since 3
39   */
40  z: number;
41}
42
43/**
44 * @syscap SystemCapability.Sensors.Sensor
45 * @import import sensor from '@system.sensor';
46 * @permission ohos.permission.ACCELEROMETER
47 * @since 3
48 * @deprecated since 8
49 */
50export interface subscribeAccelerometerOptions {
51  /**
52   * Execution frequency of the callback function for listening to acceleration sensor data.
53   * Available values are as follows:
54   *   1. game: Extremely high frequency (20 ms per callback), which is applicable to gaming.
55   *   2. ui: High frequency (60 ms per callback), which is applicable to UI updating.
56   *   3. normal: Regular frequency (200 ms per callback), which is application to low power consumption.
57   * The default value is normal.
58   * @since 3
59   */
60  interval: string;
61
62  /**
63   * Called when acceleration sensor data changes.
64   * @since 3
65   */
66  success: (data: AccelerometerResponse) => void;
67
68  /**
69   * Called when the listening fails.
70   * @since 3
71   */
72  fail?: (data: string, code: number) => void;
73}
74
75/**
76 * @syscap SystemCapability.Sensors.Sensor
77 * @import import sensor from '@system.sensor';
78 * @since 3
79 * @deprecated since 8
80 */
81export interface CompassResponse {
82  /**
83   * Direction of the device (in degrees).
84   * @since 3
85   */
86  direction: number;
87}
88
89/**
90 * @syscap SystemCapability.Sensors.Sensor
91 * @import import sensor from '@system.sensor';
92 * @since 3
93 * @deprecated since 8
94 */
95export interface SubscribeCompassOptions {
96  /**
97   * Called when compass sensor data changes.
98   * @since 3
99   */
100  success: (data: CompassResponse) => void;
101
102  /**
103   * Called when the listening fails.
104   * @since 3
105   */
106  fail?: (data: string, code: number) => void;
107}
108
109/**
110 * @syscap SystemCapability.Sensors.Sensor
111 * @import import sensor from '@system.sensor';
112 * @since 3
113 * @deprecated since 8
114 */
115export interface ProximityResponse {
116  /**
117   * Distance between a visible object and the device screen
118   * @since 3
119   */
120  distance: number;
121}
122
123/**
124 * @syscap SystemCapability.Sensors.Sensor
125 * @import import sensor from '@system.sensor';
126 * @since 3
127 * @deprecated since 8
128 */
129export interface SubscribeProximityOptions {
130  /**
131   * Called when distance sensor data changes.
132   * @since 3
133   */
134  success: (data: ProximityResponse) => void;
135
136  /**
137   * Called when the listening fails.
138   * @since 3
139   */
140  fail?: (data: string, code: number) => void;
141}
142
143/**
144 * @syscap SystemCapability.Sensors.Sensor
145 * @import import sensor from '@system.sensor';
146 * @since 3
147 * @deprecated since 8
148 */
149export interface LightResponse {
150  /**
151   * Light intensity, in lux.
152   * @since 3
153   */
154  intensity: number;
155}
156
157/**
158 * @syscap SystemCapability.Sensors.Sensor
159 * @import import sensor from '@system.sensor';
160 * @since 3
161 * @deprecated since 8
162 */
163export interface SubscribeLightOptions {
164  /**
165   * Called when ambient light sensor data changes.
166   * @since 3
167   */
168  success: (data: LightResponse) => void;
169
170  /**
171   * Called when the listening fails.
172   * @since 3
173   */
174  fail?: (data: string, code: number) => void;
175}
176
177/**
178 * @syscap SystemCapability.Sensors.Sensor
179 * @import import sensor from '@system.sensor';
180 * @permission ohos.permission.ACTIVITY_MOTION
181 * @since 3
182 * @deprecated since 8
183 */
184export interface StepCounterResponse {
185  /**
186   * Number of steps counted.
187   * Each time the device restarts, the value is recalculated from 0 in phone, tablet.
188   * @since 3
189   */
190  steps: number;
191}
192
193/**
194 * @syscap SystemCapability.Sensors.Sensor
195 * @import import sensor from '@system.sensor';
196 * @permission ohos.permission.ACTIVITY_MOTION
197 * @since 3
198 * @deprecated since 8
199 */
200export interface SubscribeStepCounterOptions {
201  /**
202   * Called when step counter sensor data changes.
203   * @since 3
204   */
205  success: (data: StepCounterResponse) => void;
206
207  /**
208   * Called when the listening fails.
209   * @since 3
210   */
211  fail?: (data: string, code: number) => void;
212}
213
214/**
215 * @syscap SystemCapability.Sensors.Sensor
216 * @import import sensor from '@system.sensor';
217 * @since 3
218 * @deprecated since 8
219 */
220export interface BarometerResponse {
221  /**
222   * Pressure, in pascal.
223   * @since 3
224   */
225  pressure: number;
226}
227
228/**
229 * @syscap SystemCapability.Sensors.Sensor
230 * @import import sensor from '@system.sensor';
231 * @since 3
232 * @deprecated since 8
233 */
234export interface SubscribeBarometerOptions {
235  /**
236   * Called when the barometer sensor data changes.
237   * @since 3
238   */
239  success: (data: BarometerResponse) => void;
240
241  /**
242   * Called when the listening fails.
243   * @since 3
244   */
245  fail?: (data: string, code: number) => void;
246}
247
248/**
249 * @syscap SystemCapability.Sensors.Sensor
250 * @import import sensor from '@system.sensor';
251 * @permission ohos.permission.READ_HEALTH_DATA
252 * @since 3
253 * @deprecated since 8
254 */
255export interface HeartRateResponse {
256  /**
257   * Heart rate.
258   * 255 indicates an invalid value in lite wearable.
259   * @since 3
260   */
261  heartRate: number;
262}
263
264/**
265 * @syscap SystemCapability.Sensors.Sensor
266 * @import import sensor from '@system.sensor';
267 * @permission ohos.permission.READ_HEALTH_DATA
268 * @since 3
269 * @deprecated since 8
270 */
271export interface SubscribeHeartRateOptions {
272  /**
273   * Called when the heart rate sensor data changes.
274   * @since 3
275   */
276  success: (data: HeartRateResponse) => void;
277
278  /**
279   * Called when the listening fails
280   * @since 3
281   */
282  fail?: (data: string, code: number) => void;
283}
284
285/**
286 * @syscap SystemCapability.Sensors.Sensor
287 * @import import sensor from '@system.sensor';
288 * @since 3
289 * @deprecated since 8
290 */
291export interface OnBodyStateResponse {
292  /**
293   * Whether the sensor is worn.
294   * @since 3
295   */
296  value: boolean;
297}
298
299/**
300 * @syscap SystemCapability.Sensors.Sensor
301 * @import import sensor from '@system.sensor';
302 * @since 3
303 * @deprecated since 8
304 */
305export interface SubscribeOnBodyStateOptions {
306  /**
307   * Called when the wearing status changes.
308   * @since 3
309   */
310  success: (data: OnBodyStateResponse) => void;
311
312  /**
313   * Called when the listening fails.
314   * @since 3
315   */
316  fail?: (data: string, code: number) => void;
317}
318
319/**
320 * @syscap SystemCapability.Sensors.Sensor
321 * @import import sensor from '@system.sensor';
322 * @since 3
323 * @deprecated since 8
324 */
325export interface GetOnBodyStateOptions {
326  /**
327   * Called when the sensor wearing state is obtained
328   * @since 3
329   */
330  success: (data: OnBodyStateResponse) => void;
331
332  /**
333   * Called when the sensor wearing state fails to be obtained
334   * @since 3
335   */
336  fail?: (data: string, code: number) => void;
337
338  /**
339   * Called when the execution is completed
340   * @since 3
341   */
342  complete?: () => void;
343}
344
345/**
346 * @syscap SystemCapability.Sensors.Sensor
347 * @import import sensor from '@system.sensor';
348 * @since 6
349 * @deprecated since 8
350 */
351export interface DeviceOrientationResponse {
352  /**
353   * alpha
354   * @since 6
355   */
356  alpha: number;
357
358  /**
359   * beta
360   * @since 6
361   */
362  beta: number;
363
364  /**
365   * gamma
366   * @since 6
367   */
368  gamma: number;
369}
370
371/**
372 * @syscap SystemCapability.Sensors.Sensor
373 * @import import sensor from '@system.sensor';
374 * @since 6
375 * @deprecated since 8
376 */
377export interface SubscribeDeviceOrientationOptions {
378  /**
379   * Execution frequency of the callback function for listening to device orientation sensor data.
380   * Available values are as follows:
381   *   1. game: Extremely high frequency (20 ms per callback), which is applicable to gaming.
382   *   2. ui: High frequency (60 ms per callback), which is applicable to UI updating.
383   *   3. normal: Regular frequency (200 ms per callback), which is application to low power consumption.
384   * The default value is normal.
385   * @since 6
386   */
387  interval: string;
388
389  /**
390   * Called when device orientation sensor data changes.
391   * @since 6
392   */
393  success: (data: DeviceOrientationResponse) => void;
394
395  /**
396   * Called when the listening fails.
397   * @since 6
398   */
399  fail?: (data: string, code: number) => void;
400}
401
402/**
403 * @syscap SystemCapability.Sensors.Sensor
404 * @import import sensor from '@system.sensor';
405 * @permission ohos.permission.GYROSCOPE
406 * @since 6
407 * @deprecated since 8
408 */
409export interface GyroscopeResponse {
410  /**
411   * X-coordinate
412   * @since 6
413   */
414  x: number;
415
416  /**
417   * Y-coordinate
418   * @since 6
419   */
420  y: number;
421
422  /**
423   * Z-coordinate
424   * @since 6
425   */
426  z: number;
427}
428
429/**
430 * @syscap SystemCapability.Sensors.Sensor
431 * @import import sensor from '@system.sensor';
432 * @permission ohos.permission.GYROSCOPE
433 * @since 6
434 * @deprecated since 8
435 */
436export interface SubscribeGyroscopeOptions {
437  /**
438   * Execution frequency of the callback function for listening to gyroscope sensor data.
439   * Available values are as follows:
440   *   1. game: Extremely high frequency (20 ms per callback), which is applicable to gaming.
441   *   2. ui: High frequency (60 ms per callback), which is applicable to UI updating.
442   *   3. normal: Regular frequency (200 ms per callback), which is application to low power consumption.
443   * The default value is normal.
444   * @since 6
445   */
446  interval: string;
447
448  /**
449   * Called when gyroscope sensor data changes.
450   * @since 6
451   */
452  success: (data: GyroscopeResponse) => void;
453
454  /**
455   * Called when the listening fails.
456   * @since 6
457   */
458  fail?: (data: string, code: number) => void;
459}
460
461/**
462 * @syscap SystemCapability.Sensors.Sensor
463 * @import import sensor from '@system.sensor';
464 * @since 6
465 * @deprecated since 8
466 */
467export default class Sensor {
468  /**
469   * Listens to acceleration sensor data changes.
470   * If this API is called multiple times, the last call takes effect.
471   * @param options Options.
472   * @syscap SystemCapability.Sensors.Sensor
473   * @permission ohos.permission.ACCELEROMETER
474   * @since 3
475   * @deprecated since 8
476   */
477  static subscribeAccelerometer(options: subscribeAccelerometerOptions): void;
478
479  /**
480   * Cancels listening to acceleration sensor data.
481   * @syscap SystemCapability.Sensors.Sensor
482   * @permission ohos.permission.ACCELEROMETER
483   * @since 3
484   * @deprecated since 8
485   */
486  static unsubscribeAccelerometer(): void;
487
488  /**
489   * Listens to compass sensor data changes.
490   * If this API is called multiple times, the last call takes effect.
491   * @param options Options.
492   * @syscap SystemCapability.Sensors.Sensor
493   * @since 3
494   * @deprecated since 8
495   */
496  static subscribeCompass(options: SubscribeCompassOptions): void;
497
498  /**
499   * Cancels listening to compass sensor data.
500   * @syscap SystemCapability.Sensors.Sensor
501   * @since 3
502   * @deprecated since 8
503   */
504  static unsubscribeCompass(): void;
505
506  /**
507   * Listens to distance sensor data changes.
508   * If this API is called multiple times, the last call takes effect.
509   * @param options Options.
510   * @syscap SystemCapability.Sensors.Sensor
511   * @since 3
512   * @deprecated since 8
513   */
514  static subscribeProximity(options: SubscribeProximityOptions): void;
515
516  /**
517   * Cancels listening to distance sensor data.
518   * @param options Options.
519   * @syscap SystemCapability.Sensors.Sensor
520   * @since 3
521   * @deprecated since 8
522   */
523  static unsubscribeProximity(): void;
524
525  /**
526   * Listens to ambient light sensor data changes.
527   * If this API is called multiple times, the last call takes effect.
528   * @param options Options.
529   * @syscap SystemCapability.Sensors.Sensor
530   * @since 3
531   * @deprecated since 8
532   */
533  static subscribeLight(options: SubscribeLightOptions): void;
534
535  /**
536   * Cancels listening to ambient light sensor data.
537   * @syscap SystemCapability.Sensors.Sensor
538   * @since 3
539   * @deprecated since 8
540   */
541  static unsubscribeLight(): void;
542
543  /**
544   * Listens to step counter sensor data changes.
545   * If this API is called multiple times, the last call takes effect.
546   * @param options Options.
547   * @syscap SystemCapability.Sensors.Sensor
548   * @permission ohos.permission.ACTIVITY_MOTION
549   * @since 3
550   * @deprecated since 8
551   */
552  static subscribeStepCounter(options: SubscribeStepCounterOptions): void;
553
554  /**
555   * Cancels listening to step counter sensor data.
556   * @syscap SystemCapability.Sensors.Sensor
557   * @permission ohos.permission.ACTIVITY_MOTION
558   * @since 3
559   * @deprecated since 8
560   */
561  static unsubscribeStepCounter(): void;
562
563  /**
564   * Listens to barometer sensor data changes.
565   * If this API is called multiple times, the last call takes effect.
566   * @param options Options.
567   * @syscap SystemCapability.Sensors.Sensor
568   * @since 3
569   * @deprecated since 8
570   */
571  static subscribeBarometer(options: SubscribeBarometerOptions): void;
572
573  /**
574   * Cancels listening to barometer sensor data.
575   * @syscap SystemCapability.Sensors.Sensor
576   * @since 3
577   * @deprecated since 8
578   */
579  static unsubscribeBarometer(): void;
580
581  /**
582   * Listens to changes of heart rate sensor data.
583   * If this API is called multiple times, the last call takes effect.
584   * @param options Options.
585   * @syscap SystemCapability.Sensors.Sensor
586   * @permission ohos.permission.READ_HEALTH_DATA
587   * @since 3
588   * @deprecated since 8
589   */
590  static subscribeHeartRate(options: SubscribeHeartRateOptions): void;
591
592  /**
593   * Cancels listening to heart rate sensor data.
594   * @syscap SystemCapability.Sensors.Sensor
595   * @permission ohos.permission.READ_HEALTH_DATA
596   * @since 3
597   * @deprecated since 8
598   */
599  static unsubscribeHeartRate(): void;
600
601  /**
602   * Listens to whether a sensor is worn.
603   * If this API is called multiple times, the last call takes effect.
604   * @param options Options.
605   * @syscap SystemCapability.Sensors.Sensor
606   * @since 3
607   * @deprecated since 8
608   */
609  static subscribeOnBodyState(options: SubscribeOnBodyStateOptions): void;
610
611  /**
612   * Cancels listening to whether the sensor is worn.
613   * @syscap SystemCapability.Sensors.Sensor
614   * @since 3
615   * @deprecated since 8
616   */
617  static unsubscribeOnBodyState(): void;
618
619  /**
620   * Obtains the sensor wearing state.
621   * @param options Options.
622   * @syscap SystemCapability.Sensors.Sensor
623   * @since 3
624   * @deprecated since 8
625   */
626  static getOnBodyState(options: GetOnBodyStateOptions): void;
627
628  /**
629   * Listens to device orientation sensor data changes.
630   * If this API is called multiple times, the last call takes effect.
631   * @param options Options.
632   * @syscap SystemCapability.Sensors.Sensor
633   * @since 6
634   * @deprecated since 8
635   */
636  static subscribeDeviceOrientation(options: SubscribeDeviceOrientationOptions): void;
637
638  /**
639   * Cancels listening to device orientation sensor data.
640   * @syscap SystemCapability.Sensors.Sensor
641   * @since 6
642   * @deprecated since 8
643   */
644  static unsubscribeDeviceOrientation(): void;
645
646  /**
647   * Listens to gyroscope sensor data changes.
648   * If this API is called multiple times, the last call takes effect.
649   * @param options Options.
650   * @syscap SystemCapability.Sensors.Sensor
651   * @permission ohos.permission.GYROSCOPE
652   * @since 6
653   * @deprecated since 8
654   */
655  static subscribeGyroscope(options: SubscribeGyroscopeOptions): void;
656
657  /**
658   * Cancels listening to gyroscope sensor data.
659   * @syscap SystemCapability.Sensors.Sensor
660   * @permission ohos.permission.GYROSCOPE
661   * @since 6
662   * @deprecated since 8
663   */
664  static unsubscribeGyroscope(): void;
665}
666