Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
<!doctype html>
<html lang="en"><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<title>Mower</title>
<link rel="stylesheet" href="/vendor/leaflet/leaflet.css"/>
<style>
:root{
--bg:#000;--panel:#15181e;--panel2:#1c2128;--line:#262b33;--ink:#f4f6f8;--mut:#7d8895;
--blue:#3e6ae1;--ok:#2ecd8a;--warn:#e8b13a;--bad:#e5504a;
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;height:100%;background:var(--bg);color:var(--ink);user-select:none;
font:16px/1.4 -apple-system,BlinkMacSystemFont,"SF Pro Display","Segoe UI",Roboto,Arial,sans-serif;
-webkit-font-smoothing:antialiased;overscroll-behavior:none}
.wrap{max-width:500px;margin:0 auto;min-height:100%;padding:18px 18px calc(18px + env(safe-area-inset-bottom));
display:flex;flex-direction:column;gap:16px}
/* header */
header{display:flex;align-items:center;gap:10px;padding-top:env(safe-area-inset-top)}
.brand{display:flex;align-items:center;gap:9px;flex:1}
.mark{width:24px;height:24px;border-radius:50%;border:2.5px solid var(--ok);position:relative}
.mark::after{content:"";position:absolute;inset:5px;border-radius:50%;background:var(--ok)}
.brand b{font-weight:600;font-size:15px;letter-spacing:.2px}
.brand span{color:var(--mut);font-size:12px}
.batt{display:flex;align-items:center;gap:7px;font-size:14px;font-variant-numeric:tabular-nums;color:var(--mut)}
.batt b{color:var(--ink);font-weight:600}
.cell{width:26px;height:13px;border:1.5px solid var(--mut);border-radius:3px;position:relative;padding:1.5px}
.cell::after{content:"";position:absolute;right:-3px;top:3px;width:2px;height:5px;background:var(--mut);border-radius:0 1px 1px 0}
.cell i{display:block;height:100%;background:var(--ok);border-radius:1px;transition:width .6s,background .6s}
/* hero status */
.status{text-align:center;margin-top:4px}
.status .verb{font-size:30px;font-weight:600;letter-spacing:.5px;transition:color .3s}
.status .sub{color:var(--mut);font-size:13.5px;margin-top:3px;height:18px;transition:color .3s}
.status.bad .verb{color:var(--bad)} .status.warn .verb{color:var(--warn)} .status.go .verb{color:var(--ok)}
/* mower stage */
.stage{position:relative;height:230px;display:flex;align-items:center;justify-content:center}
.glow{position:absolute;width:340px;height:340px;border-radius:50%;
background:radial-gradient(closest-side,rgba(62,106,225,.16),transparent 70%);transition:background .4s}
.stage.go .glow{background:radial-gradient(closest-side,rgba(46,205,138,.16),transparent 70%)}
.stage.bad .glow{background:radial-gradient(closest-side,rgba(229,80,74,.20),transparent 70%)}
svg.mower{position:relative;height:215px;transition:filter .3s}
.chips{display:flex;justify-content:center;gap:8px;flex-wrap:wrap;margin-top:-6px}
.chip{font-size:12px;color:var(--mut);background:var(--panel);border:1px solid var(--line);border-radius:20px;padding:5px 12px}
.chip b{color:var(--ink);font-weight:600}
.chip.warn{color:var(--warn);border-color:#5a4413}.chip.bad{color:var(--bad);border-color:#5a2420}
.cams{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.cam{position:relative;border-radius:14px;overflow:hidden;border:1px solid var(--line);background:#0c1014;aspect-ratio:16/9}
.cam img{width:100%;height:100%;display:block;object-fit:cover}
.cam .cl{position:absolute;left:8px;bottom:6px;font-size:10px;color:#cdd6df;background:rgba(0,0,0,.55);padding:2px 7px;border-radius:10px;letter-spacing:.05em;backdrop-filter:blur(4px)}
/* map */
.mapcard{border-radius:20px;overflow:hidden;border:1px solid var(--line);height:230px;position:relative;background:#0c1014}
#map{height:100%;width:100%;filter:saturate(.85) brightness(.92)}
.maptag{position:absolute;left:12px;top:10px;z-index:500;font-size:11px;color:var(--mut);
background:rgba(0,0,0,.55);padding:3px 9px;border-radius:20px;backdrop-filter:blur(6px)}
.heading-arrow{filter:drop-shadow(0 0 6px rgba(62,106,225,.9))}
.mapctl{position:absolute;right:10px;top:10px;z-index:500;display:flex;gap:6px}
.mapctl button{font-size:12px;font-weight:600;border:none;color:#fff;border-radius:20px;padding:7px 12px;
background:rgba(20,24,30,.85);backdrop-filter:blur(8px);box-shadow:0 0 0 1px rgba(255,255,255,.08)}
.mapctl button.go{background:var(--blue)} .mapctl button.warn{background:#2a2017;color:var(--warn)}
.hint{position:absolute;left:12px;bottom:10px;z-index:500;font-size:11px;color:#cfd6dd;
background:rgba(0,0,0,.6);padding:4px 10px;border-radius:20px;display:none}
/* routes */
.routes{display:flex;flex-direction:column;gap:8px}
.rhead{display:flex;align-items:center;justify-content:space-between;color:var(--mut);font-size:12px;
text-transform:uppercase;letter-spacing:.08em;padding:0 2px}
.route{display:flex;align-items:center;gap:10px;background:var(--panel);border:1px solid var(--line);
border-radius:14px;padding:11px 14px}
.route .rn{flex:1;font-weight:600;font-size:14.5px}
.route .rt{font-size:11px;color:var(--mut);background:var(--panel2);padding:2px 8px;border-radius:20px}
.route .rt.coverage{color:#bcd0f0} .route .rt.taught{color:#bfe9d6}
.route button{border:none;border-radius:10px;padding:9px 14px;font-weight:600;font-size:13px}
.route .run{background:var(--ok);color:#04130c} .route .del{background:transparent;color:#6b7682;font-size:18px;padding:6px 8px}
.empty{color:#566; font-size:13px;text-align:center;padding:10px;color:var(--mut)}
/* controls */
.seg{display:flex;background:var(--panel);border-radius:16px;padding:5px;gap:4px}
.seg button{flex:1;background:transparent;border:none;color:var(--mut);font-size:14.5px;font-weight:600;
padding:13px 0;border-radius:12px;transition:.2s}
.seg button.active{background:var(--blue);color:#fff}
.row{display:flex;gap:11px}
.btn{flex:1;border:none;background:var(--panel);color:var(--ink);font-size:15.5px;font-weight:600;
padding:17px 10px;border-radius:16px;min-height:58px;transition:.15s}
.btn:active{transform:scale(.97)}
.btn.primary{background:var(--ink);color:#000}
.btn.armed{background:var(--ok);color:#04130c}
.btn.blade.on{background:var(--bad);color:#fff}
.btn.teach.on{background:var(--blue);color:#fff}
.btn:disabled{opacity:.35}
.estop{border:none;border-radius:18px;font-size:17px;font-weight:700;letter-spacing:1.5px;padding:20px;
min-height:66px;background:#1a1012;color:var(--bad);box-shadow:inset 0 0 0 1.5px rgba(229,80,74,.45);transition:.15s}
.estop:active{transform:scale(.98)}
.estop.engaged{background:var(--bad);color:#fff;box-shadow:none;animation:pulse 1.1s infinite}
@keyframes pulse{50%{background:#c2403b}}
.foot{color:#4f5862;font-size:10.5px;text-align:center;margin-top:auto;letter-spacing:.2px}
.off{position:fixed;inset:0;background:rgba(0,0,0,.6);display:none;align-items:center;justify-content:center;
color:var(--mut);font-size:14px;z-index:900}
</style></head>
<body>
<div class="wrap">
<header>
<div class="brand"><div class="mark"></div><b>Mower</b><span>Gravely ZT 52"</span></div>
<div class="batt"><b id="bpct">—</b><span id="bv" style="color:var(--mut)"></span>
<svg id="bspark" width="52" height="16" viewBox="0 0 52 16" style="opacity:.8"><polyline id="bline" fill="none" stroke="#2ecd8a" stroke-width="1.5" points=""/></svg>
<div class="cell"><i id="bfill" style="width:0"></i></div></div>
</header>
<div class="status" id="status">
<div class="verb" id="verb">—</div>
<div class="sub" id="sub"></div>
</div>
<div class="stage" id="stage">
<div class="glow"></div>
<!-- top-down mower mockup -->
<svg class="mower" id="mower" viewBox="0 0 200 215" fill="none" xmlns="http://www.w3.org/2000/svg">
<!-- obstacle arc (front) -->
<path id="obsArc" d="M55 26 A 50 50 0 0 1 145 26" stroke="#e5504a" stroke-width="5"
stroke-linecap="round" opacity="0" fill="none"/>
<!-- cutting deck (52") -->
<rect id="deck" x="14" y="30" width="172" height="44" rx="14" fill="#20262e" stroke="#2c333d" stroke-width="1.5"/>
<!-- blade discs -->
<circle id="b1" cx="60" cy="52" r="13" fill="#171c22"/>
<circle id="b2" cx="100" cy="52" r="13" fill="#171c22"/>
<circle id="b3" cx="140" cy="52" r="13" fill="#171c22"/>
<!-- front casters -->
<circle cx="36" cy="22" r="8" fill="#11151a"/><circle cx="164" cy="22" r="8" fill="#11151a"/>
<!-- frame body -->
<rect x="52" y="74" width="96" height="104" rx="16" fill="#262d36"/>
<!-- brain box -->
<rect x="74" y="96" width="52" height="40" rx="8" fill="#2f3946" stroke="#3e6ae1" stroke-width="1.5"/>
<circle cx="100" cy="116" r="6" fill="#3e6ae1" id="brain"/>
<!-- seat -->
<rect x="76" y="144" width="48" height="30" rx="10" fill="#1b212a"/>
<!-- rear drive wheels -->
<rect x="20" y="120" width="22" height="70" rx="10" fill="#0e1116" stroke="#222933" stroke-width="1.5"/>
<rect x="158" y="120" width="22" height="70" rx="10" fill="#0e1116" stroke="#222933" stroke-width="1.5"/>
<!-- gps mast dot -->
<circle cx="100" cy="86" r="3.4" fill="#2ecd8a"/>
</svg>
</div>
<div class="chips">
<div class="chip" id="cGps">GPS —</div>
<div class="chip" id="cSpd">—</div>
<div class="chip" id="cSlope">TILT —</div>
<div class="chip" id="cOh">OVERHEAD —</div>
</div>
<div class="cams">
<div class="cam"><img id="camFront" alt="front camera"><span class="cl" id="camFrontLabel">FRONT</span></div>
<div class="cam"><img id="camRear" alt="rear camera"><span class="cl">REAR</span></div>
</div>
<div class="mapcard">
<div class="maptag">live position</div>
<div class="mapctl" id="mapctl">
<button id="drawBtn" onclick="toggleDraw()">✏︎ Draw zone</button>
<button id="fenceBtn" onclick="toggleFence()">⛨ Fence</button>
<button id="koBtn" onclick="startKeepout()" style="display:none">+ Keep-out</button>
<button id="hotBtn" onclick="addHotspots()" style="display:none"></button>
<button id="planBtn" class="go" onclick="planZone()" style="display:none">Plan coverage</button>
<button id="setFenceBtn" class="go" onclick="setFence()" style="display:none">Set fence</button>
<button id="clearBtn" class="warn" onclick="clearDraw()" style="display:none">✕</button>
</div>
<div class="hint" id="hint">tap the map to add boundary points</div>
<div id="map"></div>
</div>
<div class="routes">
<div class="rhead"><span>Routes & zones</span><span id="rcount"></span></div>
<div id="routeList"></div>
</div>
<div class="seg" id="seg">
<button data-mode="MANUAL">Manual</button>
<button data-mode="HOLD">Hold</button>
<button data-mode="AUTO">Auto</button>
</div>
<div class="row">
<button class="btn" id="armBtn" onclick="toggleArm()">Arm</button>
<button class="btn primary" id="startBtn" onclick="cmd('start')">Start mow</button>
<button class="btn" onclick="cmd('pause')">Pause</button>
</div>
<div class="row">
<button class="btn teach" id="teachBtn" onclick="toggleTeach()">Teach path</button>
<button class="btn blade" id="bladeBtn" onclick="toggleBlade()">Blade off</button>
</div>
<div class="row">
<button class="btn" id="engineBtn" onclick="toggleEngine()">Engine</button>
<button class="btn" id="dumpBtn" onclick="cmd('bagger_dump')">Dump bags</button>
<button class="btn" id="blowerBtn" onclick="toggleBlower()">Blower</button>
<button class="btn" id="trimBtn" onclick="toggleTrimmer()">Trimmer</button>
<button class="btn" id="sprayBtn" onclick="toggleSprayer()">Sprayer</button>
</div>
<div class="foot" id="svcline" style="text-align:left"></div>
<button class="estop" id="estopBtn" onclick="estop()">EMERGENCY STOP</button>
<div class="foot">The on-screen E-STOP commands HOLD · disarm · blade-off. The physical e-stop & RC kill are the real safety chain.</div>
</div>
<div class="off" id="off">reconnecting…</div>
<script src="/vendor/leaflet/leaflet.js"></script>
<script>
let st={}, map, marker, path, pts=[], mapReady=false, planRoute=null, shownRouteId=null, ghost=null, obsLayer=null;
function initMap(lat,lon){
map=L.map('map',{zoomControl:false,attributionControl:false}).setView([lat,lon],18);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{maxZoom:20}).addTo(map);
L.control.attribution({prefix:false}).addAttribution('© OpenStreetMap').addTo(map);
path=L.polyline([],{color:'#2ecd8a',weight:4,opacity:.9}).addTo(map);
const icon=L.divIcon({className:'',html:
'<svg class="heading-arrow" id="arrow" width="34" height="34" viewBox="0 0 34 34">'+
'<circle cx="17" cy="17" r="9" fill="rgba(62,106,225,.25)"/>'+
'<path d="M17 4 L25 24 L17 19 L9 24 Z" fill="#3e6ae1" stroke="#fff" stroke-width="1.2"/></svg>',
iconSize:[34,34],iconAnchor:[17,17]});
marker=L.marker([lat,lon],{icon}).addTo(map);
map.on('click', onMapClick);
ghost=L.circleMarker([lat,lon],{radius:7,color:'#8fd0ff',fillOpacity:0,weight:2,dashArray:'3 3',interactive:false}).addTo(map);
obsLayer=L.layerGroup().addTo(map);
loadObstacles();
mapReady=true;
loadRoutes();
}
// 63: remembered obstacle hits — repeated marks suggest a permanent fence cut
async function loadObstacles(){
try{
const hits=await (await fetch('/api/obstacles')).json();
obsLayer.clearLayers();
hits.forEach(h=>L.circleMarker([h.lat,h.lon],{radius:6,color:'#e5504a',fillColor:'#e5504a',
fillOpacity:.25,weight:1,interactive:false}).addTo(obsLayer));
hotspots=await (await fetch('/api/obstacles/hotspots')).json();
hotspots.forEach(h=>L.polygon(h.keepout,{color:'#e5504a',weight:1.5,dashArray:'4 4',
fillOpacity:.05,interactive:false}).addTo(obsLayer));
showHotBtn();
}catch(e){}
}
// repeated sonar stops at one spot -> offered as keep-outs while drawing a zone
let hotspots=[];
function showHotBtn(){
const b=document.getElementById('hotBtn');
b.style.display=(drawing&&hotspots.length)?'block':'none';
b.textContent='⚑ '+hotspots.length+' sonar spot'+(hotspots.length===1?'':'s');
}
function addHotspots(){
if(!zone){ document.getElementById('sub').textContent='⚠ draw the lawn boundary, then + Keep-out, first'; return; }
hotspots.forEach(h=>{ holes.push(h.keepout);
frozen.push(L.polygon(h.keepout,{color:'#e0525a',weight:2,fillOpacity:.25,interactive:false}).addTo(map)); });
document.getElementById('sub').textContent='added '+hotspots.length+' sonar keep-out'+(hotspots.length===1?'':'s');
document.getElementById('hotBtn').style.display='none';
}
setInterval(loadObstacles, 30000);
// 61: ghost mower — where the plan says it SHOULD be (nearest point on the plan)
function updateGhost(s){
if(!ghost||!planRoute) return;
const lls=planRoute.getLatLngs(); if(!lls||lls.length<2) return;
let best=null,bd=1e18;
for(let i=0;i<lls.length-1;i++){
const a=lls[i],b=lls[i+1];
const t=Math.max(0,Math.min(1,((s.lat-a.lat)*(b.lat-a.lat)+(s.lon-a.lng)*(b.lng-a.lng))/
(((b.lat-a.lat)**2+(b.lng-a.lng)**2)||1e-12)));
const q=[a.lat+t*(b.lat-a.lat), a.lng+t*(b.lng-a.lng)];
const d=(s.lat-q[0])**2+(s.lon-q[1])**2;
if(d<bd){bd=d;best=q;}
}
if(best) ghost.setLatLng(best);
}
// ---- zone / fence drawing + coverage ----
let drawing=false, fencing=false, bPts=[], bMarkers=[], bPoly=null, planLayer=null, fenceLayer=null;
// zone drawing: the first ring is the lawn; each "+ Keep-out" freezes the ring
// being drawn and starts a new one — beds, trees, the shed — left unmowed.
let zone=null, holes=[], frozen=[];
const HINT_ZONE='tap the map to add boundary points', HINT_KO='tap the corners of a bed / tree / shed to leave unmowed';
function toggleDraw(){
if(fencing) toggleFence();
drawing=!drawing;
document.getElementById('drawBtn').textContent = drawing?'Drawing…':'✏︎ Draw zone';
document.getElementById('drawBtn').classList.toggle('go',drawing);
document.getElementById('planBtn').style.display = drawing?'block':'none';
document.getElementById('koBtn').style.display = drawing?'block':'none';
showHotBtn();
document.getElementById('clearBtn').style.display = (drawing||fencing)?'block':'none';
document.getElementById('hint').style.display = drawing?'block':'none';
document.getElementById('hint').textContent = HINT_ZONE;
if(!drawing) clearDraw(true);
}
function startKeepout(){
const ring=bPts.map(ll=>[ll.lat,ll.lng]);
if(!zone){
if(ring.length<3){ document.getElementById('sub').textContent='⚠ draw the lawn boundary first (3+ points)'; return; }
zone=ring;
} else if(ring.length>=3){ holes.push(ring); }
const isZone = ring===zone;
frozen.push(L.polygon(ring,{color:isZone?'#3e6ae1':'#e0525a',weight:2,
fillOpacity:isZone?.08:.25,interactive:false}).addTo(map));
bMarkers.forEach(m=>m.remove()); bMarkers=[]; bPts=[];
if(bPoly){bPoly.remove();bPoly=null;}
document.getElementById('hint').textContent = HINT_KO;
}
function toggleFence(){
if(drawing) toggleDraw();
fencing=!fencing;
document.getElementById('fenceBtn').textContent = fencing?'Fencing…':'⛨ Fence';
document.getElementById('fenceBtn').classList.toggle('go',fencing);
document.getElementById('setFenceBtn').style.display = fencing?'block':'none';
document.getElementById('clearBtn').style.display = (drawing||fencing)?'block':'none';
const h=document.getElementById('hint');
h.style.display = fencing?'block':'none';
h.textContent = fencing?'tap the boundary the machine must stay inside — Set with 0 points clears it'
:'tap the map to add boundary points';
if(!fencing) clearDraw(true);
}
function onMapClick(e){
if(!drawing && !fencing) return;
const col = fencing ? '#2ecd8a' : (zone ? '#e0525a' : '#3e6ae1');
bPts.push(e.latlng);
bMarkers.push(L.circleMarker(e.latlng,{radius:5,color:col,fillColor:col,fillOpacity:1}).addTo(map));
if(bPoly) bPoly.remove();
bPoly=L.polygon(bPts,{color:col,weight:2,dashArray:'5 5',fillOpacity:.08}).addTo(map);
}
function clearDraw(keepMode){
bMarkers.forEach(m=>m.remove()); bMarkers=[]; bPts=[];
if(bPoly){bPoly.remove();bPoly=null;}
frozen.forEach(l=>l.remove()); frozen=[]; zone=null; holes=[];
if(!keepMode){ if(drawing) toggleDraw(); if(fencing) toggleFence(); }
}
async function setFence(){
const polygon=bPts.map(ll=>[ll.lat,ll.lng]); // empty = clear the fence
const r=await fetch('/api/fence',{method:'POST',headers:{'Content-Type':'application/json'},
body:JSON.stringify({polygon})});
const j=await r.json();
document.getElementById('sub').textContent=(j.ok?'':'⚠ ')+j.msg;
if(j.ok){ clearDraw(true); toggleFence(); }
}
function renderFence(s){
const poly=s.fence||[];
const key=JSON.stringify(poly);
if(renderFence._key===key) return; renderFence._key=key;
if(fenceLayer){fenceLayer.remove();fenceLayer=null;}
if(poly.length>=3 && s.fence_enabled)
fenceLayer=L.polygon(poly,{color:'#2ecd8a',weight:2.5,fillOpacity:.03,interactive:false}).addTo(map);
}
async function planZone(){
const ring=bPts.map(ll=>[ll.lat,ll.lng]);
const polygon=zone||ring, keepouts=zone?holes.concat(ring.length>=3?[ring]:[]):[];
if(polygon.length<3){ document.getElementById('sub').textContent='⚠ tap at least 3 boundary points'; return; }
const r=await fetch('/api/zones/plan',{method:'POST',headers:{'Content-Type':'application/json'},
body:JSON.stringify({name:'Zone '+new Date().toLocaleTimeString().slice(0,5),polygon,keepouts,turns:'smooth'})});
const j=await r.json();
if(j.ok){
if(planLayer) planLayer.remove();
planLayer=L.polyline(j.points,{color:'#3e6ae1',weight:2,opacity:.5}).addTo(map);
document.getElementById('sub').textContent=j.msg;
clearDraw(); toggleDraw(); loadRoutes();
} else { document.getElementById('sub').textContent='⚠ '+j.msg; }
}
// ---- routes list ----
async function loadRoutes(){
try{
const list=await (await fetch('/api/missions')).json();
const el=document.getElementById('routeList');
document.getElementById('rcount').textContent=list.length?list.length:'';
if(!list.length){ const d=document.createElement('div'); d.className='empty';
d.textContent='No routes yet — Teach a path or draw a zone on the map.'; el.replaceChildren(d); return; }
// build DOM with textContent — never interpolate route names (user input) into HTML
el.replaceChildren(...list.map(r=>{
const row=document.createElement('div'); row.className='route';
const nm=document.createElement('span'); nm.className='rn'; nm.textContent=r.name;
const tp=document.createElement('span');
tp.className='rt '+(r.type==='coverage'?'coverage':'taught'); // constrained class, not raw input
tp.textContent=r.type+' · '+r.n;
const run=document.createElement('button'); run.className='run'; run.textContent='Run';
run.addEventListener('click',()=>runRoute(r.id));
const del=document.createElement('button'); del.className='del'; del.textContent='✕';
del.addEventListener('click',()=>delRoute(r.id));
row.append(nm,tp,run,del); return row;
}));
}catch(e){}
}
async function runRoute(id){
if(!st.armed){ document.getElementById('sub').textContent='⚠ arm first, then Run'; return; }
await cmd('run_route',{id});
}
async function delRoute(id){
await fetch('/api/missions/delete',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({id})});
loadRoutes();
}
setInterval(loadRoutes, 4000); // pick up teach-saved routes
async function loadPlan(id){
try{ const r=await (await fetch('/api/route?id='+encodeURIComponent(id))).json();
if(r&&r.points){ if(planRoute) planRoute.remove();
planRoute=L.polyline(r.points,{color:'#3a8ddb',weight:3,opacity:.45,dashArray:'4 6'}).addTo(map);
map.fitBounds(planRoute.getBounds(),{padding:[30,30],maxZoom:19}); } }catch(e){}
}
function updateMap(s){
if(!mapReady){ initMap(s.lat,s.lon); }
renderFence(s);
updateGhost(s);
if(s.route_id!==shownRouteId){ // new run (or cleared) → reset overlays
shownRouteId=s.route_id; pts=[]; path.setLatLngs([]);
if(s.route_id) loadPlan(s.route_id);
else if(planRoute){ planRoute.remove(); planRoute=null; }
}
const ll=[s.lat,s.lon];
marker.setLatLng(ll);
const a=document.getElementById('arrow'); if(a) a.style.transform='rotate('+(s.heading||0)+'deg)';
if(s.speed>0){ pts.push(ll); path.setLatLngs(pts); } // green = actually mowed
map.panTo(ll,{animate:true,duration:.6});
}
async function cmd(c,args){try{const r=await fetch('/api/command',{method:'POST',
headers:{'Content-Type':'application/json'},body:JSON.stringify({cmd:c,args:args||{}})});
const j=await r.json(); if(!j.ok) document.getElementById('sub').textContent='⚠ '+j.msg;}catch(e){}}
function toggleArm(){cmd(st.armed?'disarm':'arm');}
function toggleBlade(){cmd('blade',{on:!st.blade});}
function toggleTeach(){cmd(st.mission==='teaching'?'teach_stop':'teach_start');}
function estop(){st.estop?cmd('clear_estop'):cmd('estop');}
function toggleEngine(){cmd(st.engine==='run'?'engine_stop':'engine_start');}
function toggleBlower(){cmd('boom',{blower:!(st.boom&&st.boom.blower)});}
function toggleTrimmer(){cmd('boom',{trimmer:!(st.boom&&st.boom.trimmer)});}
function toggleSprayer(){
if(!(st.sprayer&&st.sprayer.attached)){ cmd('sprayer',{attached:true}); return; }
cmd('sprayer',{spraying:!(st.sprayer&&st.sprayer.spraying)});
}
document.querySelectorAll('#seg button').forEach(b=>b.onclick=()=>cmd('mode',{mode:b.dataset.mode}));
function verbFor(s){
if(s.estop) return ['EMERGENCY STOP','bad'];
if(s.fence_breach) return ['OUTSIDE FENCE','bad'];
if(s.mission==='running'){
if((s.slope||0)>15) return ['TOO STEEP','bad'];
if((s.overhead_m??9)<1.6) return ['LOW BRANCH','warn'];
if(s.obstacle) return ['HOLDING','warn'];
return ['MOWING','go'];
}
if(s.obstacle) return ['HOLDING','warn'];
if(s.mission==='teaching') return ['LEARNING PATH','go'];
if(s.mission==='paused') return ['PAUSED','warn'];
if(s.armed) return ['READY','go'];
return ['PARKED',''];
}
function render(s){
st=s;
document.getElementById('off').style.display = s.connected?'none':'flex';
// battery
document.getElementById('bpct').textContent=s.battery_pct+'%';
document.getElementById('bv').textContent=' '+s.battery_v+'V';
const f=document.getElementById('bfill'); f.style.width=s.battery_pct+'%';
// sparkline (60): last 60 voltage samples
(render._bh=render._bh||[]).push(s.battery_v); if(render._bh.length>60) render._bh.shift();
const bl=document.getElementById('bline');
if(bl){ const h=render._bh, mn=Math.min(...h), mx=Math.max(...h), sp=(mx-mn)||0.1;
bl.setAttribute('points', h.map((v,i)=>(i*52/59).toFixed(1)+','+(14-(v-mn)/sp*12).toFixed(1)).join(' ')); }
f.style.background = s.battery_pct>40?'var(--ok)':(s.battery_pct>20?'var(--warn)':'var(--bad)');
// status verb
const [verb,cls]=verbFor(s);
document.getElementById('verb').textContent=verb;
document.getElementById('status').className='status '+cls;
document.getElementById('stage').className='stage '+cls;
// attachments + service strip
const eB=document.getElementById('engineBtn');
if(eB){ eB.textContent = s.engine==='run'?'Engine ■':(s.engine==='crank'?'Cranking…':'Engine ▶');
eB.classList.toggle('armed', s.engine==='run'); }
const dB=document.getElementById('dumpBtn');
if(dB){ const bg=s.bagger||{}; dB.textContent = bg.state && bg.state!=='idle' ? ('Dump: '+bg.state)
: ('Dump '+Math.round(bg.fill_pct||0)+'%');
dB.disabled = !(bg.attached); }
const blB=document.getElementById('blowerBtn');
if(blB) blB.classList.toggle('armed', !!(s.boom&&s.boom.blower));
const tB=document.getElementById('trimBtn');
if(tB) tB.classList.toggle('armed', !!(s.boom&&s.boom.trimmer));
const spB=document.getElementById('sprayBtn');
if(spB){ const sp=s.sprayer||{};
spB.textContent = !sp.attached ? 'Hitch sprayer' :
(sp.spraying ? 'Spray '+Math.round(sp.tank_pct)+'% · d'+(sp.pump_duty||0) : 'Sprayer '+Math.round(sp.tank_pct)+'%');
spB.classList.toggle('armed', !!sp.spraying); }
const svc=document.getElementById('svcline');
if(svc){
const bits=[];
if(s.xte_m!=null) bits.push('XTE '+(s.xte_m<0.005?'0.00':s.xte_m.toFixed(2))+' m');
if(s.engine_hours!=null) bits.push('engine '+(+s.engine_hours).toFixed(1)+' h');
if(s.oil_due_h!=null) bits.push('oil in '+s.oil_due_h+' h');
if(s.blade_due_h!=null) bits.push('blades in '+s.blade_due_h+' h');
if(s.weather&&s.weather.precip_prob!=null) bits.push('rain '+s.weather.precip_prob+'%');
if(s.tire_warnings&&s.tire_warnings.length) bits.push('⚠ '+s.tire_warnings.join(' · '));
else bits.push('tyres ✓');
svc.textContent=bits.join(' · ');
}
let sub = s.mode+' · '+(s.speed??0).toFixed(1)+' m/s';
if(s.mission==='running' && s.route_id!=null) sub += ' · '+(s.progress||0)+'% mowed';
if(s.mission==='teaching') sub='recording · '+s.taught_points+' pts';
if(s.estop) sub='tap E-STOP to clear';
if(s.obstacle) sub='obstacle '+(s.obstacle_range||'')+' m ahead';
document.getElementById('sub').textContent=sub;
// mower svg state
const deckRed=s.blade && !s.estop;
document.getElementById('deck').setAttribute('fill', deckRed?'#3a1714':'#20262e');
['b1','b2','b3'].forEach(id=>document.getElementById(id).setAttribute('fill', deckRed?'#e5504a':'#171c22'));
document.getElementById('obsArc').setAttribute('opacity', s.obstacle?'1':'0');
document.getElementById('brain').setAttribute('fill', s.connected?'#3e6ae1':'#444');
document.getElementById('mower').style.filter = s.estop?'grayscale(.4) brightness(.8)':'none';
// chips
const fix=(s.gps_fix||'').toUpperCase().replace('_',' ');
document.getElementById('cGps').innerHTML='GPS <b>'+fix+'</b> · '+s.sats;
document.getElementById('cSpd').innerHTML='<b>'+(s.speed??0).toFixed(1)+'</b> m/s';
const sl=document.getElementById('cSlope'); sl.innerHTML='TILT <b>'+(s.slope||0).toFixed(0)+'°</b>';
sl.className='chip '+(s.slope>15?'bad':(s.slope>=12?'warn':''));
const oh=document.getElementById('cOh'), ohv=(s.overhead_m??9);
oh.innerHTML='OVERHEAD <b>'+(ohv>=5?'clear':ohv.toFixed(1)+'m')+'</b>';
oh.className='chip '+(ohv<1.6?'bad':(ohv<2.0?'warn':''));
// camera-AI label: grass coverage + any detected hazards
const haz=(s.objects||[]).filter(o=>o!=='grass');
document.getElementById('camFrontLabel').textContent =
'FRONT · '+(s.grass_pct||0)+'% grass'+(haz.length?' · ⚠ '+haz.join(', '):'');
// controls
document.querySelectorAll('#seg button').forEach(x=>x.classList.toggle('active',x.dataset.mode===s.mode));
const arm=document.getElementById('armBtn'); arm.textContent=s.armed?'Disarm':'Arm'; arm.classList.toggle('armed',s.armed);
document.getElementById('startBtn').disabled=!(s.mode==='AUTO'&&s.armed&&!s.estop);
const bb=document.getElementById('bladeBtn'); bb.textContent='Blade '+(s.blade?'on':'off'); bb.classList.toggle('on',s.blade);
document.getElementById('teachBtn').textContent=s.mission==='teaching'?('Stop · '+s.taught_points):'Teach path';
document.getElementById('teachBtn').classList.toggle('on',s.mission==='teaching');
const e=document.getElementById('estopBtn');
e.textContent=s.estop?'TAP TO CLEAR':'EMERGENCY STOP'; e.classList.toggle('engaged',s.estop);
// map
updateMap(s);
}
const es=new EventSource('/events');
es.onmessage=e=>{try{render(JSON.parse(e.data));}catch(_){}}
es.onerror=()=>{document.getElementById('off').style.display='flex';}
// live camera feeds (sim: synthetic SVG; real hardware: MJPEG). cache-bust each refresh.
function refreshCams(){
const t=Date.now();
const f=document.getElementById('camFront'); if(f) f.src='/camera/front.svg?'+t;
const r=document.getElementById('camRear'); if(r) r.src='/camera/rear.svg?'+t;
}
refreshCams(); setInterval(refreshCams, 600);
</script>
</body></html>
b1b1ea139This file is pinned to the selected release. Download the original to open it in your design tool.