Skip to content

Commit 43b8ff2

Browse files
author
thyttan
committed
ateatimer: make time flash green when starting timer
1 parent c5f326a commit 43b8ff2

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

apps/ateatimer/app.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// Tea Timer Application for Bangle.js 2 using sched library
22

3+
let appRect = Bangle.appRect;
4+
let middleY = appRect.y+appRect.w/2;
5+
let middleRect = {x:appRect.x, y:middleY-20, w:appRect.w, h:40}
6+
let GREEN = g.theme.dark?0x03E0:0x07E0;
7+
8+
39
let timerDuration = (() => {
410
let file = require("Storage").open("ateatimer.data", "r");
511
let data = file.read(4); // Assuming 4 bytes for storage
@@ -14,7 +20,7 @@ function saveDefaultDuration() {
1420
}
1521

1622
function drawTime() {
17-
g.clear();
23+
g.clearRect(middleRect);
1824
g.setFont("Vector", 40);
1925
g.setFontAlign(0, 0); // Center align
2026

@@ -25,6 +31,10 @@ function drawTime() {
2531

2632
g.drawString(timeStr, g.getWidth() / 2, g.getHeight() / 2);
2733

34+
g.flip();
35+
}
36+
37+
function drawButtons() {
2838
// Draw Increase button (triangle pointing up)
2939
g.fillPoly([
3040
g.getWidth() / 2, g.getHeight() / 2 - 80, // Top vertex
@@ -42,6 +52,12 @@ function drawTime() {
4252
g.flip();
4353
}
4454

55+
function drawInit() {
56+
g.clear(true);
57+
drawButtons();
58+
drawTime();
59+
}
60+
4561
function startTimer() {
4662
if (timerRunning) return;
4763
if (timeRemaining == 0) return;
@@ -52,6 +68,11 @@ function startTimer() {
5268
saveDefaultDuration();
5369
scheduleTimer();
5470

71+
// Flash the time in green to indicate the timer started
72+
g.setColor(GREEN)
73+
drawTime();
74+
g.reset();
75+
5576
// Start the secondary timer to update the display
5677
setInterval(updateDisplay, 1000);
5778
}
@@ -125,7 +146,7 @@ function updateDisplay() {
125146
drawTime();
126147
if (timeRemaining <= 0) {
127148
timeRemaining = 0;
128-
clearInterval(updateDisplay);
149+
clearInterval(updateDisplay); // FIX: Improper argument, should be a int returned when calling setInterval, not the function name.
129150
timerRunning = false;
130151
}
131152
}
@@ -146,11 +167,10 @@ Bangle.on("touch", (zone, xy) => {
146167
});
147168

148169
let isRunning = require("sched").getAlarm("ateatimer");
170+
// Draw the initial timer display
171+
drawInit();
149172
if (isRunning) {
150173
timerRunning = true;
151174
// Start the timer to update the display
152175
setInterval(updateDisplay, 1000);
153-
} else {
154-
// Draw the initial timer display
155-
drawTime();
156-
}
176+
}

0 commit comments

Comments
 (0)