-
-
Save rwaldron/d2c8fcbab5a3da4c4dae to your computer and use it in GitHub Desktop.
From "duino"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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