Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created January 13, 2012 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwaldron/d2c8fcbab5a3da4c4dae to your computer and use it in GitHub Desktop.
Save rwaldron/d2c8fcbab5a3da4c4dae to your computer and use it in GitHub Desktop.
From "duino"
var Board = function (options) {
this.log('info', 'initializing');
this.debug = options && options.debug || false;
this.writeBuffer = [];
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.serial.write('!990001.');
process.on('SIGINT', function(){
self.log('info', 'sending debug mode toggle off to board');
self.serial.write('!990000.');
delete self.serial;
setTimeout(function(){
process.exit();
}, 100);
});
}
if (self.writeBuffer.length > 0) {
self.processWriteBuffer();
}
self.serial.write('!.\n!.\n!.\n'); // -_-
self.emit('ready');
}, 500);
});
}
var Board = function (options) {
this.log('info', 'initializing');
this.debug = options && options.debug || false;
this.writeBuffer = [];
this.detect({ (err, serial)
if (err) throw err;
this.serial = serial;
this.emit('connected');
this.log('info', 'binding serial events');
this.serial.on('data', { (data)
this.log('receive', data.toString().red);
this.emit('data', data);
});
setTimeout({ ()
this.log('info', 'board ready');
this.sendClearingBytes();
if (this.debug) {
this.log('info', 'sending debug mode toggle on to board');
this.serial.write('!990001.');
process.on('SIGINT', { ()
this.log('info', 'sending debug mode toggle off to board');
this.serial.write('!990000.');
delete this.serial;
setTimeout({ ()
process.exit();
}, 100);
});
}
if (this.writeBuffer.length > 0) {
this.processWriteBuffer();
}
this.serial.write('!.\n!.\n!.\n'); // -_-
this.emit('ready');
}, 500);
});
}
var Board = function (options) {
this.log('info', 'initializing');
this.debug = options && options.debug || false;
this.writeBuffer = [];
this.detect({ |err, serial|
if (err) throw err;
this.serial = serial;
this.emit('connected');
this.log('info', 'binding serial events');
this.serial.on('data', { |data|
this.log('receive', data.toString().red);
this.emit('data', data);
});
setTimeout({ ||
this.log('info', 'board ready');
this.sendClearingBytes();
if (this.debug) {
this.log('info', 'sending debug mode toggle on to board');
this.serial.write('!990001.');
process.on('SIGINT', { ||
this.log('info', 'sending debug mode toggle off to board');
this.serial.write('!990000.');
delete this.serial;
setTimeout({ ||
process.exit();
}, 100);
});
}
if (this.writeBuffer.length > 0) {
this.processWriteBuffer();
}
this.serial.write('!.\n!.\n!.\n'); // -_-
this.emit('ready');
}, 500);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment