[widalarmeta] Add option to only show when on clock

master
Logan B 2025-07-30 20:39:56 -05:00
parent 7675484149
commit ceeac6cbb3
No known key found for this signature in database
4 changed files with 52 additions and 36 deletions

View File

@ -14,3 +14,4 @@
0.10: Change 4x5 font to 6x8, teletext is now default font 0.10: Change 4x5 font to 6x8, teletext is now default font
0.11: Bugfix: handle changes in alarms (e.g. done without a load, such as via fastload) 0.11: Bugfix: handle changes in alarms (e.g. done without a load, such as via fastload)
0.12: Redraw when screen turns on or watch is unlocked 0.12: Redraw when screen turns on or watch is unlocked
0.13: Add option to only show when on clock

View File

@ -2,7 +2,7 @@
"id": "widalarmeta", "id": "widalarmeta",
"name": "Alarm & Timer ETA", "name": "Alarm & Timer ETA",
"shortName": "Alarm ETA", "shortName": "Alarm ETA",
"version": "0.12", "version": "0.13",
"description": "A widget that displays the time to the next Alarm or Timer in hours and minutes, maximum 24h (configurable).", "description": "A widget that displays the time to the next Alarm or Timer in hours and minutes, maximum 24h (configurable).",
"icon": "widget.png", "icon": "widget.png",
"type": "widget", "type": "widget",

View File

@ -7,6 +7,7 @@
padHours: true, padHours: true,
showSeconds: 0, // 0=never, 1=only when display is unlocked, 2=for less than a minute showSeconds: 0, // 0=never, 1=only when display is unlocked, 2=for less than a minute
font: 1, // 0=segment style font, 1=teletext font, 2=6x8:1x2 font: 1, // 0=segment style font, 1=teletext font, 2=6x8:1x2
whenToShow: 0, // 0=always, 1=on clock only
}, require("Storage").readJSON(CONFIGFILE,1) || {}); }, require("Storage").readJSON(CONFIGFILE,1) || {});
function writeSettings() { function writeSettings() {
@ -59,5 +60,14 @@
writeSettings(); writeSettings();
} }
}, },
/*LANG*/'When To Show': {
value: settings.whenToShow,
min: 0, max: 1,
format: v => [/*LANG*/"Always", /*LANG*/"On Clock Only"][v === undefined ? 0 : v],
onchange: v => {
settings.whenToShow = v;
writeSettings();
}
},
}); });
}) })

View File

@ -8,6 +8,7 @@
padHours: true, padHours: true,
showSeconds: 0, // 0=never, 1=only when display is unlocked, 2=for less than a minute showSeconds: 0, // 0=never, 1=only when display is unlocked, 2=for less than a minute
font: 1, // 0=segment style font, 1=teletext font, 2=6x8:1x2 font: 1, // 0=segment style font, 1=teletext font, 2=6x8:1x2
whenToShow: 0, // 0=always, 1=on clock only
}, require("Storage").readJSON("widalarmeta.json",1) || {}); }, require("Storage").readJSON("widalarmeta.json",1) || {});
if (config.font == 0) { if (config.font == 0) {
@ -55,44 +56,48 @@
let calcWidth = 0; let calcWidth = 0;
let drawSeconds = false; let drawSeconds = false;
if (next > 0 && next <= config.maxhours*60*60*1000) { // If always showing, or the clock is visible
const hours = Math.floor((next-1) / 3600000).toString(); if (config.whenToShow === 0 || Bangle.CLOCK) {
const minutes = Math.floor(((next-1) % 3600000) / 60000).toString(); // Determine text and width
const seconds = Math.floor(((next-1) % 60000) / 1000).toString(); if (next > 0 && next <= config.maxhours*60*60*1000) {
drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60); const hours = Math.floor((next-1) / 3600000).toString();
const minutes = Math.floor(((next-1) % 3600000) / 60000).toString();
const seconds = Math.floor(((next-1) % 60000) / 1000).toString();
drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60);
g.reset(); // reset the graphics context to defaults (color/font/etc) g.reset(); // reset the graphics context to defaults (color/font/etc)
g.setFontAlign(-1,0); // center font in y direction g.setFontAlign(-1,0); // center font in y direction
g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23); g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23);
var text = ""; var text = "";
if (config.padHours) { if (config.padHours) {
text += hours.padStart(2, '0'); text += hours.padStart(2, '0');
} else { } else {
text += hours; text += hours;
} }
text += ":" + minutes.padStart(2, '0'); text += ":" + minutes.padStart(2, '0');
if (drawSeconds) { if (drawSeconds) {
text += ":" + seconds.padStart(2, '0'); text += ":" + seconds.padStart(2, '0');
} }
if (config.font == 0) { if (config.font == 0) {
g.setFont("5x9Numeric7Seg:1x2"); g.setFont("5x9Numeric7Seg:1x2");
} else if (config.font == 1) { } else if (config.font == 1) {
g.setFont("Teletext5x9Ascii:1x2"); g.setFont("Teletext5x9Ascii:1x2");
} else { } else {
// Default to this if no other font is set. // Default to this if no other font is set.
g.setFont("6x8:1x2"); g.setFont("6x8:1x2");
} }
g.drawString(text, this.x+1, this.y+12); g.drawString(text, this.x+1, this.y+12);
calcWidth = g.stringWidth(text) + 2; // One pixel on each side calcWidth = g.stringWidth(text) + 2; // One pixel on each side
this.bellVisible = false; this.bellVisible = false;
} else if (config.drawBell && this.numActiveAlarms > 0) { } else if (config.drawBell && this.numActiveAlarms > 0) {
calcWidth = 24; calcWidth = 24;
// next alarm too far in future, draw only widalarm bell // next alarm too far in future, draw only widalarm bell
if (this.bellVisible !== true || fromInterval !== true) { if (this.bellVisible !== true || fromInterval !== true) {
g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y); g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y);
this.bellVisible = true; this.bellVisible = true;
}
} }
} }