-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[BackLite] Add button release check #4005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
b2de155
0e83a45
d4c845c
616283d
f7da463
b2868e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
0.01: New app! (settings, boot.js). | ||
0.02: Fix settings defaulting brightness to 0 | ||
0.03: When button is released, cancel long press check. (Remove false triggers) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,26 +11,36 @@ | |||||||||||||||||||||
//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); | ||||||||||||||||||||||
//remove large settings object from memory | ||||||||||||||||||||||
delete s; | ||||||||||||||||||||||
s=null; | ||||||||||||||||||||||
const longPressTime=400; //(ms) | ||||||||||||||||||||||
|
||||||||||||||||||||||
var longPressTimer; | ||||||||||||||||||||||
Bangle.on('lock', function(isLocked) { | ||||||||||||||||||||||
Bangle.setLCDBrightness(0); | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (!isLocked) { | ||||||||||||||||||||||
// Just unlocked — give a short delay and check if BTN1 is still pressed | ||||||||||||||||||||||
setTimeout(() => { | ||||||||||||||||||||||
longPressTimer=setTimeout(() => { | ||||||||||||||||||||||
if (digitalRead(BTN1)) { | ||||||||||||||||||||||
//set brightness until. locked. | ||||||||||||||||||||||
Comment on lines
+25
to
27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think my below suggestion is right unless there's a race between 'clearTimeout()` and the invocation of the timeout func. If you add debug logs to both the timeout function (each arm of the
Suggested change
|
||||||||||||||||||||||
Bangle.setLCDBrightness(getSettings().brightness); | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
Bangle.setLCDBrightness(0); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
clearTimeout(longPressTimer) | ||||||||||||||||||||||
RKBoss6 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
}, longPressTime); // Slight delay to allow unlock to settle | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
setWatch(() => { | ||||||||||||||||||||||
if (longPressTimer) { | ||||||||||||||||||||||
clearTimeout(longPressTimer); | ||||||||||||||||||||||
longPressTimer = null; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}, BTN1, { repeat:true, edge:'rising' }); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.