mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Fixed "warning: comparison between signed and unsigned integer expressions"
Also return if length is too short
This commit is contained in:
parent
17feb495be
commit
a032e01465
2 changed files with 14 additions and 7 deletions
|
@ -62,7 +62,7 @@ uint8_t PS4Parser::getAnalogHat(AnalogHatEnum a) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PS4Parser::Parse(uint8_t len, uint8_t *buf) {
|
void PS4Parser::Parse(uint8_t len, uint8_t *buf) {
|
||||||
if (len > 0 && buf) {
|
if (len > 1 && buf) {
|
||||||
#ifdef PRINTREPORT
|
#ifdef PRINTREPORT
|
||||||
Notify(PSTR("\r\n"), 0x80);
|
Notify(PSTR("\r\n"), 0x80);
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
|
@ -72,10 +72,17 @@ void PS4Parser::Parse(uint8_t len, uint8_t *buf) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (buf[0] == 0x01) // Check report ID
|
if (buf[0] == 0x01) // Check report ID
|
||||||
memcpy(&ps4Data, buf + 1, min(len - 1, sizeof(ps4Data)));
|
memcpy(&ps4Data, buf + 1, min((uint8_t)(len - 1), sizeof(ps4Data)));
|
||||||
else if (buf[0] == 0x11) // This report is send via Bluetooth, it has an offset of 2 compared to the USB data
|
else if (buf[0] == 0x11) { // This report is send via Bluetooth, it has an offset of 2 compared to the USB data
|
||||||
memcpy(&ps4Data, buf + 3, min(len - 3, sizeof(ps4Data)));
|
if (len < 4) {
|
||||||
else {
|
#ifdef DEBUG_USB_HOST
|
||||||
|
Notify(PSTR("\r\nReport is too short: "), 0x80);
|
||||||
|
D_PrintHex<uint8_t > (len, 0x80);
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memcpy(&ps4Data, buf + 3, min((uint8_t)(len - 3), sizeof(ps4Data)));
|
||||||
|
} else {
|
||||||
#ifdef DEBUG_USB_HOST
|
#ifdef DEBUG_USB_HOST
|
||||||
Notify(PSTR("\r\nUnknown report id: "), 0x80);
|
Notify(PSTR("\r\nUnknown report id: "), 0x80);
|
||||||
D_PrintHex<uint8_t > (buf[0], 0x80);
|
D_PrintHex<uint8_t > (buf[0], 0x80);
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
//#define PRINTREPORT // Uncomment to print the report send by the PS Buzz Controllers
|
//#define PRINTREPORT // Uncomment to print the report send by the PS Buzz Controllers
|
||||||
|
|
||||||
void PSBuzz::ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
|
void PSBuzz::ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
|
||||||
if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID && len > 0 && buf) {
|
if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID && len > 2 && buf) {
|
||||||
#ifdef PRINTREPORT
|
#ifdef PRINTREPORT
|
||||||
Notify(PSTR("\r\n"), 0x80);
|
Notify(PSTR("\r\n"), 0x80);
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
|
@ -29,7 +29,7 @@ void PSBuzz::ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
|
||||||
Notify(PSTR(" "), 0x80);
|
Notify(PSTR(" "), 0x80);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
memcpy(&psbuzzButtons, buf + 2, min(len - 2, sizeof(psbuzzButtons)));
|
memcpy(&psbuzzButtons, buf + 2, min((uint8_t)(len - 2), sizeof(psbuzzButtons)));
|
||||||
|
|
||||||
if (psbuzzButtons.val != oldButtonState.val) { // Check if anything has changed
|
if (psbuzzButtons.val != oldButtonState.val) { // Check if anything has changed
|
||||||
buttonClickState.val = psbuzzButtons.val & ~oldButtonState.val; // Update click state variable
|
buttonClickState.val = psbuzzButtons.val & ~oldButtonState.val; // Update click state variable
|
||||||
|
|
Loading…
Reference in a new issue