Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 119 lines (81 sloc) 2.43 KB
#!/usr/bin/env node
var
c = require('ansi')(process.stdout),
argv = require('optimist').argv,
version = require(__dirname + '/../package.json').version,
repl = require('../lib/repl'),
serial = require('../lib/serial'),
Tpad = require('../lib/tpad'),
cleanup = c.reset.bind(c),
color = require('color')
flash = require('../firmware'),
command = argv._[0] || null;
c.hex('CCFF00');
console.log([
'_/_/_/_/_/ _/_/_/ _/_/ _/_/_/',
' _/ _/ _/ _/ _/ _/ _/',
' _/ _/_/_/ _/_/_/_/ _/ _/',
' _/ _/ _/ _/ _/ _/',
'_/ _/ _/ _/ _/_/_/'].join('\n'));
c.hex('aaaaaa');
console.log('version:', version);
c.reset();
c.green();
serial.init();
var currentRepl = repl.start(), currentSerialPort;
currentRepl.context.color = color;
var spinner = "|/-\\", spinnerPos = 0, spinnerTimer;
serial.on('searching', function() {
c.grey();
process.stdout.write('searching ');
spinnerTimer = setInterval(function() {
c.back(1);
process.stdout.write(spinner[spinnerPos]);
c.reset();
spinnerPos++;
if (spinnerPos >= spinner.length) {
spinnerPos = 0;
}
}, 50);
});
serial.on('connected', function() {
clearInterval(spinnerTimer);
});
// Normal repl mode
if (!command) {
require('../command')(currentRepl);
serial.on('connected', function(config) {
clearInterval(spinnerTimer);
c.green();
console.log('\n\nconnected to a', config.tpad.name, 'with', config.tpad.pads, 'pads');
c.reset();
currentRepl.updatePrompt(config.tpad);
currentRepl.context.sp = currentSerialPort = config.serialport;
var tpad = currentRepl.context.tpad = new Tpad(config);
c.reset();
});
serial.on('disconnected', function() {
c.red();
currentSerialPort = null;
console.log('disconnected');
});
} else {
switch (command) {
case 'flash':
console.log('Please connect _only_ the tpad you want to flash')
serial.on('connected', function(config) {
serial.removeAllListeners('searching');
// Disable reconnect as it gets in the way of the flashing operation
config.serialport.removeAllListeners('close');
// allow the user to specify a development version of the tpad firmware
config.location = argv._[1] || null;
flash(config);
});
break;
}
}
process.on('unhandledException', function(e) {
console.log(e);
cleanup();
});
process.on('exit', cleanup);
Something went wrong with that request. Please try again.