Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

status indicators (Num, Caps) #11

Open
kolivusha opened this issue Dec 19, 2019 · 2 comments
Open

status indicators (Num, Caps) #11

kolivusha opened this issue Dec 19, 2019 · 2 comments

Comments

@kolivusha
Copy link

I noticed that while pressing NumLock it changes actually switches the status, but keyboard LED is not showing this.
Interestingly with the USBHIDBootKbd.ino Indicators work fine ( without switching it the status on the connected device)
I was trying to compere this code to Code here to USBHIDBootKbd (part of USB 2.0 shiled library, and could not isolate the difference.
Do you have any ideas on how to fix this ?
(Thanks a lot for the code and the effort!)

@ManoShu
Copy link

ManoShu commented Apr 21, 2020

I was able to set the indicator keys with those modifications:

  1. On the command mode of the Bluetooth module, I changed the SH command from SH,0230 to SH,0238 (this enables bit 3, sending reports to the TX pin of the module). Restart the module (R,1)
    Now every time the module connects to a device (at least on windows, on android it doesn't send), it might send the current key state with this format: 0xFE 0x2 0x1 0x[LEDS], where LEDS is the byte containing the bits for each state (Num = bit 0, Caps = 1, Scroll = 2, etc.)

  2. On my sketch (sadly Juan's sketch is not enough for my purpose), I listen to the bytes sent by the Bluetooth module for the key state message. When found, I pass the LEDS byte to the USB device like this:

uint8_t lockLeds = ...;  // the LEDS byte from the message
//hidSelector is an HIDComposite-inherited class that I use to receive keyboard/mouse raw HID data
//the HIDBoot<> classes should have access to the same method
auto res = hidSelector.SetReport(0, 0, 2, 0, 1, &lockLeds);
//error result
if (res != 0)
{
  Serial.print("[!!!!!!!] SetReport returned ");
  Serial.print(res, HEX);
  Serial.print(" for lock key state ");
  Serial.println(lockLeds, HEX);
}

The sketch files are here.
I made a separate class to check for this message (bt_reporter).

Sorry if the code is a bit messy, but I hope it helped you.

EDIT: I also set the Bluetooth module baud rate to 57600 instead do 115200, as I am using SoftwareSerial for communication and was worried about not receiving the data properly. At this speed it's very rare to the key state message to become corrupted.

@trantuananh1996
Copy link

Thanks @ManoShu, I've use your idea to modify my sketch, now my kbd can display status indicator :D
At the time I made my sketch, I already set BT module to SH,0238, but I don't know why it not working, but with your code it working now :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants