led: Parse color values and pass them down the chain

We parse RGB color values as HEX ('#RRGGBB') and use those when a RGB
LED is available. Single color LEDs won't see a change.
This commit is contained in:
Guido Günther
2024-06-13 15:19:03 +02:00
parent efd088daa8
commit a4c35a8e61
10 changed files with 215 additions and 36 deletions
+1
View File
@@ -78,6 +78,7 @@ test_fbd_deps = [
# HW independent tests
fbd_tests = [
'fbd-feedback-led',
'fbd-feedback-profile',
'fbd-feedback-theme',
'fbd-event',
+65
View File
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2024 The Phosh Developers
*
* SPDX-License-Identifier: GPL-3.0+
*
* Author: Guido Günther <agx@sigxcpu.org>
*/
#define GMOBILE_USE_UNSTABLE_API
#include "fbd-feedback-led.c"
static void
test_fbd_feedback_led_parse_color (void)
{
FbdLedRgbColor rgb = { 0 };
g_assert_true (parse_hex_color ("#11aaBB", &rgb));
g_assert_cmpint (rgb.r, ==, 0x11);
g_assert_cmpint (rgb.g, ==, 0xaa);
g_assert_cmpint (rgb.b, ==, 0xbb);
g_assert_true (parse_hex_color ("#000000", &rgb));
g_assert_cmpint (rgb.r, ==, 0x00);
g_assert_cmpint (rgb.g, ==, 0x00);
g_assert_cmpint (rgb.b, ==, 0x00);
g_assert_false (parse_hex_color ("#1bc", &rgb));
g_assert_false (parse_hex_color ("11aaBB", &rgb));
g_assert_false (parse_hex_color ("", &rgb));
g_assert_false (parse_hex_color ("#", &rgb));
g_assert_false (parse_hex_color ("#QWERTY", &rgb));
}
static void
test_fbd_feedback_led_color_string_to_color (void)
{
FbdLedRgbColor rgb = { 0 };
g_assert_cmpint (color_string_to_color ("red", NULL), ==, FBD_FEEDBACK_LED_COLOR_RED);
g_assert_cmpint (color_string_to_color ("#11aaBB", &rgb), ==, FBD_FEEDBACK_LED_COLOR_RGB);
g_assert_cmpint (rgb.r, ==, 0x11);
g_assert_cmpint (rgb.g, ==, 0xaa);
g_assert_cmpint (rgb.b, ==, 0xbb);
g_assert_cmpint (color_string_to_color ("#00FF00", &rgb), ==, FBD_FEEDBACK_LED_COLOR_RGB);
g_assert_cmpint (rgb.r, ==, 0x00);
g_assert_cmpint (rgb.g, ==, 0xFF);
g_assert_cmpint (rgb.b, ==, 0x00);
}
gint
main (gint argc, gchar *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func("/feedbackd/fbd/feedback-led/parse-color", test_fbd_feedback_led_parse_color);
g_test_add_func("/feedbackd/fbd/feedback-led/color-string-to-color",
test_fbd_feedback_led_color_string_to_color);
return g_test_run();
}