From 99625f04b9bd99d2fe9582e96357b9ca0211cf09 Mon Sep 17 00:00:00 2001 From: jes Date: Mon, 11 Dec 2017 16:12:01 +0200 Subject: [PATCH] reworked boards list && thermistors list parsed from file #17 && #18 fixed --- app/mc-tool.js | 30 +++++++++++++++++++++++++----- app/server.js | 16 ++++++++++++---- static/main.js | 1 + 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/mc-tool.js b/app/mc-tool.js index 828ca649a7..3ca5a1aed5 100644 --- a/app/mc-tool.js +++ b/app/mc-tool.js @@ -184,7 +184,7 @@ var groups=[ ['TODO: //LCDs'], ] var type=i=>i.value==undefined?'BOOL':'string' -var type1=i=>i.value&&(i.select?'select':/\".*\"/.test(i.value)?'string':/false|true/.test(i.value)?'boolean':'numeric')||undefined //" +var type1=i=>i.value&&(i.select?'select':/\".*\"/.test(i.value)?'string':/^false|true$/.test(i.value)?'boolean':'numeric')||undefined //" var section0=i=>i.name+' '+type(i)+(i.condition.length&&(' == '+i.condition.join(' AND '))||'') var section=i=>({name:i.name,type:type(i),condition:i.condition.length&&i.condition||undefined,value:i.value||!i.disabled}) 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=>{ .catch(a=>(console.log('fail update h file: ',file,a),a)) } -exports.getBoards=(file)=>{ - return Promise.resolve(file) +exports.getBoards = file => Promise.resolve(file) .then(inFile) + .catch(a => '') .then(text2array) .then(a=>a.map(i=>i.replace(/(.*#define\s+BOARD_.+?)(\/\/.*)/,"$1"))) .then(a=>a.map(i=>i.match(/.*#define\s+(\w+)\s+(\d+)\s*/))) .then(a=>a.filter(i=>i)) - .then(a => ({list: a.map(i => i[1]), objs: a.map(i => ({name: i[1], value: i[2]}))})) -// .then(JSON.stringify) + .then(a => ({ + list: a.map(i => i[1]), + objs: a.map(i => ({name: i[1], value: i[2]})), + select: a.reduce((p, i) => (p[i[1]] = i[1] + ' (' + i[2] + ')', p), {}) + })) + +const thermistors = /THERMISTOR_ID\s+==\s+(-?\d*).*\n.*THERMISTOR_NAME\s+"([^"]+)/g; +const splitter = (regex, str) => { + var list = [], m; + while ((m = regex.exec(str)) !== null) { + if (m.index === regex.lastIndex) regex.lastIndex++; + list.push(m); + } + return list; } +exports.getThermistors = file => Promise.resolve(file) + .then(inFile) + .catch(a => '') + .then(text => splitter(thermistors, text)) + .then(a => ({ + list: a.map(i => i[2]), + select: a.reduce((p, i) => (p[i[1]] = i[2] + ' (' + i[1] + ')', p), {'0': 'Not used'}) + })) diff --git a/app/server.js b/app/server.js index 2bab93b232..fc17cf700b 100644 --- a/app/server.js +++ b/app/server.js @@ -191,13 +191,21 @@ app.get('/checkout/:branch', function (req, res) { var getBoards = () => seek4File('boards.h', [ 'Marlin', path.join('Marlin', 'src', 'core')]) .then(mctool.getBoards); +var getThermistors = () => + seek4File('thermistornames.h', [ 'Marlin', path.join('Marlin', 'src', 'lcd')]) + .then(mctool.getThermistors); var get_cfg=()=>{ var base=Promise.all([git.root(),git.Tag()]); var setBoards = a => getBoards() - .then(a => JSON.stringify(a.list)) - .catch(e => '' ) - .then(boards => (Object.assign(a.defs['MOTHERBOARD'], {select: boards, type:"select"}), a)); + .then(boards => (Object.assign(a.defs['MOTHERBOARD'], {select: boards.select, type:"select"}), a)); + var setThermistors = defs => getThermistors() + .then(a => { + Object.keys(defs.defs) + .filter(i => /^TEMP_SENSOR/.test(i)) + .map(i => Object.assign(defs.defs[i], {select: a.select, type: "select"})) + return defs; + }) var list=['Configuration.h','Configuration_adv.h'] .map(f => base .then(p=> @@ -206,7 +214,7 @@ var get_cfg=()=>{ ) .then(o=>(o.names.filter(n=>hints.d2i(n.name),1).map(n=>o.defs[n.name].hint=!0),o)) .then(a => Object.assign(a, {names: undefined, type: 'file'})) - .then(a => a.defs['MOTHERBOARD'] && setBoards(a) || a) + .then(a => 'MOTHERBOARD' in a.defs ? setBoards(a).then(setThermistors) : a) ); return Promise.all(list) } diff --git a/static/main.js b/static/main.js index 6a112d9b11..67b64f5d77 100644 --- a/static/main.js +++ b/static/main.js @@ -331,6 +331,7 @@ $(function(){ val.remove(),p.remove(),sel.remove(); else{ var dv=(def.changed&&def.changed.value||def.value); + if (typeof def.select != "object") if (def.type=='select'){ //try to recover ugly json var json=def.select.trim(); if (json[0]=='[')