Skip to content

Commit

Permalink
reworked boards list && thermistors list parsed from file #17 && #18
Browse files Browse the repository at this point in the history
…fixed
  • Loading branch information
akaJes committed Dec 11, 2017
1 parent 0570fd8 commit 99625f0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
30 changes: 25 additions & 5 deletions app/mc-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'})
}))
16 changes: 12 additions & 4 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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=>
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]=='[')
Expand Down

0 comments on commit 99625f0

Please sign in to comment.