From 4e6767a3f081c079443aa332553daab90da952a4 Mon Sep 17 00:00:00 2001 From: RockyZeroFour Date: Fri, 31 Jan 2025 13:44:57 +0100 Subject: [PATCH] Filter for report ID - Possibility to filter for a specific report ID - Allows to select wanted report if interface has multiple reports of the same kind --- src/gfx_settings.c | 52 +++++++++++++++++++++++++++------------------- src/usb/usbh_hid.c | 11 ++++++++++ src/xlat.c | 18 +++++++++++++++- src/xlat.h | 20 ++++++++++++++++-- 4 files changed, 77 insertions(+), 24 deletions(-) diff --git a/src/gfx_settings.c b/src/gfx_settings.c index bd243dc..2e2ce17 100644 --- a/src/gfx_settings.c +++ b/src/gfx_settings.c @@ -28,6 +28,7 @@ lv_slider_t *debounce_dropdown; lv_dropdown_t *trigger_dropdown; lv_dropdown_t *detection_dropdown; lv_dropdown_t *interface_dropdown; +lv_dropdown_t *reportid_dropdown; lv_obj_t *prev_screen = NULL; // Pointer to store previous screen LV_IMG_DECLARE(xlat_logo); @@ -117,17 +118,33 @@ static void event_handler(lv_event_t* e) uint16_t sel = lv_dropdown_get_selected(obj); switch (sel) { - // Auto + // AUTO case 0: xlat_set_interface_selection(XLAT_INTERFACE_AUTO); break; - // Any specific interface number + // interface number default: xlat_set_interface_selection(XLAT_INTERFACE_0 + sel - 1); break; } } + else if (obj == (lv_obj_t *)reportid_dropdown) { + // Interface number changed + uint16_t sel = lv_dropdown_get_selected(obj); + + switch (sel) { + // AUTO id + case 0: + xlat_set_reportid_selection(XLAT_REPORTID_AUTO); + break; + + // report ID number + default: + xlat_set_reportid_selection(XLAT_REPORTID_0 + sel - 1); + break; + } + } else { printf("Unknown event\n"); } @@ -151,7 +168,6 @@ void gfx_settings_create_page(lv_obj_t *previous_screen) // Will align this after determining max label width lv_obj_add_event_cb((struct _lv_obj_t *) edge_dropdown, event_handler, LV_EVENT_VALUE_CHANGED, NULL); - // Debounce Time Label & Slider lv_obj_t *debounce_label = lv_label_create(settings_screen); lv_label_set_text(debounce_label, "Debounce Time:"); @@ -162,7 +178,6 @@ void gfx_settings_create_page(lv_obj_t *previous_screen) // Will align this after determining max label width lv_obj_add_event_cb((struct _lv_obj_t *) debounce_dropdown, event_handler, LV_EVENT_VALUE_CHANGED, NULL); - // Auto-Trigger Level Label & Dropdown lv_obj_t *trigger_label = lv_label_create(settings_screen); lv_label_set_text(trigger_label, "Auto-trigger Level:"); @@ -173,7 +188,6 @@ void gfx_settings_create_page(lv_obj_t *previous_screen) // Will align this after determining max label width lv_obj_add_event_cb((struct _lv_obj_t *) trigger_dropdown, event_handler, LV_EVENT_VALUE_CHANGED, NULL); - // Click, motion & key detection label lv_obj_t *detection_mode = lv_label_create(settings_screen); lv_label_set_text(detection_mode, "Detection Mode:"); @@ -194,6 +208,11 @@ void gfx_settings_create_page(lv_obj_t *previous_screen) lv_dropdown_set_options((lv_obj_t *) interface_dropdown, "AUTO\n0\n1\n2\n3\n4\n5\n6\n7\n8"); lv_obj_add_event_cb((struct _lv_obj_t *) interface_dropdown, event_handler, LV_EVENT_VALUE_CHANGED, NULL); + // ReportID selection dropdown + reportid_dropdown = (lv_dropdown_t *) lv_dropdown_create(settings_screen); + lv_dropdown_set_options((lv_obj_t *) reportid_dropdown, "AUTO id\nid0\nid1\nid2\nid3\nid4\nid5\nid6\nid7\nid8"); + lv_obj_add_event_cb((struct _lv_obj_t *) reportid_dropdown, event_handler, LV_EVENT_VALUE_CHANGED, NULL); + // If we don't add this label, the y-value of the last item will be 0 lv_obj_t *debounce_label2 = lv_label_create(settings_screen); lv_label_set_text(debounce_label2, ""); @@ -212,6 +231,7 @@ void gfx_settings_create_page(lv_obj_t *previous_screen) lv_obj_align((struct _lv_obj_t *) trigger_dropdown, LV_ALIGN_DEFAULT, max_width + widget_gap, lv_obj_get_y(trigger_label) - 10); lv_obj_align((struct _lv_obj_t *) detection_dropdown, LV_ALIGN_DEFAULT, max_width + widget_gap, lv_obj_get_y(detection_mode) - 10); lv_obj_align((struct _lv_obj_t *) interface_dropdown, LV_ALIGN_DEFAULT, max_width + widget_gap, lv_obj_get_y(interface_label) - 10); + lv_obj_align((struct _lv_obj_t *) reportid_dropdown, LV_ALIGN_DEFAULT, max_width + 2 * widget_gap + lv_obj_get_width((lv_obj_t *)interface_dropdown), lv_obj_get_y(interface_label) - 10); // Print all y-values for debugging //printf("edge_label y: %d\n", lv_obj_get_y(edge_label)); @@ -229,16 +249,17 @@ void gfx_settings_create_page(lv_obj_t *previous_screen) // Version number label in the top right lv_obj_t *version_label = lv_label_create(settings_screen); + // Get the version number from APP_VERSION_* defines char version_str[30]; sprintf(version_str, "XLAT v%s", APP_VERSION_FULL); lv_label_set_text(version_label, version_str); lv_obj_align(version_label, LV_ALIGN_TOP_RIGHT, -10, 10); - // Display current settings uint32_t debounce_time = xlat_get_gpio_irq_holdoff_us() / 1000; uint16_t debounce_index = 0; + switch (debounce_time) { case 20: debounce_index = 0; @@ -258,32 +279,21 @@ void gfx_settings_create_page(lv_obj_t *previous_screen) default: break; } + lv_dropdown_set_selected((lv_obj_t *) debounce_dropdown, debounce_index); // Display current detection mode lv_dropdown_set_selected((lv_obj_t *) detection_dropdown, xlat_get_mode()); - // Display current detection edge lv_dropdown_set_selected((lv_obj_t *) edge_dropdown, hw_config_input_trigger_is_rising_edge()); // Display current auto-trigger level lv_dropdown_set_selected((lv_obj_t *) trigger_dropdown, xlat_auto_trigger_level_is_high()); - // Display current interface selection - uint16_t interface_index = 0; - xlat_interface_t interface_selection = xlat_get_interface_selection(); - - switch (interface_selection) { - case XLAT_INTERFACE_AUTO: - interface_index = 0; - break; - - default: - interface_index = 1 + interface_selection - XLAT_INTERFACE_0; - break; - } + lv_dropdown_set_selected((lv_obj_t *) interface_dropdown, xlat_get_interface_selection()); - lv_dropdown_set_selected((lv_obj_t *) interface_dropdown, interface_index); + // Display current report ID selection + lv_dropdown_set_selected((lv_obj_t *) reportid_dropdown, xlat_get_reportid_selection()); } diff --git a/src/usb/usbh_hid.c b/src/usb/usbh_hid.c index ed30d61..45d53e0 100644 --- a/src/usb/usbh_hid.c +++ b/src/usb/usbh_hid.c @@ -65,6 +65,7 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit(USBH_HandleTypeDef *phost) uint8_t max_ep; uint8_t num = 0U; uint8_t interface; + uint8_t reportid; // Handle the AUTO interface detection mode if (XLAT_INTERFACE_AUTO == xlat_get_interface_selection()) { @@ -111,6 +112,16 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit(USBH_HandleTypeDef *phost) xlat_set_found_interface(interface); + // Update the report ID to search for + if (XLAT_REPORTID_AUTO == xlat_get_reportid_selection()) { + reportid = 0xFF; + } + else { + reportid = xlat_get_reportid_selection() - XLAT_REPORTID_0; + } + + xlat_set_reportid(reportid); + phost->pActiveClass->pData = (HID_HandleTypeDef *)USBH_malloc(sizeof(HID_HandleTypeDef)); HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; diff --git a/src/xlat.c b/src/xlat.c index 581e5ff..f72fd1a 100644 --- a/src/xlat.c +++ b/src/xlat.c @@ -45,10 +45,11 @@ static volatile uint_fast8_t gpio_irq_consumer = 0; // SETTINGS volatile bool xlat_initialized = false; static xlat_mode_t xlat_mode = XLAT_MODE_CLICK; -static uint8_t hid_reportid = 0; +static uint8_t hid_reportid = 0xFF; static bool auto_trigger_level_high = false; static xlat_interface_t xlat_interface = XLAT_INTERFACE_AUTO; static uint8_t found_interface = 0xFF; +static xlat_reportid_t xlat_reportid = XLAT_REPORTID_AUTO; // The Razer optical switches will constantly trigger the GPIO interrupt, while pressed // Waveform looks like this in ASCII art: @@ -160,6 +161,11 @@ static inline void hidreport_print_item(HID_ReportItem_t *item) static void hidreport_check_item(HID_ReportItem_t *item) { + // If a report ID is set then only check report item if it belongs to that + if (hid_reportid != 0xFF && hid_reportid != item->ReportID) { + return; + } + switch (item->Attributes.Usage.Page) { case 0x01: switch (item->Attributes.Usage.Usage) { @@ -636,6 +642,16 @@ void xlat_reset_latency(void) } } +void xlat_set_reportid_selection(xlat_reportid_t number) +{ + xlat_reportid = number; +} + +xlat_reportid_t xlat_get_reportid_selection() +{ + return xlat_reportid; +} + void xlat_set_reportid(uint8_t reportid) { hid_reportid = reportid; diff --git a/src/xlat.h b/src/xlat.h index 7d54219..20afb27 100644 --- a/src/xlat.h +++ b/src/xlat.h @@ -51,8 +51,8 @@ typedef enum xlat_mode { } xlat_mode_t; typedef enum xlat_interface { - XLAT_INTERFACE_AUTO = -1, - XLAT_INTERFACE_0 = 0, + XLAT_INTERFACE_AUTO = 0, + XLAT_INTERFACE_0, XLAT_INTERFACE_1, XLAT_INTERFACE_2, XLAT_INTERFACE_3, @@ -63,6 +63,19 @@ typedef enum xlat_interface { XLAT_INTERFACE_8, } xlat_interface_t; +typedef enum xlat_reportid { + XLAT_REPORTID_AUTO = 0, + XLAT_REPORTID_0, + XLAT_REPORTID_1, + XLAT_REPORTID_2, + XLAT_REPORTID_3, + XLAT_REPORTID_4, + XLAT_REPORTID_5, + XLAT_REPORTID_6, + XLAT_REPORTID_7, + XLAT_REPORTID_8, +} xlat_reportid_t; + extern volatile bool xlat_initialized; void xlat_init(void); @@ -112,4 +125,7 @@ xlat_interface_t xlat_get_interface_selection(); void xlat_set_found_interface(uint8_t number); uint8_t xlat_get_found_interface(); +void xlat_set_reportid_selection(xlat_reportid_t number); +xlat_reportid_t xlat_get_reportid_selection(); + #endif //XLAT_H