Compare commits

..

7 Commits

Author SHA1 Message Date
Tanner 4c506c7913 Make weather or temp data grey if it's old 2026-06-13 11:24:21 -06:00
tanner 8275abdb57 Swap stop watch positions 2026-03-12 12:58:52 -06:00
tanner 1c433fc56b Display both feels like and outdoor temperatures 2026-03-12 12:52:51 -06:00
tanner 14bda5c29f Use clearInterval to clear the stopwatch interval 2026-03-10 16:58:57 -06:00
tanner ea58f2101f Increase buzz duration 2026-03-10 16:54:44 -06:00
tanner 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
tanner 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
+49 -17
View File
@@ -11,14 +11,17 @@
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 temp_old = true;
let feels_like = "?";
let weather_old = true;
let drawTimer = null; let drawTimer = null;
@@ -37,24 +40,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 +93,32 @@
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);
if (temp_old) g.setColor("#888");
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(temperature, x+53, y+43);
g.setColor(g.theme.fg);
// 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);
if (weather_old) g.setColor("#888");
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(feels_like, x+53, y+74);
g.setColor(g.theme.fg);
} }
//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 +132,9 @@
let result = JSON.parse(event.resp); let result = JSON.parse(event.resp);
myMessage = result.context; myMessage = result.context;
temperature = result.temperature; temperature = result.temperature;
temp_old = result.temp_old;
feels_like = result.feels_like;
weather_old = result.weather_old;
if (watchState == STATE_IDLE) { if (watchState == STATE_IDLE) {
if (paintFace) paintFace(); if (paintFace) paintFace();
} }
@@ -193,6 +221,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 +236,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 +263,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 +291,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 +435,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