1
0
Fork 0

Merge pull request #1862 from alessandrococco/nifty-clock-patch

[Nifty Clock A&B] Bug fix and improvements
master
Gordon Williams 2022-05-23 10:39:42 +01:00 committed by GitHub
commit 0dd835014b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 78 additions and 106 deletions

View File

@ -1,2 +1,4 @@
0.01: New Clock Nifty A 0.01: New Clock Nifty A
0.02: Shows the current week number (ISO8601), can be disabled via settings "" 0.02: Shows the current week number (ISO8601), can be disabled via settings
0.03: Call setUI before loading widgets
Improve settings page

View File

@ -1,13 +1,12 @@
# Nifty-A Clock # Nifty-A Clock
Colors are black/white - photos have non correct camera color "blue" Colors are black/white - photos have non correct camera color "blue".
## This is the clock This is the clock:
![](screenshot_nifty.png) ![](screenshot_nifty.png)
## The week number (ISO8601) can be turned of in settings The week number (ISO8601) can be turned off in settings (default is `On`)
(default is **"On"**)
![](screenshot_settings_nifty.png) ![](screenshot_settings_nifty.png)

View File

@ -1,6 +1,6 @@
const locale = require("locale"); const locale = require("locale");
const is12Hour = (require("Storage").readJSON("setting.json", 1) || {})["12hour"]; const is12Hour = Object.assign({ "12hour": false }, require("Storage").readJSON("setting.json", true))["12hour"];
const CFG = require('Storage').readJSON("ffcniftya.json", 1) || {showWeekNum: true}; const showWeekNum = Object.assign({ showWeekNum: true }, require('Storage').readJSON("ffcniftya.json", true))["showWeekNum"];
/* Clock *********************************************/ /* Clock *********************************************/
const scale = g.getWidth() / 176; const scale = g.getWidth() / 176;
@ -17,16 +17,17 @@ const center = {
y: Math.round(((viewport.height - widget) / 2) + widget), y: Math.round(((viewport.height - widget) / 2) + widget),
} }
function ISO8601_week_no(date) { //copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480 // copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480
var tdt = new Date(date.valueOf()); function ISO8601_week_no(date) {
var dayn = (date.getDay() + 6) % 7; var tdt = new Date(date.valueOf());
tdt.setDate(tdt.getDate() - dayn + 3); var dayn = (date.getDay() + 6) % 7;
var firstThursday = tdt.valueOf(); tdt.setDate(tdt.getDate() - dayn + 3);
tdt.setMonth(0, 1); var firstThursday = tdt.valueOf();
if (tdt.getDay() !== 4) { tdt.setMonth(0, 1);
tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7); if (tdt.getDay() !== 4) {
} tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7);
return 1 + Math.ceil((firstThursday - tdt) / 604800000); }
return 1 + Math.ceil((firstThursday - tdt) / 604800000);
} }
function d02(value) { function d02(value) {
@ -59,7 +60,7 @@ function draw() {
g.drawString(year, centerDatesScaleX, center.y - 62 * scale); g.drawString(year, centerDatesScaleX, center.y - 62 * scale);
g.drawString(month, centerDatesScaleX, center.y - 44 * scale); g.drawString(month, centerDatesScaleX, center.y - 44 * scale);
g.drawString(day, centerDatesScaleX, center.y - 26 * scale); g.drawString(day, centerDatesScaleX, center.y - 26 * scale);
if (CFG.showWeekNum) g.drawString(d02(ISO8601_week_no(now)), centerDatesScaleX, center.y + 15 * scale); if (showWeekNum) g.drawString(weekNum, centerDatesScaleX, center.y + 15 * scale);
g.drawString(monthName, centerDatesScaleX, center.y + 48 * scale); g.drawString(monthName, centerDatesScaleX, center.y + 48 * scale);
g.drawString(dayName, centerDatesScaleX, center.y + 66 * scale); g.drawString(dayName, centerDatesScaleX, center.y + 66 * scale);
} }
@ -79,7 +80,6 @@ function clearTickTimer() {
function queueNextTick() { function queueNextTick() {
clearTickTimer(); clearTickTimer();
tickTimer = setTimeout(tick, 60000 - (Date.now() % 60000)); tickTimer = setTimeout(tick, 60000 - (Date.now() % 60000));
// tickTimer = setTimeout(tick, 3000);
} }
function tick() { function tick() {
@ -91,21 +91,16 @@ function tick() {
// Clear the screen once, at startup // Clear the screen once, at startup
g.clear(); g.clear();
// Start ticking
tick(); tick();
// Stop updates when LCD is off, restart when on
Bangle.on('lcdPower', (on) => { Bangle.on('lcdPower', (on) => {
if (on) { if (on) {
tick(); // Start ticking tick();
} else { } else {
clearTickTimer(); // stop ticking clearTickTimer();
} }
}); });
// Load widgets Bangle.setUI("clock");
Bangle.loadWidgets(); Bangle.loadWidgets();
Bangle.drawWidgets(); Bangle.drawWidgets();
// Show launcher when middle button pressed
Bangle.setUI("clock");

View File

@ -1,7 +1,7 @@
{ {
"id": "ffcniftya", "id": "ffcniftya",
"name": "Nifty-A Clock", "name": "Nifty-A Clock",
"version": "0.02", "version": "0.03",
"description": "A nifty clock with time and date", "description": "A nifty clock with time and date",
"icon": "app.png", "icon": "app.png",
"screenshots": [{"url":"screenshot_nifty.png"}], "screenshots": [{"url":"screenshot_nifty.png"}],

View File

@ -1,23 +1,15 @@
(function(back) { (function (back) {
var FILE = "ffcniftya.json"; const settings = Object.assign({ showWeekNum: true }, require("Storage").readJSON("ffcniftya.json", true));
// Load settings
var cfg = require('Storage').readJSON(FILE, 1) || { showWeekNum: true };
function writeSettings() {
require('Storage').writeJSON(FILE, cfg);
}
// Show the menu
E.showMenu({ E.showMenu({
"" : { "title" : "Nifty-A Clock" }, "": { "title": "Nifty-A Clock" },
"< Back" : () => back(), "< Back": () => back(),
'week number?': { /*LANG*/"Show Week Number": {
value: cfg.showWeekNum, value: settings.showWeekNum,
format: v => v?"On":"Off",
onchange: v => { onchange: v => {
cfg.showWeekNum = v; settings.showWeekNum = v;
writeSettings(); require("Storage").writeJSON("ffcniftya.json", settings);
} }
} }
}); });
}) })

View File

@ -1,2 +1,5 @@
0.01: New Clock Nifty B 0.01: New Clock Nifty B
0.02: Added configuration 0.02: Added configuration
0.03: Call setUI before loading widgets
Fix bug with black being unselectable
Improve settings page

View File

@ -1,9 +1,6 @@
# Nifty Series B Clock # Nifty Series B Clock
- Display Time and Date - Display Time and Date
- Color Configuration - Colour Configuration
##
![](screenshot.png) ![](screenshot.png)

View File

@ -1,9 +1,5 @@
const locale = require("locale"); const is12Hour = Object.assign({ "12hour": false }, require("Storage").readJSON("setting.json", true))["12hour"];
const storage = require('Storage'); const color = Object.assign({ color: 63488 }, require("Storage").readJSON("ffcniftyb.json", true)).color; // Default to RED
const is12Hour = (storage.readJSON("setting.json", 1) || {})["12hour"];
const color = (storage.readJSON("ffcniftyb.json", 1) || {})["color"] || 63488 /* red */;
/* Clock *********************************************/ /* Clock *********************************************/
const scale = g.getWidth() / 176; const scale = g.getWidth() / 176;
@ -19,7 +15,7 @@ const center = {
}; };
function d02(value) { function d02(value) {
return ('0' + value).substr(-2); return ("0" + value).substr(-2);
} }
function renderEllipse(g) { function renderEllipse(g) {
@ -35,8 +31,8 @@ function renderText(g) {
const month = d02(now.getMonth() + 1); const month = d02(now.getMonth() + 1);
const year = now.getFullYear(); const year = now.getFullYear();
const month2 = locale.month(now, 3); const month2 = require("locale").month(now, 3);
const day2 = locale.dow(now, 3); const day2 = require("locale").dow(now, 3);
g.setFontAlign(1, 0).setFont("Vector", 90 * scale); g.setFontAlign(1, 0).setFont("Vector", 90 * scale);
g.drawString(hour, center.x + 32 * scale, center.y - 31 * scale); g.drawString(hour, center.x + 32 * scale, center.y - 31 * scale);
@ -96,7 +92,6 @@ function startTick(run) {
stopTick(); stopTick();
run(); run();
ticker = setTimeout(() => startTick(run), 60000 - (Date.now() % 60000)); ticker = setTimeout(() => startTick(run), 60000 - (Date.now() % 60000));
// ticker = setTimeout(() => startTick(run), 3000);
} }
/* Init **********************************************/ /* Init **********************************************/
@ -104,7 +99,7 @@ function startTick(run) {
g.clear(); g.clear();
startTick(draw); startTick(draw);
Bangle.on('lcdPower', (on) => { Bangle.on("lcdPower", (on) => {
if (on) { if (on) {
startTick(draw); startTick(draw);
} else { } else {
@ -112,7 +107,6 @@ Bangle.on('lcdPower', (on) => {
} }
}); });
Bangle.setUI("clock");
Bangle.loadWidgets(); Bangle.loadWidgets();
Bangle.drawWidgets(); Bangle.drawWidgets();
Bangle.setUI("clock");

View File

@ -1,8 +1,8 @@
{ {
"id": "ffcniftyb", "id": "ffcniftyb",
"name": "Nifty-B Clock", "name": "Nifty-B Clock",
"version": "0.02", "version": "0.03",
"description": "A nifty clock (series B) with time, date and color configuration", "description": "A nifty clock (series B) with time, date and colour configuration",
"icon": "app.png", "icon": "app.png",
"screenshots": [{"url":"screenshot.png"}], "screenshots": [{"url":"screenshot.png"}],
"type": "clock", "type": "clock",

View File

@ -1,49 +1,31 @@
(function (back) { (function (back) {
const storage = require('Storage'); const settings = Object.assign({ color: 63488 }, require("Storage").readJSON("ffcniftyb.json", true));
const SETTINGS_FILE = "ffcniftyb.json";
const colors = { const colors = {
65535: 'White', 65535: /*LANG*/"White",
63488: 'Red', 63488: /*LANG*/"Red",
65504: 'Yellow', 65504: /*LANG*/"Yellow",
2047: 'Cyan', 2047: /*LANG*/"Cyan",
2016: 'Green', 2016: /*LANG*/"Green",
31: 'Blue', 31: /*LANG*/"Blue",
0: 'Black', 0: /*LANG*/"Black"
} }
function load(settings) { const menu = {};
return Object.assign(settings, storage.readJSON(SETTINGS_FILE, 1) || {}); menu[""] = { title: "Nifty-B Clock" };
} menu["< Back"] = back;
function save(settings) { Object.keys(colors).forEach(color => {
storage.write(SETTINGS_FILE, settings) var label = colors[color];
} menu[label] = {
value: settings.color == color,
const settings = load({ onchange: () => {
color: 63488 /* red */, settings.color = color;
require("Storage").write("ffcniftyb.json", settings);
setTimeout(load, 10);
}
};
}); });
const saveColor = (color) => () => { E.showMenu(menu);
settings.color = color;
save(settings);
back();
};
function showMenu(items, opt) {
items[''] = opt || {};
items['< Back'] = back;
E.showMenu(items);
}
showMenu(
Object.keys(colors).reduce((menu, color) => {
menu[colors[color]] = saveColor(color);
return menu;
}, {}),
{
title: 'Color',
selected: Object.keys(colors).indexOf(settings.color)
}
);
}); });

View File

@ -192,7 +192,15 @@
"Notifications": "Notifiche", "Notifications": "Notifiche",
"Scheduler": "Schedulatore", "Scheduler": "Schedulatore",
"Stop": "Stop", "Stop": "Stop",
"Min Font": "Dimensione minima del font" "Min Font": "Dimensione minima del font",
"White": "Bianco",
"Red": "Rosso",
"Yellow": "Giallo",
"Cyan": "Ciano",
"Green": "Verde",
"Blue": "Blu",
"Black": "Nero",
"Show Week Number": "Mostra numero settimana"
}, },
"//2": "App-specific overrides", "//2": "App-specific overrides",
"alarm": { "alarm": {