diff --git a/src/driver-etekcity.c b/src/driver-etekcity.c index bd8a015b..4676a47d 100644 --- a/src/driver-etekcity.c +++ b/src/driver-etekcity.c @@ -464,7 +464,7 @@ etekcity_read_profile(struct ratbag_profile *profile, unsigned int index) struct etekcity_settings_report *setting_report; uint8_t *buf; unsigned int report_rate; - unsigned int i, j; + unsigned int i; int dpi_x, dpi_y, hz; int rc; @@ -521,35 +521,6 @@ etekcity_read_profile(struct ratbag_profile *profile, unsigned int index) msleep(10); - for (i = 0; i < ETEKCITY_BUTTON_MAX; i++) { - const struct ratbag_button_action *action; - struct etekcity_macro *macro; - - action = etekcity_button_to_action(profile, i); - if (!action || action->type != RATBAG_BUTTON_ACTION_TYPE_MACRO) - continue; - - etekcity_set_config_profile(device, index, i); - macro = &drv_data->macros[index][i]; - buf = (uint8_t*)macro; - rc = ratbag_hidraw_raw_request(device, ETEKCITY_REPORT_ID_MACRO, - buf, ETEKCITY_REPORT_SIZE_MACRO, - HID_FEATURE_REPORT, HID_REQ_GET_REPORT); - log_info(device->ratbag, - "macro on button %d of profile %d is named '%s', and contains %d events:\n", - i, profile->index, - macro->name, macro->length); - for (j = 0; j < macro->length; j++) { - log_info(device->ratbag, - " - %s %s\n", - libevdev_event_code_get_name(EV_KEY, macro_mapping[macro->keys[j].keycode]), - macro->keys[j].flag & 0x80 ? "released" : "pressed"); - } - - } - - msleep(10); - if (rc < ETEKCITY_REPORT_SIZE_PROFILE) return; @@ -592,6 +563,12 @@ static void etekcity_read_button(struct ratbag_button *button) { const struct ratbag_button_action *action; + struct ratbag_device *device; + struct etekcity_macro *macro; + struct etekcity_data *drv_data; + uint8_t *buf; + unsigned j; + int rc; action = etekcity_button_to_action(button->profile, button->index); if (action) @@ -602,6 +579,38 @@ etekcity_read_button(struct ratbag_button *button) ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_KEY); ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_SPECIAL); ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_MACRO); + + if (action && action->type == RATBAG_BUTTON_ACTION_TYPE_MACRO) { + device = button->profile->device; + drv_data = ratbag_get_drv_data(device); + + etekcity_set_config_profile(device, + button->profile->index, + button->index); + macro = &drv_data->macros[button->profile->index][button->index]; + buf = (uint8_t*)macro; + rc = ratbag_hidraw_raw_request(device, ETEKCITY_REPORT_ID_MACRO, + buf, ETEKCITY_REPORT_SIZE_MACRO, + HID_FEATURE_REPORT, HID_REQ_GET_REPORT); + if (rc != ETEKCITY_REPORT_SIZE_MACRO) { + log_error(device->ratbag, + "Unable to retrieve the macro for button %d of profile %d: %s (%d)\n", + button->index, button->profile->index, + rc < 0 ? strerror(-rc) : "not read enough", rc); + } else { + log_info(device->ratbag, + "macro on button %d of profile %d is named '%s', and contains %d events:\n", + button->index, button->profile->index, + macro->name, macro->length); + for (j = 0; j < macro->length; j++) { + log_info(device->ratbag, + " - %s %s\n", + libevdev_event_code_get_name(EV_KEY, macro_mapping[macro->keys[j].keycode]), + macro->keys[j].flag & 0x80 ? "released" : "pressed"); + } + } + msleep(10); + } } static int