@@ -25,6 +25,11 @@ import { UsbDetector } from "../serialmonitor/usbDetector";
25
25
import { makeCompilerParserContext } from "./intellisense" ;
26
26
import { ProgrammerManager } from "./programmerManager" ;
27
27
28
+ export enum BuildMode {
29
+ Upload = "Uploading" ,
30
+ UploadProgrammer = "Uploading (programmer)" ,
31
+ } ;
32
+
28
33
/**
29
34
* Represent an Arduino application based on the official Arduino IDE.
30
35
*/
@@ -99,9 +104,10 @@ export class ArduinoApp {
99
104
* @param {bool } [compile=true] - Indicates whether to compile the code when using the CLI to upload
100
105
* @param {bool } [useProgrammer=false] - Indicate whether a specific programmer should be used
101
106
*/
102
- public async upload ( compile : boolean = true , useProgrammer : boolean = false ) {
107
+ public async upload ( buildMode : BuildMode , compile : boolean = true , useProgrammer : boolean = false ) {
103
108
const dc = DeviceContext . getInstance ( ) ;
104
109
const args : string [ ] = [ ] ;
110
+ let restoreSerialMonitor : boolean = false ;
105
111
const boardDescriptor = this . getBoardBuildString ( ) ;
106
112
if ( ! boardDescriptor ) {
107
113
return ;
@@ -133,38 +139,40 @@ export class ArduinoApp {
133
139
return ;
134
140
}
135
141
136
- if ( ( ! dc . configuration || ! / u p l o a d _ m e t h o d = [ ^ = , ] * s t [ ^ , ] * l i n k / i. test ( dc . configuration ) ) && ! dc . port ) {
137
- await selectSerial ( ) ;
138
- return ;
139
- }
142
+ if ( buildMode === BuildMode . Upload ) {
143
+ if ( ( ! dc . configuration || ! / u p l o a d _ m e t h o d = [ ^ = , ] * s t [ ^ , ] * l i n k / i. test ( dc . configuration ) ) && ! dc . port ) {
144
+ await selectSerial ( ) ;
145
+ return ;
146
+ }
140
147
141
- if ( ! compile && ! this . useArduinoCli ( ) ) {
142
- arduinoChannel . error ( "This command is only available when using the Arduino CLI" ) ;
143
- return ;
144
- }
148
+ if ( ! compile && ! this . useArduinoCli ( ) ) {
149
+ arduinoChannel . error ( "This command is only available when using the Arduino CLI" ) ;
150
+ return ;
151
+ }
145
152
146
- if ( ! this . useArduinoCli ( ) ) {
147
- args . push ( "--upload" ) ;
148
- } else {
149
- // TODO: add the --clean argument to the cli args when v 0.14 is released (this will clean up the build folder after uploading)
150
- if ( compile ) {
151
- args . push ( "compile" , "--upload" ) ;
153
+ if ( ! this . useArduinoCli ( ) ) {
154
+ args . push ( "--upload" ) ;
152
155
} else {
153
- args . push ( "upload" ) ;
156
+ // TODO: add the --clean argument to the cli args when v 0.14 is released (this will clean up the build folder after uploading)
157
+ if ( compile ) {
158
+ args . push ( "compile" , "--upload" ) ;
159
+ } else {
160
+ args . push ( "upload" ) ;
161
+ }
162
+ args . push ( "-b" , boardDescriptor ) ;
154
163
}
155
- args . push ( "-b" , boardDescriptor ) ;
156
- }
157
164
158
- if ( useProgrammer ) {
159
- if ( this . useArduinoCli ( ) ) {
160
- args . push ( "--programmer" , selectProgrammer )
161
- } else {
162
- args . push ( "--useprogrammer" , "--pref" , "programmer=arduino:" + selectProgrammer )
165
+ if ( useProgrammer ) {
166
+ if ( this . useArduinoCli ( ) ) {
167
+ args . push ( "--programmer" , selectProgrammer )
168
+ } else {
169
+ args . push ( "--useprogrammer" , "--pref" , "programmer=arduino:" + selectProgrammer )
170
+ }
163
171
}
164
- }
165
172
166
- if ( dc . port ) {
167
- args . push ( "--port" , dc . port ) ;
173
+ if ( dc . port ) {
174
+ args . push ( "--port" , dc . port ) ;
175
+ }
168
176
}
169
177
170
178
const verbose = VscodeSettings . getInstance ( ) . logLevel === "verbose" ;
@@ -175,7 +183,7 @@ export class ArduinoApp {
175
183
await vscode . workspace . saveAll ( false ) ;
176
184
177
185
arduinoChannel . show ( ) ;
178
- arduinoChannel . start ( `Upload sketch - ${ dc . sketch } ` ) ;
186
+ arduinoChannel . start ( `${ buildMode } sketch ' ${ dc . sketch } ' ` ) ;
179
187
180
188
if ( ! await this . runPreBuildCommand ( dc ) ) {
181
189
return ;
@@ -204,16 +212,20 @@ export class ArduinoApp {
204
212
205
213
// stop serial monitor when everything is prepared and good
206
214
// what makes restoring of its previous state easier
207
- const restoreSerialMonitor = await SerialMonitor . getInstance ( ) . closeSerialMonitor ( dc . port ) ;
208
- UsbDetector . getInstance ( ) . pauseListening ( ) ;
215
+ if ( buildMode === BuildMode . Upload || buildMode === BuildMode . UploadProgrammer ) {
216
+ restoreSerialMonitor = await SerialMonitor . getInstance ( ) . closeSerialMonitor ( dc . port ) ;
217
+ UsbDetector . getInstance ( ) . pauseListening ( ) ;
218
+ }
209
219
210
220
// Push sketch as last argument
211
221
args . push ( path . join ( ArduinoWorkspace . rootPath , dc . sketch ) ) ;
212
222
213
223
const cleanup = async ( ) => {
214
- UsbDetector . getInstance ( ) . resumeListening ( ) ;
215
- if ( restoreSerialMonitor ) {
216
- await SerialMonitor . getInstance ( ) . openSerialMonitor ( ) ;
224
+ if ( buildMode === BuildMode . Upload || buildMode === BuildMode . UploadProgrammer ) {
225
+ UsbDetector . getInstance ( ) . resumeListening ( ) ;
226
+ if ( restoreSerialMonitor ) {
227
+ await SerialMonitor . getInstance ( ) . openSerialMonitor ( ) ;
228
+ }
217
229
}
218
230
}
219
231
@@ -223,15 +235,15 @@ export class ArduinoApp {
223
235
args ,
224
236
) . then ( async ( ) => {
225
237
await cleanup ( ) ;
226
- arduinoChannel . end ( `Uploaded the sketch: ${ dc . sketch } ${ os . EOL } ` ) ;
238
+ arduinoChannel . end ( `${ buildMode } sketch ' ${ dc . sketch } ' ${ os . EOL } ` ) ;
227
239
} , async ( reason ) => {
228
240
await cleanup ( ) ;
229
241
const msg = reason . code ?
230
- `Exit with code=${ reason . code } ${ os . EOL } ` :
242
+ `Exit with code=${ reason . code } ` :
231
243
reason . message ?
232
244
reason . message :
233
245
JSON . stringify ( reason ) ;
234
- arduinoChannel . error ( msg ) ;
246
+ arduinoChannel . error ( ` ${ buildMode } sketch ' ${ dc . sketch } ': ${ msg } ${ os . EOL } ` ) ;
235
247
} ) ;
236
248
}
237
249
0 commit comments