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],WHITE);}, 200);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 205); setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 205);
break; break;
case "adjust": case "add":
digitalWrite([LED3,LED2,LED1],WHITE); digitalWrite([LED3,LED2,LED1],WHITE);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 5); setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 5);
break; 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); digitalWrite([LED3,LED2,LED1],WHITE);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 5); setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 5);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],WHITE);}, 200); setTimeout(function(){digitalWrite([LED3,LED2,LED1],WHITE);}, 200);
setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 205); setTimeout(function(){digitalWrite([LED3,LED2,LED1],BLACK);}, 205);
break; 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() { function fsmPressed() {
switch (fsmState) { switch (fsmState) {
case "setting": case "setting":
ledsAnim("adjust"); ledsAnim("add");
clearTimeout(fsmTm); clearTimeout(fsmTm);
fsmTm = setInterval(function() {fsmTick();}, 5000); fsmTm = setInterval(function() {fsmTick();}, 5000);
fsmCount += 30; 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; break;
} }
} }
@ -60,7 +74,18 @@ function fsmLongPressed() {
fsmTm = setTimeout(function() {fsmTick();}, 5000); fsmTm = setTimeout(function() {fsmTick();}, 5000);
fsmState = "setting"; fsmState = "setting";
fsmCount = 30; 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; break;
case "countdown": case "countdown":
ledsAnim("stop"); ledsAnim("stop");
@ -68,6 +93,12 @@ function fsmLongPressed() {
clearInterval(fsmIv); clearInterval(fsmIv);
fsmState = "reset"; fsmState = "reset";
break; 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(''); var msg = [minutes_tens.toString(),minutes_units.toString(),":",seconds_tens.toString(),seconds_units.toString()].join('');
broadcast(msg); broadcast(msg);
if (!fsmCount) { if (!fsmCount) {
broadcast(null); fsmState = "ring";
clearInterval(fsmIv); }
fsmState = "reset"; break;
case "ring":
ledsAnim("ring");
if (bcstMsg.charAt(0) == " ") {
broadcast("Time's up!");
} else {
broadcast(" Time's up!");
} }
break; break;
} }