From 81dfec8f797ec4b769511737e06d401a5106afd4 Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Tue, 15 Sep 2015 23:39:28 +0200 Subject: [PATCH] hidpp10: Add support for get/set of led color For supported devices this can get and set the led colors in RGB. This patch just adds the support in the lib. Later patches will add it to the driver and expose it in libratbag. --- src/hidpp10.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/hidpp10.h | 14 ++++++++++++ 2 files changed, 73 insertions(+) diff --git a/src/hidpp10.c b/src/hidpp10.c index 3f4a9eeb..609299ea 100644 --- a/src/hidpp10.c +++ b/src/hidpp10.c @@ -596,6 +596,65 @@ hidpp10_set_led_status(struct hidpp10_device *dev, return res; } +/* -------------------------------------------------------------------------- */ +/* 0x57: LED Color */ +/* -------------------------------------------------------------------------- */ + +#define __CMD_LED_COLOR 0x57 + +#define CMD_LED_COLOR(idx, sub) { \ + .msg = { \ + .report_id = REPORT_ID_SHORT, \ + .device_idx = idx, \ + .sub_id = sub, \ + .address = __CMD_LED_COLOR, \ + .parameters = {0x00, 0x00, 0x00 }, \ + } \ +} + +int +hidpp10_get_led_color(struct hidpp10_device *dev, + uint8_t *red, + uint8_t *green, + uint8_t *blue) +{ + unsigned idx = dev->index; + union hidpp10_message led_color = CMD_LED_COLOR(idx, GET_REGISTER_REQ); + int res; + + log_raw(dev->ratbag_device->ratbag, "Fetching LED color\n"); + + res = hidpp10_request_command(dev, &led_color); + if (res) + return res; + + *red = led_color.msg.parameters[0]; + *green = led_color.msg.parameters[1]; + *blue = led_color.msg.parameters[2]; + + return 0; +} + +int +hidpp10_set_led_color(struct hidpp10_device *dev, + uint8_t red, + uint8_t green, + uint8_t blue) +{ + unsigned idx = dev->index; + union hidpp10_message led_color = CMD_LED_COLOR(idx, SET_REGISTER_REQ); + int res; + + log_raw(dev->ratbag_device->ratbag, "Setting LED color\n"); + + led_color.msg.parameters[0] = red; + led_color.msg.parameters[1] = green; + led_color.msg.parameters[2] = blue; + + res = hidpp10_request_command(dev, &led_color); + return res; +} + /* -------------------------------------------------------------------------- */ /* 0x61: Optical Sensor Settings */ /* -------------------------------------------------------------------------- */ diff --git a/src/hidpp10.h b/src/hidpp10.h index c1f2f0c8..6e161a87 100644 --- a/src/hidpp10.h +++ b/src/hidpp10.h @@ -177,6 +177,20 @@ int hidpp10_set_led_status(struct hidpp10_device *dev, const bool led[4]); +/* -------------------------------------------------------------------------- */ +/* 0x57: LED Color */ +/* -------------------------------------------------------------------------- */ +int +hidpp10_get_led_color(struct hidpp10_device *dev, + uint8_t *red, + uint8_t *green, + uint8_t *blue); +int +hidpp10_set_led_color(struct hidpp10_device *dev, + uint8_t red, + uint8_t green, + uint8_t blue); + /* -------------------------------------------------------------------------- */ /* 0x61: Optical Sensor Settings */ /* -------------------------------------------------------------------------- */