Update save to use new /gpu-fan/save endpoint
Posts directly to custom endpoint which calls serializeConfig()
This commit is contained in:
parent
211118f8ff
commit
e8430ab8ac
@ -1,8 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// GPU Fan Controller - Embedded Web Page
|
|
||||||
// This is served directly from code at /gpu-fan
|
|
||||||
|
|
||||||
const char GPU_FAN_HTML[] PROGMEM = R"=====(
|
const char GPU_FAN_HTML[] PROGMEM = R"=====(
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
@ -171,9 +168,7 @@ c.setAttribute('data-i',i);
|
|||||||
c.onmousedown=c.ontouchstart=startDrag;
|
c.onmousedown=c.ontouchstart=startDrag;
|
||||||
pg.appendChild(c);
|
pg.appendChild(c);
|
||||||
});
|
});
|
||||||
|
drawTbl();drawTemp();
|
||||||
drawTbl();
|
|
||||||
drawTemp();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawTbl(){
|
function drawTbl(){
|
||||||
@ -202,8 +197,7 @@ if(t<=pts[0].t)return pts[0].s;
|
|||||||
if(t>=pts[pts.length-1].t)return pts[pts.length-1].s;
|
if(t>=pts[pts.length-1].t)return pts[pts.length-1].s;
|
||||||
for(let i=0;i<pts.length-1;i++){
|
for(let i=0;i<pts.length-1;i++){
|
||||||
if(t>=pts[i].t&&t<=pts[i+1].t){
|
if(t>=pts[i].t&&t<=pts[i+1].t){
|
||||||
let r=(t-pts[i].t)/(pts[i+1].t-pts[i].t);
|
return pts[i].s+(t-pts[i].t)/(pts[i+1].t-pts[i].t)*(pts[i+1].s-pts[i].s);
|
||||||
return pts[i].s+r*(pts[i+1].s-pts[i].s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 50;
|
return 50;
|
||||||
@ -312,57 +306,25 @@ document.getElementById('stxt').textContent='Err';
|
|||||||
|
|
||||||
async function save(){
|
async function save(){
|
||||||
pts.sort((a,b)=>a.t-b.t);
|
pts.sort((a,b)=>a.t-b.t);
|
||||||
|
let cfg={
|
||||||
// Build the config object
|
'mode':cMode,
|
||||||
let cfg={'GPU-Fan':{
|
|
||||||
enabled:true,
|
|
||||||
mode:cMode,
|
|
||||||
'fixed-speed':fSpd,
|
'fixed-speed':fSpd,
|
||||||
'curve-points':pts.length,
|
'curve-points':pts.length,
|
||||||
'curve-t1':pts.length>0?pts[0].t:30,
|
'curve-t1':pts[0]?.t||30,'curve-s1':pts[0]?.s||30,
|
||||||
'curve-s1':pts.length>0?pts[0].s:30,
|
'curve-t2':pts[1]?.t||50,'curve-s2':pts[1]?.s||50,
|
||||||
'curve-t2':pts.length>1?pts[1].t:50,
|
'curve-t3':pts[2]?.t||70,'curve-s3':pts[2]?.s||75,
|
||||||
'curve-s2':pts.length>1?pts[1].s:50,
|
'curve-t4':pts[3]?.t||85,'curve-s4':pts[3]?.s||100,
|
||||||
'curve-t3':pts.length>2?pts[2].t:70,
|
'curve-t5':pts[4]?.t||95,'curve-s5':pts[4]?.s||100
|
||||||
'curve-s3':pts.length>2?pts[2].s:75,
|
};
|
||||||
'curve-t4':pts.length>3?pts[3].t:85,
|
|
||||||
'curve-s4':pts.length>3?pts[3].s:100,
|
|
||||||
'curve-t5':pts.length>4?pts[4].t:95,
|
|
||||||
'curve-s5':pts.length>4?pts[4].s:100
|
|
||||||
}};
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
// First update the config
|
let r=await fetch('/gpu-fan/save',{
|
||||||
let r1=await fetch('/cfg.json',{
|
|
||||||
method:'POST',
|
method:'POST',
|
||||||
headers:{'Content-Type':'application/json'},
|
headers:{'Content-Type':'application/json'},
|
||||||
body:JSON.stringify({um:cfg})
|
body:JSON.stringify(cfg)
|
||||||
});
|
});
|
||||||
|
if(r.ok){toast('Saved!');}
|
||||||
if(!r1.ok){
|
else{toast('Failed: '+r.status,1);}
|
||||||
toast('Config update failed',1);
|
}catch(e){toast('Error!',1);console.error(e);}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then trigger a config save by posting to /json with save flag
|
|
||||||
let r2=await fetch('/json/state',{
|
|
||||||
method:'POST',
|
|
||||||
headers:{'Content-Type':'application/json'},
|
|
||||||
body:JSON.stringify({
|
|
||||||
psave:true,
|
|
||||||
'GPU-Fan':{mode:cMode}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if(r2.ok){
|
|
||||||
toast('Saved!');
|
|
||||||
}else{
|
|
||||||
toast('Save failed',1);
|
|
||||||
}
|
|
||||||
}catch(e){
|
|
||||||
console.error(e);
|
|
||||||
toast('Error: '+e.message,1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toast(m,e){
|
function toast(m,e){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user