Skip to content

Commit f40354a

Browse files
Show unsupported micro:bit V1 dialog for radio bridge (#396)
- Fix for triggering the unsupported micro:bit v1 dialog - Removal of impossible logic for attempting to trigger the dialog. --------- Co-authored-by: Matt Hillsdon <matt.hillsdon@microbit.org>
1 parent f78d84b commit f40354a

File tree

4 files changed

+24
-47
lines changed

4 files changed

+24
-47
lines changed

lang/ui.en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,11 +1040,11 @@
10401040
"description": "Unplug radio link micro:bit dialog title"
10411041
},
10421042
"unsupported-device-explain": {
1043-
"defaultMessage": "Unfortunately, we only support using micro:bit V2 when connecting two micro:bits. You have connected a <link>micro:bit V1</link>.",
1043+
"defaultMessage": "Unfortunately, we only support using micro:bit V2 when connecting using micro:bit radio. You have connected a <link>micro:bit V1</link>.",
10441044
"description": "Unsupported device dialog"
10451045
},
10461046
"unsupported-device-header": {
1047-
"defaultMessage": "micro:bit V1 is not supported for connecting two micro:bits",
1047+
"defaultMessage": "micro:bit radio connections do not support micro:bit V1",
10481048
"description": "Unsupported device dialog"
10491049
},
10501050
"unsupported-device-with-bluetooth": {

src/connect-actions.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { Logging } from "./logging/logging";
1818
export enum ConnectResult {
1919
Success = "Success",
2020
Failed = "Failed",
21-
ErrorMicrobitUnsupported = "ErrorMicrobitUnsupported",
2221
ErrorBadFirmware = "ErrorBadFirmware",
2322
ErrorNoDeviceSelected = "ErrorNoDeviceSelected",
2423
ErrorUnableToClaimInterface = "ErrorUnableToClaimInterface",
@@ -71,7 +70,6 @@ export class ConnectActions {
7170
}
7271

7372
requestUSBConnection = async (
74-
// Used for MakeCode hex downloads.
7573
options?: ConnectionAndFlashOptions
7674
): Promise<
7775
| {
@@ -121,10 +119,6 @@ export class ConnectActions {
121119
const data = Object.values(HexType).includes(hex as HexType)
122120
? getFlashDataSource(hex as HexType)
123121
: createUniversalHexFlashDataSource(hex);
124-
125-
if (!data) {
126-
return ConnectResult.ErrorMicrobitUnsupported;
127-
}
128122
try {
129123
await usb.flash(data, {
130124
partial: true,
@@ -137,36 +131,6 @@ export class ConnectActions {
137131
}
138132
};
139133

140-
requestUSBConnectionAndFlash = async (
141-
hex: string | HexType,
142-
progressCallback: (progress: number) => void
143-
): Promise<
144-
| {
145-
result: ConnectResult.Success;
146-
deviceId: number;
147-
boardVersion?: BoardVersion;
148-
}
149-
| {
150-
result: ConnectAndFlashFailResult;
151-
deviceId?: number;
152-
boardVersion?: BoardVersion;
153-
}
154-
> => {
155-
const { result, deviceId, usb } = await this.requestUSBConnection();
156-
if (result !== ConnectResult.Success) {
157-
return { result };
158-
}
159-
try {
160-
const result = await this.flashMicrobit(hex, progressCallback);
161-
return { result, deviceId, boardVersion: usb.getBoardVersion() };
162-
} catch (e) {
163-
this.logging.error(
164-
`USB request device failed/cancelled: ${JSON.stringify(e)}`
165-
);
166-
return { result: this.handleConnectAndFlashError(e) };
167-
}
168-
};
169-
170134
private handleConnectAndFlashError = (
171135
err: unknown
172136
): ConnectAndFlashFailResult => {

src/connection-stage-actions.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,27 @@ export class ConnectionStageActions {
6666
) => {
6767
this.setFlowStep(ConnectionFlowStep.WebUsbChooseMicrobit);
6868
const hex = this.getHexType();
69-
const { result, deviceId, boardVersion } =
70-
await this.actions.requestUSBConnectionAndFlash(hex, progressCallback);
71-
if (result !== ConnectResult.Success) {
72-
return this.handleConnectAndFlashFail(result);
73-
}
7469

70+
const {
71+
result: usbResult,
72+
usb,
73+
deviceId,
74+
} = await this.actions.requestUSBConnection();
75+
if (usbResult !== ConnectResult.Success) {
76+
return this.handleConnectAndFlashFail(usbResult);
77+
}
78+
const boardVersion = usb?.getBoardVersion();
79+
if (
80+
usbResult === ConnectResult.Success &&
81+
boardVersion === "V1" &&
82+
this.stage.flowType !== ConnectionFlowType.ConnectBluetooth
83+
) {
84+
return this.setFlowStep(ConnectionFlowStep.MicrobitUnsupported);
85+
}
86+
const flashResult = await this.actions.flashMicrobit(hex, progressCallback);
87+
if (flashResult !== ConnectResult.Success) {
88+
return this.handleConnectAndFlashFail(flashResult);
89+
}
7590
await this.onFlashSuccess(deviceId, onSuccess, boardVersion);
7691
};
7792

@@ -133,8 +148,6 @@ export class ConnectionStageActions {
133148
// TODO: Not sure if this is a good way of error handling because it means
134149
// there are 2 levels of switch statements to go through to provide UI
135150
switch (result) {
136-
case ConnectResult.ErrorMicrobitUnsupported:
137-
return this.setFlowStep(ConnectionFlowStep.MicrobitUnsupported);
138151
case ConnectResult.ErrorBadFirmware:
139152
return this.setFlowStep(ConnectionFlowStep.BadFirmware);
140153
case ConnectResult.ErrorNoDeviceSelected:

src/messages/ui.en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@
18241824
"unsupported-device-explain": [
18251825
{
18261826
"type": 0,
1827-
"value": "Unfortunately, we only support using micro:bit V2 when connecting two micro:bits. You have connected a "
1827+
"value": "Unfortunately, we only support using micro:bit V2 when connecting using micro:bit radio. You have connected a "
18281828
},
18291829
{
18301830
"children": [
@@ -1844,7 +1844,7 @@
18441844
"unsupported-device-header": [
18451845
{
18461846
"type": 0,
1847-
"value": "micro:bit V1 is not supported for connecting two micro:bits"
1847+
"value": "micro:bit radio connections do not support micro:bit V1"
18481848
}
18491849
],
18501850
"unsupported-device-with-bluetooth": [

0 commit comments

Comments
 (0)