Merge pull request #715 from Weiming-Hu/master

New app: Hour Strike
pull/717/head
Gordon Williams 2021-04-07 11:55:08 +01:00 committed by GitHub
commit c05d44286e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 136 additions and 1 deletions

View File

@ -3074,5 +3074,20 @@
{"name":"waypoints.json","url":"waypoints.json","evaluate":false},
{"name":"kitchen.img","url":"kitchen.icon.js","evaluate":true}
]
}
},
{
"id": "hourstrike",
"name": "Hour Strike",
"shortName": "Hour Strike",
"icon": "app-icon.png",
"version": "0.07",
"description": "Strike the clock on the hour. A great tool to remind you an hour has passed!",
"tags": "tool,alarm",
"readme": "README.md",
"storage": [
{"name":"hourstrike.app.js","url":"app.js"},
{"name":"hourstrike.boot.js","url":"boot.js"},
{"name":"hourstrike.img","url":"app-icon.js","evaluate":true}
]
}
]

View File

@ -0,0 +1,7 @@
0.01: New App
0.02: Add different strike intervals and support for quiet time
0.03: Bug fixes for setting attributes
0.04: Add more time to strike and the strength
0.05: Add display for the next strike time
0.06: Move the next strike time to the first row of display
0.07: Change the boot function to avoid reloading the entire watch

25
apps/hourstrike/README.md Normal file
View File

@ -0,0 +1,25 @@
# Hour Strike
![icon](app-icon.png)
Time passes too fast!
This app configures your `Bangle.js` so that it buzzes on the hour or on the half hour.
This app is slightly different from [Hour Chime](https://github.com/espruino/BangleApps/tree/master/apps/widchime). `Hour Chimee` runs as a widget but `Hour Strike` runs as a background task, without showing a widget.
## Features
- Strike the hour, the half hour, the quarter hour, and more
- Set up a range of hours that clock will strike
- Set up the strength of the strike
- Preview when the next strike will happen
## Known Issues
- This app does not know or check whether your clock already chimes on the hour.
## Creator
[Weiming Hu](https://weiming-hu.github.io/), using coding from the [Default Alarm](https://github.com/espruino/BangleApps/tree/master/apps/alarm).

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwwkGswAHogAEBxAAHsgXFowXPCwowQFwwwQCIUjn/zmQwPFwUj/4ACDAQwMBwNDCgPwh4DBmgwMFwU/C4vzGBgMBoRECC4f/kgwLIwgXFJBgLBl4XH+QXNLwQXFMAQXPmEDC6K8DiEBAoYXSgA1DI6MxgETL6gYBgIGBC5ynDCYMQAwKnOa4YABmTXQoQXEAAUkC5dkMAx2EowXJJBBGNAAMUBwMjMAgHBoIXLiIPBDAM/+YWCokRC5gwCAAtBC5owDAAgJBC5dBiAwGoMBigXLokQgIXFA4QXMoEAAANNqAECggXR7oXXAYQXSgvUC6sEC60N6oXW6AXUinu8IXTgPuAAMQC6UEC4SsDC58OC4XgC9RHXO66nCoLXVAAoXmABQX1A"))

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

48
apps/hourstrike/app.js Normal file
View File

@ -0,0 +1,48 @@
const storage = require('Storage');
let settings;
function updateSettings() {
storage.write('hourstrike.json', settings);
}
function resetSettings() {
settings = {
interval: 3600,
start: 9,
end: 21,
vlevel: 0.5,
next_hour: -1,
next_minute: -1,
};
updateSettings();
}
settings = storage.readJSON('hourstrike.json', 1);
if (!settings) resetSettings();
function showMainMenu() {
var mode_txt = ['Off','1 min','5 min','10 min','1/4 h','1/2 h','1 h'];
var mode_interval = [-1,60,300,600,900,1800,3600];
const mainmenu = {'': { 'title': 'Hour Strike' }};
mainmenu['Next strike '+settings.next_hour+':'+settings.next_minute] = function(){};
mainmenu['Notify every'] = {
value: mode_interval.indexOf(settings.interval),
min: 0, max: 6, format: v => mode_txt[v],
onchange: v => {
settings.interval = mode_interval[v];
if (v===0) {settings.next_hour = -1; settings.next_minute = -1;}
updateSettings();}};
mainmenu.Start = {
value: settings.start, min: 0, max: 23, format: v=>v+':00',
onchange: v=> {settings.start = v; updateSettings();}};
mainmenu.End = {
value: settings.end, min: 0, max: 23, format: v=>v+':59',
onchange: v=> {settings.end = v; updateSettings();}};
mainmenu.Strength = {
value: settings.vlevel*10, min: 1, max: 10, format: v=>v/10,
onchange: v=> {settings.vlevel = v/10; updateSettings();}};
mainmenu['< Back'] = ()=>load();
return E.showMenu(mainmenu);
}
showMainMenu();

39
apps/hourstrike/boot.js Normal file
View File

@ -0,0 +1,39 @@
(function() {
function setup () {
var settings = require('Storage').readJSON('hourstrike.json',1)||[];
var t = new Date();
var t_min_sec = t.getMinutes()*60+t.getSeconds();
var wait_msec = settings.interval>0?(settings.interval-t_min_sec%settings.interval)*1000:-1;
if (wait_msec>0) {
t.setMilliseconds(t.getMilliseconds()+wait_msec);
var t_hour = t.getHours();
if (t_hour<settings.start||t_hour>settings.end) {
var strike = new Date(t.getTime());
strike.setHours(settings.start);
strike.setMinutes(0);
if (t_hour>settings.end) {
strike.setDate(strike.getDate()+1);
}
wait_msec += strike-t;
settings.next_hour = strike.getHours();
settings.next_minute = strike.getMinutes();
} else {
settings.next_hour = t_hour;
settings.next_minute = t.getMinutes();
}
setTimeout(strike_func, wait_msec);
} else {
settings.next_hour = -1;
settings.next_minute = -1;
}
require('Storage').write('hourstrike.json', settings);
}
function strike_func () {
var setting = require('Storage').readJSON('hourstrike.json',1)||[];
Bangle.buzz(200, setting.vlevel||0.5)
.then(() => new Promise(resolve => setTimeout(resolve,200)))
.then(() => Bangle.buzz(200, setting.vlevel||0.5));
setup();
}
setup();
})();