Skip to content

Commit 925c71a

Browse files
authored
Merge branch 'espruino:master' into Smart-Battery
2 parents 2da0831 + 9360190 commit 925c71a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+590
-298
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+
})

apps/clkinfoclk/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"icon": "app.png",
66
"screenshots": [{"url":"screenshot.png"}],
77
"type": "clkinfo",
8-
"tags": "clkinfo",
8+
"tags": "clkinfo,clock",
99
"supports" : ["BANGLEJS2"],
1010
"storage": [
1111
{"name":"clkinfoclk.clkinfo.js","url":"clkinfo.js"}

apps/clkinfodist/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.01: New App!

apps/clkinfodist/app.png

4.88 KB
Loading

apps/clkinfodist/clkinfo.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(function() {
2+
let strideLength = (require("Storage").readJSON("myprofile.json",1)||{}).strideLength ?? 0.79,
3+
lastSteps = 0;
4+
function stepUpdateHandler() { distance.emit("redraw"); }
5+
var distance = {
6+
name : "Distance",
7+
get : () => { let v = (Bangle.getHealthStatus("day").steps - lastSteps)*strideLength; return {
8+
text : require("locale").distance(v,1),
9+
img : atob("GBiBAAMAAAeAAA/AAA/AAA/gAA/gwAfh4AfD4APD4AOH4AAH4ADj4AHjwAHhwADgAAACAAAHgAAPAAAHAAgCEBgAGD///BgAGAgAEA==")
10+
};},
11+
run : function() {
12+
lastSteps = (lastSteps>=Bangle.getHealthStatus("day").steps) ? 0 : Bangle.getHealthStatus("day").steps;
13+
this.emit("redraw");
14+
},
15+
show : function() { Bangle.on("step", stepUpdateHandler); stepUpdateHandler(); },
16+
hide : function() { Bangle.removeListener("step", stepUpdateHandler); }
17+
};
18+
return {
19+
name: "Bangle",
20+
items: [ distance ]
21+
};
22+
})

0 commit comments

Comments
 (0)