Actualiser puck.js

full standalone ux
This commit is contained in:
Pierre Guillod 2024-12-25 16:31:45 +01:00
parent e7164c2305
commit a23bb8aca2

53
puck.js
View file

@ -23,16 +23,30 @@ function ledsAnim(level) {
setTimeout(function(){digitalWrite([LED3,LED2,LED1],WHITE);}, 200);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 205);
break;
case "adjust":
case "add":
digitalWrite([LED3,LED2,LED1],WHITE);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 5);
break;
case "start":
case "ring":
digitalWrite([LED3,LED2,LED1],RED);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 5);
break;
case "cannot_remove":
digitalWrite([LED3,LED2,LED1],RED);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 5);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],RED);}, 200);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 205);
break;
case "remove":
digitalWrite([LED3,LED2,LED1],WHITE);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 5);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],WHITE);}, 200);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 205);
break;
case "start":
digitalWrite([LED3,LED2,LED1],WHITE);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 200);
break;
}
}
@ -44,11 +58,11 @@ var fsmTm = null;
function fsmPressed() {
switch (fsmState) {
case "setting":
ledsAnim("adjust");
ledsAnim("add");
clearTimeout(fsmTm);
fsmTm = setInterval(function() {fsmTick();}, 5000);
fsmCount += 30;
broadcast(["Set to ", fsmCount.toString(),"s"].join(''));
broadcast(["Set to ", Math.floor(fsmCount / 60).toString().padStart(2, "0"), "'", (fsmCount % 60).toString().padStart(2, "0"),"\""].join(''));
break;
}
}
@ -60,7 +74,18 @@ function fsmLongPressed() {
fsmTm = setTimeout(function() {fsmTick();}, 5000);
fsmState = "setting";
fsmCount = 30;
broadcast(["Set to ", fsmCount.toString(),"s"].join(''));
broadcast(["Set to ", Math.floor(fsmCount / 60).toString().padStart(2, "0"), "'", (fsmCount % 60).toString().padStart(2, "0"),"\""].join(''));
break;
case "setting":
clearTimeout(fsmTm);
fsmTm = setInterval(function() {fsmTick();}, 5000);
if (fsmCount > 30) {
fsmCount -= 30;
ledsAnim("remove");
} else {
ledsAnim("cannot_remove");
}
broadcast(["Set to ", Math.floor(fsmCount / 60).toString().padStart(2, "0"), "'", (fsmCount % 60).toString().padStart(2, "0"),"\""].join(''));
break;
case "countdown":
ledsAnim("stop");
@ -68,6 +93,12 @@ function fsmLongPressed() {
clearInterval(fsmIv);
fsmState = "reset";
break;
case "ring":
ledsAnim("stop");
broadcast(null);
clearInterval(fsmIv);
fsmState = "reset";
break;
}
}
@ -91,9 +122,15 @@ function fsmTick() {
var msg = [minutes_tens.toString(),minutes_units.toString(),":",seconds_tens.toString(),seconds_units.toString()].join('');
broadcast(msg);
if (!fsmCount) {
broadcast(null);
clearInterval(fsmIv);
fsmState = "reset";
fsmState = "ring";
}
break;
case "ring":
ledsAnim("ring");
if (bcstMsg.charAt(0) == " ") {
broadcast("Time's up!");
} else {
broadcast(" Time's up!");
}
break;
}