drained: change enable/disable BLE depending on state

pull/3369/head
Rob Pilling 2024-03-27 08:31:01 +00:00
parent 9b4714eac1
commit 154a9075d5
4 changed files with 37 additions and 19 deletions

View File

@ -3,3 +3,4 @@
0.03: Permit exceptions to load in low-power mode, e.g. daylight saving time. 0.03: Permit exceptions to load in low-power mode, e.g. daylight saving time.
Also avoid polluting global scope. Also avoid polluting global scope.
0.04: Enhance menu: enable bluetooth, visit settings & visit recovery 0.04: Enhance menu: enable bluetooth, visit settings & visit recovery
0.05: Enhance menu: permit toggling bluetooth

View File

@ -53,6 +53,21 @@ var draw = function () {
}, 60000 - (date.getTime() % 60000)); }, 60000 - (date.getTime() % 60000));
}; };
var reload = function () { var reload = function () {
var showMenu = function () {
var menu = {
"Restore to full power": drainedRestore,
};
if (NRF.getSecurityStatus().advertising)
menu["Disable BLE"] = function () { NRF.sleep(); showMenu(); };
else
menu["Enable BLE"] = function () { NRF.wake(); showMenu(); };
menu["Settings"] = function () { return load("setting.app.js"); };
menu["Recovery"] = function () { return Bangle.showRecoveryMenu(); };
menu["Exit menu"] = reload;
if (nextDraw)
clearTimeout(nextDraw);
E.showMenu(menu);
};
Bangle.setUI({ Bangle.setUI({
mode: "custom", mode: "custom",
remove: function () { remove: function () {
@ -60,15 +75,7 @@ var reload = function () {
clearTimeout(nextDraw); clearTimeout(nextDraw);
nextDraw = undefined; nextDraw = undefined;
}, },
btn: function () { btn: showMenu
var menu = {
"Restore to full power": drainedRestore,
"Enable BLE": function () { return NRF.wake(); },
"Settings": function () { return load("setting.app.js"); },
"Recovery": function () { return Bangle.showRecoveryMenu(); },
};
E.showMenu(menu);
}
}); });
Bangle.CLOCK = 1; Bangle.CLOCK = 1;
g.clear(); g.clear();

View File

@ -72,21 +72,31 @@ const draw = () => {
}; };
const reload = () => { const reload = () => {
const showMenu = () => {
const menu: { [k: string]: () => void } = {
"Restore to full power": drainedRestore,
};
if (NRF.getSecurityStatus().advertising)
menu["Disable BLE"] = () => { NRF.sleep(); showMenu(); };
else
menu["Enable BLE"] = () => { NRF.wake(); showMenu(); };
menu["Settings"] = () => load("setting.app.js");
menu["Recovery"] = () => Bangle.showRecoveryMenu();
menu["Exit menu"] = reload;
if(nextDraw) clearTimeout(nextDraw);
E.showMenu(menu);
};
Bangle.setUI({ Bangle.setUI({
mode: "custom", mode: "custom",
remove: () => { remove: () => {
if (nextDraw) clearTimeout(nextDraw); if (nextDraw) clearTimeout(nextDraw);
nextDraw = undefined; nextDraw = undefined;
}, },
btn: () => { btn: showMenu
const menu = {
"Restore to full power": drainedRestore,
"Enable BLE": () => NRF.wake(),
"Settings": () => load("setting.app.js"),
"Recovery": () => Bangle.showRecoveryMenu(),
};
E.showMenu(menu);
}
}); });
Bangle.CLOCK=1; Bangle.CLOCK=1;

View File

@ -1,7 +1,7 @@
{ {
"id": "drained", "id": "drained",
"name": "Drained", "name": "Drained",
"version": "0.04", "version": "0.05",
"description": "Switches to displaying a simple clock when the battery percentage is low, and disables some peripherals", "description": "Switches to displaying a simple clock when the battery percentage is low, and disables some peripherals",
"readme": "README.md", "readme": "README.md",
"icon": "icon.png", "icon": "icon.png",