Skip to content

Commit bdd85d4

Browse files
committed
upload hex file
1 parent cac79dc commit bdd85d4

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

cli-options.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"description": "compilation defines",
1717
"default": false
1818
},
19+
"file": {
20+
"description": "file for upload"
21+
},
1922
"sketch": {
2023
"description": "sketch folder, config file or template name",
2124
"alias": "s"

cli.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,14 @@ ArduinoCli.prototype.platform = function (options, cb) {
414414

415415

416416
ArduinoCli.prototype.upload = function (options, cb) {
417+
417418
var buildMeta = guessSketch (this.arduino, options);
418419

420+
var hexFile = options.file;
421+
419422
console.log (
420423
paint.cuwire(),
421-
'upload', paint.path (buildMeta.folder),
424+
'upload', paint.path (hexFile || buildMeta.folder),
422425
'using port', paint.path (options.port)
423426
);
424427

@@ -431,7 +434,8 @@ ArduinoCli.prototype.upload = function (options, cb) {
431434
serial: {
432435
port: options.port
433436
},
434-
verbose: options.verbose
437+
verbose: options.verbose,
438+
haveCompiledHex: hexFile
435439
}
436440
);
437441

uploader.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ function ArduinoUploader (compiler, platformId, boardId, boardVariant, options)
5454
// return;
5555
// }
5656

57+
58+
if (options.haveCompiledHex) {
59+
var uploadFileRegexp = /\{build\.path\}\/\{build\.project_name\}\.hex/;
60+
if (tool['upload.pattern'].match (uploadFileRegexp)) {
61+
tool['upload.pattern'] = tool['upload.pattern'].replace (uploadFileRegexp, '{upload.precompiled_hex}');
62+
tool['upload.precompiled_hex'] = options.haveCompiledHex;
63+
} else {
64+
this.emit ('error', 'upload', new Error ('Current platform doesn\'t support precompiled hex upload. "upload.pattern"='+tool['upload.pattern']));
65+
return;
66+
}
67+
}
68+
5769
// have event subscription issues without this
5870
process.nextTick (this.prepareCmd.bind (this, tool));
5971
}

0 commit comments

Comments
 (0)