Skip to main content
Version: v3

Vibrator

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Vibrator.

Methods

start

Start vibration. The passed option parameter only takes effect for this vibration. After API_LEVEL 3.6, it supports passing in vibration scene arrays and specifying repeat count, with default repeat = 0 meaning no repea

start(option?: Option | Array<Action>, repeat?: number): void

Option

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
modenumberNVIBRATOR_SCENE_SHORT_MIDDLEVibration mode, Value refer to Vibration motor mode constants2.0

Action

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
typenumberY-Vibration Scene Type3.6
durationnumberN-Duration of vibration3.6

Constants

Vibration motor mode constants
ConstantDescriptionAPI_LEVEL
VIBRATOR_SCENE_SHORT_LIGHTLight vibration intensity and short time (20ms)2.0
VIBRATOR_SCENE_SHORT_MIDDLEMedium vibration intensity, short time (20ms)2.0
VIBRATOR_SCENE_SHORT_STRONGHigh vibration intensity and short time (20ms)2.0
VIBRATOR_SCENE_DURATIONHigh vibration intensity, lasting 600ms2.0
VIBRATOR_SCENE_DURATION_LONGHigh vibration intensity, lasting 1000ms2.0
VIBRATOR_SCENE_STRONG_REMINDERHigh vibration intensity, four vibrations in 1200ms, can be used for stronger reminders2.0
VIBRATOR_SCENE_NOTIFICATIONTwo short, continuous vibrations, consistent with the watch message notification vibration feedback2.0
VIBRATOR_SCENE_CALLHigh vibration intensity, single vibration twice in 500ms, continuous vibration, need to manually stop, consistent with the watch call vibration feedback2.0
VIBRATOR_SCENE_TIMERHigh vibration intensity, single long vibration 500ms, continuous vibration, need to manually stop, consistent with the watch alarm clock, countdown vibration feedback2.0

stop

Stop vibration

stop(): void

setMode

Set the vibration mode, call start() after successful setting, it will vibrate according to the set mode

setMode(option: Option): void

Option

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
modenumberY-Vibration mode, Value refer to Vibration motor mode constants2.0

getConfig

Get Vibration Motor Configuration

getConfig(): Option

Option

PropertyTypeDescriptionAPI_LEVEL
modenumberVibration mode, Value refer to Vibration motor mode constants2.0

getType

Start from API_LEVEL 3.6

Get Vibration Scene Type

getType(): Type

Type

PropertyTypeDescriptionAPI_LEVEL
GENTLE_SHORTnumberVibration scene, light short vibration3.6
STRONG_SHORTnumberVibration scene, strong and short vibration3.6
STANDARD_CROWNnumberVibration scene, standard crown vibration3.6
STRONG_CROWNnumberVibration scene, strong crown vibration3.6
SPULSE_CROWNnumberVibration scene, single-pulse crown vibration3.6
DIPULSE_CROWNnumberVibration scene, dual-pulse crown vibration3.6
KEYCODE_CLICKnumberVibration scene, password button vibration3.6
URGENTnumberVibration scene, urgent vibration3.6
CONTINUOUSnumberVibration scene, continuous vibration3.6
PAUSEnumberVibration scene, stop vibration3.6

Example

import { Vibrator, VIBRATOR_SCENE_DURATION } from '@zos/sensor'

const vibrator = new Vibrator()
vibrator.start()

// Set scene
vibrator.setMode(VIBRATOR_SCENE_DURATION)
vibrator.start()

// Another example using vibration array
import { Vibrator } from '@zos/sensor'

const vibrator = new Vibrator()
const vibrationType = vibrator.getType()
vibrator.start([
{
type: vibrationType.GENTLE_SHORT,
duration: 2000,
},
{
type: vibrationType.URGENT,
duration: 1000,
},
])