VHS-watch/watchface/modules/heartRate.js

39 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-10-20 03:27:14 +03:00
import { getScene, SCENE_AOD } from '@zos/app'
2024-10-20 02:54:13 +03:00
import * as hmSensor from '@zos/sensor'
import * as hmUI from '@zos/ui';
import secondaryFont from '../fontData/secondaryFont';
let heartRateWg;
2024-10-20 03:27:14 +03:00
export default function () {
2024-10-20 02:54:13 +03:00
console.log("[modules]: heartrate module init")
2024-10-20 03:29:33 +03:00
if (getScene() != SCENE_AOD) {
let heart = new hmSensor.HeartRate();
updateHeartWidget(heart.getLast())
heart.onCurrentChange(() => updateHeartWidget(heart.getCurrent()))
2024-10-20 03:27:14 +03:00
hmUI.createWidget(hmUI.widget.IMG, {
x: 10,
y: 365,
src: 'misc/hb.PNG'
})
2024-10-20 03:29:33 +03:00
}
2024-10-20 02:54:13 +03:00
}
2024-10-20 03:27:14 +03:00
function updateHeartWidget(hbpm) {
if (!hbpm) {
2024-10-20 02:54:13 +03:00
hbpm = 0
}
2024-10-20 03:27:14 +03:00
if (heartRateWg) {
2024-10-20 02:54:13 +03:00
hmUI.deleteWidget(heartRateWg)
}
2024-10-20 03:29:33 +03:00
if (getScene() != SCENE_AOD) {
2024-10-20 03:27:14 +03:00
heartRateWg = hmUI.createWidget(hmUI.widget.TEXT_IMG, {
x: 100,
y: 365,
type: hmUI.data_type.BATTERY,
font_array: secondaryFont,
h_space: 1,
align_h: hmUI.align.LEFT,
text: hbpm
})
}
2024-10-20 02:54:13 +03:00
}