Skip to content

Commit 0696b12

Browse files
author
thyttan
committed
spotrem: refactor to use the Dial module
1 parent 068675e commit 0696b12

File tree

1 file changed

+1
-90
lines changed

1 file changed

+1
-90
lines changed

apps/spotrem/app.js

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ let dragHandler = function(e) {
128128
// setup volume knob here.
129129
cb(Math.sign(dx))
130130
resetOuterScopeVariables();
131-
let volumeKnob = dial(cb);
131+
let volumeKnob = require("Dial")(cb);
132132
let timingOutVolumeKnob = (e)=>{
133133
if (!e.b) {
134134
setKnobTimeout();
@@ -156,95 +156,6 @@ let dragHandler = function(e) {
156156
}
157157
};
158158

159-
160-
let dial = function(cb, options) {
161-
"ram";
162-
const SCREEN_W = g.getWidth();
163-
const SCREEN_H = g.getHeight();
164-
165-
options = Object.assign(
166-
{ stepsPerWholeTurn : 8,
167-
dialRect : {
168-
x: 0,
169-
y: 0,
170-
x2: SCREEN_W - 1,
171-
y2: SCREEN_H - 1,
172-
w: SCREEN_W,
173-
h: SCREEN_H,
174-
},
175-
}, options);
176-
177-
const DIAL_RECT = options.dialRect;
178-
179-
const CENTER = {
180-
x: DIAL_RECT.x + DIAL_RECT.w / 2,
181-
y: DIAL_RECT.y + DIAL_RECT.h / 2,
182-
};
183-
184-
const BASE_SCREEN_W = 176;
185-
const STEPS_PER_TURN = options.stepsPerWholeTurn;
186-
const BASE_THRESHOLD = 50;
187-
const THRESHOLD =
188-
BASE_THRESHOLD *
189-
(10 / STEPS_PER_TURN) *
190-
(DIAL_RECT.w / BASE_SCREEN_W);
191-
192-
let cumulative = 0;
193-
194-
function onDrag(e) {
195-
"ram";
196-
197-
if (
198-
e.x < DIAL_RECT.x ||
199-
e.x > DIAL_RECT.x2 ||
200-
e.y < DIAL_RECT.y ||
201-
e.y > DIAL_RECT.y2
202-
) {
203-
return;
204-
}
205-
206-
if (e.y < CENTER.y) {
207-
cumulative += e.dx;
208-
} else {
209-
cumulative -= e.dx;
210-
}
211-
212-
if (e.x < CENTER.x) {
213-
cumulative -= e.dy;
214-
} else {
215-
cumulative += e.dy;
216-
}
217-
218-
function stepHandler(step) {
219-
cumulative -= THRESHOLD * step;
220-
cb(step);
221-
}
222-
223-
while (cumulative > THRESHOLD) {
224-
stepHandler(1);
225-
}
226-
while (cumulative < -THRESHOLD) {
227-
stepHandler(-1);
228-
}
229-
230-
E.stopEventPropagation();
231-
}
232-
233-
return onDrag;
234-
/*
235-
if (exports.dial._handler) {
236-
Bangle.removeListener("drag", dial._handler);
237-
}
238-
239-
exports.dial._handler = onDrag;
240-
Bangle.prependListener("drag", onDrag);
241-
242-
Bangle.prependListener("swipe", ()=>{
243-
E.stopEventPropagation();
244-
}
245-
);*/
246-
};
247-
248159
// Navigation input on the main layout
249160
let setUI = function() {
250161
Bangle.setUI(

0 commit comments

Comments
 (0)