Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update microbit-connection library #1207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.33",
"@microbit/microbit-connection": "^0.0.0-alpha.35",
"@microbit/microbit-fs": "^0.10.0",
"@sanity/block-content-to-react": "^3.0.0",
"@sanity/image-url": "^1.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "./App.css";
import { DialogProvider } from "./common/use-dialogs";
import VisualViewPortCSSVariables from "./common/VisualViewportCSSVariables";
import { deployment, useDeployment } from "./deployment";
import { MicrobitWebUSBConnection } from "@microbit/microbit-connection";
import { createWebUSBConnection } from "@microbit/microbit-connection";
import { DeviceContextProvider } from "./device/device-hooks";
import { MockDeviceConnection } from "./device/mock";
import DocumentationProvider from "./documentation/documentation-hooks";
Expand Down Expand Up @@ -40,7 +40,7 @@ const isMockDeviceMode = () =>
const logging = deployment.logging;
const device = isMockDeviceMode()
? new MockDeviceConnection()
: new MicrobitWebUSBConnection({ logging });
: createWebUSBConnection({ logging });

const host = createHost(logging);
const fs = new FileSystem(logging, host, fetchMicroPython);
Expand Down
6 changes: 3 additions & 3 deletions src/device/device-hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { useFileSystem } from "../fs/fs-hooks";
import { useLogging } from "../logging/logging-hooks";
import {
ConnectionStatus,
DeviceConnection,
MicrobitWebUSBConnection,
SerialDataEvent,
ConnectionStatusEvent,
} from "@microbit/microbit-connection";
import { SimulatorDeviceConnection } from "./simulator";

const DeviceContext = React.createContext<undefined | DeviceConnection>(
const DeviceContext = React.createContext<undefined | MicrobitWebUSBConnection>(
undefined
);

Expand Down Expand Up @@ -234,7 +234,7 @@ export const DeviceContextProvider = ({
value: device,
children,
}: {
value: DeviceConnection;
value: MicrobitWebUSBConnection;
children: ReactNode;
}) => {
const syncStatusState = useState<SyncStatus>(SyncStatus.OUT_OF_SYNC);
Expand Down
13 changes: 10 additions & 3 deletions src/device/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import {
BoardVersion,
ConnectionStatus,
DeviceConnection,
DeviceConnectionEventMap,
FlashDataSource,
FlashEvent,
Expand All @@ -15,6 +14,8 @@ import {
DeviceError,
DeviceErrorCode,
TypedEventTarget,
MicrobitWebUSBConnection,
SerialConnectionEventMap,
} from "@microbit/microbit-connection";

/**
Expand All @@ -25,8 +26,8 @@ import {
* the connected state without a real device.
*/
export class MockDeviceConnection
extends TypedEventTarget<DeviceConnectionEventMap>
implements DeviceConnection
extends TypedEventTarget<DeviceConnectionEventMap & SerialConnectionEventMap>
implements MicrobitWebUSBConnection
{
status: ConnectionStatus = (navigator as any).usb
? ConnectionStatus.NO_AUTHORIZED_DEVICE
Expand All @@ -51,6 +52,12 @@ export class MockDeviceConnection
async initialize(): Promise<void> {}

dispose() {}
getDeviceId(): number | undefined {
return undefined;
}
setRequestDeviceExclusionFilters(): void {}
getDevice() {}
async softwareReset(): Promise<void> {}

async connect(): Promise<ConnectionStatus> {
const next = this.connectResults.shift();
Expand Down
15 changes: 12 additions & 3 deletions src/device/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
BoardVersion,
ConnectionStatus,
ConnectionStatusEvent,
DeviceConnection,
DeviceConnectionEventMap,
FlashEvent,
MicrobitWebUSBConnection,
SerialConnectionEventMap,
SerialDataEvent,
SerialResetEvent,
TypedEventTarget,
Expand Down Expand Up @@ -178,8 +179,8 @@ class SimulatorEventMap extends DeviceConnectionEventMap {
* This communicates with the iframe that is used to embed the simulator.
*/
export class SimulatorDeviceConnection
extends TypedEventTarget<SimulatorEventMap>
implements DeviceConnection
extends TypedEventTarget<SimulatorEventMap & SerialConnectionEventMap>
implements MicrobitWebUSBConnection
{
status: ConnectionStatus = ConnectionStatus.NO_AUTHORIZED_DEVICE;
state: SimulatorState | undefined;
Expand Down Expand Up @@ -425,4 +426,12 @@ export class SimulatorDeviceConnection
"*"
);
}

getDeviceId(): number | undefined {
return undefined;
}
setRequestDeviceExclusionFilters(): void {}
async flash(): Promise<void> {}
getDevice() {}
async softwareReset(): Promise<void> {}
}
4 changes: 2 additions & 2 deletions src/editor/codemirror/language-server/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Text } from "@codemirror/state";
import * as LSP from "vscode-languageserver-protocol";
import { Action, Diagnostic } from "../lint/lint";
import { positionToOffset } from "./positions";
import { DeviceConnection } from "@microbit/microbit-connection";
import { MicrobitWebUSBConnection } from "@microbit/microbit-connection";

const reportMicrobitVersionApiUnsupported =
"reportMicrobitVersionApiUnsupported";
Expand All @@ -22,7 +22,7 @@ const severityMapping = {
export const diagnosticsMapping = (
document: Text,
lspDiagnostics: LSP.Diagnostic[],
device: DeviceConnection,
device: MicrobitWebUSBConnection,
warnOnV2OnlyFeatures: boolean,
warnOnV2OnlyFeaturesAction: () => Action
): Diagnostic[] =>
Expand Down
6 changes: 3 additions & 3 deletions src/editor/codemirror/language-server/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { autocompletion } from "./autocompletion";
import { BaseLanguageServerView, clientFacet, uriFacet } from "./common";
import { diagnosticsMapping } from "./diagnostics";
import { signatureHelp } from "./signatureHelp";
import { DeviceConnection } from "@microbit/microbit-connection";
import { MicrobitWebUSBConnection } from "@microbit/microbit-connection";

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

constructor(
view: EditorView,
private device: DeviceConnection,
private device: MicrobitWebUSBConnection,
private intl: IntlShape,
private warnOnV2OnlyFeatures: boolean,
private disableV2OnlyFeaturesWarning: () => void
Expand Down Expand Up @@ -126,7 +126,7 @@ interface Actions {
*/
export function languageServer(
client: LanguageServerClient,
device: DeviceConnection,
device: MicrobitWebUSBConnection,
uri: string,
intl: IntlShape,
logging: Logging,
Expand Down
4 changes: 2 additions & 2 deletions src/project/project-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ActionFeedback } from "../common/use-action-feedback";
import { Dialogs } from "../common/use-dialogs";
import {
ConnectionStatus,
DeviceConnection,
MicrobitWebUSBConnection,
AfterRequestDevice,
FlashDataError,
DeviceError,
Expand Down Expand Up @@ -105,7 +105,7 @@ export enum ConnectionAction {
export class ProjectActions {
constructor(
private fs: FileSystem,
private device: DeviceConnection,
private device: MicrobitWebUSBConnection,
private actionFeedback: ActionFeedback,
private dialogs: Dialogs,
private setSelection: (selection: WorkbenchSelection) => void,
Expand Down
4 changes: 2 additions & 2 deletions src/serial/serial-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*
* SPDX-License-Identifier: MIT
*/
import { MicrobitWebUSBConnection } from "@microbit/microbit-connection";
import { Terminal } from "xterm";
import { DeviceConnection } from "@microbit/microbit-connection";
import { Logging } from "../logging/logging";

/**
Expand All @@ -13,7 +13,7 @@ import { Logging } from "../logging/logging";
export class SerialActions {
constructor(
private terminal: React.RefObject<Terminal | undefined>,
private device: DeviceConnection,
private device: MicrobitWebUSBConnection,
private onSerialSizeChange: (size: "compact" | "open") => void,
private logging: Logging
) {}
Expand Down
Loading