From 5f147027aaacb78b2a3908a11f67291eddcf7cb8 Mon Sep 17 00:00:00 2001 From: Zach Dixon Date: Mon, 9 May 2022 20:45:22 -0700 Subject: [PATCH 1/2] 12h clock format, option to disable autocycle --- apps/rebble/rebble.app.js | 25 +++++++++++++++++++++++-- apps/rebble/rebble.settings.js | 10 +++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/apps/rebble/rebble.app.js b/apps/rebble/rebble.app.js index 7c7d57939..03680eca8 100644 --- a/apps/rebble/rebble.app.js +++ b/apps/rebble/rebble.app.js @@ -1,8 +1,10 @@ var SunCalc = require("https://raw.githubusercontent.com/mourner/suncalc/master/suncalc.js"); const SETTINGS_FILE = "rebble.json"; const LOCATION_FILE = "mylocation.json"; +const GLOBAL_SETTINGS = "setting.json"; let settings; let location; +let is12Hour; Graphics.prototype.setFontLECO1976Regular22 = function(scale) { // Actual height 22 (21 - 0) @@ -34,11 +36,25 @@ function loadLocation() { function loadSettings() { settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'bg': '#0f0', 'color': 'Green'}; + is12Hour = (require("Storage").readJSON(GLOBAL_SETTINGS, 1) || {})["12hour"] || false; +} + +function formatHours(hh) { + if (is12Hour) { + let hours = parseInt(hh,10); + if (hours == 0) { + hours = 12; + } else if (hours >= 12) { + if (hours>12) hours -= 12; + } + hh = (" "+hours).substr(-2); + } + return hh; } function extractTime(d){ var h = d.getHours(), m = d.getMinutes(); - return(("0"+h).substr(-2) + ":" + ("0"+m).substr(-2)); + return(formatHours(("0"+h).substr(-2)) + ":" + ("0"+m).substr(-2)); } function updateSunRiseSunSet(lat, lon){ @@ -81,6 +97,9 @@ function draw() { let da = date.toString().split(" "); let hh = da[4].substr(0,2); let mm = da[4].substr(3,2); + + hh = formatHours(hh); + //const t = 6; if (drawCount % 60 == 0) @@ -260,7 +279,9 @@ function queueDraw() { if (drawTimeout) clearTimeout(drawTimeout); drawTimeout = setTimeout(function() { drawTimeout = undefined; - nextSidebar(); + if (!settings.autoCycle) { + nextSidebar(); + } draw(); }, 60000 - (Date.now() % 60000)); } diff --git a/apps/rebble/rebble.settings.js b/apps/rebble/rebble.settings.js index db3bab878..b4d96644d 100644 --- a/apps/rebble/rebble.settings.js +++ b/apps/rebble/rebble.settings.js @@ -2,7 +2,7 @@ const SETTINGS_FILE = "rebble.json"; // initialize with default settings... - let s = {'bg': '#0f0', 'color': 'Green'} + let s = {'bg': '#0f0', 'color': 'Green', 'autoCycle': true} // ...and overwrite them with any saved values // This way saved values are preserved if a new version adds more settings @@ -33,6 +33,14 @@ s.bg = bg_code[v]; save(); }, + }, + 'Auto Cycle': { + value: "autoCycle" in s ? s.autoCycle : true, + format: () => (s.autoCycle ? 'Yes' : 'No'), + onchange: () => { + s.autoCycle = !s.autoCycle; + save(); + } } }); }) From 7822c4489d0ffadcbe8b0cad518cc89c76dafa96 Mon Sep 17 00:00:00 2001 From: Zach Dixon Date: Mon, 9 May 2022 22:30:20 -0700 Subject: [PATCH 2/2] Fix settings variable conflict and updated version --- apps/rebble/ChangeLog | 3 ++- apps/rebble/metadata.json | 2 +- apps/rebble/rebble.app.js | 2 +- apps/rebble/rebble.settings.js | 20 ++++++++++---------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/apps/rebble/ChangeLog b/apps/rebble/ChangeLog index b80dfef94..667dc0ad0 100644 --- a/apps/rebble/ChangeLog +++ b/apps/rebble/ChangeLog @@ -2,4 +2,5 @@ 0.02: Fix typo to Purple 0.03: Added dependancy on Pedometer Widget 0.04: Fixed icon and png to 48x48 pixels -0.05: added charging icon \ No newline at end of file +0.05: added charging icon +0.06: Add 12h support and autocycle control \ No newline at end of file diff --git a/apps/rebble/metadata.json b/apps/rebble/metadata.json index b26fb6a27..c44d1c279 100644 --- a/apps/rebble/metadata.json +++ b/apps/rebble/metadata.json @@ -2,7 +2,7 @@ "id": "rebble", "name": "Rebble Clock", "shortName": "Rebble", - "version": "0.05", + "version": "0.06", "description": "A Pebble style clock, with configurable background, three sidebars including steps, day, date, sunrise, sunset, long live the rebellion", "readme": "README.md", "icon": "rebble.png", diff --git a/apps/rebble/rebble.app.js b/apps/rebble/rebble.app.js index 03680eca8..251087ae1 100644 --- a/apps/rebble/rebble.app.js +++ b/apps/rebble/rebble.app.js @@ -35,7 +35,7 @@ function loadLocation() { } function loadSettings() { - settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'bg': '#0f0', 'color': 'Green'}; + settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'bg': '#0f0', 'color': 'Green', 'autoCycle': true}; is12Hour = (require("Storage").readJSON(GLOBAL_SETTINGS, 1) || {})["12hour"] || false; } diff --git a/apps/rebble/rebble.settings.js b/apps/rebble/rebble.settings.js index b4d96644d..91142d72d 100644 --- a/apps/rebble/rebble.settings.js +++ b/apps/rebble/rebble.settings.js @@ -2,19 +2,19 @@ const SETTINGS_FILE = "rebble.json"; // initialize with default settings... - let s = {'bg': '#0f0', 'color': 'Green', 'autoCycle': true} + let localSettings = {'bg': '#0f0', 'color': 'Green', 'autoCycle': true} // ...and overwrite them with any saved values // This way saved values are preserved if a new version adds more settings const storage = require('Storage') - let settings = storage.readJSON(SETTINGS_FILE, 1) || s; + let settings = storage.readJSON(SETTINGS_FILE, 1) || localSettings; const saved = settings || {} for (const key in saved) { - s[key] = saved[key] + localSettings[key] = saved[key] } function save() { - settings = s + settings = localSettings storage.write(SETTINGS_FILE, settings) } @@ -25,20 +25,20 @@ '': { 'title': 'Rebble Clock' }, '< Back': back, 'Colour': { - value: 0 | color_options.indexOf(s.color), + value: 0 | color_options.indexOf(localSettings.color), min: 0, max: 5, format: v => color_options[v], onchange: v => { - s.color = color_options[v]; - s.bg = bg_code[v]; + localSettings.color = color_options[v]; + localSettings.bg = bg_code[v]; save(); }, }, 'Auto Cycle': { - value: "autoCycle" in s ? s.autoCycle : true, - format: () => (s.autoCycle ? 'Yes' : 'No'), + value: "autoCycle" in localSettings ? localSettings.autoCycle : true, + format: () => (localSettings.autoCycle ? 'Yes' : 'No'), onchange: () => { - s.autoCycle = !s.autoCycle; + localSettings.autoCycle = !localSettings.autoCycle; save(); } }