W3C home > Mailing lists > Public > public-web-bluetooth-log@w3.org > January 2016

Re: [web-bluetooth] Helper functions to read values

From: François Beaufort via GitHub <sysbot+gh@w3.org>
Date: Thu, 21 Jan 2016 14:49:54 +0000
To: public-web-bluetooth-log@w3.org
Message-ID: <issue_comment.created-173593614-1453387793-sysbot+gh@w3.org>
Here's what it looks like at 
https://github.com/beaufortfrancois/sandbox/blob/gh-pages/web-bluetooth/utils/utils.js
 below. What do you think?

```js
BluetoothGATTCharacteristic.prototype.getFloat32Value = 
function(byteOffset, littleEndian = true) {
  return this.value.getFloat32(byteOffset, littleEndian);
};

BluetoothGATTCharacteristic.prototype.getFloat64Value = 
function(byteOffset, littleEndian = true) {
  return this.value.getFloat64(byteOffset, littleEndian);
};

BluetoothGATTCharacteristic.prototype.getInt16Value = 
function(byteOffset, littleEndian = true) {
  return this.value.getInt16(byteOffset, littleEndian);
};

BluetoothGATTCharacteristic.prototype.getInt32Value = 
function(byteOffset, littleEndian = true) {
  return this.value.getInt32(byteOffset, littleEndian);
};

BluetoothGATTCharacteristic.prototype.getInt8Value = 
function(byteOffset) {
  return this.value.getInt8(byteOffset);
};

BluetoothGATTCharacteristic.prototype.getStringValue = 
function(utfLabel = 'utf8') {
  var decoder = new TextDecoder(utfLabel);
  return decoder.decode(this.value);
};

BluetoothGATTCharacteristic.prototype.getUint16Value = 
function(byteOffset, littleEndian = true) {
  return this.value.getUint16(byteOffset, littleEndian);
};

BluetoothGATTCharacteristic.prototype.getUint32Value = 
function(byteOffset, littleEndian = true) {
  return this.value.getUint32(byteOffset, littleEndian);
};

BluetoothGATTCharacteristic.prototype.getUint8Value = 
function(byteOffset) {
  return this.value.getUint8(byteOffset);
};
```

-- 
GitHub Notification of comment by beaufortfrancois
Please view or discuss this issue at 
https://github.com/WebBluetoothCG/web-bluetooth/issues/126#issuecomment-173593614
 using your GitHub account
Received on Thursday, 21 January 2016 14:49:55 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 21 January 2016 14:49:56 UTC