Skip to content

Commit 6aa2027

Browse files
authored
Merge branch 'espruino:master' into smartbatt-module
2 parents 9eaff57 + b7daabb commit 6aa2027

Some content is hidden

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

43 files changed

+391
-104
lines changed

apps/backlite/ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
0.01: New app! (settings, boot.js).
2+
0.02: Fix settings defaulting brightness to 0

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+
require("Storage").writeJSON("setting.json", s);
15+
//remove large settings object from memory
16+
delete s;
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.02",
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+
4+
var settings = require("Storage").readJSON(FILE, 1) || {};
5+
6+
if (!isFinite(settings.brightness)) settings.brightness = 0.3;
7+
8+
function writeSettings() {
9+
require("Storage").writeJSON(FILE, settings);
10+
}
11+
12+
E.showMenu({
13+
"" : { "title" : "BackLite" },
14+
"< Back": back, // fallback if run standalone
15+
"Brightness": {
16+
value: 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/counter2/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
0.04: Fix lint warnings
55
0.05: Fix on not reading counter defaults in Settings
66
0.06: Added ability to display only one counter and fast-scrolling
7+
0.07: Add option to keep unlocked

apps/counter2/app.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ var s = Object.assign({
77
fullscreen:true,
88
buzz: true,
99
colortext: true,
10+
keepunlocked: false,
1011
}, require('Storage').readJSON("counter2.json", true) || {});
1112

1213
var sGlob = Object.assign({
1314
timeout: 10,
1415
}, require('Storage').readJSON("setting.json", true) || {});
1516

17+
const lockTimeout = s.keepunlocked ? 0 : 1000;
18+
if (s.keepunlocked) {
19+
Bangle.setOptions({lockTimeout});
20+
Bangle.setLocked(false);
21+
}
22+
1623
const f1 = (s.colortext) ? "#f00" : "#fff";
1724
const f2 = (s.colortext) ? "#00f" : "#fff";
1825
const b1 = (s.colortext) ? g.theme.bg : "#f00";
@@ -80,7 +87,7 @@ function updateScreen() {
8087
Bangle.on('lock', e => {
8188
drag = undefined;
8289
var timeOutTimer = sGlob.timeout * 1000;
83-
Bangle.setOptions({backlightTimeout: timeOutTimer, lockTimeout: timeOutTimer});
90+
Bangle.setOptions({backlightTimeout: timeOutTimer, lockTimeout});
8491
if (dragtimeout) clearTimeout(dragtimeout);
8592
fastupdateoccurring = false;
8693
});
@@ -102,7 +109,7 @@ Bangle.on("drag", e => {
102109
drag = undefined;
103110
if (dragtimeout) {
104111
let timeOutTimer = 1000;
105-
Bangle.setOptions({backlightTimeout: timeOutTimer, lockTimeout: timeOutTimer});
112+
Bangle.setOptions({backlightTimeout: timeOutTimer, lockTimeout});
106113
clearTimeout(dragtimeout);
107114
}
108115
fastupdateoccurring = false;
@@ -134,7 +141,7 @@ function resetcounter(which) {
134141
fastupdateoccurring = false;
135142
if (dragtimeout) {
136143
let timeOutTimer = 1000;
137-
Bangle.setOptions({backlightTimeout: timeOutTimer, lockTimeout: timeOutTimer});
144+
Bangle.setOptions({backlightTimeout: timeOutTimer, lockTimeout});
138145
clearTimeout(dragtimeout);
139146
}
140147
if (which == null) {
@@ -152,7 +159,6 @@ function resetcounter(which) {
152159
ignoreonce = true;
153160
}
154161

155-
156162
updateScreen();
157163

158164
setWatch(function() {
@@ -163,6 +169,6 @@ setWatch(function() {
163169
}
164170
}
165171
var timeOutTimer = sGlob.timeout * 1000;
166-
Bangle.setOptions({backlightTimeout: timeOutTimer, lockTimeout: timeOutTimer});
172+
Bangle.setOptions({backlightTimeout: timeOutTimer, lockTimeout});
167173
load();
168174
}, BTN1, {repeat:true, edge:"falling"});

apps/counter2/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "counter2",
33
"name": "Counter2",
4-
"version": "0.06",
4+
"version": "0.07",
55
"description": "Dual Counter",
66
"readme":"README.md",
77
"icon": "counter2-icon.png",

apps/counter2/settings.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,17 @@
7070
onchange: v => {
7171
settings.buzz = v;
7272
writeSettings();
73+
},
74+
};
75+
appMenu['Keep unlocked'] = {
76+
value: settings.keepunlocked,
77+
onchange: v => {
78+
settings.keepunlocked = v;
79+
writeSettings();
7380
},
7481
};
7582
E.showMenu(appMenu);
7683
}
7784

7885
showMainMenu();
79-
})
86+
})

0 commit comments

Comments
 (0)