Buzzer
Start from API_LEVEL
3.6
. Please refer to API_LEVEL.
Buzzer.
Methods
isEnabled
Get whether other options in the system buzzer scene settings are turned on, Settings - > Sound & Vibration - > Buzzer Scene - > Other
isEnabled(): boolean
getSourceType
Get buzzer mode
getSourceType(): Type
Type
Value | Type | Description | API_LEVEL |
---|---|---|---|
ALARM | number | Alarm clock | 3.6 |
REMIND_1 | number | Reminder 1 | 3.6 |
REMIND_2 | number | Reminder 2 | 3.6 |
OPERATE | number | Operation | 3.6 |
SUCCESS | number | Success | 3.6 |
FAILURE | number | Failure | 3.6 |
getStrength
Get buzzer strength, '0' - weak, '1' - medium, '2' - high
getStrength(): number
start
Start beeping, you can pass in type
to specify the built-in beeping mode of the system,repeatCount
is the number of repetitions, default 0
, do not repeat
start(type: number, repeatCount: 0): void
stop
Stop buzzer
stop(): void
Example
import { createWidget, widget, prop, align, text_style } from '@zos/ui'
import { Buzzer } from '@zos/sensor'
import { px } from '@zos/utils'
const sceneList = ['ALARM', 'REMIND_1', 'REMIND_2', 'OPERATE', 'SUCCESS', 'FAILURE']
Page({
state: {
pageName: 'BUZZER',
currentIndex: 0,
},
build() {
const buzzer = new Buzzer()
const sceneText = createWidget(widget.TEXT, {
x: px(0),
y: px(120),
w: px(480),
h: px(46),
color: 0xffffff,
text_size: px(20),
align_h: align.CENTER_H,
align_v: align.CENTER_V,
text_style: text_style.NONE,
text: `${sceneList[this.state.currentIndex]}`,
})
const startBuzzer = () => {
const alarmType = buzzer.getSourceType()[sceneList[this.state.currentIndex]]
if (buzzer.isEnabled()) {
buzzer.start(alarmType)
}
this.state.currentIndex = (this.state.currentIndex + 1) % sceneList.length
sceneText.setProperty(prop.MORE, {
text: `BUZZER: ${sceneList[this.state.currentIndex]}`,
})
}
createWidget(widget.BUTTON, {
x: px(80),
y: px(300),
w: px(300),
h: px(60),
radius: px(12),
normal_color: 0xfc6950,
press_color: 0xfeb4a8,
text: 'START BUZZER',
click_func: startBuzzer,
})
},
})