Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4aa62b4
Add files via upload
eholstine Feb 23, 2026
2afebfa
Delete apps/Sun_Moon_Watch.js
eholstine Feb 23, 2026
d39eea8
Delete apps/sunmoonclk.img
eholstine Feb 23, 2026
eb9bbea
Delete apps/sunmoonclk.info
eholstine Feb 23, 2026
2b9bcdf
Delete apps/sunmoonclk.png
eholstine Feb 23, 2026
dd618e6
Create sunmoonclk
eholstine Feb 23, 2026
fbf5e70
Delete apps/sunmoonclk
eholstine Feb 23, 2026
c278cc2
Create sunmoonclk.js
eholstine Feb 23, 2026
1d2a02a
Delete apps/sunmoonclk/sunmoonclk.js
eholstine Feb 23, 2026
7cff19f
Create test.js
eholstine Feb 23, 2026
8d4d2ae
Add files via upload
eholstine Feb 23, 2026
e522ac9
Delete apps/sunmoonclk/test.js
eholstine Feb 23, 2026
bc42c9f
Add files via upload
eholstine Feb 25, 2026
fd49c16
Delete apps/sunmoonclk/screenshot (1).png
eholstine Feb 25, 2026
2a48ee9
Delete apps/sunmoonclk/screenshot (2).png
eholstine Feb 25, 2026
87f9e94
Add files via upload
eholstine Feb 25, 2026
41da040
Add files via upload
eholstine Feb 25, 2026
59d6cce
Update metadata.json
eholstine Feb 25, 2026
ee968e4
Merge branch 'espruino:master' into master
eholstine Feb 25, 2026
31514f4
Delete apps/sunmoonclk/Sun_Moon_Watch.js
eholstine Feb 25, 2026
b37ad5c
Delete apps/sunmoonclk/sunmoonclk.info
eholstine Feb 25, 2026
2c072c6
Add files via upload
eholstine Feb 25, 2026
bf883ea
Update metadata.json
eholstine Feb 25, 2026
4c4291e
Delete apps/sunmoonclk directory
eholstine Feb 26, 2026
e4aebe4
Revert "Delete apps/sunmoonclk directory"
bobrippling Feb 27, 2026
c36684d
sunmoon: add changelog and fix metadata/filenames
bobrippling Feb 27, 2026
c5fec1e
Update app-icon.js
eholstine Mar 1, 2026
bd55b8d
Update metadata.json
eholstine Mar 2, 2026
2761890
Update metadata.json
eholstine Mar 2, 2026
6cb4c8a
Update app-icon.js
eholstine Mar 2, 2026
3c4e172
Merge branch 'espruino:master' into master
eholstine Mar 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/sunmoonclk/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.01: Initial app
1 change: 1 addition & 0 deletions apps/sunmoonclk/app-icon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 102 additions & 0 deletions apps/sunmoonclk/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Load fonts
require("Font7x11Numeric7Seg").add(Graphics);
// X/Y are the position of the bottom right of the HH:MM text - make it central!
const X = g.getWidth()/2 + 45,
Y = g.getHeight()/2 + 40;

function draw() {
// work out how to display the current time
var d = new Date();
var clock = require("locale").time(d, 1 /*omit seconds*/);
var seconds = d.getSeconds().toString().padStart(2,0);
var meridian = require("locale").meridian(d);

// Reset the state of the graphics library
g.reset();
// draw the current time (4x size 7 segment)
g.setFontAlign(1,1); // align bottom right
g.setFont("7x11Numeric7Seg:4");
g.drawString(clock, X, Y, true /*clear background*/);
// draw the meridian(am/pm) and seconds (2x size 7 segment)
g.setFontAlign(-1,1); // align bottom left
g.setFont("6x8:2");
g.drawString(meridian, X+4, Y-26, true /*clear background*/);
g.setFont("7x11Numeric7Seg:2");
g.drawString(seconds, X+2, Y, true /*clear background*/);
// draw the date, in a normal font
g.setFont("6x8", 2);
g.setFontAlign(0,-40); // align center bottom
// pad the date - this clears the background if the date were to change length
var dateStr = " "+require("locale").date(d)+" ";
g.drawString(dateStr, g.getWidth()/2, Y+15, true /*clear background*/);

// Get current time
let now = new Date();
let h = now.getHours();
let m = now.getMinutes();
let timeStr = ("0" + h).slice(-2) + ":" + ("0" + m).slice(-2);

// Draw sun or moon icon
if (h >= 6 && h < 18) {
drawSun(g.getWidth()/2, g.getHeight()/2 - 38);
} else {
clearSun(g.getWidth()/2, g.getHeight()/2 - 38);
drawMoon(g.getWidth()/2, g.getHeight()/2 - 38);
}
}

function drawSun(x, y) {
g.setColor("#FF8C00"); // orange
g.fillCircle(x, y, 12);
for (let i = 0; i < 8; i++) {
let angle = i * Math.PI / 4;
g.drawLine(
x + Math.cos(angle) * 16,
y + Math.sin(angle) * 16,
x + Math.cos(angle) * 22,
y + Math.sin(angle) * 22
);
}
}
function clearSun(x, y) {
g.setColor("#000000"); // black
g.fillCircle(x, y, 12);
for (let i = 0; i < 8; i++) {
let angle = i * Math.PI / 4;
g.drawLine(
x + Math.cos(angle) * 16,
y + Math.sin(angle) * 16,
x + Math.cos(angle) * 22,
y + Math.sin(angle) * 22
);
}
}
function drawMoon(x, y) {
g.setColor("#F5F5F5"); // white smoke
g.fillCircle(x, y, 12);
g.setColor(0, 0, 0); // mask for crescent
g.fillCircle(x + 5, y - 2, 12);
}

// Clear the screen once, at startup
g.clear();
// draw immediately at first
draw();
// now draw every second
var secondInterval = setInterval(draw, 1000);
// Stop updates when LCD is off, restart when on
Bangle.on('lcdPower',on=>{
if (secondInterval) clearInterval(secondInterval);
secondInterval = undefined;
if (on) {
secondInterval = setInterval(draw, 1000);
draw(); // draw immediately
}
});
/* Show launcher when middle button pressed
This should be done *before* Bangle.loadWidgets so that
widgets know if they're being loaded into a clock app or not */
Bangle.setUI("clock");
// Load widgets
Bangle.loadWidgets();
Bangle.drawWidgets();
22 changes: 22 additions & 0 deletions apps/sunmoonclk/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"id": "sunmoonclk",
"name": "Sun and Moon Clock",
"version": "0.01",
"author": "ehartwork",
"description": "A basic clock with sun and moon images to represent day and night hours. Day is set from 6:00 AM to 5:59 PM and night is set from 6:00 PM to 5:59 AM.",
"icon": "sunmoonclk.png",
"screenshots": [{"url":"screenshot_sun.png"},
{"url":"screenshot_moon.png"}],
"type": "clock",
"tags": "clock",
"supports": ["BANGLEJS","BANGLEJS2"],
"allow_emulator": true,
"storage": [
{"name":"sunmoonclk.app.js","url":"app.js"},
{"name":"sunmoonclk.img","url":"app-icon.js","evaluate":true}
]

}



Binary file added apps/sunmoonclk/screenshot_moon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/sunmoonclk/screenshot_sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/sunmoonclk/sunmoonclk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading