Skip to content

Commit ceeac6c

Browse files
committed
[widalarmeta] Add option to only show when on clock
1 parent 7675484 commit ceeac6c

File tree

4 files changed

+55
-39
lines changed

4 files changed

+55
-39
lines changed

apps/widalarmeta/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
0.10: Change 4x5 font to 6x8, teletext is now default font
1515
0.11: Bugfix: handle changes in alarms (e.g. done without a load, such as via fastload)
1616
0.12: Redraw when screen turns on or watch is unlocked
17+
0.13: Add option to only show when on clock

apps/widalarmeta/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "widalarmeta",
33
"name": "Alarm & Timer ETA",
44
"shortName": "Alarm ETA",
5-
"version": "0.12",
5+
"version": "0.13",
66
"description": "A widget that displays the time to the next Alarm or Timer in hours and minutes, maximum 24h (configurable).",
77
"icon": "widget.png",
88
"type": "widget",

apps/widalarmeta/settings.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
padHours: true,
88
showSeconds: 0, // 0=never, 1=only when display is unlocked, 2=for less than a minute
99
font: 1, // 0=segment style font, 1=teletext font, 2=6x8:1x2
10+
whenToShow: 0, // 0=always, 1=on clock only
1011
}, require("Storage").readJSON(CONFIGFILE,1) || {});
1112

1213
function writeSettings() {
@@ -59,5 +60,14 @@
5960
writeSettings();
6061
}
6162
},
63+
/*LANG*/'When To Show': {
64+
value: settings.whenToShow,
65+
min: 0, max: 1,
66+
format: v => [/*LANG*/"Always", /*LANG*/"On Clock Only"][v === undefined ? 0 : v],
67+
onchange: v => {
68+
settings.whenToShow = v;
69+
writeSettings();
70+
}
71+
},
6272
});
6373
})

apps/widalarmeta/widget.js

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
padHours: true,
99
showSeconds: 0, // 0=never, 1=only when display is unlocked, 2=for less than a minute
1010
font: 1, // 0=segment style font, 1=teletext font, 2=6x8:1x2
11+
whenToShow: 0, // 0=always, 1=on clock only
1112
}, require("Storage").readJSON("widalarmeta.json",1) || {});
1213

1314
if (config.font == 0) {
@@ -55,44 +56,48 @@
5556
let calcWidth = 0;
5657
let drawSeconds = false;
5758

58-
if (next > 0 && next <= config.maxhours*60*60*1000) {
59-
const hours = Math.floor((next-1) / 3600000).toString();
60-
const minutes = Math.floor(((next-1) % 3600000) / 60000).toString();
61-
const seconds = Math.floor(((next-1) % 60000) / 1000).toString();
62-
drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60);
63-
64-
g.reset(); // reset the graphics context to defaults (color/font/etc)
65-
g.setFontAlign(-1,0); // center font in y direction
66-
g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23);
67-
68-
var text = "";
69-
if (config.padHours) {
70-
text += hours.padStart(2, '0');
71-
} else {
72-
text += hours;
73-
}
74-
text += ":" + minutes.padStart(2, '0');
75-
if (drawSeconds) {
76-
text += ":" + seconds.padStart(2, '0');
77-
}
78-
if (config.font == 0) {
79-
g.setFont("5x9Numeric7Seg:1x2");
80-
} else if (config.font == 1) {
81-
g.setFont("Teletext5x9Ascii:1x2");
82-
} else {
83-
// Default to this if no other font is set.
84-
g.setFont("6x8:1x2");
85-
}
86-
g.drawString(text, this.x+1, this.y+12);
87-
88-
calcWidth = g.stringWidth(text) + 2; // One pixel on each side
89-
this.bellVisible = false;
90-
} else if (config.drawBell && this.numActiveAlarms > 0) {
91-
calcWidth = 24;
92-
// next alarm too far in future, draw only widalarm bell
93-
if (this.bellVisible !== true || fromInterval !== true) {
94-
g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y);
95-
this.bellVisible = true;
59+
// If always showing, or the clock is visible
60+
if (config.whenToShow === 0 || Bangle.CLOCK) {
61+
// Determine text and width
62+
if (next > 0 && next <= config.maxhours*60*60*1000) {
63+
const hours = Math.floor((next-1) / 3600000).toString();
64+
const minutes = Math.floor(((next-1) % 3600000) / 60000).toString();
65+
const seconds = Math.floor(((next-1) % 60000) / 1000).toString();
66+
drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60);
67+
68+
g.reset(); // reset the graphics context to defaults (color/font/etc)
69+
g.setFontAlign(-1,0); // center font in y direction
70+
g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23);
71+
72+
var text = "";
73+
if (config.padHours) {
74+
text += hours.padStart(2, '0');
75+
} else {
76+
text += hours;
77+
}
78+
text += ":" + minutes.padStart(2, '0');
79+
if (drawSeconds) {
80+
text += ":" + seconds.padStart(2, '0');
81+
}
82+
if (config.font == 0) {
83+
g.setFont("5x9Numeric7Seg:1x2");
84+
} else if (config.font == 1) {
85+
g.setFont("Teletext5x9Ascii:1x2");
86+
} else {
87+
// Default to this if no other font is set.
88+
g.setFont("6x8:1x2");
89+
}
90+
g.drawString(text, this.x+1, this.y+12);
91+
92+
calcWidth = g.stringWidth(text) + 2; // One pixel on each side
93+
this.bellVisible = false;
94+
} else if (config.drawBell && this.numActiveAlarms > 0) {
95+
calcWidth = 24;
96+
// next alarm too far in future, draw only widalarm bell
97+
if (this.bellVisible !== true || fromInterval !== true) {
98+
g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y);
99+
this.bellVisible = true;
100+
}
96101
}
97102
}
98103

0 commit comments

Comments
 (0)