Can now set the LEDs on a keyboard

This commit is contained in:
Kristian Lauszus 2013-11-25 01:45:24 +01:00
parent 45465fa928
commit 4099314100
4 changed files with 43 additions and 3 deletions

View file

@ -381,3 +381,11 @@ void BTHID::setProtocol() {
uint8_t command = 0x70 | protocolMode; // Set Protocol, see HID specs page 33 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]); 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]);
}

View file

@ -102,6 +102,9 @@ public:
protocolMode = mode; protocolMode = mode;
}; };
/** Used to set the leds on a keyboard */
void setLeds(uint8_t data);
/** True if a device is connected */ /** True if a device is connected */
bool connected; bool connected;

View file

@ -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; KbdRptParser keyboardPrs(&hid);
MouseRptParser mousePrs; MouseRptParser mousePrs;
void setup() { void setup() {

View file

@ -2,16 +2,45 @@
#define __kbdrptparser_h_ #define __kbdrptparser_h_
class KbdRptParser : public KeyboardReportParser { class KbdRptParser : public KeyboardReportParser {
private: public:
void PrintKey(uint8_t mod, uint8_t key); KbdRptParser(BTHID *p) : pBTHID(p) {};
protected: protected:
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);
virtual void OnKeyDown(uint8_t mod, uint8_t key); virtual void OnKeyDown(uint8_t mod, uint8_t key);
virtual void OnKeyUp(uint8_t mod, uint8_t key); virtual void OnKeyUp(uint8_t mod, uint8_t key);
virtual void OnKeyPressed(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) { void KbdRptParser::PrintKey(uint8_t m, uint8_t key) {
MODIFIERKEYS mod; MODIFIERKEYS mod;
*((uint8_t*)&mod) = m; *((uint8_t*)&mod) = m;