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