mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-08 07:33:53 +01:00
Add ratbagd_led_has_mode() and the required dbus additions
To be able to query which modes are available. Exposed via ratbagctl as ./build/ratbagctl.devel led 0 capabilities event4 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -295,6 +295,10 @@ hidpp20drv_read_led_1300(struct ratbag_led *led, struct hidpp20drv_data* data)
|
||||
default:
|
||||
led->mode = RATBAG_LED_ON;
|
||||
}
|
||||
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_ON);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_BREATHING);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_OFF);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -332,6 +336,11 @@ hidpp20drv_read_led_8070(struct ratbag_led *led, struct hidpp20drv_data* drv_dat
|
||||
led->hz = h_led->period; /* FIXME: should be ceil(1000.0 / h_led->period), but that would be very small */
|
||||
led->brightness = h_led->brightness * 255 / 100;
|
||||
led->colordepth = RATBAG_LED_COLORDEPTH_RGB_888;
|
||||
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_ON);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_CYCLE);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_BREATHING);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_OFF);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -106,6 +106,11 @@ test_read_led(struct ratbag_led *led)
|
||||
struct ratbag_test_profile *p = &d->profiles[led->profile->index];
|
||||
struct ratbag_test_led t_led = p->leds[led->index];
|
||||
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_ON);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_CYCLE);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_BREATHING);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_OFF);
|
||||
|
||||
switch (t_led.mode) {
|
||||
case RATBAG_LED_ON:
|
||||
led->mode = RATBAG_LED_ON;
|
||||
|
||||
@@ -274,6 +274,7 @@ struct ratbag_led {
|
||||
unsigned index;
|
||||
enum ratbag_led_type type;
|
||||
enum ratbag_led_mode mode;
|
||||
uint32_t modes; /**< supported modes */
|
||||
struct ratbag_color color;
|
||||
enum ratbag_led_colordepth colordepth;
|
||||
unsigned int hz; /**< rate of action in hz */
|
||||
@@ -535,6 +536,16 @@ ratbag_resolution_set_cap(struct ratbag_resolution *res,
|
||||
res->capabilities = (1 << cap);
|
||||
}
|
||||
|
||||
static inline void
|
||||
ratbag_led_set_mode_capability(struct ratbag_led *led,
|
||||
enum ratbag_led_mode mode)
|
||||
{
|
||||
assert(mode <= RATBAG_LED_BREATHING);
|
||||
assert(mode < sizeof(led->modes) * 8);
|
||||
|
||||
led->modes |= (1 << mode);
|
||||
}
|
||||
|
||||
/* list of all supported drivers */
|
||||
struct ratbag_driver etekcity_driver;
|
||||
struct ratbag_driver hidpp20_driver;
|
||||
|
||||
@@ -1458,6 +1458,18 @@ ratbag_led_get_type(struct ratbag_led *led)
|
||||
return led->type;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT int
|
||||
ratbag_led_has_mode(struct ratbag_led *led,
|
||||
enum ratbag_led_mode mode)
|
||||
{
|
||||
assert(mode <= RATBAG_LED_BREATHING);
|
||||
|
||||
if (mode == RATBAG_LED_OFF)
|
||||
return 1;
|
||||
|
||||
return (led->modes & (1 << mode));
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT struct ratbag_color
|
||||
ratbag_led_get_color(struct ratbag_led *led)
|
||||
{
|
||||
|
||||
@@ -1182,6 +1182,23 @@ ratbag_profile_get_led(struct ratbag_profile *profile, unsigned int index);
|
||||
*/
|
||||
enum ratbag_led_type
|
||||
ratbag_led_get_type(struct ratbag_led *led);
|
||||
|
||||
/**
|
||||
* @ingroup led
|
||||
*
|
||||
* This function returns true if the given mode is supported by the LED, or
|
||||
* false otherwise.
|
||||
*
|
||||
* @param led A previously initialized ratbag LED
|
||||
* @param mode The LED mode @ref ratbag_led_mode to check for
|
||||
* @return True if supported, false otherwise
|
||||
*
|
||||
* @see ratbag_led_set_mode
|
||||
*/
|
||||
int
|
||||
ratbag_led_has_mode(struct ratbag_led *led,
|
||||
enum ratbag_led_mode mode);
|
||||
|
||||
/**
|
||||
* @ingroup led
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user