grandfatherclock: implement settings menu
parent
717d263159
commit
53f4415675
|
|
@ -0,0 +1,83 @@
|
|||
(function(back) {
|
||||
|
||||
const configFile = "grandfatherclock.json";
|
||||
|
||||
let config = Object.assign({
|
||||
twelve_hour: true,
|
||||
swap_meridian: false,
|
||||
hour_attention_buzz_ms: 1000,
|
||||
hour_count_buzz_ms: 250,
|
||||
fraction_count_buzz_ms: 250,
|
||||
fractions_of_hour: 4, // 4 = 15min intervals, 6 = 10min intervals
|
||||
wait_ms: 500,
|
||||
meridian_buzz_ms: 50,
|
||||
meridian_buzz_wait_ms: 300
|
||||
}, require('Storage').readJSON("grandfatherclock.json", true) || {});
|
||||
|
||||
let writeConfig = function() {
|
||||
require('Storage').writeJSON(configFile, config);
|
||||
};
|
||||
|
||||
E.showMenu({
|
||||
"": {"title" : "Grandfather Clock"},
|
||||
"< Back": () => back(),
|
||||
"12 / 24 hour": {
|
||||
value: config.twelve_hour,
|
||||
format: v => v ? "12" : "24",
|
||||
onchange: v => {
|
||||
config.twelve_hour = v;
|
||||
writeConfig();
|
||||
}
|
||||
},"Swap meridian": {
|
||||
value: config.swap_meridian,
|
||||
format: v => v ? "Yes" : "No",
|
||||
onchange: v => {
|
||||
config.swap_meridian = v;
|
||||
writeConfig();
|
||||
}
|
||||
},"Hr attn. buzz length (ms)": {
|
||||
value: config.hour_attention_buzz_ms,
|
||||
onchange: v => {
|
||||
config.hour_attention_buzz_ms = v;
|
||||
writeConfig();
|
||||
}
|
||||
},"Hr count buzz (ms)": {
|
||||
value: config.hour_count_buzz_ms,
|
||||
onchange: v => {
|
||||
config.hour_count_buzz_ms = v;
|
||||
writeConfig();
|
||||
}
|
||||
},"Frac. count buzz (ms)": {
|
||||
value: config.fraction_count_buzz_ms,
|
||||
onchange: v => {
|
||||
config.fraction_count_buzz_ms = v;
|
||||
writeConfig();
|
||||
}
|
||||
},"Fracs. of hour": {
|
||||
value: config.fractions_of_hour,
|
||||
onchange: v => {
|
||||
config.fractions_of_hour = v;
|
||||
writeConfig();
|
||||
}
|
||||
},"Count wait (ms)": {
|
||||
value: config.wait_ms,
|
||||
onchange: v => {
|
||||
config.wait_ms = v;
|
||||
writeConfig();
|
||||
}
|
||||
},"Meridian buzz (ms)": {
|
||||
value: config.meridian_buzz_ms,
|
||||
onchange: v => {
|
||||
config.meridian_buzz_ms = v;
|
||||
writeConfig();
|
||||
}
|
||||
},"Meridian wait (ms)": {
|
||||
value: config.meridian_buzz_wait_ms,
|
||||
onchange: v => {
|
||||
config.meridian_buzz_wait_ms = v;
|
||||
writeConfig();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
|
|
@ -2,36 +2,39 @@
|
|||
|
||||
WIDGETS["grandfatherclock"] = {
|
||||
area: "tr",
|
||||
width: 16,
|
||||
draw: function() {
|
||||
g.reset();
|
||||
g.drawImage(atob("EBiDASSTJJISSSSZJJJCSSTJ///ISSZP///5CTJ/////ITJ/////ITJ/+B//ITJ/+B//ITJ//+P/ITJ/////ISZP///5CSRJ///ICSQJJJJACSYBJJIBCSYABgABCSYABgABCSYAJAABCSYANgABCSYBtgABCSYNtsABCSYBtgABCSYAMAABCSYAAAABCSZJJJJJCQ=="), this.x, this.y);
|
||||
}
|
||||
};
|
||||
|
||||
// todo: all of these configurable through app settings menu.
|
||||
const twelve_hour = true;
|
||||
const swap_meridian = false;
|
||||
const hour_attention_buzz_ms = 1000;
|
||||
const hour_count_buzz_ms = 250;
|
||||
const fraction_count_buzz_ms = 250;
|
||||
const fractions_of_hour = 4; // 4 = 15min intervals, 6 = 10min intervals
|
||||
const wait_ms = 500;
|
||||
const meridian_buzz_ms = 50;
|
||||
const meridian_buzz_wait_ms = 300;
|
||||
// sensible defaults
|
||||
let config = Object.assign({
|
||||
twelve_hour: true,
|
||||
swap_meridian: false,
|
||||
hour_attention_buzz_ms: 1000,
|
||||
hour_count_buzz_ms: 250,
|
||||
fraction_count_buzz_ms: 250,
|
||||
fractions_of_hour: 4, // 4 = 15min intervals, 6 = 10min intervals
|
||||
wait_ms: 500,
|
||||
meridian_buzz_ms: 50,
|
||||
meridian_buzz_wait_ms: 300
|
||||
}, require('Storage').readJSON("grandfatherclock.json", true) || {}); // or, load the app settings file.
|
||||
|
||||
let date;
|
||||
let fractionMs = 3600000 / fractions_of_hour;
|
||||
let fractionMs = 3600000 / config.fractions_of_hour;
|
||||
|
||||
let chime = function () {
|
||||
date = new Date();
|
||||
let hourFrac = Math.floor(date.getMinutes() / (60 / fractions_of_hour));
|
||||
let hourFrac = Math.floor(date.getMinutes() / (60 / config.fractions_of_hour));
|
||||
|
||||
if (hourFrac == 0) { // if it's an o'clock hour
|
||||
let chimeHour = (twelve_hour ? date.getHours() % 12 : date.getHours());
|
||||
if (chimeHour == 0) (twelve_hour ? chimeHour += 12 : chimeHour += 24);
|
||||
let chimeHour = (config.twelve_hour ? date.getHours() % 12 : date.getHours());
|
||||
if (chimeHour == 0) (config.twelve_hour ? chimeHour += 12 : chimeHour += 24);
|
||||
|
||||
Bangle.buzz(hour_attention_buzz_ms).then(() => { // initial buzz
|
||||
setTimeout(hourChime, wait_ms, chimeHour); // wait a period before doing the first chime
|
||||
Bangle.buzz(config.hour_attention_buzz_ms).then(() => { // initial buzz
|
||||
setTimeout(hourChime, config.wait_ms, chimeHour); // wait a period before doing the first chime
|
||||
});
|
||||
} else { // if it's a fraction of an hour
|
||||
fractionChime(hourFrac);
|
||||
|
|
@ -42,27 +45,27 @@
|
|||
|
||||
let hourChime = function (hoursLeftToChime) {
|
||||
hoursLeftToChime--;
|
||||
Bangle.buzz(hour_count_buzz_ms).then(() => { // recursive. buzz and wait to do the next buzz.
|
||||
Bangle.buzz(config.hour_count_buzz_ms).then(() => { // recursive. buzz and wait to do the next buzz.
|
||||
if (hoursLeftToChime > 0) {
|
||||
setTimeout(hourChime, wait_ms, hoursLeftToChime);
|
||||
} else if (twelve_hour) { // once finished with the hour count
|
||||
setTimeout(meridianChime, wait_ms, (date.getHours() >= 12)); // if in twelve hour mode, queue up the meridian chime.
|
||||
setTimeout(hourChime, config.wait_ms, hoursLeftToChime);
|
||||
} else if (config.twelve_hour) { // once finished with the hour count
|
||||
setTimeout(meridianChime, config.wait_ms, (date.getHours() >= 12)); // if in twelve hour mode, queue up the meridian chime.
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let fractionChime = function (fractionsLeftToChime) {
|
||||
fractionsLeftToChime--;
|
||||
Bangle.buzz(fraction_count_buzz_ms).then(() => { // recursive. buzz and wait to do the next buzz.
|
||||
if (fractionsLeftToChime > 0) setTimeout(fractionChime, wait_ms, fractionsLeftToChime);
|
||||
Bangle.buzz(config.fraction_count_buzz_ms).then(() => { // recursive. buzz and wait to do the next buzz.
|
||||
if (fractionsLeftToChime > 0) setTimeout(fractionChime, config.wait_ms, fractionsLeftToChime);
|
||||
});
|
||||
};
|
||||
|
||||
let meridianChime = function (meridian) {
|
||||
if ((swap_meridian ? !meridian : meridian)) { // default: if PM
|
||||
Bangle.buzz(meridian_buzz_ms).then(setTimeout(Bangle.buzz, meridian_buzz_wait_ms, meridian_buzz_ms)); // buzz once, wait, buzz again.
|
||||
if ((config.swap_meridian ? !meridian : meridian)) { // default: if PM
|
||||
Bangle.buzz(config.meridian_buzz_ms).then(setTimeout(Bangle.buzz, config.meridian_buzz_wait_ms, config.meridian_buzz_ms)); // buzz once, wait, buzz again.
|
||||
} else { // default: if AM
|
||||
Bangle.buzz(meridian_buzz_ms); // buzz once.
|
||||
Bangle.buzz(config.meridian_buzz_ms); // buzz once.
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue