I've got a USB keyboard connected to my Arduino Uno with a USB Host Shield. I'm reading keystrokes using this example from the USB Host Shield library.
I need to toggle the LEDs in the keyboard (that indicate the state of Caps Lock, Num Lock etc.)
This thread mentions using Usb.setReport()
, but this method doesn't seem to exist any more: there's no such method in Usb.cpp in the library. There does seem to be a method called SetReport
in the USBHID class, which looks like it takes the same arguments, which I'm trying to use.
What I'm currently doing:
void keyboard_setup(){
static HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
if (Usb.Init() == -1) {
Serial.println("OSC did not start.");
}
delay(200);
HidKeyboard.SetReportParser(0, &Prs);
static USBHID usbhid(&Usb);
uint8_t leds = 1;
#define KBD_ADDR 1
#define KBD_IF 0
usbhid.SetReport( KBD_ADDR, 0, 1, KBD_IF, 0, &leds );
delay(100);
leds = 255;
usbhid.SetReport( KBD_ADDR, 0, 1, KBD_IF, 0, &leds );
delay(100);
Neither call to SetReport seems to work, and I'm not certain the values of KBD_ADDR or KBD_IF are correct (I'm using ones that I've seen in examples), or event that calling SetReport is right .
What am I doing wrong?