Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add: final phases to flash process

  • Loading branch information...
commit 3ed7c74a22b2bb1acaa4cd39e5cd32303b68acd3 1 parent 4646799
@tmpvar authored
Showing with 83 additions and 39 deletions.
  1. +44 −15 bin/tpad
  2. +37 −23 firmware/index.js
  3. +2 −1  package.json
View
59 bin/tpad
@@ -8,7 +8,9 @@ var
serial = require('../lib/serial'),
Tpad = require('../lib/tpad'),
cleanup = c.reset.bind(c),
- color = require('color');
+ color = require('color')
+ flash = require('../firmware'),
+ command = argv._[0] || null;
c.hex('CCFF00');
@@ -54,26 +56,53 @@ serial.on('searching', function() {
}, 50);
});
-serial.on('connected', function(config) {
+serial.on('connected', function() {
clearInterval(spinnerTimer);
+});
- c.green();
+// Normal repl mode
+if (!command) {
- console.log('\n\nconnected to a', config.tpad.name, 'with', config.tpad.pads, 'pads');
- c.reset();
- currentRepl.updatePrompt(config.tpad);
+ 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');
+ flash(config);
+ });
+
+ break;
+ }
+}
- 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');
-});
process.on('unhandledException', function(e) {
View
60 firmware/index.js
@@ -21,9 +21,8 @@ var firmware = module.exports = function(options) {
// TODO: ensure you can specify a firmware dir
firmware.fetch(function(err, folder) {
- console.log(folder);
firmware.build(folder, function(err) {
- firmware.flash(folder);
+ firmware.flash(folder, options);
});
});
@@ -48,8 +47,6 @@ firmware.fetch = function(fn) {
passed = 0,
where = 0;
- // TODO: check if the sha exists
-
fs.exists(shaDir, function(exists) {
if (!exists) {
req = request(url, sha);
@@ -93,39 +90,56 @@ firmware.build = function(dir, fn) {
exec('make', {
cwd : dir
}, function (error, stdout, stderr) {
- console.log('stdout: ' + stdout);
- console.log('stderr: ' + stderr);
- if (error !== null) {
- console.log('exec error: ' + error);
+ if (error) {
+ throw error;
+ } else {
+ fn();
}
- fn();
});
};
// Basically wait for the known tpad connection to drop
// wait 2 seconds then run avrdude
-firmware.waitForUser = function(dir, fn) {
- setTimeout(function() {
- // TODO: figure out what type of tpad is attached
- fn(dir + '/tpad/tpad4-mega');
- }, 2000);
+firmware.waitForUser = function(dir, options, fn) {
+
+ var state = 0;
+ setTimeout(function tick() {
+ fs.exists(options.serialport.port, function(e) {
+
+ // ready to go!
+ if (!e) {
+ process.stdout.write('.')
+ state = 1;
+ setTimeout(tick, 100);
+ } else if (state === 1) {
+ console.log('ready to flash.. waiting');
+ options.serialport.close();
+ setTimeout(function() {
+ fn(dir + '/tpad/' + options.tpad.name);
+ }, 2000);
+ } else {
+ setTimeout(tick, 100);
+ }
+ });
+ }, 100);
};
-firmware.flash = function(dir) {
+firmware.flash = function(dir, options, fn) {
+
console.log('Please press reset on the device.....');
- firmware.waitForUser(dir, function(tpadFirmwareDir) {
+ firmware.waitForUser(dir,options, function(tpadFirmwareDir) {
console.log('flashing...');
+ var env = process.env;
+ env.AVRDUDE_PORT = options.serialport.port;
exec('make avrdude', {
cwd : tpadFirmwareDir,
- // TODO: specify AVRDUDE_PORT
- }, function (error, stdout, stderr) {
- console.log('stdout: ' + stdout);
- console.log('stderr: ' + stderr);
- if (error !== null) {
- console.log('exec error: ' + error);
- }
+ env : env
+ }, function (err, stdout, stderr) {
+ if (err) { throw err; }
+ console.log('OK!')
+ process.exit();
});
});
};
View
3  package.json
@@ -15,7 +15,8 @@
"color": "~0.4.1",
"midi": "~v0.5.0",
"socket.io": "~0.9.6",
- "optimist": "~0.3.4"
+ "optimist": "~0.3.4",
+ "tar": "~0.1.13"
},
"bin": {
"tpad": "./bin/tpad"
Please sign in to comment.
Something went wrong with that request. Please try again.