Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
noopkat committed Nov 28, 2015
1 parent 50f8048 commit 1721d0c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions avrgirl-arduino.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ AvrgirlArduino.prototype._validateBoard = function(callback) {
if (!this.board) {
// cannot find a matching board in supported list
return callback(new Error('"' + this.options.board + '" is not a supported board type.'));

} else if (!this.protocol.chip) {
// something went wrong trying to set up the protocol
return callback(new Error('not a supported programming protocol: ' + this.board.protocol));

} else if (!this.options.port && this.options.board === 'pro-mini') {
// when using a pro mini, a port is required in the options
return callback(new Error('using a pro-mini, please specify the port in your options.'));

} else {
// all good
return callback(null);
Expand All @@ -59,9 +62,11 @@ AvrgirlArduino.prototype._validateBoard = function(callback) {
AvrgirlArduino.prototype.flash = function(file, callback) {
var _this = this;

// validate board properties first
_this._validateBoard(function(error) {
if (error) { return callback(error); }

// set up serialport connection
_this.connection._setup(function(error) {
if (error) { return callback(error); }

Expand Down
13 changes: 7 additions & 6 deletions lib/avr109.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ var Serialport = require('serialport');
var async = require('async');

var Avr109 = function(board, connection, debug) {
this.debug = debug ? console.log.bind(console) : function() {};
this.board = board;
this.connection = connection;

var Protocol = function() { return protocol; };

// do I want to use 'chip' here? maybe just protocol
this.chip = new Protocol();
this.debug = debug ? console.log.bind(console) : function() {};
};

/**
Expand Down Expand Up @@ -42,6 +40,12 @@ Avr109.prototype._upload = function(file, callback) {
_this.debug('connected');

_this._write(data, function(error) {
var color = (error ? colors.red : colors.green);
_this.debug(color('flash complete.'));

// Always close the serialport
_this.serialPort.close();

return callback(error);
});
});
Expand All @@ -68,9 +72,6 @@ Avr109.prototype._write = function(data, callback) {
flasher.fuseCheck.bind(flasher)
],
function(error) {
var color = (error ? colors.red : colors.green);
_this.debug(color('flash complete.'));

return callback(error);
});
});
Expand Down
6 changes: 3 additions & 3 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Connection.prototype._setup = function(callback) {
}
});
} else {
// when a port is manually specified
_this._setUpSerial(function(error) {
return callback(error);
});

}
};

Expand All @@ -61,7 +61,7 @@ Connection.prototype._sniffPort = function(callback) {
var pidList = _this.board.productId;

_this._listPorts(function(error, ports) {

// filter for a match by product id
var portMatch = ports.filter(function(p) {
return pidList.indexOf(p._standardPid) !== -1;
});
Expand Down Expand Up @@ -163,7 +163,7 @@ Connection.prototype._listPorts = function(callback) {
if (ports[i].productId) {
pid = ports[i].productId;
} else if (ports[i].pnpId) {
try {
try {
pid = '0x' + /PID_\d*/.exec(ports[i].pnpId)[0].substr(4);
} catch (err) {
pid = '';
Expand Down
3 changes: 1 addition & 2 deletions lib/stk500v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ var colors = require('colors');
var tools = require('./tools');

var Stk500v1 = function(board, connection, debug) {
this.debug = debug ? console.log.bind(console) : function() {};
this.board = board;
this.connection = connection;

// do I want to use 'chip' here? maybe just protocol
this.chip = new Protocol({
quiet: true
});
this.debug = debug ? console.log.bind(console) : function() {};
};

/**
Expand Down

0 comments on commit 1721d0c

Please sign in to comment.