mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Can now set the LEDs on a keyboard
This commit is contained in:
parent
45465fa928
commit
4099314100
4 changed files with 43 additions and 3 deletions
|
@ -380,4 +380,12 @@ void BTHID::Run() {
|
|||
void BTHID::setProtocol() {
|
||||
uint8_t command = 0x70 | protocolMode; // Set Protocol, see HID specs page 33
|
||||
pBtd->L2CAP_Command(hci_handle, &command, 1, control_scid[0], control_scid[1]);
|
||||
}
|
||||
|
||||
void BTHID::setLeds(uint8_t data) {
|
||||
uint8_t buf[3];
|
||||
buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
|
||||
buf[1] = 0x01; // Report ID
|
||||
buf[2] = data;
|
||||
pBtd->L2CAP_Command(hci_handle, buf, 3, interrupt_scid[0], interrupt_scid[1]);
|
||||
}
|
3
BTHID.h
3
BTHID.h
|
@ -102,6 +102,9 @@ public:
|
|||
protocolMode = mode;
|
||||
};
|
||||
|
||||
/** Used to set the leds on a keyboard */
|
||||
void setLeds(uint8_t data);
|
||||
|
||||
/** True if a device is connected */
|
||||
bool connected;
|
||||
|
||||
|
|
|
@ -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;
|
||||
KbdRptParser keyboardPrs(&hid);
|
||||
MouseRptParser mousePrs;
|
||||
|
||||
void setup() {
|
||||
|
|
|
@ -2,16 +2,45 @@
|
|||
#define __kbdrptparser_h_
|
||||
|
||||
class KbdRptParser : public KeyboardReportParser {
|
||||
private:
|
||||
void PrintKey(uint8_t mod, uint8_t key);
|
||||
public:
|
||||
KbdRptParser(BTHID *p) : pBTHID(p) {};
|
||||
|
||||
protected:
|
||||
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);
|
||||
virtual void OnKeyPressed(uint8_t key);
|
||||
|
||||
private:
|
||||
void PrintKey(uint8_t mod, uint8_t key);
|
||||
BTHID *pBTHID;
|
||||
};
|
||||
|
||||
uint8_t KbdRptParser::HandleLockingKeys(HID* hid, uint8_t key) {
|
||||
uint8_t old_keys = kbdLockingKeys.bLeds;
|
||||
|
||||
switch (key) {
|
||||
case KEY_NUM_LOCK:
|
||||
Serial.println(F("Num lock"));
|
||||
kbdLockingKeys.kbdLeds.bmNumLock = ~kbdLockingKeys.kbdLeds.bmNumLock;
|
||||
break;
|
||||
case KEY_CAPS_LOCK:
|
||||
Serial.println(F("Caps lock"));
|
||||
kbdLockingKeys.kbdLeds.bmCapsLock = ~kbdLockingKeys.kbdLeds.bmCapsLock;
|
||||
break;
|
||||
case KEY_SCROLL_LOCK:
|
||||
Serial.println(F("Scroll lock"));
|
||||
kbdLockingKeys.kbdLeds.bmScrollLock = ~kbdLockingKeys.kbdLeds.bmScrollLock;
|
||||
break;
|
||||
}
|
||||
|
||||
if (old_keys != kbdLockingKeys.bLeds && pBTHID)
|
||||
pBTHID->setLeds(kbdLockingKeys.bLeds);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void KbdRptParser::PrintKey(uint8_t m, uint8_t key) {
|
||||
MODIFIERKEYS mod;
|
||||
*((uint8_t*)&mod) = m;
|
||||
|
|
Loading…
Reference in a new issue