@@ -35,6 +35,9 @@ export class PicoMpyCom extends EventEmitter {
35
35
private resetResolve ?: (
36
36
value : OperationResult | PromiseLike < OperationResult >
37
37
) => void ;
38
+ // flag to indicate if main.py exists on the board
39
+ // so the follow op can account for it
40
+ private mainPyExists = false ;
38
41
39
42
private constructor ( ) {
40
43
// TODO: maybe set option to auto capture rejections
@@ -118,7 +121,13 @@ export class PicoMpyCom extends EventEmitter {
118
121
}
119
122
} ;
120
123
this . once ( PicoSerialEvents . interrupt , onInter ) ;
121
- readUntil ( this . serialPort , 2 , ">OK" , null , this . followReset )
124
+ readUntil (
125
+ this . serialPort ,
126
+ 2 ,
127
+ this . mainPyExists ? "\n>>> " : ">OK" ,
128
+ null ,
129
+ this . followReset
130
+ )
122
131
. catch ( ( ) => {
123
132
// Do nothing
124
133
} )
@@ -288,6 +297,38 @@ export class PicoMpyCom extends EventEmitter {
288
297
this . resetInProgress = true ;
289
298
this . followReset = receiver ;
290
299
this . resetResolve = resolve ;
300
+
301
+ // check if main.py is present
302
+ const result = await executeAnyCommand (
303
+ this . serialPort ,
304
+ this ,
305
+ {
306
+ type : CommandType . getItemStat ,
307
+ args : { item : "main.py" } ,
308
+ } ,
309
+ undefined ,
310
+ pythonInterpreterPath ,
311
+ undefined
312
+ ) ;
313
+
314
+ if ( result . type !== OperationResultType . getItemStat ) {
315
+ // reset state
316
+ this . resetInProgress = false ;
317
+ this . followReset = undefined ;
318
+ this . resetResolve = undefined ;
319
+
320
+ // continue processing of the queue
321
+ this . executeNextOperation ( ) ;
322
+
323
+ resolve ( {
324
+ type : OperationResultType . commandResult ,
325
+ result : false ,
326
+ } ) ;
327
+
328
+ return ;
329
+ }
330
+
331
+ this . mainPyExists = result . stat !== null && ! result . stat . isDir ;
291
332
}
292
333
293
334
readyStateCb ?.( true ) ;
0 commit comments