Skip to main content
Version: v2

Vibrator

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Vibrator.

Methods

start

Start vibration, if the option parameter is passed, it will only work for this vibration

start(option?: Option): void

Option

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

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

Example

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

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

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