Skip to content

Commit 81a785b

Browse files
Update microbit-connection library (#1207)
1 parent feb6ca2 commit 81a785b

File tree

10 files changed

+41
-25
lines changed

10 files changed

+41
-25
lines changed

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
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.33",
19+
"@microbit/microbit-connection": "^0.0.0-alpha.35",
2020
"@microbit/microbit-fs": "^0.10.0",
2121
"@sanity/block-content-to-react": "^3.0.0",
2222
"@sanity/image-url": "^1.0.1",

src/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import "./App.css";
1010
import { DialogProvider } from "./common/use-dialogs";
1111
import VisualViewPortCSSVariables from "./common/VisualViewportCSSVariables";
1212
import { deployment, useDeployment } from "./deployment";
13-
import { MicrobitWebUSBConnection } from "@microbit/microbit-connection";
13+
import { createWebUSBConnection } from "@microbit/microbit-connection";
1414
import { DeviceContextProvider } from "./device/device-hooks";
1515
import { MockDeviceConnection } from "./device/mock";
1616
import DocumentationProvider from "./documentation/documentation-hooks";
@@ -40,7 +40,7 @@ const isMockDeviceMode = () =>
4040
const logging = deployment.logging;
4141
const device = isMockDeviceMode()
4242
? new MockDeviceConnection()
43-
: new MicrobitWebUSBConnection({ logging });
43+
: createWebUSBConnection({ logging });
4444

4545
const host = createHost(logging);
4646
const fs = new FileSystem(logging, host, fetchMicroPython);

src/device/device-hooks.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import { useFileSystem } from "../fs/fs-hooks";
1515
import { useLogging } from "../logging/logging-hooks";
1616
import {
1717
ConnectionStatus,
18-
DeviceConnection,
18+
MicrobitWebUSBConnection,
1919
SerialDataEvent,
2020
ConnectionStatusEvent,
2121
} from "@microbit/microbit-connection";
2222
import { SimulatorDeviceConnection } from "./simulator";
2323

24-
const DeviceContext = React.createContext<undefined | DeviceConnection>(
24+
const DeviceContext = React.createContext<undefined | MicrobitWebUSBConnection>(
2525
undefined
2626
);
2727

@@ -234,7 +234,7 @@ export const DeviceContextProvider = ({
234234
value: device,
235235
children,
236236
}: {
237-
value: DeviceConnection;
237+
value: MicrobitWebUSBConnection;
238238
children: ReactNode;
239239
}) => {
240240
const syncStatusState = useState<SyncStatus>(SyncStatus.OUT_OF_SYNC);

src/device/mock.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import {
77
BoardVersion,
88
ConnectionStatus,
9-
DeviceConnection,
109
DeviceConnectionEventMap,
1110
FlashDataSource,
1211
FlashEvent,
@@ -15,6 +14,8 @@ import {
1514
DeviceError,
1615
DeviceErrorCode,
1716
TypedEventTarget,
17+
MicrobitWebUSBConnection,
18+
SerialConnectionEventMap,
1819
} from "@microbit/microbit-connection";
1920

2021
/**
@@ -25,8 +26,8 @@ import {
2526
* the connected state without a real device.
2627
*/
2728
export class MockDeviceConnection
28-
extends TypedEventTarget<DeviceConnectionEventMap>
29-
implements DeviceConnection
29+
extends TypedEventTarget<DeviceConnectionEventMap & SerialConnectionEventMap>
30+
implements MicrobitWebUSBConnection
3031
{
3132
status: ConnectionStatus = (navigator as any).usb
3233
? ConnectionStatus.NO_AUTHORIZED_DEVICE
@@ -51,6 +52,12 @@ export class MockDeviceConnection
5152
async initialize(): Promise<void> {}
5253

5354
dispose() {}
55+
getDeviceId(): number | undefined {
56+
return undefined;
57+
}
58+
setRequestDeviceExclusionFilters(): void {}
59+
getDevice() {}
60+
async softwareReset(): Promise<void> {}
5461

5562
async connect(): Promise<ConnectionStatus> {
5663
const next = this.connectResults.shift();

src/device/simulator.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import {
77
BoardVersion,
88
ConnectionStatus,
99
ConnectionStatusEvent,
10-
DeviceConnection,
1110
DeviceConnectionEventMap,
1211
FlashEvent,
12+
MicrobitWebUSBConnection,
13+
SerialConnectionEventMap,
1314
SerialDataEvent,
1415
SerialResetEvent,
1516
TypedEventTarget,
@@ -178,8 +179,8 @@ class SimulatorEventMap extends DeviceConnectionEventMap {
178179
* This communicates with the iframe that is used to embed the simulator.
179180
*/
180181
export class SimulatorDeviceConnection
181-
extends TypedEventTarget<SimulatorEventMap>
182-
implements DeviceConnection
182+
extends TypedEventTarget<SimulatorEventMap & SerialConnectionEventMap>
183+
implements MicrobitWebUSBConnection
183184
{
184185
status: ConnectionStatus = ConnectionStatus.NO_AUTHORIZED_DEVICE;
185186
state: SimulatorState | undefined;
@@ -425,4 +426,12 @@ export class SimulatorDeviceConnection
425426
"*"
426427
);
427428
}
429+
430+
getDeviceId(): number | undefined {
431+
return undefined;
432+
}
433+
setRequestDeviceExclusionFilters(): void {}
434+
async flash(): Promise<void> {}
435+
getDevice() {}
436+
async softwareReset(): Promise<void> {}
428437
}

src/editor/codemirror/language-server/diagnostics.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Text } from "@codemirror/state";
77
import * as LSP from "vscode-languageserver-protocol";
88
import { Action, Diagnostic } from "../lint/lint";
99
import { positionToOffset } from "./positions";
10-
import { DeviceConnection } from "@microbit/microbit-connection";
10+
import { MicrobitWebUSBConnection } from "@microbit/microbit-connection";
1111

1212
const reportMicrobitVersionApiUnsupported =
1313
"reportMicrobitVersionApiUnsupported";
@@ -22,7 +22,7 @@ const severityMapping = {
2222
export const diagnosticsMapping = (
2323
document: Text,
2424
lspDiagnostics: LSP.Diagnostic[],
25-
device: DeviceConnection,
25+
device: MicrobitWebUSBConnection,
2626
warnOnV2OnlyFeatures: boolean,
2727
warnOnV2OnlyFeaturesAction: () => Action
2828
): Diagnostic[] =>

src/editor/codemirror/language-server/view.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { autocompletion } from "./autocompletion";
1717
import { BaseLanguageServerView, clientFacet, uriFacet } from "./common";
1818
import { diagnosticsMapping } from "./diagnostics";
1919
import { signatureHelp } from "./signatureHelp";
20-
import { DeviceConnection } from "@microbit/microbit-connection";
20+
import { MicrobitWebUSBConnection } from "@microbit/microbit-connection";
2121

2222
/**
2323
* The main extension. This synchronises the diagnostics between the client
@@ -60,7 +60,7 @@ class LanguageServerView extends BaseLanguageServerView implements PluginValue {
6060

6161
constructor(
6262
view: EditorView,
63-
private device: DeviceConnection,
63+
private device: MicrobitWebUSBConnection,
6464
private intl: IntlShape,
6565
private warnOnV2OnlyFeatures: boolean,
6666
private disableV2OnlyFeaturesWarning: () => void
@@ -126,7 +126,7 @@ interface Actions {
126126
*/
127127
export function languageServer(
128128
client: LanguageServerClient,
129-
device: DeviceConnection,
129+
device: MicrobitWebUSBConnection,
130130
uri: string,
131131
intl: IntlShape,
132132
logging: Logging,

src/project/project-actions.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ActionFeedback } from "../common/use-action-feedback";
1919
import { Dialogs } from "../common/use-dialogs";
2020
import {
2121
ConnectionStatus,
22-
DeviceConnection,
22+
MicrobitWebUSBConnection,
2323
AfterRequestDevice,
2424
FlashDataError,
2525
DeviceError,
@@ -105,7 +105,7 @@ export enum ConnectionAction {
105105
export class ProjectActions {
106106
constructor(
107107
private fs: FileSystem,
108-
private device: DeviceConnection,
108+
private device: MicrobitWebUSBConnection,
109109
private actionFeedback: ActionFeedback,
110110
private dialogs: Dialogs,
111111
private setSelection: (selection: WorkbenchSelection) => void,

src/serial/serial-actions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* SPDX-License-Identifier: MIT
55
*/
6+
import { MicrobitWebUSBConnection } from "@microbit/microbit-connection";
67
import { Terminal } from "xterm";
7-
import { DeviceConnection } from "@microbit/microbit-connection";
88
import { Logging } from "../logging/logging";
99

1010
/**
@@ -13,7 +13,7 @@ import { Logging } from "../logging/logging";
1313
export class SerialActions {
1414
constructor(
1515
private terminal: React.RefObject<Terminal | undefined>,
16-
private device: DeviceConnection,
16+
private device: MicrobitWebUSBConnection,
1717
private onSerialSizeChange: (size: "compact" | "open") => void,
1818
private logging: Logging
1919
) {}

0 commit comments

Comments
 (0)