From a23bb8aca22386e72c46c7f87f083d73ff6a4cb0 Mon Sep 17 00:00:00 2001 From: pierre Date: Wed, 25 Dec 2024 16:31:45 +0100 Subject: [PATCH] Actualiser puck.js full standalone ux --- puck.js | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/puck.js b/puck.js index 61ce53f..107e295 100644 --- a/puck.js +++ b/puck.js @@ -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; }