firmware: v6 — handshake ! + heartbeat movimiento
ESP32-CAM: - Envia '!' por Serial cuando el servidor esta listo - Watchdog subido a 800ms (compatible con heartbeat 150ms) ESP8266: - waitForReady(): bloquea hasta recibir '!' (max 90s) - loop(): ignora comandos hasta recibir '!' — sin movimiento al arrancar - Si ESP32 se reinicia (OTA), detecta nuevo '!' y reanuda Web (index.html): - Heartbeat: reenvio del comando de movimiento cada 150ms mientras tecla/boton pulsado - Mantiene vivo el watchdog y garantiza que el motor no pare solo - carStop() limpia el intervalo y envia S al soltar Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
e634138924
commit
c1b587b0a8
@@ -272,10 +272,16 @@ spEl.addEventListener('input',applySpeed);applySpeed();
|
||||
|
||||
let pX=90,pY=90;const ST=10;
|
||||
|
||||
// Heartbeat: reenvía el comando de movimiento cada 150ms mientras está pulsado
|
||||
// Mantiene vivo el watchdog del ESP32 (800ms) y garantiza que el motor siga
|
||||
let carIval=null;
|
||||
const carGo=(cmd)=>{send(cmd);if(carIval)clearInterval(carIval);carIval=setInterval(()=>send(cmd),150);};
|
||||
const carStop=()=>{if(carIval){clearInterval(carIval);carIval=null;}send('S');};
|
||||
|
||||
[['b-F','F'],['b-B','B'],['b-L','L'],['b-R','R']].forEach(([id,cmd])=>{
|
||||
const el=document.getElementById(id);
|
||||
const dn=()=>{el.classList.add('on');send(cmd);};
|
||||
const up=()=>{el.classList.remove('on');send('S');};
|
||||
const dn=()=>{el.classList.add('on');carGo(cmd);};
|
||||
const up=()=>{el.classList.remove('on');carStop();};
|
||||
el.addEventListener('mousedown',dn);el.addEventListener('mouseup',up);el.addEventListener('mouseleave',up);
|
||||
el.addEventListener('touchstart',e=>{e.preventDefault();dn();},{passive:false});
|
||||
el.addEventListener('touchend',e=>{e.preventDefault();up();},{passive:false});
|
||||
@@ -303,10 +309,10 @@ document.getElementById('b-led').addEventListener('click',()=>send('K'));
|
||||
|
||||
const held=new Set();
|
||||
document.addEventListener('keydown',e=>{
|
||||
if(e.repeat||held.has(e.key))return;held.add(e.key);
|
||||
if(held.has(e.key))return;held.add(e.key);
|
||||
switch(e.key){
|
||||
case'w':case'W':send('F');break;case's':case'S':send('B');break;
|
||||
case'a':case'A':send('L');break;case'd':case'D':send('R');break;
|
||||
case'w':case'W':carGo('F');break;case's':case'S':carGo('B');break;
|
||||
case'a':case'A':carGo('L');break;case'd':case'D':carGo('R');break;
|
||||
case'ArrowUp':pY=Math.max(0,pY-ST);send('Y'+pY);break;
|
||||
case'ArrowDown':pY=Math.min(180,pY+ST);send('Y'+pY);break;
|
||||
case'ArrowLeft':pX=Math.min(180,pX+ST);send('X'+pX);break;
|
||||
@@ -319,7 +325,7 @@ document.addEventListener('keydown',e=>{
|
||||
});
|
||||
document.addEventListener('keyup',e=>{
|
||||
held.delete(e.key);
|
||||
if('wWsSaAdD'.includes(e.key)&&e.key.trim())send('S');
|
||||
if('wWsSaAdD'.includes(e.key)&&e.key.trim())carStop();
|
||||
if('eE'.includes(e.key))eH();
|
||||
});
|
||||
</script>
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user