limit resources that can be specified in build config

This commit is contained in:
andreas 2023-10-04 17:37:03 +02:00
parent 0574e8b47b
commit 4a388561ab
4 changed files with 87 additions and 21 deletions

View File

@ -9,14 +9,17 @@ types:
value: M5_CAN_KIT value: M5_CAN_KIT
description: "M5 Stack CAN Kit" description: "M5 Stack CAN Kit"
url: "http://docs.m5stack.com/en/atom/atom_can" url: "http://docs.m5stack.com/en/atom/atom_can"
resource: can
- value: M5_SERIAL_KIT_232 - value: M5_SERIAL_KIT_232
description: "M5 Stack RS232 Base" description: "M5 Stack RS232 Base"
label: "Atomic RS232 Base" label: "Atomic RS232 Base"
url: "http://docs.m5stack.com/en/atom/Atomic%20RS232%20Base" url: "http://docs.m5stack.com/en/atom/Atomic%20RS232%20Base"
resource: serial
- value: M5_SERIAL_KIT_485 - value: M5_SERIAL_KIT_485
description: "M5 Stack RS485 Base" description: "M5 Stack RS485 Base"
label: "Atomic RS485 Base" label: "Atomic RS485 Base"
url: "http://docs.m5stack.com/en/atom/Atomic%20RS485%20Base" url: "http://docs.m5stack.com/en/atom/Atomic%20RS485%20Base"
resource: serial
- &m5groovei2c - &m5groovei2c
type: multi type: multi
key: m5groovei2c key: m5groovei2c
@ -32,6 +35,7 @@ types:
url: "http://docs.m5stack.com/en/unit/can" url: "http://docs.m5stack.com/en/unit/can"
description: "M5 Can unit" description: "M5 Can unit"
value: M5_CANUNIT value: M5_CANUNIT
resource: can
- &m5grooveserial - &m5grooveserial
type: select type: select
label: "M5 Groove Serial Unit" label: "M5 Groove Serial Unit"
@ -43,11 +47,13 @@ types:
value: SERIAL_GROOVE_485 value: SERIAL_GROOVE_485
description: "M5 RS485 unit" description: "M5 RS485 unit"
url: "http://docs.m5stack.com/en/unit/rs485" url: "http://docs.m5stack.com/en/unit/rs485"
resource: serial
- label: "Tail485" - label: "Tail485"
value: SERIAL_GROOVE_485 value: SERIAL_GROOVE_485
key: tail485 key: tail485
description: "M5 Tail 485" description: "M5 Tail 485"
url: "http://docs.m5stack.com/en/atom/tail485" url: "http://docs.m5stack.com/en/atom/tail485"
resource: serial
- &m5groove - &m5groove
type: select type: select
@ -63,7 +69,11 @@ types:
- label: 'Serial' - label: 'Serial'
children: children:
- *m5grooveserial - *m5grooveserial
resources:
default: &esp32default
serial: 2
can: 1
i2c: 1
config: config:
children: children:
@ -76,6 +86,7 @@ config:
label: m5stack-atom label: m5stack-atom
description: "M5 Stack Atom light" description: "M5 Stack Atom light"
url: "http://docs.m5stack.com/en/core/atom_lite" url: "http://docs.m5stack.com/en/core/atom_lite"
resource: *esp32default
children: children:
- *m5base - *m5base
- *m5groove - *m5groove
@ -83,6 +94,7 @@ config:
label: m5stack-atoms3 label: m5stack-atoms3
description: "M5 Stack AtomS3 light" description: "M5 Stack AtomS3 light"
url: "http://docs.m5stack.com/en/core/AtomS3%20Lite" url: "http://docs.m5stack.com/en/core/AtomS3%20Lite"
resource: *esp32default
children: children:
- *m5base - *m5base
- *m5groove - *m5groove

View File

@ -91,6 +91,9 @@
display: none; display: none;
color: red; color: red;
} }
.configui .error .value{
color: red;
}
.configui #warn.warn{ .configui #warn.warn{
display: block; display: block;
} }
@ -131,3 +134,7 @@
.configui .label { .configui .label {
width: 10em; width: 10em;
} }
.configui .row input{
flex-grow: 1;
width: initial;
}

View File

@ -33,6 +33,10 @@
<span class="label">Build Flags</span> <span class="label">Build Flags</span>
<input type="text" id="buildflags" disabled> <input type="text" id="buildflags" disabled>
</div> </div>
<div class="row hidden error">
<span class="label">Error</span>
<span class="value" id="configError"></span>
</div>
<div class="row"> <div class="row">
<button id="start">Start</button> <button id="start">Start</button>
</div> </div>

View File

@ -56,6 +56,11 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
enableEl('start',false); enableEl('start',false);
return; return;
} }
let e=document.getElementById('configError');
if (e.textContent) {
enableEl('start',false);
return;
}
if (displayMode != 'existing'){ if (displayMode != 'existing'){
if (currentPipeline !== undefined){ if (currentPipeline !== undefined){
//check pipeline state //check pipeline state
@ -261,7 +266,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
if (val === undefined) val=key; if (val === undefined) val=key;
re.setAttribute('type', 'radio'); re.setAttribute('type', 'radio');
re.setAttribute('name', name); re.setAttribute('name', name);
re.addEventListener('change', (ev) => callback(v.children,key,val,false)); re.addEventListener('change', (ev) => callback(v.children,key,val,v.resource,false));
if (v.description && v.url) { if (v.description && v.url) {
let lnk = addEl('a', 'radioDescription', ef, v.description); let lnk = addEl('a', 'radioDescription', ef, v.description);
lnk.setAttribute('href', v.url); lnk.setAttribute('href', v.url);
@ -269,7 +274,7 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
} }
if (key == current) { if (key == current) {
re.setAttribute('checked','checked'); re.setAttribute('checked','checked');
callback(v.children,key,val,true); callback(v.children,key,val,v.resource,true);
} }
}); });
} }
@ -307,9 +312,9 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
configList.forEach((cfg)=>{ configList.forEach((cfg)=>{
let name=prefix?(prefix+SEPARATOR+cfg.key):cfg.key; let name=prefix?(prefix+SEPARATOR+cfg.key):cfg.key;
let current=config[name]; let current=config[name];
buildSelector(frame,cfg,name,current,(children,key,value,initial)=>{ buildSelector(frame,cfg,name,current,(children,key,value,resource,initial)=>{
buildSelectors(name,children,initial); buildSelectors(name,children,initial);
configStruct[name]={cfg:cfg, key: key, value:value}; configStruct[name]={cfg:cfg, key: key, value:value,resource:resource};
buildValues(initial); buildValues(initial);
}) })
}) })
@ -321,27 +326,65 @@ import fileDownload from "https://cdn.skypack.dev/js-file-download@0.4.12"
if (! initial){ if (! initial){
config={}; config={};
} }
for (let k in configStruct){ let allowedResources={};
let struct=configStruct[k]; let currentResources={};
if (! struct || ! struct.cfg || struct.value === undefined) continue; let errors="";
config[k]=struct.key; for (let round = 0; round <= 1; round++) {
if (struct.cfg.target !== undefined) { //round1: find allowed resources
if (struct.cfg.target === 'environment') { //round2: really collect values
environment = struct.value; for (let k in configStruct) {
} let struct = configStruct[k];
if (struct.cfg.target === 'define') { if (!struct || !struct.cfg || struct.value === undefined) continue;
flags += " -D" + struct.value; if (round > 0) config[k] = struct.key;
} if (struct.cfg.target !== undefined) {
const DEFPRFX = "define:"; if (struct.cfg.target === 'environment') {
if (struct.cfg.target.indexOf(DEFPRFX) == 0) { if (round > 0) environment = struct.value;
let def = struct.cfg.target.substring(DEFPRFX.length); else allowedResources=struct.resource;
flags += " -D" + def + "=" + struct.value; continue;
}
if (round < 1) continue;
if (struct.resource){
let resList=currentResources[struct.resource];
if (! resList){
resList=[];
currentResources[struct.resource]=resList;
}
resList.push(struct);
}
if (struct.cfg.target === 'define') {
flags += " -D" + struct.value;
continue;
}
const DEFPRFX = "define:";
if (struct.cfg.target.indexOf(DEFPRFX) == 0) {
let def = struct.cfg.target.substring(DEFPRFX.length);
flags += " -D" + def + "=" + struct.value;
continue;
}
} }
} }
} }
document.getElementById('environment').value=environment; document.getElementById('environment').value=environment;
document.getElementById('buildflags').value=flags; document.getElementById('buildflags').value=flags;
//check resources
for (let k in currentResources){
let resList=currentResources[k];
if (allowedResources[k] !== undefined){
if (resList.length > allowedResources[k]){
errors+=" more than "+allowedResources[k]+" "+k+" device(s) used";
}
}
}
if (errors){
setValue('configError',errors);
setVisible('configError',true,true);
}
else{
setValue('configError','');
setVisible('configError',false,true);
}
if (! initial) findPipeline(); if (! initial) findPipeline();
updateStart();
} }
let findIdx=0; let findIdx=0;
const findPipeline=()=>{ const findPipeline=()=>{