Skip to content

Commit

Permalink
Slight refactoring after receiving PR
Browse files Browse the repository at this point in the history
  • Loading branch information
maximevince committed Apr 30, 2024
1 parent ca00497 commit 2166074
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/gfx_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ void gfx_set_byte_offsets_text(void)
uint8_t interface = xlat_get_found_interface();

if (button->found && x->found && y->found && XLAT_MODE_KEY != xlat_get_mode()) {
sprintf(text, "Mouse Data (#%d): id@%d click@%d motion@%d,%d", interface, xlat_get_reportid(), button->byte_offset, x->byte_offset, y->byte_offset);
sprintf(text, "Mouse Data (#%d): id%d click@%d motion@%d,%d", interface, xlat_get_reportid(), button->byte_offset, x->byte_offset, y->byte_offset);
} else if (key->found && XLAT_MODE_KEY == xlat_get_mode()) {
sprintf(text, "Keyboard Data (#%d): id@%d pressed@%d", interface, xlat_get_reportid(), key->byte_offset);
sprintf(text, "Keyboard Data (#%d): id%d pressed@%d", interface, xlat_get_reportid(), key->byte_offset);
} else {
// offsets not found
sprintf(text, (XLAT_MODE_KEY == xlat_get_mode()) ? "Keyboard Data: offsets not found" : "Mouse Data: offsets not found");
Expand Down
16 changes: 10 additions & 6 deletions src/gfx_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ static void event_handler(lv_event_t* e)
// Motion [M]
case 1:
xlat_set_mode(XLAT_MODE_MOTION);
break;
break;

// Key [K]
// Key [K]
case 2:
xlat_set_mode(XLAT_MODE_KEY);
break;
break;

// Click [M]
// Click [M]
case 3:
default:
xlat_set_mode(XLAT_MODE_CLICK);
break;
}
}
else if (obj == (lv_obj_t *)interface_dropdown) {
Expand All @@ -118,11 +120,12 @@ static void event_handler(lv_event_t* e)
// Auto
case 0:
xlat_set_interface_selection(XLAT_INTERFACE_AUTO);
break;
break;

// Any specific interface number
default:
xlat_set_interface_selection(XLAT_INTERFACE_0 + sel - 1);
break;
}
}
else {
Expand Down Expand Up @@ -275,10 +278,11 @@ void gfx_settings_create_page(lv_obj_t *previous_screen)
switch (interface_selection) {
case XLAT_INTERFACE_AUTO:
interface_index = 0;
break;
break;

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

lv_dropdown_set_selected((lv_obj_t *) interface_dropdown, interface_index);
Expand Down
7 changes: 3 additions & 4 deletions src/usb/usbh_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost)
__IO USBH_StatusTypeDef status = USBH_FAIL;
uint8_t idx = 0U;
uint8_t i = 0U;
bool stop = false;

/* check for Host pending port disconnect event */
if (phost->device.is_disconnected == 1U)
Expand Down Expand Up @@ -709,15 +708,15 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost)
{
phost->pActiveClass = NULL;

for (idx = 0U, stop = false; idx < USBH_MAX_NUM_SUPPORTED_CLASS && !stop; idx++)
for (idx = 0U; idx < USBH_MAX_NUM_SUPPORTED_CLASS; idx++)
{
// Check if the device has an interface where the class is supported
for (i = 0U; i < USBH_MAX_NUM_INTERFACES && !stop; i++)
for (i = 0U; i < USBH_MAX_NUM_INTERFACES; i++)
{
if (phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[i].bInterfaceClass)
{
phost->pActiveClass = phost->pClass[idx];
stop = true;
break;
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/usb/usbh_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit(USBH_HandleTypeDef *phost)
// Handle the AUTO interface detection mode
if (XLAT_INTERFACE_AUTO == xlat_get_interface_selection()) {
// First try to find a Mouse or Keyboard interface depending on the detection mode, specifically:
interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, (XLAT_MODE_KEY == xlat_get_mode()) ? HID_KEYBRD_BOOT_CODE : HID_MOUSE_BOOT_CODE);
interface = USBH_FindInterface(phost,
phost->pActiveClass->ClassCode,
HID_BOOT_CODE,
(XLAT_MODE_KEY == xlat_get_mode()) ? HID_KEYBRD_BOOT_CODE : HID_MOUSE_BOOT_CODE);

// Broaden the search criteria to no specific protocol
if (interface == 0xFFU) {
Expand Down Expand Up @@ -272,8 +275,7 @@ static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost)
if (classReqStatus == USBH_OK) {
HID_Handle->ctl_state = USBH_HID_REQ_IDLE;

if (phost->pUser != NULL)
{
if (phost->pUser != NULL) {
/* all requests performed*/
phost->pUser(phost, HOST_USER_CLASS_ACTIVE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/xlat.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ void xlat_usb_hid_event(void)
uint8_t hid_raw_data[64];

if (USBH_HID_GetRawData(phost, hid_raw_data) == USBH_OK) {
// check reportId for ULX
// check reportId
if (hid_reportid && (hid_raw_data[0] != hid_reportid)) {
// ignore
goto out;
Expand Down

0 comments on commit 2166074

Please sign in to comment.