Skip to content

Commit 9a4fb65

Browse files
committed
Fix #239, Soft-resets before and after file run
Signed-off-by: paulober <[email protected]>
1 parent f3032e4 commit 9a4fb65

File tree

6 files changed

+37
-4
lines changed

6 files changed

+37
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ All notable changes to the "MicroPico" extension will be documented in this file
1010

1111
---
1212

13+
## [4.0.6] - 2024-09-16
14+
15+
### Added
16+
17+
- Soft-resets before and after executing scripts by default (#239)
18+
- `micropico.noSoftResetOnRun` setting to disable soft-resets before and after executing scripts (default: false)
19+
1320
## [4.0.5] - 2024-09-16
1421

1522
### Changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ This extension contributes the following settings:
9191
* `micropico.softResetAfterUpload`: Soft-resets your board after any upload action. Usefull if you are developing with `main.py` or `boot.py`.
9292
* `micropico.executeOnConnect`: Path to a MicroPython script on the Pico to execute on connect. Leave empty to disable. (must be relative to the root of the Pico's filesystem; doesn't need to begin with a slash; overrides `micropico.openOnStart` setting)
9393
* `micropico.importOnConnect`: A MicroPython module to import in vREPL on connect. Leave empty to disable.
94+
* `micropico.noSoftResetOnRun`: Disables the soft-resets before and after running a file on the Pico.
9495

9596
## Extension Context Keys
9697

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,13 @@
488488
"title": "MicroPython module to import on connect",
489489
"description": "A MicroPython module to import in vREPL on connect. Leave empty to disable.",
490490
"order": 14
491+
},
492+
"micropico.noSoftResetOnRun": {
493+
"type": "boolean",
494+
"default": false,
495+
"title": "Disable the soft-resets before and after executing a file.",
496+
"description": "Soft-resets are used to clean REPL state so changes in classes and other structs are reflected correctly.",
497+
"order": 15
491498
}
492499
}
493500
},

src/activator.mts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ export default class Activator {
446446
// [Command] Run File
447447
disposable = vscode.commands.registerCommand(
448448
commandPrefix + "run",
449-
async (resourceURI?: vscode.Uri) => {
449+
async (resourceURI?: vscode.Uri, noSoftReset = false) => {
450450
if (PicoMpyCom.getInstance().isPortDisconnected()) {
451451
void vscode.window.showWarningMessage(
452452
"Please connect to the Pico first."
@@ -472,7 +472,12 @@ export default class Activator {
472472
return;
473473
}
474474
}
475+
const forceDisableSoftReset =
476+
this.settings?.getBoolean(SettingsKey.noSoftResetOnRun) ?? false;
475477

478+
if (!noSoftReset && !forceDisableSoftReset) {
479+
await PicoMpyCom.getInstance().softReset();
480+
}
476481
await focusTerminal(this.terminalOptions);
477482
// TODO: maybe freeze terminal until this operation runs to prevent user input
478483
const data = await PicoMpyCom.getInstance().runFile(
@@ -493,6 +498,9 @@ export default class Activator {
493498
}
494499
}
495500
);
501+
if (!noSoftReset && !forceDisableSoftReset) {
502+
await PicoMpyCom.getInstance().softReset();
503+
}
496504
this.ui?.userOperationStopped();
497505
if (data.type !== OperationResultType.commandResult || !data.result) {
498506
this.logger.warn("Failed to execute script on Pico.");
@@ -507,7 +515,7 @@ export default class Activator {
507515

508516
disposable = vscode.commands.registerCommand(
509517
commandPrefix + "remote.run",
510-
async (fileOverride?: string | vscode.Uri) => {
518+
async (fileOverride?: string | vscode.Uri, noSoftReset = false) => {
511519
if (PicoMpyCom.getInstance().isPortDisconnected()) {
512520
void vscode.window.showWarningMessage(
513521
"Please connect to the Pico first."
@@ -534,7 +542,12 @@ export default class Activator {
534542

535543
return;
536544
}
545+
const forceDisableSoftReset =
546+
this.settings?.getBoolean(SettingsKey.noSoftResetOnRun) ?? false;
537547

548+
if (!noSoftReset && !forceDisableSoftReset) {
549+
await PicoMpyCom.getInstance().softReset();
550+
}
538551
await focusTerminal(this.terminalOptions);
539552
await PicoMpyCom.getInstance().runRemoteFile(
540553
file,
@@ -556,6 +569,9 @@ export default class Activator {
556569
}
557570
}
558571
);
572+
if (!noSoftReset && !forceDisableSoftReset) {
573+
await PicoMpyCom.getInstance().softReset();
574+
}
559575
this.ui?.userOperationStopped();
560576
commandExecuting = false;
561577
this.terminal?.melt();
@@ -1934,7 +1950,8 @@ export default class Activator {
19341950
if (scriptToExecute !== undefined && scriptToExecute.trim() !== "") {
19351951
void vscode.commands.executeCommand(
19361952
commandPrefix + "remote.run",
1937-
scriptToExecute
1953+
scriptToExecute,
1954+
true
19381955
);
19391956
}
19401957

src/flash.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export async function flashPicoInteractively(
117117

118118
devices = { is2040: type === "RP2040", type };
119119
}
120-
} catch (error) {
120+
} catch {
121121
/*this.logger.debug(
122122
"Failed to check for USB MSDs:",
123123
error instanceof Error

src/settings.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export enum SettingsKey {
1818
softResetAfterUpload = "softResetAfterUpload",
1919
executeOnConnect = "executeOnConnect",
2020
importOnConnect = "importOnConnect",
21+
noSoftResetOnRun = "noSoftResetOnRun",
2122
}
2223

2324
export type Setting = string | boolean | string[] | null | undefined;

0 commit comments

Comments
 (0)