Skip to content

Commit 99625f0

Browse files
committed
reworked boards list && thermistors list parsed from file #17 && #18 fixed
1 parent 0570fd8 commit 99625f0

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

app/mc-tool.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ var groups=[
184184
['TODO: //LCDs'],
185185
]
186186
var type=i=>i.value==undefined?'BOOL':'string'
187-
var type1=i=>i.value&&(i.select?'select':/\".*\"/.test(i.value)?'string':/false|true/.test(i.value)?'boolean':'numeric')||undefined //"
187+
var type1=i=>i.value&&(i.select?'select':/\".*\"/.test(i.value)?'string':/^false|true$/.test(i.value)?'boolean':'numeric')||undefined //"
188188
var section0=i=>i.name+' '+type(i)+(i.condition.length&&(' == '+i.condition.join(' AND '))||'')
189189
var section=i=>({name:i.name,type:type(i),condition:i.condition.length&&i.condition||undefined,value:i.value||!i.disabled})
190190
var section1=(p,i)=>(p[i.name]={changed:i.changed,type:type1(i),condition:i.condition.length&&i.condition||undefined,value:i.value,disabled:i.disabled,line:i.line,select:i.select},p)
@@ -312,13 +312,33 @@ module.exports.makeHfile=(root,name,dir)=>conf=>{
312312
.catch(a=>(console.log('fail update h file: ',file,a),a))
313313
}
314314

315-
exports.getBoards=(file)=>{
316-
return Promise.resolve(file)
315+
exports.getBoards = file => Promise.resolve(file)
317316
.then(inFile)
317+
.catch(a => '')
318318
.then(text2array)
319319
.then(a=>a.map(i=>i.replace(/(.*#define\s+BOARD_.+?)(\/\/.*)/,"$1")))
320320
.then(a=>a.map(i=>i.match(/.*#define\s+(\w+)\s+(\d+)\s*/)))
321321
.then(a=>a.filter(i=>i))
322-
.then(a => ({list: a.map(i => i[1]), objs: a.map(i => ({name: i[1], value: i[2]}))}))
323-
// .then(JSON.stringify)
322+
.then(a => ({
323+
list: a.map(i => i[1]),
324+
objs: a.map(i => ({name: i[1], value: i[2]})),
325+
select: a.reduce((p, i) => (p[i[1]] = i[1] + ' (' + i[2] + ')', p), {})
326+
}))
327+
328+
const thermistors = /THERMISTOR_ID\s+==\s+(-?\d*).*\n.*THERMISTOR_NAME\s+"([^"]+)/g;
329+
const splitter = (regex, str) => {
330+
var list = [], m;
331+
while ((m = regex.exec(str)) !== null) {
332+
if (m.index === regex.lastIndex) regex.lastIndex++;
333+
list.push(m);
334+
}
335+
return list;
324336
}
337+
exports.getThermistors = file => Promise.resolve(file)
338+
.then(inFile)
339+
.catch(a => '')
340+
.then(text => splitter(thermistors, text))
341+
.then(a => ({
342+
list: a.map(i => i[2]),
343+
select: a.reduce((p, i) => (p[i[1]] = i[2] + ' (' + i[1] + ')', p), {'0': 'Not used'})
344+
}))

app/server.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,21 @@ app.get('/checkout/:branch', function (req, res) {
191191
var getBoards = () =>
192192
seek4File('boards.h', [ 'Marlin', path.join('Marlin', 'src', 'core')])
193193
.then(mctool.getBoards);
194+
var getThermistors = () =>
195+
seek4File('thermistornames.h', [ 'Marlin', path.join('Marlin', 'src', 'lcd')])
196+
.then(mctool.getThermistors);
194197

195198
var get_cfg=()=>{
196199
var base=Promise.all([git.root(),git.Tag()]);
197200
var setBoards = a => getBoards()
198-
.then(a => JSON.stringify(a.list))
199-
.catch(e => '' )
200-
.then(boards => (Object.assign(a.defs['MOTHERBOARD'], {select: boards, type:"select"}), a));
201+
.then(boards => (Object.assign(a.defs['MOTHERBOARD'], {select: boards.select, type:"select"}), a));
202+
var setThermistors = defs => getThermistors()
203+
.then(a => {
204+
Object.keys(defs.defs)
205+
.filter(i => /^TEMP_SENSOR/.test(i))
206+
.map(i => Object.assign(defs.defs[i], {select: a.select, type: "select"}))
207+
return defs;
208+
})
201209
var list=['Configuration.h','Configuration_adv.h']
202210
.map(f => base
203211
.then(p=>
@@ -206,7 +214,7 @@ var get_cfg=()=>{
206214
)
207215
.then(o=>(o.names.filter(n=>hints.d2i(n.name),1).map(n=>o.defs[n.name].hint=!0),o))
208216
.then(a => Object.assign(a, {names: undefined, type: 'file'}))
209-
.then(a => a.defs['MOTHERBOARD'] && setBoards(a) || a)
217+
.then(a => 'MOTHERBOARD' in a.defs ? setBoards(a).then(setThermistors) : a)
210218
);
211219
return Promise.all(list)
212220
}

static/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ $(function(){
331331
val.remove(),p.remove(),sel.remove();
332332
else{
333333
var dv=(def.changed&&def.changed.value||def.value);
334+
if (typeof def.select != "object")
334335
if (def.type=='select'){ //try to recover ugly json
335336
var json=def.select.trim();
336337
if (json[0]=='[')

0 commit comments

Comments
 (0)