1
0
forked from drath/libratbag

steelseries: make most of implicit conversions explicit

Did not fix brightness and LED color, they deserve being changed on
libratbag side.
This commit is contained in:
Yaroslav Chvanov
2023-05-19 22:44:50 +03:00
parent ab4504d3ed
commit 9b36ff7dd1

View File

@@ -101,7 +101,7 @@ struct steelseries_led_cycle {
};
struct steelseries_led_cycle_spec {
int hid_report_type; /* either HID_OUTPUT_REPORT or HID_FEATURE_REPORT */
uint8_t hid_report_type;/* either HID_OUTPUT_REPORT or HID_FEATURE_REPORT */
int header_len; /* number of bytes in the header */
uint8_t cmd_val; /* command value for the color command */
bool has_2_led_ids; /* some mice have 2 fields for led id */
@@ -144,7 +144,7 @@ steelseries_test_hidraw(struct ratbag_device *device)
}
static void
button_defaults_for_layout(struct ratbag_button *button, int button_count)
button_defaults_for_layout(struct ratbag_button *button, size_t button_count)
{
/* The default button mapping vary depending on the number of buttons
* on the device. */
@@ -297,12 +297,7 @@ steelseries_probe(struct ratbag_device *device)
struct ratbag_resolution *resolution;
struct ratbag_button *button;
struct ratbag_led *led;
struct dpi_list *dpilist = NULL;
struct dpi_range *dpirange = NULL;
int button_count;
int device_version;
int led_count;
int quirk;
int rc;
unsigned int report_rates[] = { 125, 250, 500, 1000 };
@@ -323,17 +318,19 @@ steelseries_probe(struct ratbag_device *device)
return -EINVAL;
}
button_count = ratbag_device_data_steelseries_get_button_count(device->data);
if (button_count == -1)
button_count = 0;
rc = ratbag_device_data_steelseries_get_button_count(device->data);
if (rc == -1)
rc = 0;
const unsigned int button_count = (unsigned int)rc;
led_count = ratbag_device_data_steelseries_get_led_count(device->data);
if (led_count == -1)
led_count = 0;
rc = ratbag_device_data_steelseries_get_led_count(device->data);
if (rc == -1)
rc = 0;
const unsigned int led_count = (unsigned int)rc;
dpirange = ratbag_device_data_steelseries_get_dpi_range(device->data);
dpilist = ratbag_device_data_steelseries_get_dpi_list(device->data);
quirk = ratbag_device_data_steelseries_get_quirk(device->data);
const enum steelseries_quirk quirk = ratbag_device_data_steelseries_get_quirk(device->data);
const struct dpi_list *dpilist = ratbag_device_data_steelseries_get_dpi_list(device->data);
const struct dpi_range *dpirange = ratbag_device_data_steelseries_get_dpi_range(device->data);
ratbag_device_init_profiles(device,
STEELSERIES_NUM_PROFILES,
@@ -451,29 +448,29 @@ steelseries_write_dpi(struct ratbag_resolution *resolution)
buf_len = STEELSERIES_REPORT_SIZE_SHORT;
msg.msg.parameters[0] = STEELSERIES_ID_DPI_SHORT;
msg.msg.parameters[1] = resolution->index + 1;
msg.msg.parameters[2] = i;
msg.msg.parameters[1] = (uint8_t)resolution->index + 1;
msg.msg.parameters[2] = (uint8_t)i;
break;
}
case 2:
buf_len = STEELSERIES_REPORT_SIZE;
msg.msg.parameters[0] = STEELSERIES_ID_DPI;
msg.msg.parameters[2] = resolution->index + 1;
msg.msg.parameters[3] = resolution->dpi_x / (size_t)dpirange->step - 1;
msg.msg.parameters[2] = (uint8_t)resolution->index + 1;
msg.msg.parameters[3] = (uint8_t)(resolution->dpi_x / (size_t)dpirange->step - 1);
msg.msg.parameters[6] = 0x42; /* not sure if needed */
break;
case 3:
buf_len = STEELSERIES_REPORT_SIZE;
msg.msg.parameters[0] = STEELSERIES_ID_DPI_PROTOCOL3;
msg.msg.parameters[2] = resolution->index + 1;
msg.msg.parameters[3] = resolution->dpi_x / (size_t)dpirange->step - 1;
msg.msg.parameters[2] = (uint8_t)resolution->index + 1;
msg.msg.parameters[3] = (uint8_t)(resolution->dpi_x / (size_t)dpirange->step - 1);
msg.msg.parameters[5] = 0x42; /* not sure if needed */
break;
case 4:
buf_len = STEELSERIES_REPORT_SIZE;
msg.msg.parameters[0] = STEELSERIES_ID_DPI_PROTOCOL4;
msg.msg.parameters[1] = resolution->index + 1;
msg.msg.parameters[2] = resolution->dpi_x / (size_t)dpirange->step - 1;
msg.msg.parameters[1] = (uint8_t)resolution->index + 1;
msg.msg.parameters[2] = (uint8_t)(resolution->dpi_x / (size_t)dpirange->step - 1);
break;
default:
return -ENOTSUP;
@@ -525,12 +522,12 @@ steelseries_write_report_rate(struct ratbag_profile *profile)
case 2:
buf_len = STEELSERIES_REPORT_SIZE;
msg.msg.parameters[0] = STEELSERIES_ID_REPORT_RATE;
msg.msg.parameters[2] = 1000 / profile->hz;
msg.msg.parameters[2] = (uint8_t)1000 / profile->hz;
break;
case 3:
buf_len = STEELSERIES_REPORT_SIZE;
msg.msg.parameters[0] = STEELSERIES_ID_REPORT_RATE_PROTOCOL3;
msg.msg.parameters[2] = 1000 / profile->hz;
msg.msg.parameters[2] = (uint8_t)1000 / profile->hz;
break;
default:
return -ENOTSUP;
@@ -556,8 +553,8 @@ steelseries_write_buttons(struct ratbag_profile *profile)
return 0;
const bool is_senseiraw = ratbag_device_data_steelseries_get_quirk(device->data) == STEELSERIES_QUIRK_SENSEIRAW;
const int button_size = is_senseiraw ? 3 : 5;
const int report_size = is_senseiraw ? STEELSERIES_REPORT_SIZE_SHORT : STEELSERIES_REPORT_LONG_SIZE;
const size_t button_size = is_senseiraw ? 3 : 5;
const size_t report_size = is_senseiraw ? STEELSERIES_REPORT_SIZE_SHORT : STEELSERIES_REPORT_LONG_SIZE;
const int max_modifiers = is_senseiraw ? 0 : 3;
union steelseries_message msg = {
@@ -569,7 +566,6 @@ steelseries_write_buttons(struct ratbag_profile *profile)
ratbag_profile_for_each_button(profile, button) {
struct ratbag_button_action *action = &button->action;
uint16_t code;
unsigned int key;
unsigned int modifiers;
@@ -578,7 +574,7 @@ steelseries_write_buttons(struct ratbag_profile *profile)
switch (action->type) {
case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
msg.msg.parameters[idx] = action->action.button;
msg.msg.parameters[idx] = (uint8_t)action->action.button;
break;
case RATBAG_BUTTON_ACTION_TYPE_MACRO:
@@ -592,9 +588,9 @@ steelseries_write_buttons(struct ratbag_profile *profile)
break;
}
code = ratbag_hidraw_get_keyboard_usage_from_keycode(
const uint8_t keyboard_code = ratbag_hidraw_get_keyboard_usage_from_keycode(
device, key);
if (code) {
if (keyboard_code) {
if (is_senseiraw) {
msg.msg.parameters[idx] = STEELSERIES_BUTTON_KEY;
} else {
@@ -618,12 +614,12 @@ steelseries_write_buttons(struct ratbag_profile *profile)
msg.msg.parameters[++idx] = 0xE7;
}
msg.msg.parameters[idx + 1] = code;
msg.msg.parameters[idx + 1] = keyboard_code;
} else {
code = ratbag_hidraw_get_consumer_usage_from_keycode(
const uint16_t consumer_code = ratbag_hidraw_get_consumer_usage_from_keycode(
device, action->action.key.key);
msg.msg.parameters[idx] = STEELSERIES_BUTTON_CONSUMER;
msg.msg.parameters[idx + 1] = code;
msg.msg.parameters[idx + 1] = (uint8_t)consumer_code;
}
break;
@@ -677,7 +673,7 @@ steelseries_write_led_v1(struct ratbag_led *led)
};
msg.msg.parameters[0] = STEELSERIES_ID_LED_EFFECT_SHORT;
msg.msg.parameters[1] = quirk == STEELSERIES_QUIRK_RIVAL100 ? 0x00 : led->index + 1;
msg.msg.parameters[1] = quirk == STEELSERIES_QUIRK_RIVAL100 ? 0x00 : (uint8_t)led->index + 1;
switch(led->mode) {
case RATBAG_LED_OFF:
@@ -712,7 +708,7 @@ steelseries_write_led_v1(struct ratbag_led *led)
if (quirk == STEELSERIES_QUIRK_SENSEIRAW) {
msg.msg.parameters[0] = STEELSERIES_ID_LED_INTENSITY_SHORT;
msg.msg.parameters[1] = led->index + 1;
msg.msg.parameters[1] = (uint8_t)led->index + 1;
if (led->mode == RATBAG_LED_OFF || led->brightness == 0) {
msg.msg.parameters[2] = 1;
} else {
@@ -722,7 +718,7 @@ steelseries_write_led_v1(struct ratbag_led *led)
} else {
if (quirk != STEELSERIES_QUIRK_RIVAL100) {
msg.msg.parameters[0] = STEELSERIES_ID_LED_COLOR_SHORT;
msg.msg.parameters[1] = led->index + 1;
msg.msg.parameters[1] = (uint8_t)led->index + 1;
} else {
msg.msg.parameters[0] = STEELSERIES_ID_LED_COLOR_SHORT_RIVAL100;
msg.msg.parameters[1] = 0x00;
@@ -799,7 +795,7 @@ construct_cycle_buffer(struct steelseries_led_cycle *cycle,
buf[spec->point_count_idx] = npoints;
/* this seems to be the minimum allowed */
duration = max(buf[spec->point_count_idx] * 330, cycle->duration);
duration = max((uint16_t)(buf[spec->point_count_idx] * 330), cycle->duration);
set_unaligned_le_u16(&buf[spec->duration_idx], duration);
}
@@ -826,7 +822,7 @@ steelseries_write_led_cycle(struct ratbag_led *led,
const struct ratbag_color blue = { 0x00, 0x00, 0xFF };
create_cycle(&cycle);
cycle.led_id = led->index;
cycle.led_id = (uint8_t)led->index;
switch(led->mode) {
case RATBAG_LED_OFF:
@@ -863,7 +859,7 @@ steelseries_write_led_cycle(struct ratbag_led *led,
list_append(&cycle.points, &point[2].link);
list_append(&cycle.points, &point[3].link);
cycle.duration = led->ms;
cycle.duration = (uint16_t)led->ms;
break;
case RATBAG_LED_BREATHING:
point[0].color = black;
@@ -879,7 +875,7 @@ steelseries_write_led_cycle(struct ratbag_led *led,
list_append(&cycle.points, &point[1].link);
list_append(&cycle.points, &point[2].link);
cycle.duration = led->ms;
cycle.duration = (uint16_t)led->ms;
break;
default:
return -EINVAL;