-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Helper functions to read values #126
Comments
I think these features should be prototyped in a helper library before we put them in the spec, so they have a chance to evolve faster than they would in Blink. Shall we start a sibling repository to hold that helper library? |
Eventually we should, for now let's focus on the spec and implementation. |
I'd be happy to start this helper library. |
@g-ortuno @jyasskin Before going further, is it what you were thinking of? |
Yes, that's great. I think I'd make 2 changes: I'd either default the |
Will do that tomorrow then. Thanks for the feedback. On Thu, Jan 7, 2016, 7:15 PM Jeffrey Yasskin notifications@github.com
|
I've changed default Regarding the default/removal of |
Here's what it would look like: https://github.com/beaufortfrancois/sandbox/blob/gh-pages/web-bluetooth/utils/utils.js It will work when https://code.google.com/p/chromium/issues/detail?id=575577 is fixed |
I wonder how useful these function will be when characteristic returns a On Fri, Jan 8, 2016 at 1:48 AM François Beaufort notifications@github.com
|
Hopefully it won't be needed anymore. |
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? 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);
}; |
I'd be happy to have this as a simple npm module, but I'd like to wait to change the spec until we see it being widely used. I'll close this issue in this repository, but we can reopen later if it turns out people want this. |
In Android we have helper functions to more easily read and write values to and from characteristics:
[getFloatValue()](https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html#getFloatValue%28int, int%29)
[getIntValue()](https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html#getIntValue%28int, int%29)
getStringValue()
They are really useful since developers don't have to worry about bytes if all they are doing is reading/writing integers. Could we add similar helper functions?
The text was updated successfully, but these errors were encountered: