File tree 2 files changed +5
-9
lines changed
2 files changed +5
-9
lines changed Original file line number Diff line number Diff line change @@ -115,8 +115,8 @@ export class DeviceInformationService {
115
115
private async readStringCharacteristic ( uuid : BluetoothCharacteristicUUID ) : Promise < string | undefined > {
116
116
try {
117
117
const view = await this . helper . getCharacteristicValue ( uuid ) ;
118
- const buffer = view . buffer . slice ( view . byteOffset , view . byteOffset + view . byteLength ) ;
119
- return String . fromCharCode . apply ( null , Array . from ( new Uint8Array ( buffer ) ) ) ;
118
+ const decoder = new TextDecoder ( ) ;
119
+ return decoder . decode ( view . buffer ) ;
120
120
} catch ( _e ) {
121
121
return undefined ;
122
122
}
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ export class LedService {
73
73
74
74
/**
75
75
* Write text to the LED matrix
76
- * @param text Te text to display
76
+ * @param text The text to display
77
77
*/
78
78
public async writeText ( text : string ) : Promise < void > {
79
79
const encoded = this . encodeString ( text ) ;
@@ -116,12 +116,8 @@ export class LedService {
116
116
}
117
117
118
118
private encodeString ( text : string ) : ArrayBuffer {
119
- const buffer = new ArrayBuffer ( text . length ) ;
120
- const view = new Uint8Array ( buffer ) ;
121
- for ( let i = 0 ; i < text . length ; i ++ ) {
122
- view [ i ] = text . charCodeAt ( i ) ;
123
- }
124
- return buffer ;
119
+ const encoder = new TextEncoder ( ) ;
120
+ return encoder . encode ( text ) ;
125
121
}
126
122
127
123
private viewToLedMatrix ( view : DataView ) : LedMatrix {
You can’t perform that action at this time.
0 commit comments