Skip to content

Commit

Permalink
fix path to arduino
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasferry committed Nov 27, 2017
1 parent 45f449a commit 2e7e7c9
Showing 1 changed file with 47 additions and 39 deletions.
86 changes: 47 additions & 39 deletions nodes/core/external/thingml-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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 !== "") {
Expand All @@ -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
});
});

}

Expand Down

0 comments on commit 2e7e7c9

Please sign in to comment.