From 2e7e7c9c3f17cc8e9aa7d8fecec746c558e8f2d9 Mon Sep 17 00:00:00 2001 From: nicolasferry Date: Mon, 27 Nov 2017 22:44:03 +0100 Subject: [PATCH] fix path to arduino --- nodes/core/external/thingml-engine.js | 86 +++++++++++++++------------ 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/nodes/core/external/thingml-engine.js b/nodes/core/external/thingml-engine.js index 0aac05d394..cb44971c9d 100644 --- a/nodes/core/external/thingml-engine.js +++ b/nodes/core/external/thingml-engine.js @@ -4,13 +4,13 @@ var spawn = require('child_process').spawn; var fs = require('fs'); -function compileThingML(node){ - var output='generated'; +function compileThingML(node) { + var output = 'generated'; var java; - var hasError=false; + var hasError = false; - if(node.source === '') { + if (node.source === '') { if (!fs.existsSync(output)) { console.log('Creating ' + output + ' folder...'); fs.mkdirSync(output); @@ -27,10 +27,10 @@ function compileThingML(node){ java = spawn('java', [ '-jar', './lib/thingml/ThingML2CLI.jar', '-c', node.target, - '-s', node.name+'.thingml', + '-s', node.name + '.thingml', '-o', output ]); - }else{ + } else { java = spawn('java', [ '-jar', './lib/thingml/ThingML2CLI.jar', '-c', node.target, @@ -42,42 +42,42 @@ function compileThingML(node){ java.stdout.setEncoding('utf8'); java.stdout.on('data', (data) => { data.trim().split('\n').forEach(line => { - if (line.startsWith('[WARNING]')) { - console.log('[WARNING]'+line); - } else if (line.startsWith('[ERROR]')) {//ideally, that should arrive on stderr - hasError = true; - console.log('[ERROR]'+line); - } else { - console.log('[INFO]'+line); - } -}); -}); + if (line.startsWith('[WARNING]')) { + console.log('[WARNING]' + line); + } else if (line.startsWith('[ERROR]')) { //ideally, that should arrive on stderr + hasError = true; + console.log('[ERROR]' + line); + } else { + console.log('[INFO]' + line); + } + }); + }); java.on('error', (err) => { hasError = true; - console.log('Something went wrong with the compiler!'); -}); + console.log('Something went wrong with the compiler!'); + }); java.on('exit', (code) => { if (hasError) { console.log('Cannot complete because of errors!'); } else { console.log('Done!'); - if(node.target.indexOf("arduino") >=0){ - compileAndUpload(node); - } -} -}); + if (node.target.indexOf("arduino") >= 0) { + compileAndUpload(node); + } + } + }); } //This function calls Arduino ID to compile Arduino sketches // and to deploy them -function compileAndUpload(node){ - var board='arduino:avr:'+node.ardtype; - if(node.cpu.indexOf("") < 0){ - board+=+':cpu='+node.cpu; +function compileAndUpload(node) { + var board = 'arduino:avr:' + node.ardtype; + if (node.cpu.indexOf("") < 0) { + board += +':cpu=' + node.cpu; } /*if(node.libraries !== "") { @@ -89,36 +89,44 @@ function compileAndUpload(node){ } }*/ + + //We Should install libaries first - var arduino = spawn('/Applications/Arduino.app/Contents/MacOS/Arduino', [ - '--board', board, + var path_to_ardui = ""; + if (os.platform === "darwin") { + path_to_ardui = '/Applications/Arduino.app/Contents/MacOS/Arduino'; + } else { + path_to_ardui = 'arduino'; + } + var arduino = spawn(path_to_ardui, [ + '--board ', board, '--port', node.port, - '--upload', 'generated/'+node.name+'/'+node.name+'.ino', + '--upload', 'generated/' + node.name + '/' + node.name + '.ino', ]); arduino.stdout.setEncoding('utf8'); arduino.stdout.on('data', (data) => { data.trim().split('\n').forEach(line => { - console.log('[INFO]'+line); -}); -}); + console.log('[INFO]' + line); + }); + }); arduino.stderr.setEncoding('utf8'); arduino.stderr.on('data', (data) => { data.trim().split('\n').forEach(line => { - console.log('[WARNING]'+line); -}); -}); + console.log('[WARNING]' + line); + }); + }); arduino.on('error', (err) => { - console.log('Something went wrong with the compiler!'+err); -}); + console.log('Something went wrong with the compiler!' + err); + }); arduino.on('exit', (code) => { console.log('Done!'); //TODO: add feedback process done -}); + }); }