From 42e5c40f93146e46c56488346f9fc597c465c3c5 Mon Sep 17 00:00:00 2001 From: Richard Sailer Date: Mon, 19 Aug 2019 05:55:11 +0200 Subject: [PATCH] introduce set_color_code_region() with sane error checking --- src/tuxedo_keyboard.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/tuxedo_keyboard.c b/src/tuxedo_keyboard.c index 1329a1f..aedfc21 100644 --- a/src/tuxedo_keyboard.c +++ b/src/tuxedo_keyboard.c @@ -373,6 +373,31 @@ static int set_color(u32 region, u32 color) return tuxedo_evaluate_wmi_method(SET_KB_LED, cmd, NULL); } +static int set_color_code_region(u32 region, u32 colorcode) +{ + int err; + if (0 == (err = set_color(region, colorcode))) { + // after succesfully setting color, update our state struct + // depending on which region was changed + switch (region) { + case REGION_LEFT: + kbd_led_state.color.left = colorcode; + break; + case REGION_CENTER: + kbd_led_state.color.center = colorcode; + break; + case REGION_RIGHT: + kbd_led_state.color.right = colorcode; + break; + case REGION_EXTRA: + kbd_led_state.color.extra = colorcode; + break; + } + } + + return err; +} + static int set_color_string_region(const char *color_string, size_t size, u32 region) { u32 colorcode;