diff --git a/src/hidpp10.c b/src/hidpp10.c index 9e91ca4c..6ccd3702 100644 --- a/src/hidpp10.c +++ b/src/hidpp10.c @@ -835,7 +835,7 @@ hidpp10_fill_buttons(struct hidpp10_device *dev, button->keys.key = b->keyboard_keys.key; break; case PROFILE_BUTTON_TYPE_SPECIAL: - button->special.special = ffs(hidpp_get_unaligned_le_u16(&b->special.flags1)); + button->special.special = hidpp_get_unaligned_le_u16(&b->special.flags1); break; case PROFILE_BUTTON_TYPE_CONSUMER_CONTROL: button->consumer_control.consumer_control = @@ -993,6 +993,40 @@ hidpp10_get_profile(struct hidpp10_device *dev, int8_t number, struct hidpp10_pr return 0; } +static const enum ratbag_button_action_special hidpp10_profiles_specials[] = { + [0x00] = RATBAG_BUTTON_ACTION_SPECIAL_INVALID, + [0x01] = RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_LEFT, + [0x02] = RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_RIGHT, + [0x03] = RATBAG_BUTTON_ACTION_SPECIAL_BATTERY_LEVEL, + [0x04] = RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_UP, + [0x05 ... 0x07] = RATBAG_BUTTON_ACTION_SPECIAL_INVALID, + [0x08] = RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_DOWN, + [0x09] = RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_CYCLE_UP, + [0x0a ... 0x0f] = RATBAG_BUTTON_ACTION_SPECIAL_INVALID, + [0x11] = RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_CYCLE_UP, + + [0x12 ... 0xff] = RATBAG_BUTTON_ACTION_SPECIAL_INVALID, +}; + +enum ratbag_button_action_special +hidpp10_onboard_profiles_get_special(uint8_t code) +{ + return hidpp10_profiles_specials[code]; +} + +uint8_t +hidpp10_onboard_profiles_get_code_from_special(enum ratbag_button_action_special special) +{ + uint8_t i = 0; + + while (++i) { + if (hidpp10_profiles_specials[i] == special) + return i; + } + + return RATBAG_BUTTON_ACTION_SPECIAL_INVALID; +} + /* -------------------------------------------------------------------------- */ /* 0x51: LED Status */ /* -------------------------------------------------------------------------- */ diff --git a/src/hidpp10.h b/src/hidpp10.h index 2f6cf7c8..59cbe6f8 100644 --- a/src/hidpp10.h +++ b/src/hidpp10.h @@ -435,6 +435,13 @@ hidpp10_get_current_profile(struct hidpp10_device *dev, int8_t *current_profile) int hidpp10_get_profile(struct hidpp10_device *dev, int8_t number, struct hidpp10_profile *profile); + +enum ratbag_button_action_special +hidpp10_onboard_profiles_get_special(uint8_t code); + +uint8_t +hidpp10_onboard_profiles_get_code_from_special(enum ratbag_button_action_special special); + /* -------------------------------------------------------------------------- */ /* 0x51: LED Status */ /* -------------------------------------------------------------------------- */ diff --git a/src/libratbag.h b/src/libratbag.h index b6ed2312..c2917577 100644 --- a/src/libratbag.h +++ b/src/libratbag.h @@ -1139,6 +1139,9 @@ enum ratbag_button_action_special { /* second mode for buttons */ RATBAG_BUTTON_ACTION_SPECIAL_SECOND_MODE, + /* battery level */ + RATBAG_BUTTON_ACTION_SPECIAL_BATTERY_LEVEL, + }; /** diff --git a/tools/shared.c b/tools/shared.c index 8d0bb030..9ac94d66 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -115,6 +115,9 @@ const static struct map { /* Second mode for buttons */ { RATBAG_BUTTON_ACTION_SPECIAL_SECOND_MODE, "secondary mode" }, + /* battery level */ + { RATBAG_BUTTON_ACTION_SPECIAL_BATTERY_LEVEL, "battery level" }, + /* must be the last entry in the table */ { RATBAG_BUTTON_ACTION_SPECIAL_INVALID, NULL }, };