Vibrator
Start from API_LEVEL
2.0
. Please refer to API_LEVEL.
Vibrator.
Methods
start
Start vibration, the'option 'parameter passed in only takes effect for this vibration, and supports passing in vibration scene arrays after API_LEVEL 3.6
start(option?: Option | Array<Action>): void
Option
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
mode | number | N | VIBRATOR_SCENE_SHORT_MIDDLE | Vibration mode, Value refer to Vibration motor mode constants | 2.0 |
Action
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
type | number | Y | - | Vibration Scene Type | 3.6 |
duration | number | N | - | Duration of vibration | 3.6 |
Constants
Vibration motor mode constants
Constant | Description | API_LEVEL |
---|---|---|
VIBRATOR_SCENE_SHORT_LIGHT | Light vibration intensity and short time (20ms) | 2.0 |
VIBRATOR_SCENE_SHORT_MIDDLE | Medium vibration intensity, short time (20ms) | 2.0 |
VIBRATOR_SCENE_SHORT_STRONG | High vibration intensity and short time (20ms) | 2.0 |
VIBRATOR_SCENE_DURATION | High vibration intensity, lasting 600ms | 2.0 |
VIBRATOR_SCENE_DURATION_LONG | High vibration intensity, lasting 1000ms | 2.0 |
VIBRATOR_SCENE_STRONG_REMINDER | High vibration intensity, four vibrations in 1200ms, can be used for stronger reminders | 2.0 |
VIBRATOR_SCENE_NOTIFICATION | Two short, continuous vibrations, consistent with the watch message notification vibration feedback | 2.0 |
VIBRATOR_SCENE_CALL | High vibration intensity, single vibration twice in 500ms, continuous vibration, need to manually stop , consistent with the watch call vibration feedback | 2.0 |
VIBRATOR_SCENE_TIMER | High vibration intensity, single long vibration 500ms, continuous vibration, need to manually stop , consistent with the watch alarm clock, countdown vibration feedback | 2.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
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
mode | number | Y | - | Vibration mode, Value refer to Vibration motor mode constants | 2.0 |
getConfig
Get Vibration Motor Configuration
getConfig(): Option
Option
Property | Type | Description | API_LEVEL |
---|---|---|---|
mode | number | Vibration mode, Value refer to Vibration motor mode constants | 2.0 |
getType
Start from API_LEVEL
3.6
Get Vibration Scene Type
getType(): Type
Type
Property | Type | Description | API_LEVEL |
---|---|---|---|
GENTLE_SHORT | number | Vibration scene, light short vibration | 3.6 |
STRONG_SHORT | number | Vibration scene, strong and short vibration | 3.6 |
STANDARD_CROWN | number | Vibration scene, standard crown vibration | 3.6 |
STRONG_CROWN | number | Vibration scene, strong crown vibration | 3.6 |
SPULSE_CROWN | number | Vibration scene, single-pulse crown vibration | 3.6 |
DIPULSE_CROWN | number | Vibration scene, dual-pulse crown vibration | 3.6 |
KEYCODE_CLICK | number | Vibration scene, password button vibration | 3.6 |
URGENT | number | Vibration scene, urgent vibration | 3.6 |
CONTINUOUS | number | Vibration scene, continuous vibration | 3.6 |
PAUSE | number | Vibration scene, stop vibration | 3.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()