add node debug toggle
This commit is contained in:
parent
00af61dcff
commit
84559145e8
1 changed files with 4 additions and 2 deletions
|
@ -3,8 +3,9 @@ var events = require('events'),
|
||||||
util = require('util'),
|
util = require('util'),
|
||||||
serial = require("serialport");
|
serial = require("serialport");
|
||||||
|
|
||||||
var Arduino = function (baudrate) {
|
var Arduino = function (baudrate, debug) {
|
||||||
this.baudrate = baudrate && baudrate || 9600;
|
this.baudrate = baudrate && baudrate || 9600;
|
||||||
|
this.debug = debug && debug || false;
|
||||||
this.writeBuffer = [];
|
this.writeBuffer = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +39,11 @@ Arduino.prototype.setup = function () {
|
||||||
self.serial.on('open', function () { setTimeout(function () {
|
self.serial.on('open', function () { setTimeout(function () {
|
||||||
self.serial.write(new Buffer('00000000'));
|
self.serial.write(new Buffer('00000000'));
|
||||||
self.serial.write(new Buffer('Zn000000', 'ascii'));
|
self.serial.write(new Buffer('Zn000000', 'ascii'));
|
||||||
|
if(self.debug) { self.serial.write(new Buffer('P0000000', 'ascii')); }
|
||||||
self.emit('success');
|
self.emit('success');
|
||||||
|
|
||||||
self.serial.on('data', function(data){
|
self.serial.on('data', function(data){
|
||||||
console.log(data);
|
if(self.debug) { console.log(data) };
|
||||||
self.emit('data', data);
|
self.emit('data', data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Reference in a new issue