Merge pull request #3933 from RKBoss6/BackLite

Create BackLite App
master
Rob Pilling 2025-07-23 18:09:59 +01:00 committed by GitHub
commit 9360190b80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 99 additions and 0 deletions

1
apps/backlite/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: New app! (settings, boot.js).

20
apps/backlite/README.md Normal file
View File

@ -0,0 +1,20 @@
# BackLite
### This app needs the latest settings app update (v 0.80), to ensure that setting the brightness to `0` does not default to `1`.
BackLite is an app which greatly conserves battery life by only turning the backlight on when you long press the button from a locked state.
Modern watches have a dedicated button to turn the backlight on, so as not to waste battery in an already light environment. This app recreates that functionality for the Bangle.js, which only has one button.
#### Warning: This app overwrites the LCD brightness setting in `Bangle.js LCD settings`. If it is changed, the app will basically lose functionality. It auto-fixes itself every boot, so if you change the brightness, just reboot :)
# Usage
When you unlock with a press of the button, or any other way you unlock the watch, the backlight will not turn on, as most of the time you are able to read it, due to the transreflective display on the Bangle.js 2.
If you press and hold the button to unlock the watch (for around half a second), the backlight will turn on for 5 seconds - just enough to see what you need to see. After that, it will turn off again.
Some apps like `Light Switch Widget` will prevent this app from working properly.
# Settings
`Brightness` - The LCD brightness when unlocked with a long press.
# Creator
RKBoss6
TODO: Add a setting for long press time, or light duration

36
apps/backlite/boot.js Normal file
View File

@ -0,0 +1,36 @@
{
let getSettings = function(){
return Object.assign({
// default values
brightness: 0.3,
}, require('Storage').readJSON("BackLite.settings.json", true) || {});
};
//Set LCD to zero every reboot
let s = require("Storage").readJSON("setting.json", 1) || {};
s.brightness = 0;
if (!("lcdTimeout" in s)) s.lcdTimeout = 5; // fallback so logic doesn't break
require("Storage").writeJSON("setting.json", s);
const longPressTime=400; //(ms)
Bangle.on('lock', function(isLocked) {
Bangle.setLCDBrightness(0);
if (!isLocked) {
// Just unlocked — give a short delay and check if BTN1 is still pressed
setTimeout(() => {
if (digitalRead(BTN1)) {
//set brightness until. locked.
Bangle.setLCDBrightness(getSettings().brightness);
} else {
Bangle.setLCDBrightness(0);
}
}, longPressTime); // Slight delay to allow unlock to settle
}
});
}

BIN
apps/backlite/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

@ -0,0 +1,17 @@
{
"id": "backlite",
"name": "BackLite",
"version": "0.01",
"description": "Conserves battery life by turning the backlight on only on a long press of the button from a locked state. **Requires the latest settings update (v0.80)**",
"icon": "icon.png",
"type": "bootloader",
"tags": "system",
"readme": "README.md",
"supports": ["BANGLEJS2"],
"storage": [
{"name":"backlite.boot.js","url":"boot.js"},
{"name":"backlite.settings.js","url":"settings.js"}
],
"data": [{"name":"BackLite.settings.json"}]
}

25
apps/backlite/settings.js Normal file
View File

@ -0,0 +1,25 @@
(function(back) {
var FILE = "BackLite.settings.json";
// Load settings
var settings = Object.assign({
brightness: 0.3,
}, require('Storage').readJSON(FILE, true) || {});
function writeSettings() {
require('Storage').writeJSON(FILE, settings);
}
// Show the menu
E.showMenu({
"" : { "title" : "BackLite" },
'Brightness': {
value: 0.3|settings.brightness,
min: 0.1, max: 1,
step: 0.1,
onchange: v => {
settings.brightness = v;
writeSettings();
}
},
});
})