HeartRate
Start from API_LEVEL
2.0
. Please refer to API_LEVEL.
HeartRate Sensor.
permission code: data:user.hd.heart_rate
Methods
getCurrent
Get the current heart rate measurement, this method needs to be used in the onCurrentChange
callback function
getCurrent(): number
getLast
Get the most recent heart rate measurement (single measurement or heart rate monitoring measurement, continuous heart rate measurement onCurrentChange
results are not counted)
getLast(): number
getToday
Get the heart rate measurement data in minutes from 0:00 to the current moment of the day, the longest array is 60*24
getToday(): Array<number>
onCurrentChange
Start from API_LEVEL
2.1
Call this method and start measuring heart rate continuously, call the callback function when there is a measurement result, call the getCurrent
method in the callback function to get the heart rate measurement value, if you want to stop the heart rate measurement, you need to call the offCurrentChange
method
onCurrentChange(callback: () => void): void
offCurrentChange
Start from API_LEVEL
2.1
Cancel continuous heart rate measurement and cancel callback function listeners
offCurrentChange(callback: () => void): void
onLastChange
Start from API_LEVEL
2.1
Register the heart rate single measurement change event callback function
onLastChange(callback: () => void): void
offLastChange
Start from API_LEVEL
2.1
Cancel the heart rate single measurement change event callback function
offLastChange(callback: () => void): void
Example
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)