Skip to content

Commit

Permalink
Merge pull request #9 from lwille/master
Browse files Browse the repository at this point in the history
throw is evil
  • Loading branch information
Cam Pedersen committed Apr 24, 2012
2 parents e19c968 + d44af87 commit 299f1b4
Showing 1 changed file with 39 additions and 33 deletions.
72 changes: 39 additions & 33 deletions lib/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,45 @@ var Board = function (options) {

var self = this;
this.detect(function (err, serial) {
if (err) throw err;
self.serial = serial;
self.emit('connected');

self.log('info', 'binding serial events');
self.serial.on('data', function(data){
self.log('receive', data.toString().red);
self.emit('data', data);
});

setTimeout(function(){
self.log('info', 'board ready');
self.sendClearingBytes();

if (self.debug) {
self.log('info', 'sending debug mode toggle on to board');
self.write('99' + self.normalizePin(0) + self.normalizeVal(1));
process.on('SIGINT', function(){
self.log('info', 'sending debug mode toggle off to board');
self.write('99' + self.normalizePin(0) + self.normalizeVal(0));
delete self.serial;
setTimeout(function(){
process.exit();
}, 100);
});
}

if (self.writeBuffer.length > 0) {
self.processWriteBuffer();
}

self.emit('ready');
}, 500);
if (err) {
if(self.listeners('error').length)
self.emit('error', err);
else
throw new Error(err);
}else{
self.serial = serial;
self.emit('connected');

self.log('info', 'binding serial events');
self.serial.on('data', function(data){
self.log('receive', data.toString().red);
self.emit('data', data);
});

setTimeout(function(){
self.log('info', 'board ready');
self.sendClearingBytes();

if (self.debug) {
self.log('info', 'sending debug mode toggle on to board');
self.write('99' + self.normalizePin(0) + self.normalizeVal(1));
process.on('SIGINT', function(){
self.log('info', 'sending debug mode toggle off to board');
self.write('99' + self.normalizePin(0) + self.normalizeVal(0));
delete self.serial;
setTimeout(function(){
process.exit();
}, 100);
});
}

if (self.writeBuffer.length > 0) {
self.processWriteBuffer();
}

self.emit('ready');
}, 500);
}
});
}

Expand Down

0 comments on commit 299f1b4

Please sign in to comment.