Skip to content

Commit 9360190

Browse files
authored
Merge pull request #3933 from RKBoss6/BackLite
Create BackLite App
2 parents 2cc5a9b + 26e6f12 commit 9360190

File tree

6 files changed

+99
-0
lines changed

6 files changed

+99
-0
lines changed

apps/backlite/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.01: New app! (settings, boot.js).

apps/backlite/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# BackLite
2+
### This app needs the latest settings app update (v 0.80), to ensure that setting the brightness to `0` does not default to `1`.
3+
4+
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.
5+
6+
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.
7+
8+
#### 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 :)
9+
# Usage
10+
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.
11+
12+
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.
13+
14+
Some apps like `Light Switch Widget` will prevent this app from working properly.
15+
# Settings
16+
`Brightness` - The LCD brightness when unlocked with a long press.
17+
# Creator
18+
RKBoss6
19+
20+
TODO: Add a setting for long press time, or light duration

apps/backlite/boot.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
let getSettings = function(){
3+
return Object.assign({
4+
// default values
5+
brightness: 0.3,
6+
7+
}, require('Storage').readJSON("BackLite.settings.json", true) || {});
8+
};
9+
10+
11+
//Set LCD to zero every reboot
12+
let s = require("Storage").readJSON("setting.json", 1) || {};
13+
s.brightness = 0;
14+
if (!("lcdTimeout" in s)) s.lcdTimeout = 5; // fallback so logic doesn't break
15+
require("Storage").writeJSON("setting.json", s);
16+
17+
const longPressTime=400; //(ms)
18+
19+
Bangle.on('lock', function(isLocked) {
20+
Bangle.setLCDBrightness(0);
21+
22+
if (!isLocked) {
23+
// Just unlocked — give a short delay and check if BTN1 is still pressed
24+
setTimeout(() => {
25+
if (digitalRead(BTN1)) {
26+
//set brightness until. locked.
27+
Bangle.setLCDBrightness(getSettings().brightness);
28+
} else {
29+
Bangle.setLCDBrightness(0);
30+
}
31+
}, longPressTime); // Slight delay to allow unlock to settle
32+
}
33+
});
34+
35+
}
36+

apps/backlite/icon.png

1.44 MB
Loading

apps/backlite/metadata.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"id": "backlite",
3+
"name": "BackLite",
4+
"version": "0.01",
5+
"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)**",
6+
"icon": "icon.png",
7+
"type": "bootloader",
8+
"tags": "system",
9+
"readme": "README.md",
10+
"supports": ["BANGLEJS2"],
11+
"storage": [
12+
{"name":"backlite.boot.js","url":"boot.js"},
13+
{"name":"backlite.settings.js","url":"settings.js"}
14+
15+
],
16+
"data": [{"name":"BackLite.settings.json"}]
17+
}

apps/backlite/settings.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(function(back) {
2+
var FILE = "BackLite.settings.json";
3+
// Load settings
4+
var settings = Object.assign({
5+
brightness: 0.3,
6+
}, require('Storage').readJSON(FILE, true) || {});
7+
8+
function writeSettings() {
9+
require('Storage').writeJSON(FILE, settings);
10+
}
11+
12+
// Show the menu
13+
E.showMenu({
14+
"" : { "title" : "BackLite" },
15+
'Brightness': {
16+
value: 0.3|settings.brightness,
17+
min: 0.1, max: 1,
18+
step: 0.1,
19+
onchange: v => {
20+
settings.brightness = v;
21+
writeSettings();
22+
}
23+
},
24+
});
25+
})

0 commit comments

Comments
 (0)