diff --git a/package-lock.json b/package-lock.json index 1d8c0078d..95e2c4c5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@codemirror/view": "^6.26.3", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", - "@microbit/microbit-connection": "^0.0.0-alpha.3", + "@microbit/microbit-connection": "^0.0.0-alpha.4", "@microbit/microbit-fs": "^0.9.2", "@sanity/block-content-to-react": "^3.0.0", "@sanity/image-url": "^1.0.1", @@ -4020,9 +4020,9 @@ } }, "node_modules/@microbit/microbit-connection": { - "version": "0.0.0-alpha.3", - "resolved": "https://registry.npmjs.org/@microbit/microbit-connection/-/microbit-connection-0.0.0-alpha.3.tgz", - "integrity": "sha512-ZckWkYkQ78bCHcBSivht1HRQRtYes6is99ZCWgPggLsSFcZ84DFjlIA/QJnFSgBUT/k4Fn20ZJeGN7aVU0gy9w==", + "version": "0.0.0-alpha.4", + "resolved": "https://registry.npmjs.org/@microbit/microbit-connection/-/microbit-connection-0.0.0-alpha.4.tgz", + "integrity": "sha512-+ifTMR8NHhgTlCmkIN+CxT32w0c9v8gMbxI3a+K+5s89ZU7KinhxDyJ6QbRr8Vb3Qt5eJhh3hwa6VIHhTiXtrg==", "dependencies": { "@microbit/microbit-universal-hex": "^0.2.2", "@types/web-bluetooth": "^0.0.20", diff --git a/package.json b/package.json index 52a810b7a..2e29ce924 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@codemirror/view": "^6.26.3", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", - "@microbit/microbit-connection": "^0.0.0-alpha.3", + "@microbit/microbit-connection": "^0.0.0-alpha.4", "@microbit/microbit-fs": "^0.9.2", "@sanity/block-content-to-react": "^3.0.0", "@sanity/image-url": "^1.0.1", diff --git a/src/fs/fs.test.ts b/src/fs/fs.test.ts index 2505d9995..d903d80bb 100644 --- a/src/fs/fs.test.ts +++ b/src/fs/fs.test.ts @@ -9,7 +9,7 @@ import * as fs from "fs"; import * as fsp from "fs/promises"; import { NullLogging } from "../deployment/default/logging"; -import { BoardId } from "@microbit/microbit-connection"; +import { MicroPythonSource } from "../micropython/micropython"; import { diff, FileSystem, @@ -20,7 +20,6 @@ import { } from "./fs"; import { DefaultHost } from "./host"; import { defaultInitialProject } from "./initial-project"; -import { MicroPythonSource } from "../micropython/micropython"; const hexes = Promise.all([ fs.readFileSync("src/micropython/microbit-micropython-v1.hex", { @@ -39,7 +38,7 @@ const fsMicroPythonSource: MicroPythonSource = async () => { hex: v1, }, { - boardId: 0x9003, + boardId: 0x9903, hex: v2, }, ]; @@ -218,11 +217,12 @@ describe("Filesystem", () => { expect(typeof data).toEqual("string"); }); - it("creates board-specific data for flashing", async () => { - const boardId = BoardId.parse("9900"); - const partial = await ufs.partialFlashData(boardId); - const full = await ufs.fullFlashData(boardId); - expect(partial.length).toBeLessThan(full.length); + it("creates board-specific data for flashing V1", async () => { + await ufs.asFlashDataSource()("V1"); + }); + + it("creates board-specific data for flashing V2", async () => { + await ufs.asFlashDataSource()("V2"); }); it("gives useful stats", async () => { diff --git a/src/fs/fs.ts b/src/fs/fs.ts index b58925247..ba93f24e5 100644 --- a/src/fs/fs.ts +++ b/src/fs/fs.ts @@ -12,8 +12,8 @@ import sortBy from "lodash.sortby"; import { lineNumFromUint8Array } from "../common/text-util"; import { BoardId, - FlashDataSource, FlashDataError, + BoardVersion, } from "@microbit/microbit-connection"; import { Logging } from "../logging/logging"; import { MicroPythonSource } from "../micropython/micropython"; @@ -170,10 +170,7 @@ export const isNameLengthValid = (filename: string): boolean => * or fire any events. This plays well with uncontrolled embeddings of * third-party text editors. */ -export class FileSystem - extends TypedEventTarget - implements FlashDataSource -{ +export class FileSystem extends TypedEventTarget { private initializing: Promise | undefined; private storage: FSStorage; private fileVersions: Map = new Map(); @@ -463,22 +460,16 @@ export class FileSystem return this.storage.clearDirty(); } - async fullFlashData(boardId: BoardId): Promise { - try { - const fs = await this.initialize(); - return fs.getIntelHex(boardId.normalize().id); - } catch (e: any) { - throw new FlashDataError(e.message); - } - } - - async partialFlashData(boardId: BoardId): Promise { - try { - const fs = await this.initialize(); - return fs.getIntelHexBytes(boardId.normalize().id); - } catch (e: any) { - throw new FlashDataError(e.message); - } + asFlashDataSource() { + return async (boardVersion: BoardVersion) => { + try { + const fs = await this.initialize(); + const boardId = BoardId.forVersion(boardVersion).id; + return fs.getIntelHex(boardId); + } catch (e: any) { + throw new FlashDataError(e.message); + } + }; } async files(): Promise> { diff --git a/src/project/project-actions.tsx b/src/project/project-actions.tsx index 8dc7f5676..69a6b308a 100644 --- a/src/project/project-actions.tsx +++ b/src/project/project-actions.tsx @@ -140,11 +140,7 @@ export class ProjectActions { this.webusbNotSupportedError(finalFocusRef); } else { if (await this.showConnectHelp(forceConnectHelp, finalFocusRef)) { - return this.connectInternal( - { serial: userAction !== ConnectionAction.FLASH }, - userAction, - finalFocusRef - ); + return this.connectInternal({}, userAction, finalFocusRef); } } }; @@ -543,7 +539,10 @@ export class ProjectActions { progress: value, }); }; - await this.device.flash(this.fs, { partial: true, progress }); + await this.device.flash(this.fs.asFlashDataSource(), { + partial: true, + progress, + }); } catch (e) { if (e instanceof FlashDataError) { this.actionFeedback.expectedError({