Merge pull request #1813 from zachstr2/master
Add 12h support, auto-cycle control to Rebble Clockmaster
commit
2e98a731a8
|
|
@ -2,4 +2,5 @@
|
||||||
0.02: Fix typo to Purple
|
0.02: Fix typo to Purple
|
||||||
0.03: Added dependancy on Pedometer Widget
|
0.03: Added dependancy on Pedometer Widget
|
||||||
0.04: Fixed icon and png to 48x48 pixels
|
0.04: Fixed icon and png to 48x48 pixels
|
||||||
0.05: added charging icon
|
0.05: added charging icon
|
||||||
|
0.06: Add 12h support and autocycle control
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "rebble",
|
"id": "rebble",
|
||||||
"name": "Rebble Clock",
|
"name": "Rebble Clock",
|
||||||
"shortName": "Rebble",
|
"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",
|
"description": "A Pebble style clock, with configurable background, three sidebars including steps, day, date, sunrise, sunset, long live the rebellion",
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
"icon": "rebble.png",
|
"icon": "rebble.png",
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
var SunCalc = require("https://raw.githubusercontent.com/mourner/suncalc/master/suncalc.js");
|
var SunCalc = require("https://raw.githubusercontent.com/mourner/suncalc/master/suncalc.js");
|
||||||
const SETTINGS_FILE = "rebble.json";
|
const SETTINGS_FILE = "rebble.json";
|
||||||
const LOCATION_FILE = "mylocation.json";
|
const LOCATION_FILE = "mylocation.json";
|
||||||
|
const GLOBAL_SETTINGS = "setting.json";
|
||||||
let settings;
|
let settings;
|
||||||
let location;
|
let location;
|
||||||
|
let is12Hour;
|
||||||
|
|
||||||
Graphics.prototype.setFontLECO1976Regular22 = function(scale) {
|
Graphics.prototype.setFontLECO1976Regular22 = function(scale) {
|
||||||
// Actual height 22 (21 - 0)
|
// Actual height 22 (21 - 0)
|
||||||
|
|
@ -33,12 +35,26 @@ function loadLocation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadSettings() {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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){
|
function extractTime(d){
|
||||||
var h = d.getHours(), m = d.getMinutes();
|
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){
|
function updateSunRiseSunSet(lat, lon){
|
||||||
|
|
@ -81,6 +97,9 @@ function draw() {
|
||||||
let da = date.toString().split(" ");
|
let da = date.toString().split(" ");
|
||||||
let hh = da[4].substr(0,2);
|
let hh = da[4].substr(0,2);
|
||||||
let mm = da[4].substr(3,2);
|
let mm = da[4].substr(3,2);
|
||||||
|
|
||||||
|
hh = formatHours(hh);
|
||||||
|
|
||||||
//const t = 6;
|
//const t = 6;
|
||||||
|
|
||||||
if (drawCount % 60 == 0)
|
if (drawCount % 60 == 0)
|
||||||
|
|
@ -260,7 +279,9 @@ function queueDraw() {
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
drawTimeout = setTimeout(function() {
|
drawTimeout = setTimeout(function() {
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
nextSidebar();
|
if (!settings.autoCycle) {
|
||||||
|
nextSidebar();
|
||||||
|
}
|
||||||
draw();
|
draw();
|
||||||
}, 60000 - (Date.now() % 60000));
|
}, 60000 - (Date.now() % 60000));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,19 @@
|
||||||
const SETTINGS_FILE = "rebble.json";
|
const SETTINGS_FILE = "rebble.json";
|
||||||
|
|
||||||
// initialize with default settings...
|
// initialize with default settings...
|
||||||
let s = {'bg': '#0f0', 'color': 'Green'}
|
let localSettings = {'bg': '#0f0', 'color': 'Green', 'autoCycle': true}
|
||||||
|
|
||||||
// ...and overwrite them with any saved values
|
// ...and overwrite them with any saved values
|
||||||
// This way saved values are preserved if a new version adds more settings
|
// This way saved values are preserved if a new version adds more settings
|
||||||
const storage = require('Storage')
|
const storage = require('Storage')
|
||||||
let settings = storage.readJSON(SETTINGS_FILE, 1) || s;
|
let settings = storage.readJSON(SETTINGS_FILE, 1) || localSettings;
|
||||||
const saved = settings || {}
|
const saved = settings || {}
|
||||||
for (const key in saved) {
|
for (const key in saved) {
|
||||||
s[key] = saved[key]
|
localSettings[key] = saved[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
settings = s
|
settings = localSettings
|
||||||
storage.write(SETTINGS_FILE, settings)
|
storage.write(SETTINGS_FILE, settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,14 +25,22 @@
|
||||||
'': { 'title': 'Rebble Clock' },
|
'': { 'title': 'Rebble Clock' },
|
||||||
'< Back': back,
|
'< Back': back,
|
||||||
'Colour': {
|
'Colour': {
|
||||||
value: 0 | color_options.indexOf(s.color),
|
value: 0 | color_options.indexOf(localSettings.color),
|
||||||
min: 0, max: 5,
|
min: 0, max: 5,
|
||||||
format: v => color_options[v],
|
format: v => color_options[v],
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
s.color = color_options[v];
|
localSettings.color = color_options[v];
|
||||||
s.bg = bg_code[v];
|
localSettings.bg = bg_code[v];
|
||||||
save();
|
save();
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
'Auto Cycle': {
|
||||||
|
value: "autoCycle" in localSettings ? localSettings.autoCycle : true,
|
||||||
|
format: () => (localSettings.autoCycle ? 'Yes' : 'No'),
|
||||||
|
onchange: () => {
|
||||||
|
localSettings.autoCycle = !localSettings.autoCycle;
|
||||||
|
save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue