Merge pull request #1740 from frigis1/gbalarms

[Android] Add handling of GB alarms
master
Gordon Williams 2022-04-25 13:33:20 +01:00 committed by GitHub
commit 40c8257ac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 2 deletions

View File

@ -6,3 +6,4 @@
0.05: Fix handling of message actions
0.06: Option to keep messages after a disconnect (default false) (fix #1186)
0.07: Include charging state in battery updates to phone
0.08: Handling of alarms

View File

@ -21,6 +21,7 @@ of Gadgetbridge - making your phone make noise so you can find it.
* `Keep Msgs` - default is `Off`. When Gadgetbridge disconnects, should Bangle.js
keep any messages it has received, or should it delete them?
* `Messages` - launches the messages app, showing a list of messages
* `Alarms` - opens a submenu where you can set default settings for alarms such as vibration pattern, repeat, and auto snooze
## How it works

View File

@ -4,7 +4,33 @@
Bluetooth.println(JSON.stringify(message));
}
function getCurrentTime() {
var time = new Date();
return (
time.getHours() * 3600000 +
time.getMinutes() * 60000 +
time.getSeconds() * 1000
);
}
//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;
}
var settings = require("Storage").readJSON("android.settings.json",1)||{};
//default alarm settings
if (settings.rp == undefined) settings.rp = true;
if (settings.as == undefined) settings.as = true;
if (settings.vibrate == undefined) settings.vibrate = "..";
require('Storage').writeJSON("android.settings.json", settings);
var _GB = global.GB;
global.GB = (event) => {
// feed a copy to other handlers if there were any
@ -44,6 +70,32 @@
title:event.name||"Call", body:"Incoming call\n"+event.number});
require("messages").pushMessage(event);
},
"alarm" : function() {
//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);
}
var alarms = require("sched").getAlarms();
for (j = 0; j < event.d.length; j++) {
//prevents all alarms from going off at once??
var last = (event.d[j].h * 3600000 + event.d[j].m * 60000 < getCurrentTime()) ? (new Date()).getDate() : 0;
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 : last,
rp : settings.rp,
as : settings.as,
vibrate : settings.vibrate
};
alarms.push(a);
}
require("sched").setAlarms(alarms);
require("sched").reload();
},
};
var h = HANDLERS[event.t];
if (h) h(); else console.log("GB Unknown",event);

View File

@ -2,7 +2,7 @@
"id": "android",
"name": "Android Integration",
"shortName": "Android",
"version": "0.07",
"version": "0.08",
"description": "Display notifications/music/etc sent from the Gadgetbridge app on Android. This replaces the old 'Gadgetbridge' Bangle.js widget.",
"icon": "app.png",
"tags": "tool,system,messages,notifications,gadgetbridge",

View File

@ -24,7 +24,28 @@
updateSettings();
}
},
/*LANG*/"Messages" : ()=>load("messages.app.js")
/*LANG*/"Messages" : ()=>load("messages.app.js"),
/*LANG*/"Alarms" : () => E.showMenu({
"" : { "title" : "Find Phone" },
"< Back" : ()=>E.showMenu(mainmenu),
/*LANG*/"Vibrate": require("buzz_menu").pattern(settings.vibrate, v => {settings.vibrate = v; updateSettings();}),
/*LANG*/"Repeat": {
value: settings.rp,
format : v=>v?/*LANG*/"Yes":/*LANG*/"No",
onchange: v => {
settings.rp = v;
updateSettings();
}
},
/*LANG*/"Auto snooze": {
value: settings.as,
format : v=>v?/*LANG*/"Yes":/*LANG*/"No",
onchange: v => {
settings.as = v;
updateSettings();
}
},
})
};
E.showMenu(mainmenu);
})