some scope related bug fixes

This commit is contained in:
Shannon Sterz 2016-01-14 21:43:45 +01:00
parent 54850cde26
commit fac756b226
2 changed files with 11 additions and 10 deletions

View file

@ -10,35 +10,36 @@ var Arduino = function (baudrate) {
} }
Arduino.prototype.setup = function () { Arduino.prototype.setup = function () {
var self = this;
child.exec('cd ../arduino && ino build && ino upload', function(err, stdout, stderr){ child.exec('cd ../arduino && ino build && ino upload', function(err, stdout, stderr){
if(err){console.log('Please install the ino utility and connect arduino!\nIf there are other open programs that communicate with the arduino, close them!'); return this.success = false;} if(err){console.log('Please install the ino utility and connect arduino!\nIf there are other open programs that communicate with the arduino, close them!'); return self.success = false;}
var buff = stdout.slice(stdout.indexOf('Guessing serial port ... ')+25); var buff = stdout.slice(stdout.indexOf('Guessing serial port ... ')+25);
buff = buff.slice(0, buff.indexOf('\n')); buff = buff.slice(0, buff.indexOf('\n'));
console.log('Guessing serial port ... ' + buff); console.log('Guessing serial port ... ' + buff);
this.serial = new serial(buff, { self.serial = new serial(buff, {
baudrate: this.baudrate, baudrate: self.baudrate,
parser: serial.parsers.readline('\n') parser: serial.parsers.readline('\n')
}, false); }, false);
this.serial.open(function (error) { self.serial.open(function (error) {
if ( error ) { if ( error ) {
console.log('Please check arduino!') console.log('Please check arduino!')
return this.success = false; return self.success = false;
} }
serialPort.write(new Buffer('00000000')); serialPort.write(new Buffer('00000000'));
}); });
this.success = true; self.success = true;
this.processWriteBuffer(); self.processWriteBuffer();
}); });
} }
Arduino.prototype.write = function (m) { Arduino.prototype.write = function (m) {
if (this.success) { if (this.serial) {
this.serial.write(m); this.serial.write(m);
} else { } else {
this.writeBuffer.push(m); this.writeBuffer.push(m);

View file

@ -3,7 +3,7 @@ var router = express.Router();
var Arduino = new require('../ar-com/arduino'); var Arduino = new require('../ar-com/arduino');
var arduino = new Arduino(); var arduino = new Arduino();
arduino.setup() arduino.setup();
/* GET home page. */ /* GET home page. */
router.get('/', function(req, res, next) { router.get('/', function(req, res, next) {