added small time on top
parent
22c68bb5d4
commit
2012e73421
|
|
@ -1,33 +1,55 @@
|
||||||
// timeout used to update every minute
|
{
|
||||||
var drawTimeout;
|
// timeout used to update every minute
|
||||||
|
var drawTimeout;
|
||||||
|
require('Font4x5Numeric').add(Graphics);
|
||||||
|
|
||||||
// https://www.espruino.com/Bangle.js+Locale
|
// https://www.espruino.com/Bangle.js+Locale
|
||||||
// schedule a draw for the next 3 minutes
|
// schedule a draw for the next 3 minutes
|
||||||
function queueDraw() {
|
function queueDraw() {
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
drawTimeout = setTimeout(function () {
|
drawTimeout = setTimeout(function () {
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
draw();
|
draw();
|
||||||
}, 180000 - (Date.now() % 180000));
|
}, 180000 - (Date.now() % 180000));
|
||||||
}
|
}
|
||||||
|
|
||||||
function wordFromHour(h) {
|
function wordFromHour(h) {
|
||||||
const HOUR_WORDS = [
|
const HOUR_WORDS = [
|
||||||
"Midnight", "Early", "Quiet", "Still", "Dawn", "Earlybird",
|
'Midnight',
|
||||||
"Sunrise", "Morning", "Bright", "Active", "Busy", "Pre-noon",
|
'Early',
|
||||||
"Noon", "Post-noon", "Afternoon", "Siesta", "Breezy", "Evening",
|
'Quiet',
|
||||||
"Twilight", "Dinner", "Cozy", "Relax", "Quietude", "Night"
|
'Still',
|
||||||
|
'Dawn',
|
||||||
|
'Earlybird',
|
||||||
|
'Sunrise',
|
||||||
|
'Morning',
|
||||||
|
'Bright',
|
||||||
|
'Active',
|
||||||
|
'Busy',
|
||||||
|
'Pre-noon',
|
||||||
|
'Noon',
|
||||||
|
'Post-noon',
|
||||||
|
'Afternoon',
|
||||||
|
'Siesta',
|
||||||
|
'Breezy',
|
||||||
|
'Evening',
|
||||||
|
'Twilight',
|
||||||
|
'Dinner',
|
||||||
|
'Cozy',
|
||||||
|
'Relax',
|
||||||
|
'Quietude',
|
||||||
|
'Night',
|
||||||
];
|
];
|
||||||
|
|
||||||
return HOUR_WORDS[h];
|
return HOUR_WORDS[h];
|
||||||
}
|
}
|
||||||
|
|
||||||
function wordsFromDayMonth(day) {
|
function wordsFromDayMonth(day) {
|
||||||
const DAY_WORD_ARRAY = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
const DAY_WORD_ARRAY = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||||
return DAY_WORD_ARRAY[day];
|
return DAY_WORD_ARRAY[day];
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
var x = g.getWidth() / 2;
|
var x = g.getWidth() / 2;
|
||||||
var y = g.getHeight() / 2;
|
var y = g.getHeight() / 2;
|
||||||
g.reset();
|
g.reset();
|
||||||
|
|
@ -44,17 +66,24 @@ function draw() {
|
||||||
// draw time
|
// draw time
|
||||||
g.setBgColor(g.theme.bg);
|
g.setBgColor(g.theme.bg);
|
||||||
g.clear();
|
g.clear();
|
||||||
g.setFontAlign(-1, 0).setFont("Vector", 36);
|
|
||||||
|
// Draw military time at the top
|
||||||
|
g.setColor(g.theme.bg2);
|
||||||
|
g.setFontAlign(0, 0).setFont('4x5Numeric', 2);
|
||||||
|
var militaryTime = ('0' + h).slice(-2) + ('0' + m).slice(-2);
|
||||||
|
g.drawString(militaryTime, x, 20);
|
||||||
|
|
||||||
|
g.setFontAlign(-1, 0).setFont('Vector', 36);
|
||||||
|
|
||||||
// Calculate exact progress through the hour (0 to 1)
|
// Calculate exact progress through the hour (0 to 1)
|
||||||
var progress = (m + (s / 60)) / 60;
|
var progress = (m + s / 60) / 60;
|
||||||
|
|
||||||
// Get total width of the word and starting position
|
// Get total width of the word and starting position
|
||||||
var totalWidth = g.stringWidth(timeStr);
|
var totalWidth = g.stringWidth(timeStr);
|
||||||
var startX = x - totalWidth / 2;
|
var startX = x - totalWidth / 2;
|
||||||
|
|
||||||
// Calculate the exact position where the color should change
|
// Calculate the exact position where the color should change
|
||||||
var colorChangeX = startX + (totalWidth * progress);
|
var colorChangeX = startX + totalWidth * progress;
|
||||||
|
|
||||||
// First draw the entire text in the uncolored version
|
// First draw the entire text in the uncolored version
|
||||||
g.setColor(g.theme.fg2);
|
g.setColor(g.theme.fg2);
|
||||||
|
|
@ -71,28 +100,30 @@ function draw() {
|
||||||
|
|
||||||
// draw date at bottom of screen
|
// draw date at bottom of screen
|
||||||
g.setColor(g.theme.fg2);
|
g.setColor(g.theme.fg2);
|
||||||
g.setFontAlign(0, 0).setFont("Vector", 20);
|
g.setFontAlign(0, 0).setFont('Vector', 20);
|
||||||
g.drawString(g.wrapString(dateStr, g.getWidth()).join("\n"), x, g.getHeight() - 30);
|
g.drawString(g.wrapString(dateStr, g.getWidth()).join('\n'), x, g.getHeight() - 30);
|
||||||
|
|
||||||
queueDraw();
|
queueDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the screen once/, at startup
|
// Clear the screen once/, at startup
|
||||||
g.clear();
|
g.clear();
|
||||||
// draw immediately at first, queue update
|
// draw immediately at first, queue update
|
||||||
draw();
|
draw();
|
||||||
// Stop updates when LCD is off, restart when on
|
// Stop updates when LCD is off, restart when on
|
||||||
Bangle.on('lcdPower', on => {
|
Bangle.on('lcdPower', (on) => {
|
||||||
if (on) {
|
if (on) {
|
||||||
draw(); // draw immediately, queue redraw
|
draw(); // draw immediately, queue redraw
|
||||||
} else { // stop draw timer
|
} else {
|
||||||
|
// stop draw timer
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show launcher when middle button pressed
|
// Show launcher when middle button pressed
|
||||||
Bangle.setUI("clock");
|
Bangle.setUI('clock');
|
||||||
// Load widgets
|
// Load widgets
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue