From 154a9075d5fb775f2e5eeabf980b1ba4ab705810 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Wed, 27 Mar 2024 08:31:01 +0000 Subject: [PATCH] drained: change enable/disable BLE depending on state --- apps/drained/ChangeLog | 1 + apps/drained/app.js | 25 ++++++++++++++++--------- apps/drained/app.ts | 28 +++++++++++++++++++--------- apps/drained/metadata.json | 2 +- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/apps/drained/ChangeLog b/apps/drained/ChangeLog index 8d196b10d..65c93e70f 100644 --- a/apps/drained/ChangeLog +++ b/apps/drained/ChangeLog @@ -3,3 +3,4 @@ 0.03: Permit exceptions to load in low-power mode, e.g. daylight saving time. Also avoid polluting global scope. 0.04: Enhance menu: enable bluetooth, visit settings & visit recovery +0.05: Enhance menu: permit toggling bluetooth diff --git a/apps/drained/app.js b/apps/drained/app.js index 37cc8c71d..c74affea3 100644 --- a/apps/drained/app.js +++ b/apps/drained/app.js @@ -53,6 +53,21 @@ var draw = function () { }, 60000 - (date.getTime() % 60000)); }; 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({ mode: "custom", remove: function () { @@ -60,15 +75,7 @@ var reload = function () { clearTimeout(nextDraw); nextDraw = undefined; }, - btn: function () { - 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); - } + btn: showMenu }); Bangle.CLOCK = 1; g.clear(); diff --git a/apps/drained/app.ts b/apps/drained/app.ts index ed40262fa..499609f5f 100644 --- a/apps/drained/app.ts +++ b/apps/drained/app.ts @@ -72,21 +72,31 @@ const draw = () => { }; 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({ mode: "custom", remove: () => { if (nextDraw) clearTimeout(nextDraw); nextDraw = undefined; }, - btn: () => { - const menu = { - "Restore to full power": drainedRestore, - "Enable BLE": () => NRF.wake(), - "Settings": () => load("setting.app.js"), - "Recovery": () => Bangle.showRecoveryMenu(), - }; - E.showMenu(menu); - } + btn: showMenu }); Bangle.CLOCK=1; diff --git a/apps/drained/metadata.json b/apps/drained/metadata.json index ea18f6fcf..115289d09 100644 --- a/apps/drained/metadata.json +++ b/apps/drained/metadata.json @@ -1,7 +1,7 @@ { "id": "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", "readme": "README.md", "icon": "icon.png",