Skip to main content
Version: v3

BloodOxygen

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Blood oxygen Sensor.

info

permission code: data:user.hd.spo2

Methods

getCurrent

Get the current measured blood oxygen result

getCurrent(): Result

Result

PropertyTypeDescriptionAPI_LEVEL
valuenumberBlood oxygen measurement values2.0
timenumberMeasurement time2.0
retCodenumberResult code, refer to retCode description2.0

retCode

ValueTypeDescriptionAPI_LEVEL
0numberMeasurement invalid2.0
1numberContinue measuring2.0
2numberMeasurement success2.0
3numberMeasurement failure2.0
4numberNot wearing2.0
5numberMeasurement timeout2.0
6numberInvalid wearing2.0
7numberInvalid signal2.0
8numberLow blood oxygen value2.0
9numberHigh blood oxygen value2.0
10numberMeasurement invalid2.0

getLastDay

Returns the average blood sample data for the past 24 hours, with an array length of 24

getLastDay(): Array<number>

start

Start from API_LEVEL 2.1

Start blood oxygen measurement, it is recommended to call stop to stop the last measurement before calling the start method

start(): void

stop

Start from API_LEVEL 2.1

Cancel blood oxygen measurement

stop(): void

onChange

Register a callback function to listen for blood oxygen measurement change events

onChange(callback: () => void): void

offChange

Cancel a callback function to listen for blood oxygen measurement change events

offChange(callback: () => void): void

getLastFewHour

Start from API_LEVEL 3.0

Obtain blood oxygen measurements for the last hour and sort the results in chronological order

getLastFewHour(hour: number): Array<Data>

Data

PropertyTypeDescriptionAPI_LEVEL
spo2numberBlood oxygen measurement value3.0
timenumberTime of measurement of blood oxygen values, UTC time stamp in seconds3.0

Example

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)