adafruit / Bluefruit_LE_Connect_Android

Android port of Adafruit's Bluefruit LE Connect app
MIT License
122 stars 100 forks source link

'Controller' mode data is incorrect #13

Closed microbuilder closed 9 years ago

microbuilder commented 9 years ago

Color data should be in the following format (rather than the four byte float as previously documented):

0x21 0x43 uint8_tR uint8_tG uint8_tB CRC8

All of the other values should also end with a CRC8 checksum byte ... they don't have this at present.

As an example of what iOS sends: "!C", which works out to: 0x21 '!', 0x43 'C', 0x4e (78), 0x37 (55), 0xff (255), 0x17 (checksum) for the color red = 78, green=55, blue=255

microbuilder commented 9 years ago

Color data was fixed here but the CRC byte is still missing

microbuilder commented 9 years ago

The checksum byte was added (and verified to match iOS output) here: https://github.com/adafruit/Bluefruit_LE_Connect_Android/commit/f5a32b515de45b51d94e03ea39970e414796834a

This is a bit of a hack, though, and the checksum logic should actually be moved one level higher to ControllerActivity since every Controller payload will require this one byte checksum using the same algorithm (add all bytes and then invert).

The bytesToHex code can possibly be replaced with http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/DatatypeConverter.html#printHexBinary(byte), though the formatting should be updates the match the string below to make is easier to read:

0xAA 0xBB 0xCC 0xDD ...

instead of:

AABBCCDD ...