BangleApps/apps/findphone/app.js

57 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-05-07 14:33:11 +00:00
//notify your phone
2021-10-02 13:13:20 +00:00
const fontSize = g.getWidth() / 8;
var finding = false;
2020-05-07 14:33:11 +00:00
function draw() {
// show message
g.clear(g.theme.bg);
2021-10-02 13:13:20 +00:00
g.setColor(g.theme.fg);
g.setFont("Vector", fontSize);
g.setFontAlign(0,0);
if (finding) {
g.drawString("Finding...", g.getWidth()/2, (g.getHeight()/2)-20);
g.drawString("Click to stop", g.getWidth()/2, (g.getHeight()/2)+20);
} else {
g.drawString("Click to find", g.getWidth()/2, g.getHeight()/2);
}
g.flip();
}
2021-10-02 14:41:12 +00:00
function findPhone(v) {
Bluetooth.println("");
2021-10-02 14:41:12 +00:00
Bluetooth.println(JSON.stringify({t:"findPhone", n:v}));
}
function find(){
finding = !finding;
draw();
2021-10-02 14:41:12 +00:00
findPhone(finding);
}
draw();
2020-05-07 14:33:11 +00:00
//register all buttons and screen to find phone
setWatch(find, BTN1, {repeat:true});
2021-10-02 13:13:20 +00:00
if (process.env.HWVERSION == 1) {
setWatch(find, BTN2, {repeat:true});
setWatch(find, BTN3, {repeat:true});
setWatch(find, BTN4, {repeat:true});
setWatch(find, BTN5, {repeat:true});
}
if (process.env.HWVERSION == 2) {
Bangle.on('touch', function(button, xy) {
2021-10-02 13:13:20 +00:00
// click top part of the screen to stop start
if (xy.y < g.getHeight() / 2) {
find();
} else {
2021-10-02 14:41:12 +00:00
findPhone(false);
setTimeout(load, 100); // exit in 100ms
2021-10-02 13:13:20 +00:00
}
});
}