add node debug toggle

This commit is contained in:
Shannon Sterz 2016-01-30 19:06:26 +01:00
parent 00af61dcff
commit 84559145e8

View file

@ -3,8 +3,9 @@ var events = require('events'),
util = require('util'),
serial = require("serialport");
var Arduino = function (baudrate) {
var Arduino = function (baudrate, debug) {
this.baudrate = baudrate && baudrate || 9600;
this.debug = debug && debug || false;
this.writeBuffer = [];
}
@ -38,10 +39,11 @@ Arduino.prototype.setup = function () {
self.serial.on('open', function () { setTimeout(function () {
self.serial.write(new Buffer('00000000'));
self.serial.write(new Buffer('Zn000000', 'ascii'));
if(self.debug) { self.serial.write(new Buffer('P0000000', 'ascii')); }
self.emit('success');
self.serial.on('data', function(data){
console.log(data);
if(self.debug) { console.log(data) };
self.emit('data', data);
});