### SystemSounds Example Usage
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/SystemSounds.mdx
Demonstrates how to instantiate SystemSounds, get an alarm sound type, check if sounds are enabled, and start playback.
```javascript
import { SystemSounds } from '@zos/sensor'
const systemSounds = new SystemSounds()
const alarmType = systemSounds.getSourceType().ALARM
if (systemSounds.getEnabled()) {
systemSounds.start(alarmType)
}
```
--------------------------------
### Setup Simulator Environment (Linux)
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/guides/tools/simulator/setup.md
Execute the simulator setup script for Linux environments. This command should be run from the firmware directory within the simulator's installation path.
```bash
cd /opt/simulator/resources/firmware/ && sudo ./setup_for_linux.sh
```
--------------------------------
### Basic Vibrator Usage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
Demonstrates how to initialize the Vibrator, start it, and then set a specific vibration scene before starting again.
```javascript
const vibrator = new Vibrator()
vibrator.start()
// set scene
vibrator.setMode(VIBRATOR_SCENE_DURATION)
vibrator.start()
```
--------------------------------
### Launch Simulator (Linux)
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/guides/tools/simulator/setup.md
Start the simulator on Linux by executing the simulator binary from its installation directory.
```bash
cd /opt/simulator/ && ./simulator
```
--------------------------------
### Recorder Setup and Control Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/media.mdx
Shows how to initialize the recorder, set the audio format and target file, and start/stop recording.
```javascript
// Recorder
import { create, id, codec } from '@zos/media'
const recorder = create(id.RECORDER)
recorder.setFormat(codec.OPUS, {
target_file: 'data://record_file.opus'
})
// start
recorder.start()
// stop
recorder.stop()
```
--------------------------------
### Screen Sensor Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms-full.txt
Provides an example of how to get the screen status and set up listeners for screen display changes.
```javascript
const screen = new Screen()
const status = screen.getStatus()
const callback = () => {
console.log(screen.getStatus())
}
screen.onChange(callback)
// When not needed for use
screen.offChange(callback)
```
--------------------------------
### Logging Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-utils.md
Demonstrates how to get a logger instance and use its methods to log messages.
```javascript
const pageLogger = log.getLogger('page')
pageLogger.log('page created')
pageLogger.error('page error')
```
--------------------------------
### LocalStorage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms-full.txt
Provides an example of using LocalStorage to set, get, remove, and clear data. Demonstrates handling non-existent keys with a default value.
```js
const localStorage = new LocalStorage()
localStorage.setItem('test', 'test value')
const val = localStorage.getItem('test')
const defaultValue = localStorage.getItem('none_key', 'defaultValue')
localStorage.removeItem('test')
localStorage.clear()
```
--------------------------------
### Screen Sensor Usage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/Screen.mdx
Demonstrates how to initialize the Screen sensor, get its status, and set up/remove listeners for screen change events.
```javascript
import { Screen } from '@zos/sensor'
const screen = new Screen()
const status = screen.getStatus()
const callback = () => {
console.log(screen.getStatus())
}
screen.onChange(callback)
// When not needed for use
screen.offChange(callback)
```
--------------------------------
### Install Application with Zepp CLI
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/guides/faq/developer-bridge-mode.md
Once connected to the runtime environment, use the 'install' command in the Zepp CLI to build and install the project from the current directory onto the connected device.
```bash
install
```
--------------------------------
### JavaScript Example for createConnect
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/ble/createConnect.mdx
Demonstrates how to import and use the createConnect function from the @zos/ble module. Ensure necessary setup is done before calling.
```javascript
import { createConnect } from '@zos/ble'
// ...
```
--------------------------------
### Accelerometer Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/Accelerometer.mdx
Demonstrates how to initialize the Accelerometer, set the frequency mode, start listening for changes, and retrieve current accelerometer data. Includes methods for stopping the listener and unregistering the callback when no longer needed.
```javascript
import { Accelerometer, FREQ_MODE_NORMAL } from '@zos/sensor'
const accelerometer = new Accelerometer()
const callback = () => {
console.log(accelerometer.getCurrent())
}
accelerometer.onChange(callback)
accelerometer.setFreqMode(FREQ_MODE_NORMAL)
accelerometer.start()
// When not needed for use
accelerometer.offChange()
accelerometer.stop()
```
--------------------------------
### Wear Sensor Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/Wear.mdx
Demonstrates how to initialize the Wear sensor, get the current status, register a callback for status changes, and unregister the callback.
```javascript
import { Wear } from '@zos/sensor'
const wear = new Wear()
const status = wear.getStatus()
const callback = () => {
console.log(wear.getStatus())
}
wear.onChange(callback)
// When not needed for use
wear.offChange(callback)
```
--------------------------------
### Stand Sensor Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
Demonstrates how to use the Stand sensor to get current and target values, and to register/unregister change listeners.
```javascript
const stand = new Stand()
const current = stand.getCurrent()
const target = stand.getTarget()
const callback = () => {
console.log(stand.getCurrent())
}
stand.onChange(callback)
// When not needed for use
stand.offChange(callback)
```
--------------------------------
### Step Sensor Usage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/Step.mdx
Demonstrates how to initialize the Step sensor, get current and target steps, and register/unregister a step change event listener. Ensure the 'data:user.hd.step' permission is granted.
```javascript
import { Step } from '@zos/sensor'
const step = new Step()
const current = step.getCurrent()
const target = step.getTarget()
const callback = () => {
console.log(step.getCurrent())
}
step.onChange(callback)
// When not needed for use
step.offChange(callback)
```
--------------------------------
### Stand Sensor Usage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/Stand.mdx
Demonstrates how to initialize the Stand sensor, get current and target standing hours, and set up and tear down a change listener. Requires API level 2.0 and 'data:user.hd.stand' permission.
```javascript
import { Stand } from '@zos/sensor'
const stand = new Stand()
const current = stand.getCurrent()
const target = stand.getTarget()
const callback = () => {
console.log(stand.getCurrent())
}
stand.onChange(callback)
// When not needed for use
stand.offChange(callback)
```
--------------------------------
### Create a Section with Input and Button
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/guides/framework/app-settings/ui-intro.md
Example of building an AppSettingsPage with nested sections. The first section contains a text input for a 'Name' field, and the second section contains a 'Start' button with an onClick handler.
```javascript
AppSettingsPage({
build(props) {
return Section({}, [
Section(
{},
TextInput({
label: 'Name',
})
),
Section(
{},
Button({
label: 'Start',
onClick() {
// ...
}
})
)
])
}
})
```
--------------------------------
### Barometer Usage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/Barometer.mdx
Demonstrates how to initialize the Barometer, get air pressure and altitude, and set up change event listeners. Ensure you have the 'device:os.barometer' permission. Requires API level 2.1 or higher.
```javascript
import { Barometer } from '@zos/sensor'
const barometer = new Barometer()
const airPressure = barometer.getAirPressure()
const altitude = barometer.getAltitude()
const callback = () => {
console.log(barometer.getAltitude())
}
barometer.onChange(callback)
// When not needed for use
barometer.offChange(callback)
```
--------------------------------
### Compass API Usage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/Compass.mdx
Demonstrates how to initialize the Compass API, register a callback for direction changes, start listening for data, and stop when no longer needed. It checks calibration status before logging direction and angle.
```javascript
import { Compass } from '@zos/sensor'
const compass = new Compass()
const callback = () => {
if (compass.getStatus()) {
console.log(compass.getDirection())
console.log(compass.getDirectionAngle())
}
}
compass.onChange(callback)
compass.start()
// When not needed for use
compass.offChange()
compass.stop()
```
--------------------------------
### start
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/Geolocation.mdx
Starts the listening for location data. Requires the `device:os.geolocation` permission.
```APIDOC
## start
### Description
Starts listening for location data. This method requires the `device:os.geolocation` permission.
### Method
```ts
start(): void
```
```
--------------------------------
### start
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/media.mdx
Starts playing audio for a player or recording audio for a recorder.
```APIDOC
## start
### Description
Starts playing or recording.
### Method
`start(): void`
### Endpoint
Common Method
```
--------------------------------
### start
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/SystemSounds.mdx
Starts playing a system sound. Developers can specify the sound type and the number of repetitions.
```APIDOC
## start
### Description
Start playing the sound. You can pass in `type` to specify the ringtone type. `repeatCount` is the number of audio repetitions, default is `0`, which means no repeat playback.
### Method
start(sourceType: number, repeatCount: 0): void
```
--------------------------------
### Get Swiper Index Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-page.md
Get the index of the current item in swiper mode. Returns the index (starting from 1) if the scroll mode is SCROLL_MODE_SWIPER or SCROLL_MODE_SWIPER_HORIZONTAL, otherwise returns undefined. Requires API level 2.0 or higher.
```javascript
setScrollMode({
mode: SCROLL_MODE_SWIPER,
options: {
height: 480,
count: 10,
},
})
swipeToIndex({
index: 5,
})
const currentIndex = getSwiperIndex()
console.log(currentIndex)
```
--------------------------------
### Start and Set Vibration Mode
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/Vibrator.mdx
Demonstrates how to initialize the Vibrator, start a default vibration, set a specific vibration scene using VIBRATOR_SCENE_DURATION, and start the vibration again.
```javascript
import { Vibrator, VIBRATOR_SCENE_DURATION } from '@zos/sensor'
const vibrator = new Vibrator()
vibrator.start()
// set scene
vibrator.setMode(VIBRATOR_SCENE_DURATION)
vibrator.start()
```
--------------------------------
### Launch App and System App Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-router.md
Demonstrates how to launch a Mini Program using its ID and URL, and how to launch a system application like Heart Rate.
```javascript
// Jump to Mini Program
launchApp({
appId: 1000001,
url: 'pages/js_widget_sample',
params: {
type: 1,
},
})
// Jump to system App Heart Rate
launchApp({
appId: SYSTEM_APP_HR,
native: true,
})
```
--------------------------------
### Get Current Time Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
An example demonstrating how to get the current time using the Time class.
```javascript
const time = new Time()
const currentTime = time.getTime()
```
--------------------------------
### BodyTemperature API Usage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms-full.txt
A simple example demonstrating how to initialize the BodyTemperature sensor and get the current temperature reading.
```javascript
const bodyTemperature = new BodyTemperature()
bodyTemperature.getCurrent()
```
--------------------------------
### Player Event Listener Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/media.mdx
Demonstrates how to set up event listeners for player events like PREPARE and COMPLETE, and control playback.
```javascript
// Player
import { create, id } from '@zos/media'
const player = create(id.PLAYER)
player.addEventListener(player.event.PREPARE, function (result) {
if (result) {
console.log('=== prepare succeed ===')
player.start()
} else {
console.log('=== prepare fail ===')
}
})
player.addEventListener(player.event.COMPLETE, function (result) {
console.log('=== play end ===')
player.stop()
})
player.setSource(player.source.FILE, { file: '08-15s-16000-1ch.opus' })
// User control
player.prepare()
player.pause()
player.stop()
```
--------------------------------
### Start Development Server and Preview
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/guides/tools/cli/index.md
Navigate to your project's root directory and run `zeus dev` to start the development server. This command compiles your project and enables live preview in the simulator, automatically refreshing on code changes.
```sh
# Enter the project root directory
cd hello-world
# Start compilation preview
zeus dev
```
--------------------------------
### Get Disk Info Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-device.md
Retrieve and log the total disk space available on the device. This example shows how to access the 'total' property from the result of getDiskInfo.
```javascript
const { total } = getDiskInfo()
console.log(total)
```
--------------------------------
### Full MUSIC Sensor Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/watchface/api/hmSensor/sensorId/MUSIC.mdx
A comprehensive example demonstrating the creation, initialization, playback control, and metadata retrieval of the MUSIC sensor.
```javascript
const music = hmSensor.createSensor(hmSensor.id.MUSIC)
music.audInit()
music.audPlay()
music.audPause()
music.audPrev()
music.audNext()
console.log('The artist of song: ' + music.artist)
console.log('The name of song: ' + music.title)
```
--------------------------------
### Example: Initialize and Configure CYCLE_LIST
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/ui/widget/CYCLE_LIST.mdx
Provides a complete example of creating and configuring a CYCLE_LIST widget with image data, dimensions, and an item click callback. Ensure image resources are available in the specified path.
```javascript
import { createWidget, widget } from '@zos/ui'
Page({
state: {
pageName: 'CYCLE_LIST'
},
build() {
const imgArray = ['number-img/0.png', 'number-img/1.png', 'number-img/2.png', 'number-img/3.png', 'number-img/4.png']
const cycleList = createWidget(widget.CYCLE_LIST, {
x: 230,
y: 120,
h: 300,
w: 30,
data_array: imgArray,
data_size: 5,
item_height: 100,
item_click_func: (list, index) => {
console.log(index)
},
item_bg_color: 0xffffff
})
}
})
```
--------------------------------
### Rewrite PICK_DATE Widget Code Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/revision-history.mdx
Offers a rewritten code example for the PICK_DATE widget, including widget picture display. This improves the understanding of its visual setup.
```javascript
PICK_DATE({
x: 0,
y: 0,
w: 100,
h: 100
})
```
--------------------------------
### Get All Widget Properties
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/ui/getProperty.mdx
Retrieves all properties of a UI widget using prop.MORE. This example demonstrates how to get properties like angle, width (w), and height (h) from an image widget.
```javascript
import { createWidget, widget, prop } from '@zos/ui'
const img_bkg = createWidget(widget.IMG)
const img_prop = img_bkg.getProperty(prop.MORE, {})
const { angle, w, h } = img_prop
const imgHeight = img_bkg.getProperty(prop.H)
```
--------------------------------
### App Registration Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/global/App.mdx
This snippet shows how to register a Mini Program using the App() function. It includes setting global data and defining onCreate and onDestroy lifecycle callbacks. Use this to initialize your Mini Program's global state and handle its creation and destruction.
```javascript
App({
globalData: {
text: 'Hello Zepp OS',
},
onCreate() {
console.log('onCreate')
console.log(this.globalData.text)
},
onDestroy() {
console.log('onDestroy')
},
})
```
--------------------------------
### Select Target Platform for Preview
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/guides/tools/cli/index.md
Example of the prompt that appears when running `zeus preview`, allowing you to select the target device for building the preview. This ensures compatibility with your specific hardware.
```sh
? Which target would like you to build?
> 480x480-gtr-3-pro
454x454-gtr-3
? Which target would like you to build? 480x480-gtr-3-pro
begin generate qrcode
```
--------------------------------
### Directory Structure Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/guides/best-practice/code-adaptations-for-new-devices.mdx
Illustrates the directory structure for a Mini Program, showing the organization of assets for specific devices.
```txt
.
├── app.js
├── app.json
├── assets
│ ├── gtr-3-pro
│ │ ├── icon.png
│ │ └── image
│ │ └── logo.png
...
```
--------------------------------
### Fat Burning Sensor Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/FatBurning.mdx
Example demonstrating how to initialize the FatBurning sensor, get current and target values, and set up and remove an event listener for changes. Requires API_LEVEL 2.0 and the 'data:user.hd.fat_burning' permission.
```javascript
import { FatBurning } from '@zos/sensor'
const fatBurning = new FatBurning()
const current = fatBurning.getCurrent()
const target = fatBurning.getTarget()
const callback = () => {
console.log(fatBurning.getCurrent())
}
fatBurning.onChange(callback)
// When not needed for use
fatBurning.offChange(callback)
```
--------------------------------
### Preview Zepp OS Docs (Default Language)
Source: https://github.com/zepp-health/zeppos-docs/blob/main/README.md
Start the project to preview the documentation in the default language (English).
```bash
npm start
// or
yarn start
```
--------------------------------
### Example: Clear Canvas Area
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/ui/widget/CANVAS.mdx
Demonstrates clearing a 64x64 pixel area starting from coordinates (400, 0).
```javascript
canvas.clear({
x: 400,
y: 0,
w: 64,
h: 64
})
```
--------------------------------
### Example of Using EventBus
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms-full.txt
Shows how to set up an EventBus listener and emit a message.
```javascript
const eventBus = new EventBus()
eventBus.on('data', (data) => {
console.log(data)
})
eventBus.emit('data', 'Hello Zepp OS!')
```
--------------------------------
### Get Sport Data Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/app-access/getSportData.mdx
Retrieves sport data for a specified type. The callback function processes the result, parsing the data and logging the requested metric. Ensure the correct type is specified to get the desired data.
```javascript
import { getSportData } from '@zos/app-access'
const result = getSportData(
{
type: 'distance',
},
(callbackResult) => {
const { code, data } = callbackResult
if (code === 0) {
const [{ distance }] = JSON.parse(data)
console.log(distance)
}
},
)
```
--------------------------------
### Example Usage of Distance Sensor
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
Demonstrates how to get the current distance, register a change callback, and then unregister it using `offChange`.
```javascript
const distance = new Distance()
const current = distance.getCurrent()
const callback = () => {
console.log(distance.getCurrent())
}
distance.onChange(callback)
// When not needed for use
distance.offChange(callback)
```
--------------------------------
### Get Display Settings
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-display.md
Retrieves current display settings. No specific setup is required beyond having access to the ZeppOS environment.
```javascript
console.log(getSettings())
```
--------------------------------
### QRCODE Widget Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/ui/widget/QRCODE.mdx
Provides a complete example of creating a QRCODE widget within a Zepp OS Page. It shows how to set content, position, dimensions, and background properties.
```javascript
import { createWidget, widget } from '@zos/ui'
Page({
build() {
const qrcode = createWidget(widget.QRCODE, {
content: 'Hello Zepp OS',
x: 140,
y: 140,
w: 200,
h: 200,
bg_x: 120,
bg_y: 120,
bg_w: 240,
bg_h: 240
})
}
})
```
--------------------------------
### Install Libraries for Ubuntu 26.04 LTS
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/guides/faq/simulator-faq.md
Installs necessary libraries and links dynamic libraries for the simulator on Ubuntu 26.04 LTS.
```sh
# Install libraries libxss1 libcapstone5 libsdl2-dev libaio-dev
sudo apt install libxss1 libcapstone5 libsdl2-dev libaio-dev
# Link dependent dynamic libraries
# x64 version
cd /lib/x86_64-linux-gnu
# arm64/aarch64 version
cd /lib/aarch64-linux-gnu
sudo ln -s libcapstone.so libcapstone.so.4
sudo ln -s libaio.so libaio.so.1
```
--------------------------------
### Buzzer Example with UI Integration
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/Buzzer.mdx
This example demonstrates how to integrate the Buzzer API with UI elements to create an interactive button that triggers different buzzer sounds based on user selection. It includes setup for UI widgets and event handling.
```javascript
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,
})
},
})
```
--------------------------------
### Get Sport Data Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-app-access.md
Retrieves sport data, such as distance, and logs it to the console. Requires parsing the data from the callback result.
```javascript
const result = getSportData(
{
type: 'distance',
},
(callbackResult) => {
const { code, data } = callbackResult
if (code === 0) {
const [{ distance }] = JSON.parse(data)
console.log(distance)
}
},
)
```
--------------------------------
### Buzzer API
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
The Buzzer API allows for controlling device vibrations and sounds for various alerts and notifications. It provides methods to check if the buzzer is enabled, get different sound types, control the start and stop of buzzing, and get the buzzer strength.
```APIDOC
## Buzzer API
### Description
Provides functionality to control the device's buzzer for alerts and notifications.
### Methods
#### `isEnabled()`
- **Description**: Get whether other options in the system buzzer scene settings are turned on.
- **Returns**: `boolean` - True if the buzzer is enabled, false otherwise.
#### `getSourceType()`
- **Description**: Get buzzer mode.
- **Returns**: `Type` - An object mapping scene names to their corresponding buzzer types.
##### 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()`
- **Description**: Get buzzer strength.
- **Returns**: `number` - '0' for weak, '1' for medium, '2' for high.
#### `start(type: number, repeatCount: 0)`
- **Description**: 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.
- **Parameters**:
- `type` (number) - The type of buzzer sound.
- `repeatCount` (number) - The number of times to repeat the sound (default is 0).
- **Returns**: `void`
#### `stop()`
- **Description**: Stop buzzer.
- **Returns**: `void`
### Example
```js
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,
});
},
});
```
```
--------------------------------
### Example Usage
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/interaction/createModal.mdx
Demonstrates how to import and use the `createModal` function with event handling for button clicks.
```APIDOC
## Example
```js
import { createModal, MODAL_CONFIRM } from '@zos/interaction'
const dialog = createModal({
content: 'hello world',
autoHide: false,
onClick: (keyObj) => {
const { type } = keyObj
if (type === MODAL_CONFIRM) {
console.log('confirm')
} else {
dialog.show(false)
}
},
})
dialog.show(true)
```
```
--------------------------------
### SystemSounds
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
Provides functionality to interact with system sounds, including checking if sounds are enabled, getting sound types, starting, and stopping playback.
```APIDOC
## SystemSounds
### Description
Manages system sounds for various event types like alarms, messages, and camera shutters. Requires API Level 3.6.
### Methods
#### getEnabled
Gets whether the system ringtone function is turned on.
```ts
getEnabled(): boolean
```
#### getSourceType
Gets built-in system ringtone types.
```ts
getSourceType(): Type
```
##### Type
| Property | Type | Required | DefaultValue | Description |
| -------- | -------- | -------- | ------------ | --------------------------------------------------------- |
| ALARM | `number` | Y | - | Alarm clock reminder |
| MESSAGE | `number` | Y | - | Notification sound when receiving text messages or emails |
| REGULAR | `number` | Y | - | TingTing sound |
| ACHIEVE | `number` | Y | - | Goals achieved |
| CAMERA | `number` | Y | - | Camera shutter |
| ABN_HIGH | `number` | Y | - | Health data measurement abnormalities (high values) |
| ABN_LOW | `number` | Y | - | Health data measurement abnormalities (low values) |
| SOS | `number` | Y | - | SOS for help |
#### start
Starts playing the sound. Allows specifying the ringtone type and repeat count.
```ts
start(sourceType: number, repeatCount: 0): void
```
#### stop
Stops sound playback.
```ts
stop(): void
```
### Example
```js
import { SystemSounds } from '@zos/sensor'
const systemSounds = new SystemSounds()
const alarmType = systemSounds.getSourceType().ALARM
if (systemSounds.getEnabled()) {
systemSounds.start(alarmType)
}
```
```
--------------------------------
### SessionStorage Usage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/storage/sessionStorage.mdx
Demonstrates how to use the SessionStorage API to set, get, remove, and clear data. Ensure the SessionStorage class is imported.
```javascript
import { SessionStorage } from '@zos/storage'
const sessionStorage = new SessionStorage()
sessionStorage.setItem('test', 'test value')
const val = sessionStorage.getItem('test')
const defaultValue = sessionStorage.getItem('none_key', 'defaultValue')
sessionStorage.removeItem('test')
sessionStorage.clear()
```
--------------------------------
### CIRCLE Widget Configuration Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/watchface/api/hmUI/widget/CIRCLE.mdx
Provides a complete example of creating a CIRCLE widget with specific properties. Use this to understand how to set the circle's position, size, color, and transparency.
```javascript
Page({
build() {
const circle = hmUI.createWidget(hmUI.widget.CIRCLE, {
center_x: 240,
center_y: 240,
radius: 120,
color: 0xfc6950,
alpha: 200
})
}
})
```
--------------------------------
### BloodOxygen Sensor Usage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/BloodOxygen.mdx
Demonstrates how to instantiate the BloodOxygen sensor, retrieve current and historical data, set up event listeners, and start/stop measurements. Includes necessary imports and callback handling.
```javascript
import { BloodOxygen } from '@zos/sensor'
const bloodOxygen = new BloodOxygen()
const { value } = bloodOxygen.getCurrent()
const lastDay = bloodOxygen.getLastDay()
const callback = () => {
console.log(bloodOxygen.getCurrent())
}
bloodOxygen.onChange(callback)
bloodOxygen.stop()
bloodOxygen.start()
// When not needed for use
bloodOxygen.offChange(callback)
```
--------------------------------
### Preview Zepp OS Docs (Chinese Language)
Source: https://github.com/zepp-health/zeppos-docs/blob/main/README.md
Start the project to preview the documentation specifically in the Chinese language.
```bash
npm start -- --locale zh-cn
// or
yarn start --locale zh-cn
```
--------------------------------
### App Configuration Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/app-json.mdx
This snippet shows a typical 'app' configuration object, including basic program details and version information. It is used to define the metadata for a Mini Program.
```javascript
{
"app": {
"appId": 1000089,
"appName": "······",
"appType": "app",
"version": {
"code": 5,
"name": "0.0.5"
},
"icon": "logo.png",
"vender": "······",
"description": "······"
}
}
```
--------------------------------
### Get App ID by Name
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-router.md
Fuzzy matches the English name of installed Mini Programs and returns their IDs. Requires API_LEVEL 3.6 or higher.
```javascript
const appId = getAppIdByName('calculator')
console.log(appId)
```
--------------------------------
### Compile and Preview Mini Program
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/guides/quick-start/simulator-dev.mdx
Use this command to compile your project code and initiate a preview on the simulator. Ensure you are in your project's root directory.
```sh
zeus dev
```
--------------------------------
### Vibrator Scene Mode Usage
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
Shows how to set a vibration scene mode using `VIBRATOR_SCENE_DURATION` and start the vibration. This example requires importing `VIBRATOR_SCENE_DURATION`.
```javascript
import { Vibrator, VIBRATOR_SCENE_DURATION } from '@zos/sensor'
const vibrator = new Vibrator()
vibrator.setMode(VIBRATOR_SCENE_DURATION)
vibrator.start()
```
--------------------------------
### Geolocation Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
Demonstrates how to start geolocation, receive location updates, and stop the service. It logs latitude and longitude when the status is 'A' (likely indicating active).
```javascript
const geolocation = new Geolocation()
const callback = () => {
if (geolocation.getStatus() === 'A') {
console.log(geolocation.getLatitude())
console.log(geolocation.getLongitude())
}
}
geolocation.start()
geolocation.onChange(callback)
// When not needed for use
geolocation.offChange(callback)
geolocation.stop()
```
--------------------------------
### Open and Write to a File
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-fs.md
Demonstrates how to open a file with read/write/create flags and write data from a buffer to it. Ensure the file path and flags are correctly specified.
```javascript
const fd = openSync({
path: 'test.txt',
flag: O_RDWR | O_CREAT,
})
const buffer = new ArrayBuffer(4)
const result = writeSync({
fd,
buffer,
})
```
--------------------------------
### Accelerometer Usage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
Demonstrates how to initialize and use the Accelerometer sensor, including setting frequency mode and handling change events.
```javascript
const accelerometer = new Accelerometer()
const callback = () => {
console.log(accelerometer.getCurrent())
}
accelerometer.onChange(callback)
accelerator.setFreqMode(FREQ_MODE_NORMAL)
accelerometer.start()
// When not needed for use
accelerometer.offChange()
accelerometer.stop()
```
--------------------------------
### Initialize and Get Current Body Temperature
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/BodyTemperature.mdx
Example of initializing the BodyTemperature sensor and fetching the current temperature reading. Ensure the necessary permission is granted.
```javascript
import { BodyTemperature } from '@zos/sensor'
const bodyTemperature = new BodyTemperature()
bodyTemperature.getCurrent()
```
--------------------------------
### BloodOxygen API Usage Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
Demonstrates how to instantiate the BloodOxygen sensor, get current values, retrieve historical data, and manage event listeners and measurement states.
```javascript
const bloodOxygen = new BloodOxygen()
const { value } = bloodOxygen.getCurrent()
const lastDay = bloodOxygen.getLastDay()
const callback = () => {
console.log(bloodOxygen.getCurrent())
}
bloodOxygen.onChange(callback)
bloodOxygen.stop()
bloodOxygen.start()
// When not needed for use
bloodOxygen.offChange(callback)
```
--------------------------------
### Barometer Initialization and Usage
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
Shows how to import and instantiate the Barometer sensor, retrieve air pressure and altitude, and set up change event listeners.
```javascript
import { Barometer } from '@zos/sensor'
```
```javascript
const barometer = new Barometer()
const airPressure = barometer.getAirPressure()
const altitude = barometer.getAltitude()
const callback = () => {
console.log(barometer.getAltitude())
}
barometer.onChange(callback)
// When not needed for use
barometer.offChange(callback)
```
--------------------------------
### Example Settings App Structure
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/guides/framework/app-settings/register.md
A recommended code structure for developing a Settings App, demonstrating state definition, data retrieval from SettingsStorage, program logic, UI rendering, and data manipulation.
```js
AppSettingsPage({
// 1. Define state
state: {
testKey: null
},
build(props) {
// 2. Get SettingsStorage
this.getStorage(props)
// 3. Logic
const toggleButtonMap = {
['Hello Zepp OS']: 'Hello World',
['Hello World']: 'Hello Zepp OS'
}
// 4. Return Render Function
return Button({
label: this.state.testKey,
style: {
fontSize: '12px',
borderRadius: '30px',
background: '#D85E33',
color: 'white'
},
onClick: () => {
// 5. Modify the data in settingsStorage in the callback function of the event
props.settingsStorage.setItem('testKey', toggleButtonMap[this.state.testKey])
}
})
},
getStorage(props) {
this.state.testKey = props.settingsStorage.getItem('testKey') || 'Hello World'
}
})
```
--------------------------------
### DataTypeConfig Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/ui/widget/SCROLL_LIST.mdx
Configures the styling for different ranges of data items in the SCROLL_LIST. It uses 'start' and 'end' to define a closed interval and 'type_id' to link to specific item configurations.
```javascript
{
data_type_config:[
// Represents that data entries from index 0 to 2 use the style configuration with type_id 2
{
start: 0,
end: 2,
type_id: 2,
},
{
start: 3,
end: 10,
type_id: 1,
}
],
data_type_config_count:2
}
```
--------------------------------
### HeartRate Sensor Usage
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/sensor/HeartRate.mdx
Demonstrates how to initialize the HeartRate sensor, get the last recorded value, and set up a callback for current changes. Includes methods for both starting and stopping the change listener.
```javascript
import { HeartRate } from '@zos/sensor'
const heartRate = new HeartRate()
const lastValue = heartRate.getLast()
const callback = () => {
console.log(heartRate.getCurrent())
}
heartRate.onCurrentChange(callback)
// When not needed for use
heartRate.offCurrentChange(callback)
```
--------------------------------
### Start Playing or Recording
Source: https://github.com/zepp-health/zeppos-docs/blob/main/docs/reference/device-app-api/newAPI/media.mdx
Call the `start` method to begin audio playback or recording. This method is common to both Player and Record objects.
```typescript
start(): void
```
--------------------------------
### Workout Sensor Overview
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
Provides an overview of the Workout sensor, including its import, typings, permissions, and basic usage examples for getting status, history, and heart rate zone settings.
```APIDOC
## Workout Sensor
### Import
```js
import { Workout } from '@zos/sensor'
```
### Typings
- **Description**: Workout Sensor
- **API_LEVEL**: 3.0
- **Permission**: `data:user.hd.workout`
**Example Usage**:
```js
import { Workout } from '@zos/sensor'
const workout = new Workout()
const status = workout.getStatus()
const history = workout.getHistory()
const hrZoneSettings = workout.getUserHrZoneSettings()
// Example hrZoneSettings output:
// {"type":0,"rest":83,"range":[129,138,147,157,166,175]}
// {"type":1,"rest":70,"range":[90,108,126,144,162,181]}
const trackNavInfo = workout.getWorkoutTrackNavInfo()
```
> **Note**: Workout Sensor functionality starts from API_LEVEL `3.0`. Refer to [API_LEVEL](https://docs.zepp.com/docs/guides/framework/device/compatibility) for compatibility details.
> **Permission Required**: `data:user.hd.workout`
## Methods
### getStatus
Get altitude value in meters.
```ts
getStatus(): Status
```
#### Status Type
| Property | Type | Description |
| ---------------- | ------------------- | ------------------ |
| vo2Max | `number` | VO2 Max |
| trainingLoad | `number` | Training Load |
| fullRecoveryTime | `number` | Full Recovery Time |
### getHistory
Get the duration of the workout record.
```ts
getHistory(): Array
```
#### History Type
(Note: The specific properties for the `History` type are not detailed in the provided source text, only that it returns an Array of `History` objects.)
```
--------------------------------
### HeartRate Sensor Example
Source: https://github.com/zepp-health/zeppos-docs/blob/main/static/llms/@zos-sensor.md
Demonstrates how to use the HeartRate sensor to get the last and current heart rate values. It includes registering and unregistering a callback for current heart rate changes.
```javascript
const heartRate = new HeartRate()
const lastValue = heartRate.getLast()
const callback = () => {
console.log(heartRate.getCurrent())
}
heartRate.onCurrentChange(callback)
// When not needed for use
heartRate.offCurrentChange(callback)
```