Skip to content

Commit efcb956

Browse files
Warn users when using V2 API features with micro:bit V1
1 parent 2126e74 commit efcb956

14 files changed

+71
-13
lines changed

public/workers/pyright-locale-416-213af665ac61b39bb90a.worker.js renamed to public/workers/pyright-locale-416-944d07150e3adf7f5d27.worker.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/workers/pyright-main-4d883fb033fc7fbb9f75.worker.js

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

public/workers/pyright-main-4d883fb033fc7fbb9f75.worker.js.map

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

public/workers/pyright-main-fbd1b969112a733566b7.worker.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

public/workers/pyright-main-fbd1b969112a733566b7.worker.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/device/device.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ export interface ConnectOptions {
133133
serial?: boolean;
134134
}
135135

136+
export type BoardVersion = "V1" | "V2";
137+
136138
export interface DeviceConnection extends EventEmitter {
137139
status: ConnectionStatus;
138140

@@ -153,6 +155,13 @@ export interface DeviceConnection extends EventEmitter {
153155
*/
154156
connect(options?: ConnectOptions): Promise<ConnectionStatus>;
155157

158+
/**
159+
* Get the board version.
160+
*
161+
* @returns the board version or null if there is no connection.
162+
*/
163+
getBoardVersion(): BoardVersion | null;
164+
156165
/**
157166
* Flash the micro:bit.
158167
*

src/device/mock.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: MIT
55
*/
66
import {
7+
BoardVersion,
78
ConnectionStatus,
89
DeviceConnection,
910
EVENT_FLASH,
@@ -62,6 +63,10 @@ export class MockDeviceConnection
6263
return this.status;
6364
}
6465

66+
getBoardVersion(): BoardVersion | null {
67+
return "V2";
68+
}
69+
6570
/**
6671
* Flash the micro:bit.
6772
*

src/device/simulator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import EventEmitter from "events";
77
import { Logging } from "../logging/logging";
88
import {
9+
BoardVersion,
910
ConnectionStatus,
1011
DeviceConnection,
1112
EVENT_FLASH,
@@ -262,6 +263,10 @@ export class SimulatorDeviceConnection
262263
return this.status;
263264
}
264265

266+
getBoardVersion(): BoardVersion | null {
267+
return "V2";
268+
}
269+
265270
async flash(
266271
dataSource: FlashDataSource,
267272
options: {

src/device/webusb.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { withTimeout, TimeoutError } from "./async-util";
1010
import { DAPWrapper } from "./dap-wrapper";
1111
import { PartialFlashing } from "./partial-flashing";
1212
import {
13+
BoardVersion,
1314
ConnectionStatus,
1415
ConnectOptions,
1516
DeviceConnection,
@@ -172,6 +173,14 @@ export class MicrobitWebUSBConnection
172173
});
173174
}
174175

176+
getBoardVersion(): BoardVersion | null {
177+
if (!this.connection) {
178+
return null;
179+
}
180+
const boardId = this.connection.boardSerialInfo.id;
181+
return boardId.isV1() ? "V1" : boardId.isV2() ? "V2" : null;
182+
}
183+
175184
async flash(
176185
dataSource: FlashDataSource,
177186
options: {
@@ -297,7 +306,6 @@ export class MicrobitWebUSBConnection
297306
} finally {
298307
this.connection = undefined;
299308
this.setStatus(ConnectionStatus.NOT_CONNECTED);
300-
301309
this.logging.log("Disconnection complete");
302310
this.logging.event({
303311
type: "WebUSB-info",

0 commit comments

Comments
 (0)