Compare commits

...

6 Commits

Author SHA1 Message Date
8275abdb57 Swap stop watch positions 2026-03-12 12:58:52 -06:00
1c433fc56b Display both feels like and outdoor temperatures 2026-03-12 12:52:51 -06:00
14bda5c29f Use clearInterval to clear the stopwatch interval 2026-03-10 16:58:57 -06:00
ea58f2101f Increase buzz duration 2026-03-10 16:54:44 -06:00
07bb582ddd feat: Initialize buzz state for stopwatches
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
2026-03-10 16:22:44 -06:00
6d965dd016 feat: Add timed buzzing alerts to stopwatches
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
2026-03-10 16:22:18 -06:00

View File

@@ -11,14 +11,15 @@
let watchState = STATE_IDLE; 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() { let saveStopWatch = function() {
require("Storage").writeJSON("mystopwatch.json", stopWatch); require("Storage").writeJSON("mystopwatch.json", stopWatch);
} }
let stopWatchTimer = null; let stopWatchTimer = null;
let myMessage = ""; let myMessage = "";
let temperature = ""; let temperature = "?";
let feels_like = "?";
let drawTimer = null; let drawTimer = null;
@@ -37,24 +38,39 @@
let Tt1 = (stopWatch.elapsed1 || 0); let Tt1 = (stopWatch.elapsed1 || 0);
if (stopWatch.start1) { if (stopWatch.start1) {
Tt1 += Date.now() - 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); 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.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) { if (stopWatch.start2 || stopWatch.elapsed2) {
let Tt2 = (stopWatch.elapsed2 || 0); let Tt2 = (stopWatch.elapsed2 || 0);
if (stopWatch.start2) { if (stopWatch.start2) {
Tt2 += Date.now() - 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); 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.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 utcHour = Math.floor(utc / 3600);
var utcMinute = Math.floor((utc % 3600) / 60); var utcMinute = Math.floor((utc % 3600) / 60);
var utcStr = utcHour.toString().padStart(2, '0') + ":" + utcMinute.toString().padStart(2, '0'); 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_offset = date.toString().indexOf("GMT");
var tz = date.toString().substring(tz_offset+3, tz_offset+6); //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", 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 // Show date and day of week
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; 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 // don't draw date string if stopwatch 1 is running
if (!stopWatch.start2 && !stopWatch.elapsed2) { if (!stopWatch.start1 && !stopWatch.elapsed1) {
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(dateStr, x, y+76); 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"); //var wrapped = g.wrapString(myMessage, g.getWidth()-10).join("\n");
// don't draw message if stopwatch 1 is running // don't draw message if stopwatch 2 is running
if (!stopWatch.start1 && !stopWatch.elapsed1) { if (!stopWatch.start2 && !stopWatch.elapsed2) {
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(myMessage, x, y-45); g.setFontAlign(0, 0).setFont("Vector", 26).drawString(myMessage, x, y-45);
} }
@@ -107,6 +126,7 @@
let result = JSON.parse(event.resp); let result = JSON.parse(event.resp);
myMessage = result.context; myMessage = result.context;
temperature = result.temperature; temperature = result.temperature;
feels_like = result.feels_like;
if (watchState == STATE_IDLE) { if (watchState == STATE_IDLE) {
if (paintFace) paintFace(); if (paintFace) paintFace();
} }
@@ -193,6 +213,7 @@
stopWatch.start1 = Date.now(); stopWatch.start1 = Date.now();
if (!stopWatch.elapsed1) { if (!stopWatch.elapsed1) {
stopWatch.elapsed1 = 0; stopWatch.elapsed1 = 0;
stopWatch.buzz1 = 0;
} }
saveStopWatch(); saveStopWatch();
@@ -207,6 +228,7 @@
stopWatch.start2 = Date.now(); stopWatch.start2 = Date.now();
if (!stopWatch.elapsed2) { if (!stopWatch.elapsed2) {
stopWatch.elapsed2 = 0; stopWatch.elapsed2 = 0;
stopWatch.buzzed2 = false;
} }
saveStopWatch(); saveStopWatch();
@@ -233,6 +255,7 @@
let stopSW1 = function() { let stopSW1 = function() {
stopWatch.start1 = null; stopWatch.start1 = null;
stopWatch.elapsed1 = null; stopWatch.elapsed1 = null;
stopWatch.buzz1 = null;
saveStopWatch(); saveStopWatch();
if (!stopWatch.start2) { if (!stopWatch.start2) {
@@ -260,6 +283,7 @@
let stopSW2 = function() { let stopSW2 = function() {
stopWatch.start2 = null; stopWatch.start2 = null;
stopWatch.elapsed2 = null; stopWatch.elapsed2 = null;
stopWatch.buzzed2 = null;
saveStopWatch(); saveStopWatch();
if (!stopWatch.start1) { if (!stopWatch.start1) {
@@ -403,7 +427,7 @@
Bangle.removeListener('twist', handleTwist); Bangle.removeListener('twist', handleTwist);
if (drawTimer) clearTimeout(drawTimer); if (drawTimer) clearTimeout(drawTimer);
drawTimer = undefined; drawTimer = undefined;
if (stopWatchTimer) clearTimeout(stopWatchTimer); if (stopWatchTimer) clearInterval(stopWatchTimer);
stopWatchTimer = undefined; stopWatchTimer = undefined;
paintFace = undefined; // http request may resolve after font's been unloaded, so unset paintFace = undefined; // http request may resolve after font's been unloaded, so unset