ITPNYU / p5.ble.js

A Javascript library that enables communication between BLE devices and a p5 sketch using Web Bluetooth API. https://itpnyu.github.io/p5ble-website.
MIT License
41 stars 29 forks source link

float64 type doesn't work #4

Closed tigoe closed 4 years ago

tigoe commented 5 years ago

Calling for .read() or .startNotifications() using 'float64' as the data type causes a sketch to fail.

Sample:

myBLE.startNotifications(characteristic, myHandler, 'float64');

error:

crashes on line 40 of p5.ble.js

yining1023 commented 5 years ago

Thank you for filing the issue! I’ll look into it this week.

On Wed, Aug 14, 2019 at 9:37 AM Tom Igoe notifications@github.com wrote:

Calling for .read() or .startNotifications() using 'float64' as the data type causes a sketch to fail.

Sample:

myBLE.startNotifications(characteristic, myHandler, 'float64');

error:

crashes on line 40 of p5.ble.js

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ITPNYU/p5.ble.js/issues/4?email_source=notifications&email_token=ACCC2ZCVDT652IQWT66A6TDQEQC7XA5CNFSM4ILU7E22YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HFGU6EA, or mute the thread https://github.com/notifications/unsubscribe-auth/ACCC2ZDQHGOEZ6YO2372CJLQEQC7XANCNFSM4ILU7E2Q .

tigoe commented 4 years ago

Update: by adding the littleEndian flag on getFloat32(), the problem goes away. So I'd suggest adding in an option to use that flag for notifications, and the problem will be generally solvable.

tigoe commented 4 years ago

https://github.com/ITPNYU/physcomp/tree/master/Labs/LabIMUs/Nano33MadgwickBLE and https://github.com/ITPNYU/physcomp/tree/master/Labs/LabIMUs/MadgwickVisualizerBLE with a modified p5.ble.min.js show the example working. Use the non-modified p5.ble.min.js to see the issue.

yining1023 commented 4 years ago

Hi @tigoe, I published a new version of p5.ble.js 0.0.5 that fixes this issue.

Now it reads data in little-Endian by default, so the following code will be working:

myBLE.startNotifications(characteristic, myHandler, 'float64');

And if people would like to read data in big-endian format, they can pass float64-bigEndian or float32-bigEndian.

myBLE.startNotifications(characteristic, myHandler, 'float64-bigEndian');

myBLE.read works the same as myBLE.startNotifications. I added a note to the website.

Please let me know if it works for you. :)

tigoe commented 4 years ago

Works great, thanks @yining1023 I updated this example for both the Nano 33 IoT and BLE Sense as well, and it works pretty well.

yining1023 commented 4 years ago

Yay! Thank you for testing it! ❤️