2023-01-10 19:03:25 +00:00
|
|
|
// Clock with large digits using the "Anton" bold font
|
|
|
|
Graphics.prototype.setFontAnton = function(scale) {
|
2023-01-10 19:06:11 +00:00
|
|
|
// Actual height 69 (68 - 0)
|
|
|
|
g.setFontCustom(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAA/gAAAAAAAAAAP/gAAAAAAAAAH//gAAAAAAAAB///gAAAAAAAAf///gAAAAAAAP////gAAAAAAD/////gAAAAAA//////gAAAAAP//////gAAAAH///////gAAAB////////gAAAf////////gAAP/////////gAD//////////AA//////////gAA/////////4AAA////////+AAAA////////gAAAA///////wAAAAA//////8AAAAAA//////AAAAAAA/////gAAAAAAA////4AAAAAAAA///+AAAAAAAAA///gAAAAAAAAA//wAAAAAAAAAA/8AAAAAAAAAAA/AAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////AAAAAB///////8AAAAH////////AAAAf////////wAAA/////////4AAB/////////8AAD/////////+AAH//////////AAP//////////gAP//////////gAP//////////gAf//////////wAf//////////wAf//////////wAf//////////wA//8AAAAAB//4A//wAAAAAAf/4A//gAAAAAAP/4A//gAAAAAAP/4A//gAAAAAAP/4A//wAAAAAAf/4A///////////4Af//////////wAf//////////wAf//////////wAf//////////wAP//////////gAP//////////gAH//////////AAH//////////AAD/////////+AAB/////////8AAA/////////4AAAP////////gAAAD///////+AAAAAf//////4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/gAAAAAAAAAAP/gAAAAAAAAAAf/gAAAAAAAAAAf/gAAAAAAAAAAf/AAAAAAAAAAA//AAAAAAAAAAA/+AAAAAAAAAAB/8AAAAAAAAAAD//////////gAH//////////gAP//////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH/4AAAAB/gAAD//4AAAAf/gAAP//4AAAB//gAA///4AAAH//gAB///4AAAf//gAD///4AAA///gAH///4AAD///gAP///4AAH///gAP///4AAP///gAf///4AAf///gAf///4AB////gAf///4AD////gA////4AH////gA////4Af////gA////4A/////gA//wAAB/////gA//gAAH/////gA//gAAP/////gA//gAA///8//gA//gAD///w//gA//wA////g//gA////////A//gA///////8A//gA///////4A//gAf//////wA//gAf//////gA//gAf/////+AA//gAP/////8AA//gAP/////4AA//gAH/////gAA//gAD/////AAA//gAB////8AAA//gAA////wAAA//gAAP///AAAA//gAAD//8AAAA//gAAAP+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB/+AAAAAD/wAAB//8AAAAP/wAAB///AAAA//wAAB///wAAB//wAAB///4AAD//wAAB///8AAH//wAAB///+AAP//wAAB///+AAP//wAAB////AAf//wAAB////AAf//wAAB////gAf//wAAB////gA///wAAB////gA///wAAB////gA///w//AAf//wA//4A//AAA//wA//gA//AAAf/wA//gB//gAAf/wA//gB//gAAf/wA//gD//wAA//wA//wH//8AB//wA///////////gA///////////gA///////////gA///////////gAf//////////AAf//////////AAP//////////AAP/////////+AAH/////////8AAH///+/////4AAD///+f////wAAA///8P////gAAAf//4H///+AAAAH//gB///wAAAAAP4AAH/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAA//wAAAAAAAAAP//wAAAAAAAAB///wAAAAAAAAf///wAAAAAAAH////wAAAAAAA/////wAAAAAAP/////wAAAAAB//////wAAAAAf//////wAAAAH///////wAAAA////////wAAAP////////wAAA///////H/wAAA//////wH/wAAA/////8AH/wAAA/////AAH/wAAA////gAAH/wAAA///4AAAH/wAAA//+AAAAH/wAAA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gA///////////gAAAAAAAAH/4AAAAAAAAAAH/wAAAAAAAAAAH/wAAAAAAAAAAH/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB//8AAA/////+B///AAA/////+B///wAA/////+B///4AA/////+B///8AA/////+B///8AA/////+B///+AA/////+B////AA/////+B////AA/////+B////AA/////+B////gA/////+B////gA/////+B////gA/////+A////gA//gP/gAAB//wA//gf/AAAA//wA//gf/AAAAf/wA//g//AAAAf/wA//g//AAAA//wA//g//gAAA//wA//g//+AAP//wA//g////////gA//g////////gA//g////////gA//g////////gA//g////////AA//gf///////AA//gf//////+AA//gP//////+AA//gH//////8AA//gD//////4AA//gB//////wAA//gA//////AAAAAAAH////8AAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////gAAAAB///////+AAAAH////////gAAAf////////4AAB/////////8AAD/////////+AAH//////////AAH//////////gAP//////////gAP//////////gAf//////////wAf//////////wAf//////////wAf//////////wAf//////////4A//wAD/4AAf/4A//gAH/wAAP/4A//gAH/wAAP/4A//gAP/wAAP/4A//gAP/4AAf/4A//wAP/+AD//4A///wP//////4Af//4P//////wAf//4P//////wAf//4P//////wAf//4P//////wAP//4P//////gAP//4H//////gAH//4H//////AAH//4D/////+AAD//4D/////8AAB//4B/////4AAA//4A/////wAAAP/4AP////AAAAB/4AD///4AAAAAAAAAH/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//AAAAAAAAAAA//g
|
2023-01-10 19:03:25 +00:00
|
|
|
};
|
|
|
|
|
2023-01-10 19:06:11 +00:00
|
|
|
let myMessage = "";
|
2023-01-11 02:17:09 +00:00
|
|
|
let temperature = "";
|
2023-01-10 19:06:11 +00:00
|
|
|
|
|
|
|
{ // must be inside our own scope here so that when we are unloaded everything disappears
|
|
|
|
// we also define functions using 'let fn = function() {..}' for the same reason. function decls are global
|
|
|
|
let drawTimeout;
|
|
|
|
|
|
|
|
let paint = function() {
|
|
|
|
var x = g.getWidth() / 2;
|
|
|
|
var y = g.getHeight() / 2;
|
|
|
|
|
|
|
|
g.reset().clearRect(Bangle.appRect); // clear whole background (w/o widgets)
|
|
|
|
|
|
|
|
var date = new Date();
|
|
|
|
var timeStr = require("locale").time(date, 1); // Hour and minute
|
|
|
|
g.setFontAlign(0, 0).setFont("Anton").drawString(timeStr, x, y+20);
|
|
|
|
// Show date and day of week
|
2023-01-11 02:17:09 +00:00
|
|
|
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
|
|
var dateStr = date.getDate() + " " + days[date.getDay()] + " " + temperature;
|
2023-01-10 19:06:11 +00:00
|
|
|
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(dateStr, x, y+70);
|
|
|
|
|
|
|
|
//var wrapped = g.wrapString(myMessage, g.getWidth()-10).join("\n");
|
|
|
|
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(myMessage, x, y-45);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Actually draw the watch face
|
|
|
|
let draw = function() {
|
|
|
|
if (Bangle.http){
|
|
|
|
Bangle.http("https://api.home.dns.t0.vc/bangle", {timeout:3000}).then(event => {
|
2023-01-11 02:17:09 +00:00
|
|
|
let result = JSON.parse(event.resp);
|
|
|
|
myMessage = result.context;
|
|
|
|
temperature = result.temperature;
|
2023-01-10 19:06:11 +00:00
|
|
|
if (paint) paint();
|
|
|
|
}).catch((e)=>{
|
|
|
|
myMessage = "GET error";
|
|
|
|
if (paint) paint();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// queue next draw
|
|
|
|
if (drawTimeout) clearTimeout(drawTimeout);
|
|
|
|
drawTimeout = setTimeout(function() {
|
|
|
|
drawTimeout = undefined;
|
|
|
|
draw();
|
|
|
|
}, 60000 - (Date.now() % 60000));
|
|
|
|
};
|
|
|
|
|
|
|
|
let move = function(dir1, dir2) {
|
|
|
|
var direction;
|
|
|
|
|
|
|
|
if (dir1 == 1) {
|
|
|
|
direction = "right";
|
|
|
|
} else if (dir1 == -1) {
|
|
|
|
direction = "left";
|
|
|
|
} else if (dir2 == 1) {
|
|
|
|
direction = "down";
|
|
|
|
} else if (dir2 == -1) {
|
|
|
|
direction = "up";
|
|
|
|
} else {
|
|
|
|
direction = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Bangle.http){
|
|
|
|
const options = {timeout:3000, method: "post", body: direction};
|
|
|
|
Bangle.http("https://api.home.dns.t0.vc/bangle", options).then(event => {
|
|
|
|
myMessage = "Sent " + direction;
|
|
|
|
if (paint) paint();
|
|
|
|
}).catch((e)=>{
|
|
|
|
myMessage = "POST error";
|
|
|
|
if (paint) paint();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Bangle.on('swipe', move);
|
2023-01-10 19:03:25 +00:00
|
|
|
|
2023-01-10 19:06:11 +00:00
|
|
|
// Show launcher when middle button pressed
|
|
|
|
Bangle.setUI({
|
|
|
|
mode : "clock",
|
|
|
|
remove : function() {
|
|
|
|
// Called to unload all of the clock app
|
|
|
|
Bangle.removeListener('swipe', move);
|
|
|
|
if (drawTimeout) clearTimeout(drawTimeout);
|
|
|
|
drawTimeout = undefined;
|
|
|
|
paint = undefined;
|
|
|
|
delete Graphics.prototype.setFontAnton;
|
|
|
|
}});
|
|
|
|
// Load widgets
|
|
|
|
Bangle.loadWidgets();
|
|
|
|
paint();
|
|
|
|
draw();
|
|
|
|
setTimeout(Bangle.drawWidgets,0);
|
|
|
|
}
|