Skip to content

Commit fb8dfaf

Browse files
author
thyttan
committed
dial: (WIP) new module to dial settings/levels etc
1 parent c6c5475 commit fb8dfaf

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

modules/dial.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// upload to ram via espruino web ide while in development.
2+
3+
{
4+
/*
5+
Bangle.on('drag', function(event) { ... });
6+
Parameters
7+
8+
event - Object of form {x,y,dx,dy,b} containing touch coordinates, difference in touch coordinates, and an integer b containing number of touch points (currently 1 or 0)
9+
10+
11+
*/
12+
13+
let cumulativeDxPlusDy = 0;
14+
let level = 0;
15+
let dragHandler = function(e) { "ram"
16+
// Use cross product to decide if dialing down/left/screwing out or up/right/screwing in?
17+
/*
18+
// Quadrants: (1 || 2 || 3 || 4)
19+
if ((e.dx>0&&e.dy>0) || (e.dx>0&&e.dy>0) || (e.dx>0&&e.dy>0) || (e.dx>0&&e.dy>0)) { //screwing into the screen - increase
20+
21+
}
22+
23+
if ((e.dx>0&&e.dy>0) || (e.dx>0&&e.dy>0) || (e.dx>0&&e.dy>0) || (e.dx>0&&e.dy>0)) { //screwing out of the screen - decrease
24+
25+
}
26+
27+
*/
28+
29+
const PREV_DX_PLUS_DY = cumulativeDxPlusDy;
30+
if (e.y<g.getHeight()/2 ) {
31+
cumulativeDxPlusDy += e.dx;
32+
} else {
33+
cumulativeDxPlusDy -= e.dx;
34+
}
35+
if (e.x<g.getWidth()/2 ) {
36+
cumulativeDxPlusDy -= e.dy;
37+
} else {
38+
cumulativeDxPlusDy += e.dy;
39+
}
40+
41+
if (Math.abs(cumulativeDxPlusDy)<Math.abs(PREV_DX_PLUS_DY)) {
42+
cumulativeDxPlusDy = 0;
43+
}
44+
45+
let onStep = (step)=>{
46+
if (step>0) {
47+
level ++;
48+
}
49+
if (step<0) {
50+
level --;
51+
}
52+
print(step, level);
53+
g.clear().setFont("Vector:40").setFontAlign(0,0).drawString(level, 85, 85);
54+
Bangle.buzz(20, 0.2)
55+
cumulativeDxPlusDy = 0;
56+
}
57+
58+
if (cumulativeDxPlusDy > 50) {
59+
onStep(1);
60+
}
61+
if (cumulativeDxPlusDy < -50) {
62+
onStep(-1);
63+
}
64+
65+
66+
}
67+
68+
Bangle.on("drag", dragHandler);
69+
}
70+
71+

0 commit comments

Comments
 (0)