Skip to content

Commit

Permalink
Keyboard Host fixes (OpenStickCommunity#1010)
Browse files Browse the repository at this point in the history
* Added setup() call for Keyboard Host listener

* Added support for multiple modifier buttons at once.
Previous implementation did not allow combos of modifiers. Fixes OpenStickCommunity#1008
  • Loading branch information
mikepparks authored May 13, 2024
1 parent eb3a90f commit d0ae969
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/addons/keyboard_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bool KeyboardHostAddon::available() {

void KeyboardHostAddon::setup() {
listener = new KeyboardHostListener();
((KeyboardHostListener*)listener)->setup();
}

void KeyboardHostAddon::preprocess() {
Expand Down
14 changes: 12 additions & 2 deletions src/addons/keyboard_host_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,19 @@ void KeyboardHostListener::process_kbd_report(uint8_t dev_addr, hid_keyboard_rep
_keyboard_host_state.lt = 0;
_keyboard_host_state.rt = 0;

for(uint8_t i=0; i<7; i++)
// make this 13 instead of 7 to include modifier bitfields from hid_keyboard_modifier_bm_t
for(uint8_t i=0; i<13; i++)
{
uint8_t keycode = (i < 6) ? report->keycode[i] : getKeycodeFromModifier(report->modifier);
uint8_t keycode = 0;
if (i < 6) {
// process keycodes normally
keycode = report->keycode[i];
} else {
// keycode modifiers are bitfields, so the old getKeycodeFromModifier switch approach doesn't work
// keycode = getKeycodeFromModifier(report->modifier);
// new approach masks the modifier bit to determine which keys are pressed
keycode = getKeycodeFromModifier(report->modifier & (1 << (i - 6)));
}
if ( keycode )
{
_keyboard_host_state.dpad |=
Expand Down

0 comments on commit d0ae969

Please sign in to comment.