Skip to content

Commit

Permalink
Filter for report ID
Browse files Browse the repository at this point in the history
- Possibility to filter for a specific report ID
- Allows to select wanted report if interface has multiple reports of the same kind
  • Loading branch information
RockyZeroFour committed Feb 3, 2025
1 parent a120e6c commit 8e96d85
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 12 deletions.
56 changes: 46 additions & 10 deletions src/gfx_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
Expand All @@ -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:");
Expand All @@ -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:");
Expand All @@ -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:");
Expand All @@ -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, "");
Expand All @@ -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));
Expand All @@ -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;
Expand All @@ -258,21 +279,20 @@ 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;
uint16_t interface_index = 0;
xlat_interface_t interface_selection = xlat_get_interface_selection();

switch (interface_selection) {
Expand All @@ -281,9 +301,25 @@ void gfx_settings_create_page(lv_obj_t *previous_screen)
break;

default:
interface_index = 1 + interface_selection - XLAT_INTERFACE_0;
interface_index = interface_selection - XLAT_INTERFACE_0 + 1;
break;
}

lv_dropdown_set_selected((lv_obj_t *) interface_dropdown, interface_index);

// Display current report ID selection
uint16_t reportid_index = 0;
xlat_reportid_t reportid_selection = xlat_get_reportid_selection();

switch (interface_selection) {
case XLAT_REPORTID_AUTO:
reportid_index = 0;
break;

default:
reportid_index = reportid_selection - XLAT_REPORTID_0 + 1;
break;
}

lv_dropdown_set_selected((lv_obj_t *) reportid_dropdown, reportid_index);
}
11 changes: 11 additions & 0 deletions src/usb/usbh_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;

Expand Down
18 changes: 17 additions & 1 deletion src/xlat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion src/xlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef enum xlat_mode {
} xlat_mode_t;

typedef enum xlat_interface {
XLAT_INTERFACE_AUTO = -1,
XLAT_INTERFACE_AUTO = 0xFF,
XLAT_INTERFACE_0 = 0,
XLAT_INTERFACE_1,
XLAT_INTERFACE_2,
Expand All @@ -63,6 +63,19 @@ typedef enum xlat_interface {
XLAT_INTERFACE_8,
} xlat_interface_t;

typedef enum xlat_reportid {
XLAT_REPORTID_AUTO = 0xFF,
XLAT_REPORTID_0 = 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);
Expand Down Expand Up @@ -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

0 comments on commit 8e96d85

Please sign in to comment.