From cf04174506ed31ce6c6954f857c0340d8ae473df Mon Sep 17 00:00:00 2001 From: Sev Date: Thu, 18 Jul 2013 19:38:18 +0300 Subject: [PATCH 1/3] Listen for serialport's ready event --- lib/board.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/board.js b/lib/board.js index a1acf89..702029b 100644 --- a/lib/board.js +++ b/lib/board.js @@ -32,7 +32,7 @@ var Board = function (options) { self.emit('data', data); }); - setTimeout(function(){ + self.serial.on('open', function() { self.log('info', 'board ready'); self.sendClearingBytes(); @@ -53,8 +53,10 @@ var Board = function (options) { self.processWriteBuffer(); } - self.emit('ready'); - }, 500); + setTimeout(function() { + self.emit('ready'); + }, 500); + }); } }); } From f7d9023c0f43db3d4c3675118d26e10bb552b209 Mon Sep 17 00:00:00 2001 From: Sev Date: Thu, 18 Jul 2013 19:39:50 +0300 Subject: [PATCH 2/3] Insist on attaching servos --- lib/servo.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/servo.js b/lib/servo.js index de61334..2ef569d 100644 --- a/lib/servo.js +++ b/lib/servo.js @@ -18,10 +18,15 @@ var Servo = function (options) { moved: true }; - this.board.on('ready', function () { - console.log('board ready, attaching servo', this); + if (this.board.serial && this.board.serial.readStream) { + console.log('board already ready, attaching servo', this); this.attach(); - }.bind(this)); + } else { + this.board.on('ready', function () { + console.log('board ready, attaching servo', this); + this.attach(); + }.bind(this)); + } this.board.on('data', function (message) { var m = message.slice(0, -1).split('::'), From 66758514d130b58f920e90d25d543ecec5b8fa8c Mon Sep 17 00:00:00 2001 From: Sev Date: Thu, 18 Jul 2013 19:55:31 +0300 Subject: [PATCH 3/3] Update serialport's name --- lib/board.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/board.js b/lib/board.js index 702029b..d29c202 100644 --- a/lib/board.js +++ b/lib/board.js @@ -94,7 +94,7 @@ Board.prototype.detect = function (callback) { } if (!err) { found = temp; - self.log('info', 'found board at ' + temp.port); + self.log('info', 'found board at ' + temp.path); break; } else { err = new Error('Could not find Arduino');