Compare commits
6 Commits
04511d029c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 8275abdb57 | |||
| 1c433fc56b | |||
| 14bda5c29f | |||
| ea58f2101f | |||
| 07bb582ddd | |||
| 6d965dd016 |
@@ -11,14 +11,15 @@
|
||||
|
||||
let watchState = STATE_IDLE;
|
||||
|
||||
let stopWatch = require("Storage").readJSON("mystopwatch.json", true) || {start1: null, elapsed1: null, start2: null, elapsed2: null};
|
||||
let stopWatch = require("Storage").readJSON("mystopwatch.json", true) || {start1: null, elapsed1: null, buzz1: null, start2: null, elapsed2: null, buzzed2: null};
|
||||
let saveStopWatch = function() {
|
||||
require("Storage").writeJSON("mystopwatch.json", stopWatch);
|
||||
}
|
||||
let stopWatchTimer = null;
|
||||
|
||||
let myMessage = "";
|
||||
let temperature = "";
|
||||
let temperature = "?";
|
||||
let feels_like = "?";
|
||||
|
||||
let drawTimer = null;
|
||||
|
||||
@@ -37,24 +38,39 @@
|
||||
let Tt1 = (stopWatch.elapsed1 || 0);
|
||||
if (stopWatch.start1) {
|
||||
Tt1 += Date.now() - stopWatch.start1;
|
||||
|
||||
const fifteenMinutes = 15 * 60 * 1000;
|
||||
let intervals = Math.floor(Tt1 / fifteenMinutes);
|
||||
if (intervals > (stopWatch.buzz1 || 0)) {
|
||||
stopWatch.buzz1 = intervals;
|
||||
Bangle.buzz(500);
|
||||
saveStopWatch();
|
||||
}
|
||||
}
|
||||
let Ttxt1 = timeToText(Tt1);
|
||||
|
||||
g.clearRect(0, y-60, w, y-34);
|
||||
g.clearRect(0, y+61, w, y+88);
|
||||
g.setColor(g.theme.fg);
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString("S1: " + Ttxt1, x, y-45);
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(Ttxt1, x, y+74);
|
||||
}
|
||||
|
||||
if (stopWatch.start2 || stopWatch.elapsed2) {
|
||||
let Tt2 = (stopWatch.elapsed2 || 0);
|
||||
if (stopWatch.start2) {
|
||||
Tt2 += Date.now() - stopWatch.start2;
|
||||
|
||||
const oneMinute = 60 * 1000;
|
||||
if (!stopWatch.buzzed2 && Tt2 >= oneMinute) {
|
||||
stopWatch.buzzed2 = true;
|
||||
Bangle.buzz(500);
|
||||
saveStopWatch();
|
||||
}
|
||||
}
|
||||
let Ttxt2 = timeToText(Tt2);
|
||||
|
||||
g.clearRect(0, y+61, w, y+88);
|
||||
g.clearRect(0, y-60, w, y-34);
|
||||
g.setColor(g.theme.fg);
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString("S2: " + Ttxt2, x, y+76);
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(Ttxt2, x, y-45);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,25 +91,28 @@
|
||||
var utcHour = Math.floor(utc / 3600);
|
||||
var utcMinute = Math.floor((utc % 3600) / 60);
|
||||
var utcStr = utcHour.toString().padStart(2, '0') + ":" + utcMinute.toString().padStart(2, '0');
|
||||
g.setFontAlign(0, 0).setFont("Vector", 36).drawString(utcStr, x-25, y+43);
|
||||
g.setFontAlign(0, 0).setFont("Vector", 36).drawString(utcStr, x-32, y+43);
|
||||
|
||||
var tz_offset = date.toString().indexOf("GMT");
|
||||
var tz = date.toString().substring(tz_offset+3, tz_offset+6);
|
||||
g.setFontAlign(0, 0).setFont("Vector", 24).drawString(tz, x+60, y+43);
|
||||
//var tz_offset = date.toString().indexOf("GMT");
|
||||
//var tz = date.toString().substring(tz_offset+3, tz_offset+6);
|
||||
//g.setFontAlign(0, 0).setFont("Vector", 24).drawString(tz, x+60, y+43);
|
||||
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(temperature, x+53, y+43);
|
||||
|
||||
// Show date and day of week
|
||||
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
||||
var dateStr = date.getDate() + " " + days[date.getDay()] + " " + temperature;
|
||||
var dateStr = date.getDate() + " " + days[date.getDay()];
|
||||
|
||||
// don't draw date string if stopwatch 2 is running
|
||||
if (!stopWatch.start2 && !stopWatch.elapsed2) {
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(dateStr, x, y+76);
|
||||
// don't draw date string if stopwatch 1 is running
|
||||
if (!stopWatch.start1 && !stopWatch.elapsed1) {
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(dateStr, x-32, y+74);
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(feels_like, x+53, y+74);
|
||||
}
|
||||
|
||||
//var wrapped = g.wrapString(myMessage, g.getWidth()-10).join("\n");
|
||||
|
||||
// don't draw message if stopwatch 1 is running
|
||||
if (!stopWatch.start1 && !stopWatch.elapsed1) {
|
||||
// don't draw message if stopwatch 2 is running
|
||||
if (!stopWatch.start2 && !stopWatch.elapsed2) {
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(myMessage, x, y-45);
|
||||
}
|
||||
|
||||
@@ -107,6 +126,7 @@
|
||||
let result = JSON.parse(event.resp);
|
||||
myMessage = result.context;
|
||||
temperature = result.temperature;
|
||||
feels_like = result.feels_like;
|
||||
if (watchState == STATE_IDLE) {
|
||||
if (paintFace) paintFace();
|
||||
}
|
||||
@@ -193,6 +213,7 @@
|
||||
stopWatch.start1 = Date.now();
|
||||
if (!stopWatch.elapsed1) {
|
||||
stopWatch.elapsed1 = 0;
|
||||
stopWatch.buzz1 = 0;
|
||||
}
|
||||
saveStopWatch();
|
||||
|
||||
@@ -207,6 +228,7 @@
|
||||
stopWatch.start2 = Date.now();
|
||||
if (!stopWatch.elapsed2) {
|
||||
stopWatch.elapsed2 = 0;
|
||||
stopWatch.buzzed2 = false;
|
||||
}
|
||||
saveStopWatch();
|
||||
|
||||
@@ -233,6 +255,7 @@
|
||||
let stopSW1 = function() {
|
||||
stopWatch.start1 = null;
|
||||
stopWatch.elapsed1 = null;
|
||||
stopWatch.buzz1 = null;
|
||||
saveStopWatch();
|
||||
|
||||
if (!stopWatch.start2) {
|
||||
@@ -260,6 +283,7 @@
|
||||
let stopSW2 = function() {
|
||||
stopWatch.start2 = null;
|
||||
stopWatch.elapsed2 = null;
|
||||
stopWatch.buzzed2 = null;
|
||||
saveStopWatch();
|
||||
|
||||
if (!stopWatch.start1) {
|
||||
@@ -403,7 +427,7 @@
|
||||
Bangle.removeListener('twist', handleTwist);
|
||||
if (drawTimer) clearTimeout(drawTimer);
|
||||
drawTimer = undefined;
|
||||
if (stopWatchTimer) clearTimeout(stopWatchTimer);
|
||||
if (stopWatchTimer) clearInterval(stopWatchTimer);
|
||||
stopWatchTimer = undefined;
|
||||
|
||||
paintFace = undefined; // http request may resolve after font's been unloaded, so unset
|
||||
|
||||
Reference in New Issue
Block a user