Skip to content

Commit

Permalink
try to fix up simulator-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tlyu committed Dec 10, 2023
1 parent 8039b51 commit f1de869
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
50 changes: 25 additions & 25 deletions src/kaleidoscope/device/virtual/DefaultHIDReportConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "kaleidoscope/device/virtual/DefaultHIDReportConsumer.h"

// From KeyboardioHID:
#include <HID-Settings.h> // for HID_REPORTID_NKRO_KEYBOARD
#include <MultiReport/Keyboard.h> // for HID_KeyboardReport_Data_t, (anonymous u...
#include <HID-Settings.h> // for HID_REPORTID_NKRO_KEYBOARD
#include <BootKeyboard/BootKeyboard.h> // for HID_BootKeyboardReport_Data_t, (anonymous u...
// From system:
#include <stdint.h> // for uint8_t
// From Arduino core:
Expand Down Expand Up @@ -52,21 +52,21 @@ using namespace logging; // NOLINT(build/namespaces)

void DefaultHIDReportConsumer::processHIDReport(
uint8_t id, const void *data, int len, int result) {
if (id != HID_REPORTID_NKRO_KEYBOARD) {
if (id != HID_REPORTID_KEYBOARD) {
log_info("***Ignoring hid report with id = %d\n", id);
return;
}

const HID_KeyboardReport_Data_t &report_data = *static_cast<const HID_KeyboardReport_Data_t *>(data);
const HID_BootKeyboardReport_Data_t &report_data = *static_cast<const HID_BootKeyboardReport_Data_t *>(data);

std::stringstream keypresses;
bool anything = false;

if (report_data.modifiers) {
anything = true;
} else {
for (int i = 0; i < KEY_BYTES; i++) {
if (report_data.keys[i]) {
for (int i = 0; i < NKRO_KEY_BYTES; i++) {
if (report_data.nkro_keys[i]) {
anything = true;
break;
}
Expand All @@ -80,53 +80,53 @@ void DefaultHIDReportConsumer::processHIDReport(
FOREACHBIT(report_data.modifiers, keypresses,
"lctrl ", "lshift ", "lalt ", "lgui ",
"rctrl ", "rshift ", "ralt ", "rgui ")
FOREACHBIT(report_data.keys[0], keypresses,
FOREACHBIT(report_data.nkro_keys[0], keypresses,
"NO_EVENT ", "ERROR_ROLLOVER ", "POST_FAIL ", "ERROR_UNDEFINED ",
"a ", "b ", "c ", "d ")
FOREACHBIT(report_data.keys[1], keypresses,
FOREACHBIT(report_data.nkro_keys[1], keypresses,
"e ", "f ", "g ", "h ", "i ", "j ", "k ", "l ")
FOREACHBIT(report_data.keys[2], keypresses,
FOREACHBIT(report_data.nkro_keys[2], keypresses,
"m ", "n ", "o ", "p ", "q ", "r ", "s ", "t ")
FOREACHBIT(report_data.keys[3], keypresses,
FOREACHBIT(report_data.nkro_keys[3], keypresses,
"u ", "v ", "w ", "x ", "y ", "z ", "1/! ", "2/@ ")
FOREACHBIT(report_data.keys[4], keypresses,
FOREACHBIT(report_data.nkro_keys[4], keypresses,
"3/# ", "4/$ ", "5/% ", "6/^ ", "7/& ", "8/* ", "9/( ", "0/) ")
FOREACHBIT(report_data.keys[5], keypresses,
FOREACHBIT(report_data.nkro_keys[5], keypresses,
"enter ", "esc ", "del/bksp ", "tab ",
"space ", "-/_ ", "=/+ ", "[/{ ")
FOREACHBIT(report_data.keys[6], keypresses,
FOREACHBIT(report_data.nkro_keys[6], keypresses,
"]/} ", "\\/| ", "#/~ ", ";/: ", "'/\" ", "`/~ ", ",/< ", "./> ")
FOREACHBIT(report_data.keys[7], keypresses,
FOREACHBIT(report_data.nkro_keys[7], keypresses,
"//? ", "capslock ", "F1 ", "F2 ", "F3 ", "F4 ", "F5 ", "F6 ")
FOREACHBIT(report_data.keys[8], keypresses,
FOREACHBIT(report_data.nkro_keys[8], keypresses,
"F7 ", "F8 ", "F9 ", "F10 ", "F11 ", "F12 ", "prtscr ", "scrolllock ")
FOREACHBIT(report_data.keys[9], keypresses,
FOREACHBIT(report_data.nkro_keys[9], keypresses,
"pause ", "ins ", "home ", "pgup ", "del ", "end ", "pgdn ", "r_arrow ")
FOREACHBIT(report_data.keys[10], keypresses,
FOREACHBIT(report_data.nkro_keys[10], keypresses,
"l_arrow ", "d_arrow ", "u_arrow ", "numlock ",
"num/ ", "num* ", "num- ", "num+ ")
FOREACHBIT(report_data.keys[11], keypresses,
FOREACHBIT(report_data.nkro_keys[11], keypresses,
"numenter ", "num1 ", "num2 ", "num3 ",
"num4 ", "num5 ", "num6 ", "num7 ")
FOREACHBIT(report_data.keys[12], keypresses,
FOREACHBIT(report_data.nkro_keys[12], keypresses,
"num8 ", "num9 ", "num0 ", "num. ", "\\/| ", "app ", "power ", "num= ")
FOREACHBIT(report_data.keys[13], keypresses,
FOREACHBIT(report_data.nkro_keys[13], keypresses,
"F13 ", "F14 ", "F15 ", "F16 ", "F17 ", "F18 ", "F19 ", "F20 ")
FOREACHBIT(report_data.keys[14], keypresses,
FOREACHBIT(report_data.nkro_keys[14], keypresses,
"F21 ", "F22 ", "F23 ", "F24 ", "exec ", "help ", "menu ", "sel ")
FOREACHBIT(report_data.keys[15], keypresses,
FOREACHBIT(report_data.nkro_keys[15], keypresses,
"stop ", "again ", "undo ", "cut ", "copy ", "paste ", "find ", "mute ")
FOREACHBIT(report_data.keys[16], keypresses,
FOREACHBIT(report_data.nkro_keys[16], keypresses,
"volup ", "voldn ", "capslock_l ", "numlock_l ",
"scrolllock_l ", "num, ", "num= ", "(other) ")
// clang-format on

for (int i = 17; i < KEY_BYTES; i++) {
for (int i = 17; i < NKRO_KEY_BYTES; i++) {
// A little imprecise, in two ways:
// (1) obviously, "(other)" refers to many distinct keys
// (2) this might undercount the number of "other" keys pressed
// Therefore, if any keys are frequently used, they should be handled above and not via "other"
if (report_data.keys[i]) keypresses << "(other) ";
if (report_data.nkro_keys[i]) keypresses << "(other) ";
}
}

Expand Down
4 changes: 2 additions & 2 deletions testing/HIDState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void HIDStateBuilder::ProcessHidReport(
uint8_t id, const void *data, int len, int result) {
switch (id) {
case HID_REPORTID_KEYBOARD: {
LOG(ERROR) << "Dropped BootKeyboardReport: unimplemented";
ProcessKeyboardReport(KeyboardReport{data});
break;
}
case HID_REPORTID_GAMEPAD: {
Expand All @@ -100,7 +100,7 @@ void HIDStateBuilder::ProcessHidReport(
break;
}
case HID_REPORTID_NKRO_KEYBOARD: {
ProcessKeyboardReport(KeyboardReport{data});
LOG(ERROR) << "Dropped NKROKeyboardReport: unimplemented";
break;
}
default:
Expand Down
2 changes: 1 addition & 1 deletion testing/KeyboardReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ std::vector<uint8_t> KeyboardReport::ActiveNonModifierKeycodes() const {

for (uint8_t i = 0; i < HID_LAST_KEY; ++i) {
uint8_t bit = 1 << (uint8_t(i) % 8);
uint8_t keycode = report_data_.keys[i / 8] & bit;
uint8_t keycode = report_data_.nkro_keys[i / 8] & bit;
if (keycode) active_keycodes.push_back(i);
}

Expand Down
8 changes: 4 additions & 4 deletions testing/KeyboardReport.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
#include <cstdint> // for uint8_t, uint32_t
#include <vector> // for vector

#include "HID-Settings.h" // for HID_REPORTID_NKRO_KEYBOARD
#include "MultiReport/Keyboard.h" // for HID_KeyboardReport_Data_t
#include "HID-Settings.h" // for HID_REPORTID_NKRO_KEYBOARD
#include "BootKeyboard/BootKeyboard.h" // for HID_KeyboardReport_Data_t

namespace kaleidoscope {
namespace testing {

class KeyboardReport {
public:
typedef HID_KeyboardReport_Data_t ReportData;
typedef HID_BootKeyboardReport_Data_t ReportData;

static constexpr uint8_t kHidReportType = HID_REPORTID_NKRO_KEYBOARD;
static constexpr uint8_t kHidReportType = HID_REPORTID_KEYBOARD;

KeyboardReport(const void *data);

Expand Down

0 comments on commit f1de869

Please sign in to comment.