Skip to content

Commit

Permalink
Merge 13bf2f8 into 4c88107
Browse files Browse the repository at this point in the history
  • Loading branch information
noopkat committed May 30, 2021
2 parents 4c88107 + 13bf2f8 commit c3a06ef
Show file tree
Hide file tree
Showing 24 changed files with 1,529 additions and 12,814 deletions.
37 changes: 14 additions & 23 deletions avrgirl-arduino.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,19 @@ var injectDependencies = function(boards, Connection, protocols) {
*
* @param {function} callback - function to run upon completion/error
*/
AvrgirlArduino.prototype._validateBoard = function(callback) {
AvrgirlArduino.prototype._validateBoard = function() {
if (typeof this.options.board !== 'object') {
// cannot find a matching board in supported list
return callback(new Error('"' + this.options.board + '" is not a supported board type.'));
throw 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
var errorMsg = 'not a supported programming protocol: ' + this.options.board.protocol;
return callback(new Error(errorMsg));
throw new Error(errorMsg);

} else if (!this.options.port && this.options.board.name === '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);
throw new Error('using a pro-mini, please specify the port in your options.');
}
};

Expand All @@ -100,32 +96,27 @@ var injectDependencies = function(boards, Connection, protocols) {
* @param {string} file - path to hex file for uploading
* @param {function} callback - function to run upon completion/error
*/
AvrgirlArduino.prototype.flash = function(file, callback) {
var _this = this;

AvrgirlArduino.prototype.flash = async function(file) {
// validate board properties first
_this._validateBoard(function(error) {
if (error) { return callback(error); }

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

// set up serialport connection
await this.connection._init();

// upload file to board
_this.protocol._upload(file, callback);
});
});
// upload file to board
await this.protocol._upload(file);
};


/**
* Return a list of devices on serial ports. In addition to the output provided
* by SerialPort.list, it adds a platform independent PID in _pid
*
* @param {function} callback - function to run upon completion/error
*/
AvrgirlArduino.prototype.listPorts = AvrgirlArduino.listPorts =
AvrgirlArduino.prototype.list = AvrgirlArduino.list = function(callback) {
return Connection.prototype._listPorts(callback);
AvrgirlArduino.prototype.list = AvrgirlArduino.list = function() {
return Connection.prototype._listPorts();
};

/**
Expand Down
Loading

0 comments on commit c3a06ef

Please sign in to comment.