2024-05-21 20:53:50 +00:00
|
|
|
/* global GB */
|
2024-05-24 08:02:32 +00:00
|
|
|
{
|
2024-10-25 08:35:55 +00:00
|
|
|
// settings var is deleted after this executes to save memory
|
2024-10-08 10:20:46 +00:00
|
|
|
let settings = Object.assign({rp:true,as:true,vibrate:".."},
|
|
|
|
require("Storage").readJSON("android.settings.json",1)||{}
|
|
|
|
);
|
2024-05-24 08:02:32 +00:00
|
|
|
let _GB = global.GB;
|
2024-10-25 08:35:55 +00:00
|
|
|
global.GB = e => {
|
2021-11-04 17:16:02 +00:00
|
|
|
// feed a copy to other handlers if there were any
|
2024-10-25 08:35:55 +00:00
|
|
|
if (_GB) setTimeout(_GB,0,Object.assign({},e));
|
|
|
|
Bangle.emit("GB",e);
|
|
|
|
require("android").gbHandler(e);
|
2021-11-04 17:16:02 +00:00
|
|
|
};
|
2022-06-28 14:31:57 +00:00
|
|
|
// HTTP request handling - see the readme
|
2024-10-25 08:35:55 +00:00
|
|
|
Bangle.http = (url,options)=>require("android").httpHandler(url,options);
|
2021-11-04 17:16:02 +00:00
|
|
|
// Battery monitor
|
2024-10-25 08:35:55 +00:00
|
|
|
let sendBattery = function() { require("android").gbSend({ t: "status", bat: E.getBattery(), chg: Bangle.isCharging()?1:0 }); }
|
2023-01-25 09:29:34 +00:00
|
|
|
Bangle.on("charging", sendBattery);
|
2022-11-24 09:44:48 +00:00
|
|
|
NRF.on("connect", () => setTimeout(function() {
|
|
|
|
sendBattery();
|
2024-10-25 08:35:55 +00:00
|
|
|
require("android").gbSend({t: "ver", fw: process.env.VERSION, hw: process.env.HWVERSION});
|
2022-11-24 09:44:48 +00:00
|
|
|
GB({t:"force_calendar_sync_start"}); // send a list of our calendar entries to start off the sync process
|
|
|
|
}, 2000));
|
2023-01-25 09:29:34 +00:00
|
|
|
NRF.on("disconnect", () => {
|
|
|
|
// disable HRM/activity monitoring ('act' message)
|
|
|
|
GB({t:"act",stp:0,hrm:0,int:0}); // just call the handler to save duplication
|
|
|
|
// remove all messages on disconnect (if enabled)
|
|
|
|
var settings = require("Storage").readJSON("android.settings.json",1)||{};
|
|
|
|
if (!settings.keep)
|
|
|
|
require("messages").clearAll();
|
|
|
|
});
|
2021-11-04 17:16:02 +00:00
|
|
|
setInterval(sendBattery, 10*60*1000);
|
2023-08-09 08:16:33 +00:00
|
|
|
// Health tracking - if 'realtime' data is sent with 'rt:1', but let's still send our activity log every 10 mins
|
|
|
|
Bangle.on('health', h=>{
|
2024-10-25 08:35:55 +00:00
|
|
|
require("android").gbSend({ t: "act", stp: h.steps, hrm: h.bpm, mov: h.movement });
|
2021-11-04 17:16:02 +00:00
|
|
|
});
|
|
|
|
// Music control
|
|
|
|
Bangle.musicControl = cmd => {
|
|
|
|
// play/pause/next/previous/volumeup/volumedown
|
2024-10-25 08:35:55 +00:00
|
|
|
require("android").gbSend({ t: "music", n:cmd });
|
2021-11-23 20:20:37 +00:00
|
|
|
};
|
|
|
|
// Message response
|
|
|
|
Bangle.messageResponse = (msg,response) => {
|
2024-10-25 08:35:55 +00:00
|
|
|
if (msg.id=="call") return require("android").gbSend({ t: "call", n:response?"ACCEPT":"REJECT" });
|
|
|
|
if (isFinite(msg.id)) return require("android").gbSend({ t: "notify", n:response?"OPEN":"DISMISS", id: msg.id });
|
2021-11-23 20:20:37 +00:00
|
|
|
// error/warn here?
|
|
|
|
};
|
2023-05-22 14:11:21 +00:00
|
|
|
Bangle.messageIgnore = msg => {
|
2024-10-25 08:35:55 +00:00
|
|
|
if (isFinite(msg.id)) return require("android").gbSend({ t: "notify", n:"MUTE", id: msg.id });
|
2023-05-22 14:11:21 +00:00
|
|
|
};
|
2022-11-06 12:41:49 +00:00
|
|
|
// GPS overwrite logic
|
2024-10-25 08:35:55 +00:00
|
|
|
if (settings.overwriteGps) require("android").overwriteGPS();
|
2022-01-12 10:58:47 +00:00
|
|
|
// remove settings object so it's not taking up RAM
|
|
|
|
delete settings;
|
2024-05-24 08:02:32 +00:00
|
|
|
}
|