BTN improvement
parent
29e2387e4a
commit
1a5e7794f6
|
|
@ -232,72 +232,51 @@ function resetDrinksFn() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function bjsGetButtonState() {
|
|
||||||
|
|
||||||
let btn1 = BTN1.read();
|
|
||||||
let btn2 = BTN2.read();
|
|
||||||
let btn3 = BTN3.read();
|
|
||||||
let btn4 = BTN4.read();
|
|
||||||
let btn5 = BTN5.read();
|
|
||||||
if (BTN1.read()) {
|
|
||||||
addDrink();
|
|
||||||
}
|
|
||||||
if (BTN2.read()) {
|
|
||||||
resetDrinksFn();
|
|
||||||
}
|
|
||||||
if (BTN3.read()) {
|
|
||||||
removeDrink();
|
|
||||||
}
|
|
||||||
if (BTN4.read()) {
|
|
||||||
previousDrink();
|
|
||||||
}
|
|
||||||
if (BTN5.read()) {
|
|
||||||
nextDrink();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function initDragEvents() {
|
function initDragEvents() {
|
||||||
Bangle.on("drag", e => {
|
|
||||||
if (!drag) { // start dragging
|
if (BANGLEJS2) {
|
||||||
drag = {x: e.x, y: e.y};
|
Bangle.on("drag", e => {
|
||||||
} else if (!e.b) { // released
|
if (!drag) { // start dragging
|
||||||
const dx = e.x-drag.x, dy = e.y-drag.y;
|
drag = {x: e.x, y: e.y};
|
||||||
drag = null;
|
} else if (!e.b) { // released
|
||||||
if (Math.abs(dx)>Math.abs(dy)+10) {
|
const dx = e.x-drag.x, dy = e.y-drag.y;
|
||||||
// horizontal
|
drag = null;
|
||||||
if (dx < dy) {
|
if (Math.abs(dx)>Math.abs(dy)+10) {
|
||||||
//console.log("left " + dx + " " + dy);
|
// horizontal
|
||||||
previousDrink();
|
if (dx < dy) {
|
||||||
} else {
|
//console.log("left " + dx + " " + dy);
|
||||||
//console.log("right " + dx + " " + dy);
|
previousDrink();
|
||||||
nextDrink();
|
|
||||||
}
|
|
||||||
} else if (Math.abs(dy)>Math.abs(dx)+10) {
|
|
||||||
// vertical
|
|
||||||
if (dx < dy) {
|
|
||||||
//console.log("down " + dx + " " + dy);
|
|
||||||
removeDrink();
|
|
||||||
} else {
|
|
||||||
//console.log("up " + dx + " " + dy);
|
|
||||||
addDrink();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//console.log("tap " + e.x + " " + e.y);
|
//console.log("right " + dx + " " + dy);
|
||||||
if (e.x > 145 && e.y > 145) {
|
nextDrink();
|
||||||
resetDrinksFn();
|
}
|
||||||
}
|
} else if (Math.abs(dy)>Math.abs(dx)+10) {
|
||||||
|
// vertical
|
||||||
|
if (dx < dy) {
|
||||||
|
//console.log("down " + dx + " " + dy);
|
||||||
|
removeDrink();
|
||||||
|
} else {
|
||||||
|
//console.log("up " + dx + " " + dy);
|
||||||
|
addDrink();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//console.log("tap " + e.x + " " + e.y);
|
||||||
|
if (e.x > 145 && e.y > 145) {
|
||||||
|
resetDrinksFn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
} else {
|
||||||
|
setWatch(addDrink, BTN1, { repeat: true, debounce:50 });
|
||||||
|
setWatch(removeDrink, BTN3, { repeat: true, debounce:50 });
|
||||||
|
setWatch(previousDrink, BTN4, { repeat: true, debounce:50 });
|
||||||
|
setWatch(nextDrink, BTN5, { repeat: true, debounce:50 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!BANGLEJS2) {
|
|
||||||
setInterval(bjsGetButtonState, 100); // 10 Hz
|
|
||||||
}
|
|
||||||
|
|
||||||
loadMySettings();
|
loadMySettings();
|
||||||
showDrinks();
|
showDrinks();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue