Skip to content

Commit 000d8b7

Browse files
authored
Merge pull request #4087 from fparri/patch-2
Implement SOS mode with color selection
2 parents 0b42f53 + 2b57311 commit 000d8b7

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

apps/wristlight/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
0.01: New app!
22
0.02: Minor code improvements
3+
0.03: Added SOS blinking functionality with user-selected color and touch interaction to set the main screen color. Minor code improvements

apps/wristlight/app.js

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
var sosInterval;
2+
var currentColor = "#ffffff"; // last selected color
3+
14
function draw(color) {
25
if (color == undefined) {
36
color = -1;
47
}
58
g.clear();
69
g.setColor(color);
710
g.fillRect(0, 0, g.getWidth(), g.getHeight());
8-
}
911

10-
function draw2Pattern() {
11-
const colors = ["ff0000", "8080ff", "00ff00",
12-
"ffffff"];
13-
drawPattern(2, colors);
12+
// Store the current color only if it is a valid user-selected color
13+
// "#000000" is used internally when blinking (SOS off state)
14+
if (typeof color === "string" && color !== "#000000") currentColor = color;
1415
}
1516

1617
function draw3Pattern() {
@@ -24,22 +25,62 @@ function drawPattern(size, colors) {
2425
g.clear();
2526
var w = g.getWidth() / size;
2627
var h = g.getHeight() / size;
28+
29+
// Draw selectable color blocks
2730
for (var i = 0; i < size; i++) {
2831
for (var j = 0; j < size; j++) {
2932
var color = colors[i*size + j];
3033
g.setColor("#" + color);
3134
g.fillRect(j * w, i * h, j * w + w, i * h + h);
3235
}
3336
}
37+
38+
// Touching a block sets the main screen color
3439
Bangle.on("touch", function(btn, xy) {
40+
// If SOS mode is active, stop it when user interacts
41+
if (sosInterval) {
42+
clearInterval(sosInterval);
43+
sosInterval = undefined;
44+
}
45+
3546
var x = parseInt((xy.x) / w);
3647
var y = parseInt((xy.y) / h);
3748
draw("#" + colors[y * size + x]);
3849
});
3950
}
4051

41-
// Clear the screen once, at startup
42-
// draw immediately at first
52+
// Start SOS blinking using the selected color
53+
function startSOS() {
54+
if (sosInterval) return;
55+
var on = false;
56+
sosInterval = setInterval(function() {
57+
on = !on;
58+
if (on) {
59+
draw(currentColor); // active/on state
60+
} else {
61+
draw("#000000"); // off/black state
62+
}
63+
}, 200); // blinking frequency
64+
}
65+
66+
// Stop SOS blinking
67+
function stopSOS() {
68+
if (sosInterval) {
69+
clearInterval(sosInterval);
70+
sosInterval = undefined;
71+
}
72+
}
73+
74+
// Toggle SOS mode using the hardware button
75+
setWatch(function() {
76+
if (sosInterval) {
77+
stopSOS();
78+
} else {
79+
startSOS();
80+
}
81+
}, BTN1, {repeat:true, edge:"rising"});
82+
83+
// Show the color grid at startup
4384
draw3Pattern();
4485

4586
/*

apps/wristlight/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Wrist Light",
33
"shortName":"Wrist Light",
44
"icon": "wristlight48.png",
5-
"version": "0.02",
5+
"version": "0.03",
66
"description": "A flash light with different colors on your wrist",
77
"tags": "flash,light",
88
"allow_emulator":true,

0 commit comments

Comments
 (0)