]> git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/HID/le3dp/le3dp_rptparser.cpp
core: Fix Logical Maximum in report descriptor
[tmk_keyboard.git] / tmk_core / protocol / usb_hid / USB_Host_Shield_2.0 / examples / HID / le3dp / le3dp_rptparser.cpp
1 #include "le3dp_rptparser.h"
2
3 JoystickReportParser::JoystickReportParser(JoystickEvents *evt) :
4 joyEvents(evt)
5 {}
6
7 void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
8 {
9 bool match = true;
10
11 // Checking if there are changes in report since the method was last called
12 for (uint8_t i=0; i<RPT_GAMEPAD_LEN; i++) {
13 if( buf[i] != oldPad[i] ) {
14 match = false;
15 break;
16 }
17 }
18 // Calling Game Pad event handler
19 if (!match && joyEvents) {
20 joyEvents->OnGamePadChanged((const GamePadEventData*)buf);
21
22 for (uint8_t i=0; i<RPT_GAMEPAD_LEN; i++) oldPad[i] = buf[i];
23 }
24 }
25
26 void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
27 {
28 Serial.print("X: ");
29 PrintHex<uint16_t>(evt->x, 0x80);
30 Serial.print(" Y: ");
31 PrintHex<uint16_t>(evt->y, 0x80);
32 Serial.print(" Hat Switch: ");
33 PrintHex<uint8_t>(evt->hat, 0x80);
34 Serial.print(" Twist: ");
35 PrintHex<uint8_t>(evt->twist, 0x80);
36 Serial.print(" Slider: ");
37 PrintHex<uint8_t>(evt->slider, 0x80);
38 Serial.print(" Buttons A: ");
39 PrintHex<uint8_t>(evt->buttons_a, 0x80);
40 Serial.print(" Buttons B: ");
41 PrintHex<uint8_t>(evt->buttons_b, 0x80);
42 Serial.println("");
43 }
Imprint / Impressum