Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert committed Jul 11, 2024
1 parent 8f330a0 commit 8e7b5a5
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
14 changes: 7 additions & 7 deletions lib/accelerometer-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export class AccelerometerService
constructor(
private accelerometerDataCharacteristic: BluetoothRemoteGATTCharacteristic,
// @ts-ignore temporarily unused characteristic
private accelerometerPeriodCharacteristic: BluetoothRemoteGATTCharacteristic
private accelerometerPeriodCharacteristic: BluetoothRemoteGATTCharacteristic,
) {
super();
this.accelerometerDataCharacteristic.addEventListener(
"characteristicvaluechanged",
this.dataListener
this.dataListener,
);
}

Expand All @@ -34,19 +34,19 @@ export class AccelerometerService
return this.accelerometerInstance;
}
const accelerometerService = await gattServer.getPrimaryService(
profile.accelerometer.id
profile.accelerometer.id,
);
const accelerometerDataCharacteristic =
await accelerometerService.getCharacteristic(
profile.accelerometer.characteristics.data.id
profile.accelerometer.characteristics.data.id,
);
const accelerometerPeriodCharacteristic =
await accelerometerService.getCharacteristic(
profile.accelerometer.characteristics.period.id
profile.accelerometer.characteristics.period.id,
);
this.accelerometerInstance = new AccelerometerService(
accelerometerDataCharacteristic,
accelerometerPeriodCharacteristic
accelerometerPeriodCharacteristic,
);
return this.accelerometerInstance;
}
Expand All @@ -70,7 +70,7 @@ export class AccelerometerService
const data = this.dataViewToData(target.value);
this.dispatchTypedEvent(
"accelerometerdatachanged",
new AccelerometerDataEvent(data)
new AccelerometerDataEvent(data),
);
};

Expand Down
32 changes: 16 additions & 16 deletions lib/bluetooth-device-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ export class BluetoothDeviceWrapper {

constructor(
public readonly device: BluetoothDevice,
private logging: Logging = new NullLogging()
private logging: Logging = new NullLogging(),
) {
device.addEventListener(
"gattserverdisconnected",
this.handleDisconnectEvent
this.handleDisconnectEvent,
);
}

Expand All @@ -65,7 +65,7 @@ export class BluetoothDeviceWrapper {
});
if (this.duringExplicitConnectDisconnect) {
this.logging.log(
"Skipping connect attempt when one is already in progress"
"Skipping connect attempt when one is already in progress",
);
// Wait for the gattConnectPromise while showing a "connecting" dialog.
// If the user clicks disconnect while the automatic reconnect is in progress,
Expand All @@ -76,7 +76,7 @@ export class BluetoothDeviceWrapper {
this.duringExplicitConnectDisconnect++;
if (this.device.gatt === undefined) {
throw new Error(
"BluetoothRemoteGATTServer for micro:bit device is undefined"
"BluetoothRemoteGATTServer for micro:bit device is undefined",
);
}
try {
Expand All @@ -95,15 +95,15 @@ export class BluetoothDeviceWrapper {
// Do we still want to be connected?
if (!this.connecting) {
this.logging.log(
"Bluetooth GATT server connect after timeout, triggering disconnect"
"Bluetooth GATT server connect after timeout, triggering disconnect",
);
this.disconnectPromise = (async () => {
await this.disconnectInternal(false);
this.disconnectPromise = undefined;
})();
} else {
this.logging.log(
"Bluetooth GATT server connected when connecting"
"Bluetooth GATT server connected when connecting",
);
}
})
Expand All @@ -114,7 +114,7 @@ export class BluetoothDeviceWrapper {
} else {
this.logging.error(
"Bluetooth GATT server connect error after our timeout",
e
e,
);
return undefined;
}
Expand All @@ -129,7 +129,7 @@ export class BluetoothDeviceWrapper {
const gattConnectResult = await Promise.race([
this.gattConnectPromise,
new Promise<"timeout">((resolve) =>
setTimeout(() => resolve("timeout"), connectTimeoutDuration)
setTimeout(() => resolve("timeout"), connectTimeoutDuration),
),
]);
if (gattConnectResult === "timeout") {
Expand Down Expand Up @@ -163,7 +163,7 @@ export class BluetoothDeviceWrapper {

private async disconnectInternal(userTriggered: boolean): Promise<void> {
this.logging.log(
`Bluetooth disconnect ${userTriggered ? "(user triggered)" : "(programmatic)"}`
`Bluetooth disconnect ${userTriggered ? "(user triggered)" : "(programmatic)"}`,
);
this.duringExplicitConnectDisconnect++;
try {
Expand All @@ -177,7 +177,7 @@ export class BluetoothDeviceWrapper {
this.duringExplicitConnectDisconnect--;
}
this.reconnectReadyPromise = new Promise((resolve) =>
setTimeout(resolve, 3_500)
setTimeout(resolve, 3_500),
);
}

Expand All @@ -200,19 +200,19 @@ export class BluetoothDeviceWrapper {
try {
if (!this.duringExplicitConnectDisconnect) {
this.logging.log(
"Bluetooth GATT disconnected... automatically trying reconnect"
"Bluetooth GATT disconnected... automatically trying reconnect",
);
// stateOnReconnectionAttempt();
await this.reconnect();
} else {
this.logging.log(
"Bluetooth GATT disconnect ignored during explicit disconnect"
"Bluetooth GATT disconnect ignored during explicit disconnect",
);
}
} catch (e) {
this.logging.error(
"Bluetooth connect triggered by disconnect listener failed",
e
e,
);
}
};
Expand All @@ -229,10 +229,10 @@ export class BluetoothDeviceWrapper {
const serviceMeta = profile.deviceInformation;
try {
const deviceInfo = await this.assertGattServer().getPrimaryService(
serviceMeta.id
serviceMeta.id,
);
const characteristic = await deviceInfo.getCharacteristic(
serviceMeta.characteristics.modelNumber.id
serviceMeta.characteristics.modelNumber.id,
);
const modelNumberBytes = await characteristic.readValue();
const modelNumber = new TextDecoder().decode(modelNumberBytes);
Expand Down Expand Up @@ -260,7 +260,7 @@ export class BluetoothDeviceWrapper {

export const createBluetoothDeviceWrapper = async (
device: BluetoothDevice,
logging: Logging
logging: Logging,
): Promise<BluetoothDeviceWrapper | undefined> => {
try {
// Reuse our connection objects for the same device as they
Expand Down
8 changes: 4 additions & 4 deletions lib/bluetooth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class MicrobitWebBluetoothConnection
* A progress callback. Called with undefined when the process is complete or has failed.
*/
progress: (percentage: number | undefined) => void;
}
},
): Promise<void> {
throw new Error("Unsupported");
}
Expand Down Expand Up @@ -168,7 +168,7 @@ export class MicrobitWebBluetoothConnection
}
this.connection = await createBluetoothDeviceWrapper(
device,
this.logging
this.logging,
);
}
// TODO: timeout unification?
Expand All @@ -177,7 +177,7 @@ export class MicrobitWebBluetoothConnection
}

private async chooseDevice(
options: ConnectOptions
options: ConnectOptions,
): Promise<BluetoothDevice | undefined> {
if (this.device) {
return this.device;
Expand Down Expand Up @@ -209,7 +209,7 @@ export class MicrobitWebBluetoothConnection
],
}),
new Promise<"timeout">((resolve) =>
setTimeout(() => resolve("timeout"), requestDeviceTimeoutDuration)
setTimeout(() => resolve("timeout"), requestDeviceTimeoutDuration),
),
]);
if (result === "timeout") {
Expand Down
2 changes: 1 addition & 1 deletion lib/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export interface DeviceConnection
* The partial parameter reports the flash type currently in progress.
*/
progress: (percentage: number | undefined, partial: boolean) => void;
}
},
): Promise<void>;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class MockDeviceConnection
* A progress callback. Called with undefined when the process is complete or has failed.
*/
progress: (percentage: number | undefined) => void;
}
},
): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, 100));
options.progress(0.5);
Expand Down
16 changes: 8 additions & 8 deletions lib/webusb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ export class MicrobitWebUSBConnection
}
}, assumePageIsStayingOpenDelay);
},
{ once: true }
{ once: true },
);
};

private logging: Logging;

constructor(
options: MicrobitWebUSBConnectionOptions = { logging: new NullLogging() }
options: MicrobitWebUSBConnectionOptions = { logging: new NullLogging() },
) {
super();
this.logging = options.logging;
Expand All @@ -151,7 +151,7 @@ export class MicrobitWebUSBConnection
if (window.document) {
window.document.addEventListener(
"visibilitychange",
this.visibilityChangeListener
this.visibilityChangeListener,
);
}
}
Expand All @@ -166,7 +166,7 @@ export class MicrobitWebUSBConnection
if (window.document) {
window.document.removeEventListener(
"visibilitychange",
this.visibilityChangeListener
this.visibilityChangeListener,
);
}
}
Expand Down Expand Up @@ -194,13 +194,13 @@ export class MicrobitWebUSBConnection
* A progress callback. Called with undefined when the process is complete or has failed.
*/
progress: (percentage: number | undefined) => void;
}
},
): Promise<void> {
this.flashing = true;
try {
const startTime = new Date().getTime();
await this.withEnrichedErrors(() =>
this.flashInternal(dataSource, options)
this.flashInternal(dataSource, options),
);
this.dispatchTypedEvent("flash", new FlashEvent());

Expand All @@ -222,7 +222,7 @@ export class MicrobitWebUSBConnection
options: {
partial: boolean;
progress: (percentage: number | undefined, partial: boolean) => void;
}
},
): Promise<void> {
this.log("Stopping serial before flash");
await this.stopSerialInternal();
Expand Down Expand Up @@ -334,7 +334,7 @@ export class MicrobitWebUSBConnection
// Log error to console for feedback
this.log("An error occurred whilst attempting to use WebUSB.");
this.log(
"Details of the error can be found below, and may be useful when trying to replicate and debug the error."
"Details of the error can be found below, and may be useful when trying to replicate and debug the error.",
);
this.log(e);

Expand Down
10 changes: 5 additions & 5 deletions src/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
`;

const transport = document.querySelector(
"#flash > .transport"
"#flash > .transport",
)! as HTMLSelectElement;
const connect = document.querySelector("#flash > .connect")!;
const disconnect = document.querySelector("#flash > .disconnect")!;
const flash = document.querySelector("#flash > .flash")!;
const fileInput = document.querySelector(
"#flash input[type=file]"
"#flash input[type=file]",
)! as HTMLInputElement;
const statusParagraph = document.querySelector("#flash > .status")!;
const accDataGet = document.querySelector(
"#flash > .acc-controls > .acc-data-get"
"#flash > .acc-controls > .acc-data-get",
)!;
const accDataListen = document.querySelector(
"#flash > .acc-controls > .acc-data-listen"
"#flash > .acc-controls > .acc-data-listen",
)!;
const accDataStop = document.querySelector(
"#flash > .acc-controls > .acc-data-stop"
"#flash > .acc-controls > .acc-data-stop",
)!;

let connection: DeviceConnection = new MicrobitWebUSBConnection();
Expand Down

0 comments on commit 8e7b5a5

Please sign in to comment.