Added super simple clock

Ensure pedometer uses system colour scheme
pull/756/head
Gordon Williams 2021-05-26 21:06:48 +01:00
parent 6d1ac3b7c6
commit 7f80cb1625
7 changed files with 61 additions and 11 deletions

View File

@ -857,6 +857,19 @@
{"name":"sclock.img","url":"clock-simple-icon.js","evaluate":true}
]
},
{ "id": "s7clk",
"name": "Simple 7 segment Clock",
"icon": "icon.png",
"version":"0.04",
"description": "A simple 7 segment Clock with date",
"tags": "clock",
"type":"clock",
"allow_emulator":true,
"storage": [
{"name":"s7clk.app.js","url":"app.js"},
{"name":"s7clk.img","url":"icon.js","evaluate":true}
]
},
{ "id": "vibrclock",
"name": "Vibrate Clock",
"icon": "app.png",
@ -1125,7 +1138,7 @@
{ "id": "widpedom",
"name": "Pedometer widget",
"icon": "widget.png",
"version":"0.12",
"version":"0.13",
"description": "Daily pedometer widget",
"tags": "widget",
"type":"widget",

1
apps/s7clk/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: New App!

40
apps/s7clk/app.js Normal file
View File

@ -0,0 +1,40 @@
require("Font7x11Numeric7Seg").add(Graphics);
function draw() {
var d = new Date();
var size = Math.floor(g.getWidth()/(7*6));
var x = (g.getWidth()/2) - size*6,
y = (g.getHeight()/2) - size*7;
g.reset().clearRect(0,y,g.getWidth(),y+size*12+8);
g.setFont("7x11Numeric7Seg",size).setFontAlign(1,-1);
g.drawString(d.getHours(), x, y);
g.setFontAlign(-1,-1);
if (d.getSeconds()&1) g.drawString(":", x,y);
g.drawString(("0"+d.getMinutes()).substr(-2),x+size*4,y);
// draw seconds
g.setFont("7x11Numeric7Seg",size/2);
g.drawString(("0"+d.getSeconds()).substr(-2),x+size*18,y + size*7);
// date
var s = d.toString().split(" ").slice(0,4).join(" ");
g.reset().setFontAlign(0,-1);
g.drawString(s,g.getWidth()/2, y + size*12);
}
// Only update when display turns on
Bangle.on('lcdPower', function(on) {
if (secondInterval)
clearInterval(secondInterval);
secondInterval = undefined;
if (on)
secondInterval = setInterval(draw, 1000);
draw();
});
var secondInterval = setInterval(draw, 1000);
g.clear();
draw();
Bangle.loadWidgets();
Bangle.drawWidgets();
// Show launcher when middle button pressed
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});

1
apps/s7clk/icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mUygP/AC5BlH4MAn/gAwN/4EP/AFBsEMhkBwEAjEDgYJBgEGgHA4EYDwOAmEwBIIYyj/wgf+AoMH/kA/4eBJXwYLVxgAjh//AC3w"))

BIN
apps/s7clk/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

View File

@ -9,3 +9,4 @@
0.10: Fix daily goal, don't store settings in separate file
0.11: added getSteps() method for apps to retrieve step count
0.12: Respect Quiet Mode
0.13: Now use system color theme

View File

@ -4,11 +4,6 @@
'goal': 10000,
'progress': false,
}
const COLORS = {
'white': -1,
'progress': 0x001F, // Blue
'done': 0x03E0, // DarkGreen
}
const TAU = Math.PI*2;
let lastUpdate = new Date();
let stp_today = 0;
@ -27,7 +22,7 @@
function drawProgress(stps) {
const width = 24, half = width/2;
const goal = setting('goal'), left = Math.max(goal-stps,0);
const c = left ? COLORS.progress : COLORS.done;
const c = left ? "#00f" : "#090"; // blue or dark green
g.setColor(c).fillCircle(this.x + half, this.y + half, half);
if (left) {
const f = left/goal; // fraction to blank out
@ -47,7 +42,7 @@
p[i - 2] += this.x;
p[i - 1] += this.y;
}
g.setColor(0).fillPoly(p);
g.setColor(g.theme.bg).fillPoly(p);
}
}
@ -58,10 +53,9 @@
stp_today = stp_today % 100000; // cap to five digits + comma = 6 characters
}
let stps = stp_today.toString();
g.reset();
g.clearRect(this.x, this.y, this.x + width, this.y + 23); // erase background
g.reset().clearRect(this.x, this.y, this.x + width, this.y + 23); // erase background
if (setting('progress')){ drawProgress.call(this, stps); }
g.setColor(COLORS.white);
g.setColor(g.theme.fg);
if (stps.length > 3){
stps = stps.slice(0,-3) + "," + stps.slice(-3);
g.setFont("4x6", 1); // if big, shrink text to fix