led-multicolor: Scale to RGB colors to LEDs max brightness

Otherwise we might exceed max brightness and get -EINVAL.

Tested-by: Chris Vogel <chris@ween.de>
Reported-by: Chris Vogel <chris@ween.de>
Closes: https://gitlab.freedesktop.org/agx/feedbackd/-/issues/95
Signed-off-by: Guido Günther <agx@sigxcpu.org>
This commit is contained in:
Guido Günther
2025-12-29 17:33:53 +00:00
parent 704f93ef15
commit a108dda1be
2 changed files with 20 additions and 5 deletions
+9 -4
View File
@@ -15,6 +15,8 @@
#include <gio/gio.h>
#include <math.h>
#define LED_MULTI_INDEX_ATTR "multi_index"
#define LED_MULTI_INDEX_RED "red"
#define LED_MULTI_INDEX_GREEN "green"
@@ -132,11 +134,14 @@ fbd_dev_led_multicolor_set_color (FbdDevLed *led,
colors[priv->green_index] = 0;
colors[priv->blue_index] = max_brightness;
break;
case FBD_FEEDBACK_LED_COLOR_RGB:
colors[priv->red_index] = rgb->r;
colors[priv->green_index] = rgb->g;
colors[priv->blue_index] = rgb->b;
case FBD_FEEDBACK_LED_COLOR_RGB: {
float scale = max_brightness / 255.0;
/* RGB colors are 0..255 so we need to scale to 0..max_brightness */
colors[priv->red_index] = MIN (max_brightness, roundf (rgb->r * scale));
colors[priv->green_index] = MIN (max_brightness, roundf (rgb->g * scale));
colors[priv->blue_index] = MIN (max_brightness, roundf (rgb->b * scale));
break;
}
default:
g_warning("Unhandled color: %d\n", color);
return FALSE;
+11 -1
View File
@@ -38,7 +38,17 @@ if get_option('daemon')
'fbd-udev.c',
]
fbd_deps = [gio, gio_unix, glib, gmobile, gobject, gsound, gudev, json_glib]
fbd_deps = [
gio,
gio_unix,
glib,
gmobile,
gobject,
gsound,
gudev,
json_glib,
cc.find_library('m', required: false),
]
fbd_inc = [include_directories('.'), libfeedback_inc, dbus_inc]