As we were trying to track down a problem w/the gamepad HID interface (or more likely the Microsoft XAC's implementation) @dhalbert and I saw that the format strings for pack_into() were not taking into consideration whether the variable was signed. For example in gamepad.py you'll find:
The "<HBBBB" string says that it's expecting an unsigned 16-bit value followed by four unsigned bytes. However, we are sending signed bytes (-127 through 127) as defined in our descriptor.
In this case, circruitpython doesn't care because it would encode them the same way. However, CPython would error out after checking this and in general this is dangerous, because with types > 8 bit, we very much do care about endianness.
@dhalbert asked that I open an issue about this. The fix on gamepad.py is pretty simple, just change the string to "<Hbbbb", however, we should probably do a sanity check on this.
from @ATMakersBill (part of https://github.com/adafruit/circuitpython/issues/1451)
As we were trying to track down a problem w/the gamepad HID interface (or more likely the Microsoft XAC's implementation) @dhalbert and I saw that the format strings for pack_into() were not taking into consideration whether the variable was signed. For example in gamepad.py you'll find:
The "<HBBBB" string says that it's expecting an unsigned 16-bit value followed by four unsigned bytes. However, we are sending signed bytes (-127 through 127) as defined in our descriptor.
In this case, circruitpython doesn't care because it would encode them the same way. However, CPython would error out after checking this and in general this is dangerous, because with types > 8 bit, we very much do care about endianness.
@dhalbert asked that I open an issue about this. The fix on gamepad.py is pretty simple, just change the string to "<Hbbbb", however, we should probably do a sanity check on this.