BTN improvement

pull/2041/head
Hank 2022-07-12 13:51:20 +02:00
parent 29e2387e4a
commit 1a5e7794f6
1 changed files with 36 additions and 57 deletions

View File

@ -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() {
Bangle.on("drag", e => {
if (!drag) { // start dragging
drag = {x: e.x, y: e.y};
} else if (!e.b) { // released
const dx = e.x-drag.x, dy = e.y-drag.y;
drag = null;
if (Math.abs(dx)>Math.abs(dy)+10) {
// horizontal
if (dx < dy) {
//console.log("left " + dx + " " + dy);
previousDrink();
} else {
//console.log("right " + dx + " " + dy);
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();
}
if (BANGLEJS2) {
Bangle.on("drag", e => {
if (!drag) { // start dragging
drag = {x: e.x, y: e.y};
} else if (!e.b) { // released
const dx = e.x-drag.x, dy = e.y-drag.y;
drag = null;
if (Math.abs(dx)>Math.abs(dy)+10) {
// horizontal
if (dx < dy) {
//console.log("left " + dx + " " + dy);
previousDrink();
} else {
//console.log("tap " + e.x + " " + e.y);
if (e.x > 145 && e.y > 145) {
resetDrinksFn();
}
//console.log("right " + dx + " " + dy);
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 {
//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();
showDrinks();