Skip to main content
Version: v3

Gyroscope

Start from API_LEVEL 3.0 . Please refer to API_LEVEL.

Gyroscope_image}

Gyroscope. Measuring the angular velocity of the device rotating along three orthogonal axes (x, y, z), the x and y axes are parallel to the screen, the positive direction refers to the figure, the z axis is perpendicular to the device's screen, the positive direction points upward, and the direction of the rotational angular velocity is determined using the Right-hand rule. The direction of the rotation arrow in the figure is the positive direction.

info

permission code: device:os.gyroscope

Methods

start

Start listening to gyroscope data

start(): void

stop

Stop listening to gyroscope data

stop(): void

getCurrent

Get current gyroscope data

getCurrent(): Result

Result

PropertyTypeDescriptionAPI_LEVEL
xnumberAngular velocity of x-axis in DPS, degrees per second3.0
ynumberAngular velocity of y-axis in DPS, degrees per second3.0
znumberAngular velocity of z-axis in DPS, degrees per second3.0

onChange

Register the gyroscope data change event listener callback function

onChange(callback: () => void): void

offChange

Cancel the gyroscope data change event listener callback function

offChange(callback: () => void): void

setFreqMode

Start from API_LEVEL 3.0

Set the mode of trigger frequency, mode value reference frequency mode constant

setFreqMode(mode: number): void

Constants

Frequency Mode
ConstantDescriptionAPI_LEVEL
FREQ_MODE_LOWLow power mode with low trigger frequency3.0
FREQ_MODE_NORMALNormal power consumption mode, medium trigger frequency3.0
FREQ_MODE_HIGHHigh power consumption mode with high trigger frequency3.0

getFreqMode

Start from API_LEVEL 3.0

Get the mode of trigger frequency, result value reference frequency mode constant

getFreqMode(): number

Constants

Frequency Mode
ConstantDescriptionAPI_LEVEL
FREQ_MODE_LOWLow power mode with low trigger frequency3.0
FREQ_MODE_NORMALNormal power consumption mode, medium trigger frequency3.0
FREQ_MODE_HIGHHigh power consumption mode with high trigger frequency3.0

Example

import { Gyroscope, FREQ_MODE_LOW } from '@zos/sensor'

const gyroscope = new Gyroscope()

const callback = () => {
console.log(gyroscope.getCurrent())
}
gyroscope.onChange(callback)
gyroscope.setFreqMode(FREQ_MODE_LOW)
gyroscope.start()

// When not needed for use
gyroscope.offChange()
gyroscope.stop()