diff --git a/src/services/device-information.ts b/src/services/device-information.ts index 8b138a1..ec0c3bb 100644 --- a/src/services/device-information.ts +++ b/src/services/device-information.ts @@ -115,8 +115,8 @@ export class DeviceInformationService { private async readStringCharacteristic(uuid: BluetoothCharacteristicUUID): Promise { try { const view = await this.helper.getCharacteristicValue(uuid); - const buffer = view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength); - return String.fromCharCode.apply(null, Array.from(new Uint8Array(buffer))); + const decoder = new TextDecoder(); + return decoder.decode(view.buffer); } catch (_e) { return undefined; } diff --git a/src/services/led.ts b/src/services/led.ts index cc93706..d7d3909 100644 --- a/src/services/led.ts +++ b/src/services/led.ts @@ -73,7 +73,7 @@ export class LedService { /** * Write text to the LED matrix - * @param text Te text to display + * @param text The text to display */ public async writeText(text: string): Promise { const encoded = this.encodeString(text); @@ -116,12 +116,8 @@ export class LedService { } private encodeString(text: string): ArrayBuffer { - const buffer = new ArrayBuffer(text.length); - const view = new Uint8Array(buffer); - for (let i = 0; i < text.length; i++) { - view[i] = text.charCodeAt(i); - } - return buffer; + const encoder = new TextEncoder(); + return encoder.encode(text); } private viewToLedMatrix(view: DataView): LedMatrix {