Skip to content

Commit 719fff9

Browse files
author
thyttan
committed
Merge branch 'ateatimer' into app-loader
2 parents f99995c + 5537669 commit 719fff9

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

apps/ateatimer/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
0.01: First release
2-
0.02: Fix icon, utilize sched, show running timer on app relaunch
2+
0.02: Fix icon, utilize sched, show running timer on app relaunch
3+
0.03: Flash time in green when starting the timer.

apps/ateatimer/app.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
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?0x07E0:0x03E0;
7+
38
let timerDuration = (() => {
49
let file = require("Storage").open("ateatimer.data", "r");
510
let data = file.read(4); // Assuming 4 bytes for storage
@@ -14,7 +19,7 @@ function saveDefaultDuration() {
1419
}
1520

1621
function drawTime() {
17-
g.clear();
22+
g.clearRect(middleRect);
1823
g.setFont("Vector", 40);
1924
g.setFontAlign(0, 0); // Center align
2025

@@ -25,6 +30,10 @@ function drawTime() {
2530

2631
g.drawString(timeStr, g.getWidth() / 2, g.getHeight() / 2);
2732

33+
g.flip();
34+
}
35+
36+
function drawButtons() {
2837
// Draw Increase button (triangle pointing up)
2938
g.fillPoly([
3039
g.getWidth() / 2, g.getHeight() / 2 - 80, // Top vertex
@@ -42,6 +51,18 @@ function drawTime() {
4251
g.flip();
4352
}
4453

54+
function drawInit() {
55+
g.clear(true);
56+
drawButtons();
57+
drawTime();
58+
}
59+
60+
let updateIntervalID;
61+
let clearUpdateInterval = ()=>{
62+
clearInterval(updateIntervalID);
63+
updateIntervalID = undefined;
64+
}
65+
4566
function startTimer() {
4667
if (timerRunning) return;
4768
if (timeRemaining == 0) return;
@@ -52,8 +73,13 @@ function startTimer() {
5273
saveDefaultDuration();
5374
scheduleTimer();
5475

76+
// Flash the time in green to indicate the timer started
77+
g.setColor(GREEN);
78+
drawTime();
79+
g.reset();
80+
5581
// Start the secondary timer to update the display
56-
setInterval(updateDisplay, 1000);
82+
updateIntervalID = setInterval(updateDisplay, 1000);
5783
}
5884

5985
function scheduleTimer() {
@@ -73,6 +99,7 @@ function resetTimer() {
7399
require("sched").setAlarm("ateatimer", undefined);
74100
require("sched").reload();
75101

102+
clearUpdateInterval();
76103
timerRunning = false;
77104
timeRemaining = timerDuration;
78105
drawTime();
@@ -125,7 +152,7 @@ function updateDisplay() {
125152
drawTime();
126153
if (timeRemaining <= 0) {
127154
timeRemaining = 0;
128-
clearInterval(updateDisplay);
155+
clearUpdateInterval();
129156
timerRunning = false;
130157
}
131158
}
@@ -146,11 +173,10 @@ Bangle.on("touch", (zone, xy) => {
146173
});
147174

148175
let isRunning = require("sched").getAlarm("ateatimer");
176+
// Draw the initial timer display
177+
drawInit();
149178
if (isRunning) {
150179
timerRunning = true;
151180
// Start the timer to update the display
152-
setInterval(updateDisplay, 1000);
153-
} else {
154-
// Draw the initial timer display
155-
drawTime();
156-
}
181+
updateIntervalID = setInterval(updateDisplay, 1000);
182+
}

apps/ateatimer/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "A Tea Timer",
33
"shortName":"A Tea Timer",
44
"icon": "app.png",
5-
"version":"0.02",
5+
"version":"0.03",
66
"description": "Simple app for setting timers for tea. Touch up and down to change time, and time or button to start counting. When timer is running, button will stop timer and reset counter to last used value.",
77
"tags": "timer",
88
"supports": ["BANGLEJS2"],

0 commit comments

Comments
 (0)