Create boot.js

pull/1683/head
frigis1 2022-04-09 15:13:47 -07:00 committed by GitHub
parent 65b848a9c0
commit 79149dad96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 46 additions and 0 deletions

46
apps/gbalarms/boot.js Normal file
View File

@ -0,0 +1,46 @@
(function() {
var settings = require("Storage").readJSON("gbalarms.json", 1) || {};
if (!settings.rp) settings.rp = true;
if (!settings.as) settings.as = true;
if (!settings.vibrate) settings.vibrate = "..";
require('Storage').writeJSON("gbalarms.json", settings);
//convert GB DOW format to sched DOW format
function convDow(x) {
//if no DOW selected, set alarm to all DOW
if (x == 0) x = 127;
x = x.toString(2);
for (var i = 0; x.length < 7; i++) {
x = "0"+x;
}
x = x.slice(1, 7) + x.slice(0, 1);
return "0b"+x;
}
global.GB = (event) => {
if (event.t==="alarm") {
//wipe existing GB alarms
var gbalarms = require("sched").getAlarms().filter(a=>a.appid=="gbalarms");
for (i = 0; i < gbalarms.length; i++) {
require("sched").setAlarm(gbalarms[i].id, undefined);
}
for (j = 0; j < event.d.length; j++) {
var a = {
id : "gb"+j,
appid : "gbalarms",
on : true,
t : event.d[j].h * 3600000 + event.d[j].m * 60000,
dow : convDow(event.d[j].rep),
last : 0,
rp : settings.rp,
as : settings.as,
vibrate : settings.vibrate
};
require("sched").setAlarm(a.id, a);
}
}
require("sched").reload();
};
})();