From 101d551f93c1d41b2a6b8fb8aa91ecf1bcf2947d Mon Sep 17 00:00:00 2001 From: andreas Date: Sun, 17 Mar 2024 19:01:53 +0100 Subject: [PATCH] add calset and calval input types --- lib/spitask/config.json | 2 +- web/index.css | 3 +++ web/index.html | 7 ++++++ web/index.js | 54 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/lib/spitask/config.json b/lib/spitask/config.json index 1b96171..242c16c 100644 --- a/lib/spitask/config.json +++ b/lib/spitask/config.json @@ -69,7 +69,7 @@ "label": "DMS22B$i Zero", "type": "calset", "default": 2048, - "description": "Zero position (0...2^bits-1)", + "description": "Zero position (0...2^bits-1)\nuse the \"C\" button to open a calibrate dialog", "category": "spisensors$b", "capabilities": { "DMS22B$i": "true" diff --git a/web/index.css b/web/index.css index c4db397..c3ea7ee 100644 --- a/web/index.css +++ b/web/index.css @@ -114,6 +114,9 @@ body { display: flex; align-items: center; } + .value button { + margin-left: 0.5em; + } .hidden{ display: none !important; } diff --git a/web/index.html b/web/index.html index 7172b41..cc17706 100644 --- a/web/index.html +++ b/web/index.html @@ -193,6 +193,13 @@

+ diff --git a/web/index.js b/web/index.js index 92a58ea..4c90e44 100644 --- a/web/index.js +++ b/web/index.js @@ -479,7 +479,7 @@ function createCalSetInput(configItem,frame,clazz){ cb.addEventListener('click',(ev)=>{ let cs=document.getElementById("calset").cloneNode(true); cs.classList.remove("hidden"); - cs.querySelector(".heading").textContent=configItem.name; + cs.querySelector(".heading").textContent=configItem.label||configItem.name; let vel=cs.querySelector(".val"); if (caliv != 0) window.clearInterval(caliv); caliv=window.setInterval(()=>{ @@ -510,6 +510,55 @@ function createCalSetInput(configItem,frame,clazz){ el.setAttribute('name', configItem.name) return el; } +function createCalValInput(configItem,frame,clazz){ + let el = addEl('input',clazz,frame); + let cb = addEl('button','',frame,'C'); + //el.disabled=true; + cb.addEventListener('click',(ev)=>{ + const sv=function(val,cfg){ + if (configItem.eval){ + let v=parseFloat(val); + let c=parseFloat(cfg); + return(eval(configItem.eval)); + } + return v; + }; + let cs=document.getElementById("calval").cloneNode(true); + cs.classList.remove("hidden"); + cs.querySelector(".heading").textContent=configItem.label||configItem.name; + let vel=cs.querySelector(".val"); + let vinp=cs.querySelector("input"); + vinp.value=el.value; + if (caliv != 0) window.clearInterval(caliv); + caliv=window.setInterval(()=>{ + if (document.body.contains(cs)){ + fetch("/api/calibrate?name="+encodeURIComponent(configItem.name)) + .then((r)=>r.text()) + .then((txt)=>{ + txt=sv(txt,vinp.value); + if (txt != vel.textContent){ + vel.textContent=txt; + } + }) + .catch((e)=>{ + alert(e); + hideOverlay(); + window.clearInterval(caliv); + }) + } + else{ + window.clearInterval(caliv); + } + },200); + showOverlay(cs,false,[{label:'Set',click:()=>{ + el.value=vinp.value; + let cev=new Event('change'); + el.dispatchEvent(cev); + }}]); + }) + el.setAttribute('name', configItem.name) + return el; +} function createInput(configItem, frame,clazz) { let el; if (configItem.type === 'boolean' || configItem.type === 'list' || configItem.type == 'boatData') { @@ -549,6 +598,9 @@ function createInput(configItem, frame,clazz) { if (configItem.type === "calset"){ return createCalSetInput(configItem,frame,clazz); } + if (configItem.type === "calval"){ + return createCalValInput(configItem,frame,clazz); + } el = addEl('input',clazz,frame); if (configItem.readOnly) el.setAttribute('disabled',true); el.setAttribute('name', configItem.name)