mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Use reinterpret_cast to cast from BTHID to HID class, so it can be used in the parser
This commit is contained in:
parent
5f49b321cb
commit
a31cc42585
3 changed files with 10 additions and 12 deletions
|
@ -194,14 +194,14 @@ void BTHID::ACLData(uint8_t* l2capinbuf) {
|
||||||
case 0x01: // Keyboard events
|
case 0x01: // Keyboard events
|
||||||
if (pRptParser[KEYBOARD_PARSER_ID]) {
|
if (pRptParser[KEYBOARD_PARSER_ID]) {
|
||||||
uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]);
|
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<HID *> (this), 0, (uint8_t) length, &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x02: // Mouse events
|
case 0x02: // Mouse events
|
||||||
if (pRptParser[MOUSE_PARSER_ID]) {
|
if (pRptParser[MOUSE_PARSER_ID]) {
|
||||||
uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]);
|
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<HID *> (this), 0, (uint8_t) length, &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x03:
|
case 0x03:
|
||||||
|
|
|
@ -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
|
// After that you can simply create the instance like so and then press any button on the device
|
||||||
//BTHID hid(&Btd);
|
//BTHID hid(&Btd);
|
||||||
|
|
||||||
KbdRptParser keyboardPrs(&hid);
|
KbdRptParser keyboardPrs;
|
||||||
MouseRptParser mousePrs;
|
MouseRptParser mousePrs;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
#define __kbdrptparser_h_
|
#define __kbdrptparser_h_
|
||||||
|
|
||||||
class KbdRptParser : public KeyboardReportParser {
|
class KbdRptParser : public KeyboardReportParser {
|
||||||
public:
|
|
||||||
KbdRptParser(BTHID *p) : pBTHID(p) {};
|
|
||||||
|
|
||||||
protected:
|
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 OnControlKeysChanged(uint8_t before, uint8_t after);
|
||||||
|
@ -14,7 +11,6 @@ class KbdRptParser : public KeyboardReportParser {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void PrintKey(uint8_t mod, uint8_t key);
|
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) {
|
||||||
|
@ -35,8 +31,10 @@ uint8_t KbdRptParser::HandleLockingKeys(HID* hid, uint8_t key) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (old_keys != kbdLockingKeys.bLeds && pBTHID)
|
if (old_keys != kbdLockingKeys.bLeds && hid) {
|
||||||
pBTHID->setLeds(kbdLockingKeys.bLeds);
|
BTHID *pBTHID = reinterpret_cast<BTHID *> (hid); // A cast the other way around is done in BTHID.cpp
|
||||||
|
pBTHID->setLeds(kbdLockingKeys.bLeds); // Update the LEDs on the keyboard
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue