diff --git a/BTHID.cpp b/BTHID.cpp index 5cd8701d..b1c3c1f4 100644 --- a/BTHID.cpp +++ b/BTHID.cpp @@ -24,7 +24,7 @@ BTHID::BTHID(BTD *p, bool pair, const char *pin) : pBtd(p), // pointer to USB class instance - mandatory protocolMode(HID_BOOT_PROTOCOL) { - for(uint8_t i = 0; i < epMUL; i++) + for (uint8_t i = 0; i < epMUL; i++) pRptParser[i] = NULL; if (pBtd) @@ -194,14 +194,14 @@ void BTHID::ACLData(uint8_t* l2capinbuf) { case 0x01: // Keyboard events if (pRptParser[KEYBOARD_PARSER_ID]) { uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); - pRptParser[KEYBOARD_PARSER_ID]->Parse((HID*)this, 0, (uint8_t) length, &l2capinbuf[10]); + pRptParser[KEYBOARD_PARSER_ID]->Parse(reinterpret_cast (this), 0, (uint8_t) length, &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance } break; case 0x02: // Mouse events if (pRptParser[MOUSE_PARSER_ID]) { uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); - pRptParser[MOUSE_PARSER_ID]->Parse((HID*)this, 0, (uint8_t) length, &l2capinbuf[10]); + pRptParser[MOUSE_PARSER_ID]->Parse(reinterpret_cast (this), 0, (uint8_t) length, &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance } break; case 0x03: diff --git a/examples/Bluetooth/BTHID/BTHID.ino b/examples/Bluetooth/BTHID/BTHID.ino index 444cc8d2..fecc4b50 100644 --- a/examples/Bluetooth/BTHID/BTHID.ino +++ b/examples/Bluetooth/BTHID/BTHID.ino @@ -21,7 +21,7 @@ BTHID hid(&Btd, PAIR, "0000"); // After that you can simply create the instance like so and then press any button on the device //BTHID hid(&Btd); -KbdRptParser keyboardPrs(&hid); +KbdRptParser keyboardPrs; MouseRptParser mousePrs; void setup() { diff --git a/examples/Bluetooth/BTHID/KeyboardParser.h b/examples/Bluetooth/BTHID/KeyboardParser.h index 0d8c081d..ed04b50e 100644 --- a/examples/Bluetooth/BTHID/KeyboardParser.h +++ b/examples/Bluetooth/BTHID/KeyboardParser.h @@ -2,11 +2,8 @@ #define __kbdrptparser_h_ class KbdRptParser : public KeyboardReportParser { - public: - KbdRptParser(BTHID *p) : pBTHID(p) {}; - protected: - virtual uint8_t HandleLockingKeys(HID* hid, uint8_t key); + virtual uint8_t HandleLockingKeys(HID *hid, uint8_t key); virtual void OnControlKeysChanged(uint8_t before, uint8_t after); virtual void OnKeyDown(uint8_t mod, uint8_t key); virtual void OnKeyUp(uint8_t mod, uint8_t key); @@ -14,10 +11,9 @@ class KbdRptParser : public KeyboardReportParser { private: void PrintKey(uint8_t mod, uint8_t key); - BTHID *pBTHID; }; -uint8_t KbdRptParser::HandleLockingKeys(HID* hid, uint8_t key) { +uint8_t KbdRptParser::HandleLockingKeys(HID *hid, uint8_t key) { uint8_t old_keys = kbdLockingKeys.bLeds; switch (key) { @@ -35,8 +31,10 @@ uint8_t KbdRptParser::HandleLockingKeys(HID* hid, uint8_t key) { break; } - if (old_keys != kbdLockingKeys.bLeds && pBTHID) - pBTHID->setLeds(kbdLockingKeys.bLeds); + if (old_keys != kbdLockingKeys.bLeds && hid) { + BTHID *pBTHID = reinterpret_cast (hid); // A cast the other way around is done in BTHID.cpp + pBTHID->setLeds(kbdLockingKeys.bLeds); // Update the LEDs on the keyboard + } return 0; }