Skip to content

Commit cfb58bc

Browse files
authored
Merge pull request #3866 from thyttan/msgtwistscroll
msgtwscr: Temporarily activate scroll on twist function when a new message triggers the message app.
2 parents 91a9888 + c6b1c0c commit cfb58bc

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

apps/msgtwscr/ChangeLog

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

apps/msgtwscr/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Message Twist to Scroll
2+
3+
Temporarily activate scroll on twist function when a new message triggers the message app. This way it's possible to scroll through a message in the message scroller hands free.
4+
5+
## Usage
6+
7+
This is a bootloader app and only needs to be installed to add the functionality to the watch.
8+
9+
## Requests
10+
11+
Mention @thyttan in an issue on the espruino/BangleApps repository.
12+
13+
## Creator
14+
15+
thyttan

apps/msgtwscr/app.png

1.43 KB
Loading

apps/msgtwscr/boot.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
// twistThreshold How much acceleration to register a twist of the watch strap? Can be negative for opposite direction. default = 800
3+
// twistMaxY Maximum acceleration in Y to trigger a twist (low Y means watch is facing the right way up). default = -800
4+
// twistTimeout How little time (in ms) must a twist take from low->high acceleration? default = 1000
5+
let onTwistEmitDrag = ()=>{
6+
Bangle.setOptions({twistThreshold:2500, twistMaxY:-800, twistTimeout:400});
7+
let isTwistDragging = false;
8+
let twistHandler = ()=>{
9+
if (!isTwistDragging) {
10+
isTwistDragging = true;
11+
Bangle.setLocked(false);
12+
Bangle.setLCDPower(true);
13+
let i = 25;
14+
const int = setInterval(() => {
15+
Bangle.emit("drag", {dy:-3, b:i===0?0:1})
16+
i--;
17+
if (i<0) {
18+
clearInterval(int);
19+
isTwistDragging = false;
20+
}
21+
}, 10);
22+
}
23+
}
24+
Bangle.on("twist", twistHandler);
25+
// Give messagegui some extra time to add its remove function to
26+
// Bangle.uiRemove, then attach msgtwscr remove logic.
27+
setTimeout(
28+
()=>{if (Bangle.uiRemove) {
29+
let showMessageUIRemove = Bangle.uiRemove;
30+
Bangle.uiRemove = function () {
31+
Bangle.removeListener("twist", twistHandler)
32+
showMessageUIRemove();
33+
// Reset twist drag logic if we go to next message.
34+
attachAfterTimeout();
35+
}
36+
}},
37+
800)
38+
}
39+
40+
// If doing regular loads, not Bangle.load, this is used:
41+
if (global.__FILE__=="messagegui.new.js") {
42+
onTwistEmitDrag();
43+
}
44+
45+
let attachAfterTimeout = ()=>{
46+
setTimeout(()=>{
47+
if (global.__FILE__=="messagegui.new.js") {
48+
onTwistEmitDrag();
49+
}
50+
},700)
51+
// It feels like there's a more elegant solution than checking the filename
52+
// after 700 milliseconds. But this at least seems to work w/o sometimes
53+
// activating when it shouldn't.
54+
// Maybe we could add events for when fast load and/or Bangle.uiRemove occurs?
55+
// Then that could be used similarly to boot code and/or the `kill` event.
56+
}
57+
58+
// If Fastload Utils is installed this is used:
59+
Bangle.on("message", (_, msg)=>{if (Bangle.CLOCK && msg.new) {
60+
attachAfterTimeout();
61+
}});
62+
63+
}

apps/msgtwscr/metadata.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{ "id": "msgtwscr",
2+
"name": "Message Twist to Scroll",
3+
"version":"0.01",
4+
"description": "Temporarily activate scroll on twist function when a new message triggers the message app.",
5+
"icon": "app.png",
6+
"tags": "messages,tweak,scroll",
7+
"type": "bootloader",
8+
"supports" : ["BANGLEJS2"],
9+
"readme": "README.md",
10+
"storage": [
11+
{"name":"msgtwscr.boot.js","url":"boot.js"}
12+
]
13+
}

0 commit comments

Comments
 (0)