Skip to content

Commit 5042497

Browse files
Upgrade connection lib, fix for API change
1 parent b2fe2ae commit 5042497

File tree

5 files changed

+30
-40
lines changed

5 files changed

+30
-40
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@codemirror/view": "^6.26.3",
1717
"@emotion/react": "^11.11.4",
1818
"@emotion/styled": "^11.11.5",
19-
"@microbit/microbit-connection": "^0.0.0-alpha.3",
19+
"@microbit/microbit-connection": "^0.0.0-alpha.4",
2020
"@microbit/microbit-fs": "^0.9.2",
2121
"@sanity/block-content-to-react": "^3.0.0",
2222
"@sanity/image-url": "^1.0.1",

src/fs/fs.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import * as fs from "fs";
1010
import * as fsp from "fs/promises";
1111
import { NullLogging } from "../deployment/default/logging";
12-
import { BoardId } from "@microbit/microbit-connection";
12+
import { MicroPythonSource } from "../micropython/micropython";
1313
import {
1414
diff,
1515
FileSystem,
@@ -20,7 +20,6 @@ import {
2020
} from "./fs";
2121
import { DefaultHost } from "./host";
2222
import { defaultInitialProject } from "./initial-project";
23-
import { MicroPythonSource } from "../micropython/micropython";
2423

2524
const hexes = Promise.all([
2625
fs.readFileSync("src/micropython/microbit-micropython-v1.hex", {
@@ -39,7 +38,7 @@ const fsMicroPythonSource: MicroPythonSource = async () => {
3938
hex: v1,
4039
},
4140
{
42-
boardId: 0x9003,
41+
boardId: 0x9903,
4342
hex: v2,
4443
},
4544
];
@@ -218,11 +217,12 @@ describe("Filesystem", () => {
218217
expect(typeof data).toEqual("string");
219218
});
220219

221-
it("creates board-specific data for flashing", async () => {
222-
const boardId = BoardId.parse("9900");
223-
const partial = await ufs.partialFlashData(boardId);
224-
const full = await ufs.fullFlashData(boardId);
225-
expect(partial.length).toBeLessThan(full.length);
220+
it("creates board-specific data for flashing V1", async () => {
221+
await ufs.asFlashDataSource()("V1");
222+
});
223+
224+
it("creates board-specific data for flashing V2", async () => {
225+
await ufs.asFlashDataSource()("V2");
226226
});
227227

228228
it("gives useful stats", async () => {

src/fs/fs.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import sortBy from "lodash.sortby";
1212
import { lineNumFromUint8Array } from "../common/text-util";
1313
import {
1414
BoardId,
15-
FlashDataSource,
1615
FlashDataError,
16+
BoardVersion,
1717
} from "@microbit/microbit-connection";
1818
import { Logging } from "../logging/logging";
1919
import { MicroPythonSource } from "../micropython/micropython";
@@ -170,10 +170,7 @@ export const isNameLengthValid = (filename: string): boolean =>
170170
* or fire any events. This plays well with uncontrolled embeddings of
171171
* third-party text editors.
172172
*/
173-
export class FileSystem
174-
extends TypedEventTarget<EventMap>
175-
implements FlashDataSource
176-
{
173+
export class FileSystem extends TypedEventTarget<EventMap> {
177174
private initializing: Promise<void> | undefined;
178175
private storage: FSStorage;
179176
private fileVersions: Map<string, number> = new Map();
@@ -463,22 +460,16 @@ export class FileSystem
463460
return this.storage.clearDirty();
464461
}
465462

466-
async fullFlashData(boardId: BoardId): Promise<string> {
467-
try {
468-
const fs = await this.initialize();
469-
return fs.getIntelHex(boardId.normalize().id);
470-
} catch (e: any) {
471-
throw new FlashDataError(e.message);
472-
}
473-
}
474-
475-
async partialFlashData(boardId: BoardId): Promise<Uint8Array> {
476-
try {
477-
const fs = await this.initialize();
478-
return fs.getIntelHexBytes(boardId.normalize().id);
479-
} catch (e: any) {
480-
throw new FlashDataError(e.message);
481-
}
463+
asFlashDataSource() {
464+
return async (boardVersion: BoardVersion) => {
465+
try {
466+
const fs = await this.initialize();
467+
const boardId = BoardId.forVersion(boardVersion).id;
468+
return fs.getIntelHex(boardId);
469+
} catch (e: any) {
470+
throw new FlashDataError(e.message);
471+
}
472+
};
482473
}
483474

484475
async files(): Promise<Record<string, Uint8Array>> {

src/project/project-actions.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,7 @@ export class ProjectActions {
140140
this.webusbNotSupportedError(finalFocusRef);
141141
} else {
142142
if (await this.showConnectHelp(forceConnectHelp, finalFocusRef)) {
143-
return this.connectInternal(
144-
{ serial: userAction !== ConnectionAction.FLASH },
145-
userAction,
146-
finalFocusRef
147-
);
143+
return this.connectInternal({}, userAction, finalFocusRef);
148144
}
149145
}
150146
};
@@ -543,7 +539,10 @@ export class ProjectActions {
543539
progress: value,
544540
});
545541
};
546-
await this.device.flash(this.fs, { partial: true, progress });
542+
await this.device.flash(this.fs.asFlashDataSource(), {
543+
partial: true,
544+
progress,
545+
});
547546
} catch (e) {
548547
if (e instanceof FlashDataError) {
549548
this.actionFeedback.expectedError({

0 commit comments

Comments
 (0)