From 9a4fb65fe21080b6b33366af833f0e6441185c0b Mon Sep 17 00:00:00 2001 From: paulober <44974737+paulober@users.noreply.github.com> Date: Mon, 16 Sep 2024 09:57:52 +0100 Subject: [PATCH] Fix #239, Soft-resets before and after file run Signed-off-by: paulober <44974737+paulober@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ README.md | 1 + package.json | 7 +++++++ src/activator.mts | 23 ++++++++++++++++++++--- src/flash.mts | 2 +- src/settings.mts | 1 + 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d084a8..846b6cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index a026182..b386d2f 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index c92b180..f9f5387 100644 --- a/package.json +++ b/package.json @@ -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 } } }, diff --git a/src/activator.mts b/src/activator.mts index ed94107..c046805 100644 --- a/src/activator.mts +++ b/src/activator.mts @@ -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." @@ -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( @@ -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."); @@ -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." @@ -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, @@ -556,6 +569,9 @@ export default class Activator { } } ); + if (!noSoftReset && !forceDisableSoftReset) { + await PicoMpyCom.getInstance().softReset(); + } this.ui?.userOperationStopped(); commandExecuting = false; this.terminal?.melt(); @@ -1934,7 +1950,8 @@ export default class Activator { if (scriptToExecute !== undefined && scriptToExecute.trim() !== "") { void vscode.commands.executeCommand( commandPrefix + "remote.run", - scriptToExecute + scriptToExecute, + true ); } diff --git a/src/flash.mts b/src/flash.mts index 20b0d12..f76bc99 100644 --- a/src/flash.mts +++ b/src/flash.mts @@ -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 diff --git a/src/settings.mts b/src/settings.mts index 9831b8a..c7552ef 100644 --- a/src/settings.mts +++ b/src/settings.mts @@ -18,6 +18,7 @@ export enum SettingsKey { softResetAfterUpload = "softResetAfterUpload", executeOnConnect = "executeOnConnect", importOnConnect = "importOnConnect", + noSoftResetOnRun = "noSoftResetOnRun", } export type Setting = string | boolean | string[] | null | undefined;