Skip to content

Commit

Permalink
feat: Add WriteString function to bluetooth device interface
Browse files Browse the repository at this point in the history
Simplifies string formatting based on platform.
  • Loading branch information
qdot committed Jun 24, 2018
1 parent c54256f commit e5f6cf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/server/bluetooth/IBluetoothDeviceImpl.ts
Expand Up @@ -2,6 +2,7 @@ export interface IBluetoothDeviceImpl {
Name: string;
Id: string;
WriteValue: (aCharacteristic: string, aValue: Uint8Array) => Promise<void>;
WriteString: (aCharacteristic: string, aValue: string) => Promise<void>;
ReadValue: (aCharacteristic: string) => Promise<BufferSource>;
Disconnect: () => Promise<void>;
}
6 changes: 5 additions & 1 deletion src/server/bluetooth/WebBluetoothDevice.ts
Expand Up @@ -91,9 +91,13 @@ export class WebBluetoothDevice extends EventEmitter implements IBluetoothDevice
this.emit("deviceremoved");
}

public WriteString = async (aCharacteristic: string, aValue: string): Promise<void> => {
return await this.WriteValue(aCharacteristic, Buffer.from(aValue));
}

public WriteValue = async (aCharacteristic: string, aValue: Uint8Array): Promise<void> => {
if (!this._characteristics.has(aCharacteristic)) {
return;
throw new Error("Tried to access wrong characteristic!");
}
const chr = this._characteristics.get(aCharacteristic)!;
this._logger.Trace(`WebBluetoothDevice: ${this.constructor.name} writing ${aValue} to ${chr.uuid}`);
Expand Down

0 comments on commit e5f6cf4

Please sign in to comment.