Skip to content

Commit 57adde7

Browse files
fix: improve stopScript
1 parent 0cdc934 commit 57adde7

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@
948948
"cheap-watch": "^1.0.4",
949949
"consolite": "^0.3.8",
950950
"hookar": "^0.0.7-0",
951-
"micropython-ctl-cont": "^1.15.1",
951+
"micropython-ctl-cont": "^1.15.3",
952952
"picomatch": "^2.3.1",
953953
"prompts": "^2.4.2",
954954
"serialport": "^10.4.0"

src/Device.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,20 +435,26 @@ class Device {
435435
}
436436

437437
/**
438-
* @param {number} retries
438+
*
439+
* @param {number} safeBootAfterNumRetries attempt to safe boot on each retry after n failed ctrl + c attempts
440+
* @param {number} retries how many times to attempt to send ctrl + c and ctrl + f
441+
* @param {number} retryInterval how long to wait between each retry
442+
* @returns
439443
*/
440-
stopScript(retries = 10, retryInterval = 500) {
441-
this.log.debug("stop script");
444+
stopScript(safeBootAfterNumRetries = 2, retries = 10, retryInterval = 500) {
445+
this.log.debug("stop script", { safeBootAfterNumRetries, retries, retryInterval });
442446
return new Promise((resolve, reject) => {
443447
if (this.busy.get()) {
444448
let counter = 0;
445449
const intervalHandle = setInterval(() => {
446450
if (counter >= retries) {
447451
clearInterval(intervalHandle);
452+
this.log.debug("ctrl + c failed. Attempting soft reboot (ctrl + f)");
448453
reject(`timed out after ${retries} retries in ${(retries * retryInterval) / 1000}s`);
449454
} else {
450455
counter++;
451-
this.adapter.sendData("\x03");
456+
const cmd = counter > safeBootAfterNumRetries ? "\x06\x03" : "\x03";
457+
this.adapter.sendData(cmd);
452458
this.log.log(`retry stop script (${counter})`);
453459
}
454460
}, retryInterval);
@@ -459,9 +465,9 @@ class Device {
459465
clearInterval(intervalHandle);
460466
}
461467
});
462-
this.adapter.sendData("\x03");
468+
const cmd = safeBootAfterNumRetries == 0 ? "\x06\x03" : "\x03";
469+
this.adapter.sendData(cmd);
463470
} else {
464-
this.adapter.sendData("\x03");
465471
resolve();
466472
}
467473
});

src/commands/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,21 @@ class Commands {
506506
.map((device) => this.commands.disconnect({ device }))
507507
);
508508
},
509-
509+
/**
510+
*
511+
512+
* @returns
513+
*/
510514
/**
511515
* @param {{device: Device}} device
516+
* @param {number=} safeBootAfterNumRetries attempt to safe boot on each retry after n failed ctrl + c attempts
517+
* @param {number=} retries how many times to attempt to send ctrl + c and ctrl + f
518+
* @param {number=} retryInterval how long to wait between each retry
512519
*/
513-
stopScript: ({ device }) =>
520+
stopScript: ({ device }, safeBootAfterNumRetries, retries, retryInterval) =>
514521
vscode.window.withProgress(
515522
{ title: `Stopping script on "${device.displayName}"`, location: vscode.ProgressLocation.Notification },
516-
() => device.stopScript()
523+
() => device.stopScript(safeBootAfterNumRetries, retries, retryInterval).then((r) => console.log("done", r))
517524
),
518525
/**
519526
* @param {ProjectTreeItem} ctx

0 commit comments

Comments
 (0)