• 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 * @permission ohos.permission.ACCELEROMETER
19 * @since 3
20 * @deprecated since 8
21 * @useinstead ohos.sensor/sensor.AccelerometerResponse
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 * @permission ohos.permission.ACCELEROMETER
46 * @since 3
47 * @deprecated since 8
48 * @useinstead ohos.sensor/sensor#event:SensorId.ACCELEROMETER
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 * @since 3
78 * @deprecated since 8
79 * @useinstead ohos.sensor/sensor.MagneticFieldResponse
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 * @since 3
92 * @deprecated since 8
93 * @useinstead ohos.sensor/sensor#event:SensorId.MAGNETIC_FIELD
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 * @since 3
112 * @deprecated since 8
113 * @useinstead ohos.sensor/sensor.ProximityResponse
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 * @since 3
126 * @deprecated since 8
127 * @useinstead ohos.sensor/sensor#event:SensorId.PROXIMITY
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 * @since 3
146 * @deprecated since 8
147 * @useinstead ohos.sensor/sensor.LightResponse
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 * @since 3
160 * @deprecated since 8
161 * @useinstead ohos.sensor/sensor#event:SensorId.AMBIENT_LIGHT
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 * @permission ohos.permission.ACTIVITY_MOTION
180 * @since 3
181 * @deprecated since 8
182 * @useinstead ohos.sensor/sensor.PedometerResponse
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 * @permission ohos.permission.ACTIVITY_MOTION
196 * @since 3
197 * @deprecated since 8
198 * @useinstead ohos.sensor/sensor#event:SensorId.PEDOMETER
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 * @since 3
217 * @deprecated since 8
218 * @useinstead ohos.sensor/sensor.BarometerResponse
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 * @since 3
231 * @deprecated since 8
232 * @useinstead ohos.sensor/sensor#event:SensorId.BAROMETER
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 * @permission ohos.permission.READ_HEALTH_DATA
251 * @since 3
252 * @deprecated since 8
253 * @useinstead ohos.sensor/sensor.HeartRateResponse
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 * @permission ohos.permission.READ_HEALTH_DATA
267 * @since 3
268 * @deprecated since 8
269 * @useinstead ohos.sensor/sensor#event:SensorId.HEART_RATE
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 * @since 3
288 * @deprecated since 8
289 * @useinstead ohos.sensor/sensor.WearDetectionResponse
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 * @since 3
302 * @deprecated since 8
303 * @useinstead ohos.sensor/sensor#event:SensorId.WEAR_DETECTION
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 * @since 3
322 * @deprecated since 8
323 * @useinstead ohos.sensor/sensor#event:SensorId.WEAR_DETECTION
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 * @since 6
348 * @deprecated since 8
349 * @useinstead ohos.sensor/sensor.OrientationResponse
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 * @since 6
374 * @deprecated since 8
375 * @useinstead ohos.sensor/sensor#event:SensorId.ORIENTATION
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 * @permission ohos.permission.GYROSCOPE
405 * @since 6
406 * @deprecated since 8
407 * @useinstead ohos.sensor/sensor#.GyroscopeResponse
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 * @permission ohos.permission.GYROSCOPE
432 * @since 6
433 * @deprecated since 8
434 * @useinstead ohos.sensor/sensor#event:SensorId.GYROSCOPE
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 * @since 6
464 * @deprecated since 8
465 * @useinstead ohos.sensor/sensor
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   * @useinstead ohos.sensor/sensor#event:SensorId.ACCELEROMETER
477   */
478  static subscribeAccelerometer(options: subscribeAccelerometerOptions): void;
479
480  /**
481   * Cancels listening to acceleration sensor data.
482   * @syscap SystemCapability.Sensors.Sensor
483   * @permission ohos.permission.ACCELEROMETER
484   * @since 3
485   * @deprecated since 8
486   * @useinstead ohos.sensor/sensor#event:SensorId.ACCELEROMETER
487   */
488  static unsubscribeAccelerometer(): void;
489
490  /**
491   * Listens to compass sensor data changes.
492   * If this API is called multiple times, the last call takes effect.
493   * @param options Options.
494   * @syscap SystemCapability.Sensors.Sensor
495   * @since 3
496   * @deprecated since 8
497   * @useinstead ohos.sensor/sensor#event:SensorId.MAGNETIC_FIELD
498   */
499  static subscribeCompass(options: SubscribeCompassOptions): void;
500
501  /**
502   * Cancels listening to compass sensor data.
503   * @syscap SystemCapability.Sensors.Sensor
504   * @since 3
505   * @deprecated since 8
506   * @useinstead ohos.sensor/sensor#event:SensorId.MAGNETIC_FIELD
507   */
508  static unsubscribeCompass(): void;
509
510  /**
511   * Listens to distance sensor data changes.
512   * If this API is called multiple times, the last call takes effect.
513   * @param options Options.
514   * @syscap SystemCapability.Sensors.Sensor
515   * @since 3
516   * @deprecated since 8
517   * @useinstead ohos.sensor/sensor#event:SensorId.PROXIMITY
518   */
519  static subscribeProximity(options: SubscribeProximityOptions): void;
520
521  /**
522   * Cancels listening to distance sensor data.
523   * @param options Options.
524   * @syscap SystemCapability.Sensors.Sensor
525   * @since 3
526   * @deprecated since 8
527   * @useinstead ohos.sensor/sensor#event:SensorId.PROXIMITY
528   */
529  static unsubscribeProximity(): void;
530
531  /**
532   * Listens to ambient light sensor data changes.
533   * If this API is called multiple times, the last call takes effect.
534   * @param options Options.
535   * @syscap SystemCapability.Sensors.Sensor
536   * @since 3
537   * @deprecated since 8
538   * @useinstead ohos.sensor/sensor#event:SensorId.AMBIENT_LIGHT
539   */
540  static subscribeLight(options: SubscribeLightOptions): void;
541
542  /**
543   * Cancels listening to ambient light sensor data.
544   * @syscap SystemCapability.Sensors.Sensor
545   * @since 3
546   * @deprecated since 8
547   * @useinstead ohos.sensor/sensor#event:SensorId.AMBIENT_LIGHT
548   */
549  static unsubscribeLight(): void;
550
551  /**
552   * Listens to step counter sensor data changes.
553   * If this API is called multiple times, the last call takes effect.
554   * @param options Options.
555   * @syscap SystemCapability.Sensors.Sensor
556   * @permission ohos.permission.ACTIVITY_MOTION
557   * @since 3
558   * @deprecated since 8
559   * @useinstead ohos.sensor/sensor#event:SensorId.PEDOMETER
560   */
561  static subscribeStepCounter(options: SubscribeStepCounterOptions): void;
562
563  /**
564   * Cancels listening to step counter sensor data.
565   * @syscap SystemCapability.Sensors.Sensor
566   * @permission ohos.permission.ACTIVITY_MOTION
567   * @since 3
568   * @deprecated since 8
569   * @useinstead ohos.sensor/sensor#event:SensorId.PEDOMETER
570   */
571  static unsubscribeStepCounter(): void;
572
573  /**
574   * Listens to barometer sensor data changes.
575   * If this API is called multiple times, the last call takes effect.
576   * @param options Options.
577   * @syscap SystemCapability.Sensors.Sensor
578   * @since 3
579   * @deprecated since 8
580   * @useinstead ohos.sensor/sensor#event:SensorId.BAROMETER
581   */
582  static subscribeBarometer(options: SubscribeBarometerOptions): void;
583
584  /**
585   * Cancels listening to barometer sensor data.
586   * @syscap SystemCapability.Sensors.Sensor
587   * @since 3
588   * @deprecated since 8
589   * @useinstead ohos.sensor/sensor#event:SensorId.BAROMETER
590   */
591  static unsubscribeBarometer(): void;
592
593  /**
594   * Listens to changes of heart rate sensor data.
595   * If this API is called multiple times, the last call takes effect.
596   * @param options Options.
597   * @syscap SystemCapability.Sensors.Sensor
598   * @permission ohos.permission.READ_HEALTH_DATA
599   * @since 3
600   * @deprecated since 8
601   * @useinstead ohos.sensor/sensor#event:SensorId.HEART_RATE
602   */
603  static subscribeHeartRate(options: SubscribeHeartRateOptions): void;
604
605  /**
606   * Cancels listening to heart rate sensor data.
607   * @syscap SystemCapability.Sensors.Sensor
608   * @permission ohos.permission.READ_HEALTH_DATA
609   * @since 3
610   * @deprecated since 8
611   * @useinstead ohos.sensor/sensor#event:SensorId.HEART_RATE
612   */
613  static unsubscribeHeartRate(): void;
614
615  /**
616   * Listens to whether a sensor is worn.
617   * If this API is called multiple times, the last call takes effect.
618   * @param options Options.
619   * @syscap SystemCapability.Sensors.Sensor
620   * @since 3
621   * @deprecated since 8
622   * @useinstead ohos.sensor/sensor#event:SensorId.WEAR_DETECTION
623   */
624  static subscribeOnBodyState(options: SubscribeOnBodyStateOptions): void;
625
626  /**
627   * Cancels listening to whether the sensor is worn.
628   * @syscap SystemCapability.Sensors.Sensor
629   * @since 3
630   * @deprecated since 8
631   * @useinstead ohos.sensor/sensor#event:SensorId.WEAR_DETECTION
632   */
633  static unsubscribeOnBodyState(): void;
634
635  /**
636   * Obtains the sensor wearing state.
637   * @param options Options.
638   * @syscap SystemCapability.Sensors.Sensor
639   * @since 3
640   * @deprecated since 8
641   * @useinstead ohos.sensor/sensor#event:SensorId.WEAR_DETECTION
642   */
643  static getOnBodyState(options: GetOnBodyStateOptions): void;
644
645  /**
646   * Listens to device orientation sensor data changes.
647   * If this API is called multiple times, the last call takes effect.
648   * @param options Options.
649   * @syscap SystemCapability.Sensors.Sensor
650   * @since 6
651   * @deprecated since 8
652   * @useinstead ohos.sensor/sensor#event:SensorId.ORIENTATION
653   */
654  static subscribeDeviceOrientation(options: SubscribeDeviceOrientationOptions): void;
655
656  /**
657   * Cancels listening to device orientation sensor data.
658   * @syscap SystemCapability.Sensors.Sensor
659   * @since 6
660   * @deprecated since 8
661   * @useinstead ohos.sensor/sensor#event:SensorId.ORIENTATION
662   */
663  static unsubscribeDeviceOrientation(): void;
664
665  /**
666   * Listens to gyroscope sensor data changes.
667   * If this API is called multiple times, the last call takes effect.
668   * @param options Options.
669   * @syscap SystemCapability.Sensors.Sensor
670   * @permission ohos.permission.GYROSCOPE
671   * @since 6
672   * @deprecated since 8
673   * @useinstead ohos.sensor/sensor#event:SensorId.GYROSCOPE
674   */
675  static subscribeGyroscope(options: SubscribeGyroscopeOptions): void;
676
677  /**
678   * Cancels listening to gyroscope sensor data.
679   * @syscap SystemCapability.Sensors.Sensor
680   * @permission ohos.permission.GYROSCOPE
681   * @since 6
682   * @deprecated since 8
683   * @useinstead ohos.sensor/sensor#event:SensorId.GYROSCOPE
684   */
685  static unsubscribeGyroscope(): void;
686}
687