Skip to content

Commit

Permalink
Fix #239, Soft-resets before and after file run
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Sep 16, 2024
1 parent f3032e4 commit 9a4fb65
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ All notable changes to the "MicroPico" extension will be documented in this file

---

## [4.0.6] - 2024-09-16

### Added

- Soft-resets before and after executing scripts by default (#239)
- `micropico.noSoftResetOnRun` setting to disable soft-resets before and after executing scripts (default: false)

## [4.0.5] - 2024-09-16

### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ This extension contributes the following settings:
* `micropico.softResetAfterUpload`: Soft-resets your board after any upload action. Usefull if you are developing with `main.py` or `boot.py`.
* `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)
* `micropico.importOnConnect`: A MicroPython module to import in vREPL on connect. Leave empty to disable.
* `micropico.noSoftResetOnRun`: Disables the soft-resets before and after running a file on the Pico.

## Extension Context Keys

Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,13 @@
"title": "MicroPython module to import on connect",
"description": "A MicroPython module to import in vREPL on connect. Leave empty to disable.",
"order": 14
},
"micropico.noSoftResetOnRun": {
"type": "boolean",
"default": false,
"title": "Disable the soft-resets before and after executing a file.",
"description": "Soft-resets are used to clean REPL state so changes in classes and other structs are reflected correctly.",
"order": 15
}
}
},
Expand Down
23 changes: 20 additions & 3 deletions src/activator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export default class Activator {
// [Command] Run File
disposable = vscode.commands.registerCommand(
commandPrefix + "run",
async (resourceURI?: vscode.Uri) => {
async (resourceURI?: vscode.Uri, noSoftReset = false) => {
if (PicoMpyCom.getInstance().isPortDisconnected()) {
void vscode.window.showWarningMessage(
"Please connect to the Pico first."
Expand All @@ -472,7 +472,12 @@ export default class Activator {
return;
}
}
const forceDisableSoftReset =
this.settings?.getBoolean(SettingsKey.noSoftResetOnRun) ?? false;

if (!noSoftReset && !forceDisableSoftReset) {
await PicoMpyCom.getInstance().softReset();
}
await focusTerminal(this.terminalOptions);
// TODO: maybe freeze terminal until this operation runs to prevent user input
const data = await PicoMpyCom.getInstance().runFile(
Expand All @@ -493,6 +498,9 @@ export default class Activator {
}
}
);
if (!noSoftReset && !forceDisableSoftReset) {
await PicoMpyCom.getInstance().softReset();
}
this.ui?.userOperationStopped();
if (data.type !== OperationResultType.commandResult || !data.result) {
this.logger.warn("Failed to execute script on Pico.");
Expand All @@ -507,7 +515,7 @@ export default class Activator {

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

return;
}
const forceDisableSoftReset =
this.settings?.getBoolean(SettingsKey.noSoftResetOnRun) ?? false;

if (!noSoftReset && !forceDisableSoftReset) {
await PicoMpyCom.getInstance().softReset();
}
await focusTerminal(this.terminalOptions);
await PicoMpyCom.getInstance().runRemoteFile(
file,
Expand All @@ -556,6 +569,9 @@ export default class Activator {
}
}
);
if (!noSoftReset && !forceDisableSoftReset) {
await PicoMpyCom.getInstance().softReset();
}
this.ui?.userOperationStopped();
commandExecuting = false;
this.terminal?.melt();
Expand Down Expand Up @@ -1934,7 +1950,8 @@ export default class Activator {
if (scriptToExecute !== undefined && scriptToExecute.trim() !== "") {
void vscode.commands.executeCommand(
commandPrefix + "remote.run",
scriptToExecute
scriptToExecute,
true
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/flash.mts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export async function flashPicoInteractively(

devices = { is2040: type === "RP2040", type };
}
} catch (error) {
} catch {
/*this.logger.debug(
"Failed to check for USB MSDs:",
error instanceof Error
Expand Down
1 change: 1 addition & 0 deletions src/settings.mts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum SettingsKey {
softResetAfterUpload = "softResetAfterUpload",
executeOnConnect = "executeOnConnect",
importOnConnect = "importOnConnect",
noSoftResetOnRun = "noSoftResetOnRun",
}

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

0 comments on commit 9a4fb65

Please sign in to comment.