-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
80 lines (64 loc) · 1.69 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// import requirements
import AutoGUI from '@silver-zepp/autogui';
const gui = new AutoGUI();
import { Step, HeartRate, BloodOxygen } from "@zos/sensor";
const step = new Step();
const spo2 = new BloodOxygen();
const hr = new HeartRate();
class IndexPage {
init(){
// create your gui
const txt_steps = gui.text("Steps: 0", { text_size: 60 });
gui.newRow();
const txt_spo2 = gui.text("SpO2: 0");
const txt_hr = gui.text("HR: 0");
gui.newRow();
gui.button("Measure SpO2", ()=> {
spo2.start();
txt_spo2.update({ text: "Hold on for 10s..." });
setTimeout(() => {
spo2.stop();
txt_spo2.update({ text: spo2.getCurrent().value });
}, 10 * 1000);
});
// render your gui
gui.render();
// setup callbacks
const cb_Steps = () => {
txt_steps.update({ text: "Steps:" + step.getCurrent() });
};
const cb_HR = () => {
txt_hr.update({ text: "HR:" + hr.getCurrent() })
}
const cb_SpO2 = () => {
txt_spo2.update({ text: "SpO2:" + spo2.getCurrent().value })
}
// and on change events
step.onChange(cb_Steps)
hr.onCurrentChange(cb_HR)
spo2.onChange(cb_SpO2)
}
destroy(){
spo2 && spo2.stop();
}
}
Page({
build(){
this.indexPage = new IndexPage();
this.indexPage.init();
},
onDestroy(){
this.indexPage.destroy();
}
})
/** HELPERS */
// don't turn off the screen for 600 seconds
import { setPageBrightTime } from '@zos/display'
const result = setPageBrightTime({
brightTime: 600 * 1000,
})
// don't turn off the screen on wrist down for 600 seconds
import { pauseDropWristScreenOff } from '@zos/display'
pauseDropWristScreenOff({
duration: 600 * 1000,
})