},
{
"command": "raspberry-pi-pico.runProject",
- "title": "Run Pico Project",
+ "title": "Run Pico Project (USB)",
"category": "Raspberry Pi Pico",
"enablement": "raspberry-pi-pico.isPicoProject"
},
"command": "raspberry-pi-pico.uninstallPicoSDK",
"title": "Uninstall Pico SDK",
"category": "Raspberry Pi Pico"
+ },
+ {
+ "command": "raspberry-pi-pico.flashProject",
+ "title": "Flash Pico Project (SWD)",
+ "category": "Raspberry Pi Pico",
+ "enablement": "raspberry-pi-pico.isPicoProject"
}
],
"configuration": {
export default class ClearGithubApiCacheCommand extends Command {
private _logger: Logger = new Logger("ClearGithubApiCacheCommand");
+ public static readonly id = "clearGithubApiCache";
+
constructor() {
- super("clearGithubApiCache");
+ super(ClearGithubApiCacheCommand.id);
}
async execute(): Promise<void> {
--- /dev/null
+import { CommandWithResult } from "./command.mjs";
+import Logger from "../logger.mjs";
+import { tasks, window } from "vscode";
+import { EventEmitter } from "stream";
+
+export default class FlashProjectSWDCommand extends CommandWithResult<boolean> {
+ private _logger: Logger = new Logger("FlashProjectSWDCommand");
+
+ public static readonly id = "flashProject";
+
+ constructor() {
+ super(FlashProjectSWDCommand.id);
+ }
+
+ async execute(): Promise<boolean> {
+ this._logger.info("Executing flash task...");
+
+ // Get the task with the specified name
+ const task = (await tasks.fetchTasks()).find(task => task.name === "Flash");
+
+ if (task) {
+ // Execute the task
+ const emitter = new EventEmitter();
+
+ // add callbacks for task completion
+ const end = tasks.onDidEndTaskProcess(e => {
+ if (e.execution.task === task) {
+ emitter.emit(
+ "terminated",
+ e.exitCode === undefined ? -1 : e.exitCode
+ );
+ }
+ });
+ const end2 = tasks.onDidEndTask(e => {
+ if (e.execution.task === task) {
+ emitter.emit("terminated", -1);
+ }
+ });
+
+ const codePromise = new Promise<number>(resolve => {
+ emitter.on("terminated", code => {
+ if (typeof code === "number") {
+ resolve(code);
+ } else {
+ resolve(-1);
+ }
+ });
+ });
+
+ let code = -1;
+ try {
+ await tasks.executeTask(task);
+
+ code = await codePromise;
+ } finally {
+ // dispose of callbacks
+ end.dispose();
+ end2.dispose();
+ }
+
+ return code === 0;
+ } else {
+ // Task not found
+ this._logger.error("Task 'Flash' not found.");
+ void window.showErrorMessage("Task 'Flash' not found.");
+
+ return false;
+ }
+ }
+}
import NewExampleProjectCommand from "./commands/newExampleProject.mjs";
import SwitchBoardCommand from "./commands/switchBoard.mjs";
import UninstallPicoSDKCommand from "./commands/uninstallPicoSDK.mjs";
+import FlashProjectSWDCommand from "./commands/flashProjectSwd.mjs";
export async function activate(context: ExtensionContext): Promise<void> {
Logger.info(LoggerSource.extension, "Extension activation triggered");
new GetTargetCommand(),
new CompileProjectCommand(),
new RunProjectCommand(),
+ new FlashProjectSWDCommand(),
new ClearGithubApiCacheCommand(),
new ConditionalDebuggingCommand(),
new DebugLayoutCommand(),
import ImportProjectCommand from "../commands/importProject.mjs";
import NewExampleProjectCommand from "../commands/newExampleProject.mjs";
import SwitchBoardCommand from "../commands/switchBoard.mjs";
+import FlashProjectSWDCommand from "../commands/flashProjectSwd.mjs";
export class QuickAccessCommand extends TreeItem {
constructor(
const SWITCH_SDK_LABEL = "Switch SDK";
const SWITCH_BOARD_LABEL = "Switch Board";
const COMPILE_PROJECT_LABEL = "Compile Project";
-const RUN_PROJECT_LABEL = "Run Project";
+const RUN_PROJECT_LABEL = "Run Project (USB)";
+const FLASH_PROJECT_LABEL = "Flash Project (SWD)";
const CONFIGURE_CMAKE_PROJECT_LABEL = "Configure CMake";
const DEBUG_PROJECT_LABEL = "Debug Project";
const DEBUG_LAYOUT_PROJECT_LABEL = "Debug Layout";
case RUN_PROJECT_LABEL:
element.iconPath = new ThemeIcon("run");
break;
+ case FLASH_PROJECT_LABEL:
+ element.iconPath = new ThemeIcon("desktop-download");
+ break;
case CONFIGURE_CMAKE_PROJECT_LABEL:
// alt. "gather"
element.iconPath = new ThemeIcon("beaker");
title: RUN_PROJECT_LABEL,
}
),
+ new QuickAccessCommand(
+ FLASH_PROJECT_LABEL,
+ TreeItemCollapsibleState.None,
+ {
+ command: `${extensionName}.${FlashProjectSWDCommand.id}`,
+ title: FLASH_PROJECT_LABEL,
+ }
+ ),
new QuickAccessCommand(
CONFIGURE_CMAKE_PROJECT_LABEL,
TreeItemCollapsibleState.None,