G300: add support LEDs

This commit is contained in:
Thomas Hindoe Paaboel Andersen
2017-09-28 00:18:09 +02:00
committed by Thomas H. P. Andersen
parent e0de98ba01
commit 94e0842a06
2 changed files with 92 additions and 7 deletions

View File

@@ -25,9 +25,9 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1"
inkscape:cx="482.11115"
inkscape:cy="144.0202"
inkscape:zoom="2.8284271"
inkscape:cx="253.02787"
inkscape:cy="140.76165"
inkscape:document-units="px"
inkscape:current-layer="Buttons"
inkscape:document-rotation="0"
@@ -41,7 +41,7 @@
showborder="true"
inkscape:guide-bbox="true"
units="px"
inkscape:snap-global="true"
inkscape:snap-global="false"
inkscape:measure-start="200.26,379.645"
inkscape:measure-end="199.294,334.274">
<inkscape:grid
@@ -454,6 +454,55 @@
x="332.32617"
y="109.27355" />
</g>
<g
id="led0"
inkscape:label="#g4411"
style="fill:#eeee35;fill-opacity:1">
<g
id="g4457">
<path
id="led0-0"
style="color:#000000;display:inline;overflow:visible;opacity:1;fill:#eeeeec;fill-opacity:1;stroke:none;stroke-width:0.28991818;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal"
d="M 36.851726,81.915105 C 41.99239,103.21594 40.604019,101.71476 43.62439,106.21567 44.61563,98.208963 38.156084,80.727537 35.152327,69.797094 Z"
inkscape:label="#path5630"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
<path
id="led0-1"
style="color:#000000;display:inline;overflow:visible;opacity:1;fill:#eeeeec;fill-opacity:1;stroke:none;stroke-width:0.28991818;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal"
d="M 93.039402,81.561768 C 87.898738,102.8626 89.287109,101.36142 86.266738,105.86233 85.275498,97.855627 91.735044,80.3742 94.738801,69.443757 Z"
inkscape:label="#path5630"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
</g>
</g>
<g
style="display:inline"
id="led0-path"
inkscape:label="#g161"
transform="matrix(0.26458333,0,0,0.26458333,38.838971,19.46058)">
<path
inkscape:connector-curvature="0"
id="path877"
d="M 343.20703,290.50577 H 208.64438 l -18.97696,-18.97696"
style="color:#000000;display:inline;overflow:visible;opacity:1;fill:none;fill-opacity:1;stroke:#888a85;stroke-width:1;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal"
sodipodi:nodetypes="ccc" />
<rect
y="269.96875"
x="188.28125"
height="6.999999"
width="6.999999"
id="rect879"
style="color:#000000;display:inline;overflow:visible;opacity:1;fill:#2e3436;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal" />
<rect
inkscape:label="#rect881"
y="290.00577"
x="343.20703"
height="1"
width="1"
id="led0-leader"
style="color:#000000;text-align:start;display:inline;overflow:visible;fill:#888a85;fill-opacity:1;stroke:none;stroke-linecap:round" />
</g>
</g>
<g
inkscape:groupmode="layer"

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@@ -36,7 +36,7 @@
#define LOGITECH_G300_PROFILE_MAX 2
#define LOGITECH_G300_BUTTON_MAX 8
#define LOGITECH_G300_NUM_DPI 4
#define LOGITECH_G300_NUM_LED 0
#define LOGITECH_G300_NUM_LED 1
#define LOGITECH_G300_DPI_MIN 250
#define LOGITECH_G300_DPI_MAX 2500
@@ -63,10 +63,13 @@ struct logitech_g300_button {
struct logitech_g300_profile_report {
uint8_t id; /* F3, F4, F5 */
uint8_t led; /* 00=off, 01=red, 02=green, 03=yellow, 04=blue, 05=pink, 06=turquoise, 07=white */
uint8_t led_red :1;
uint8_t led_green :1;
uint8_t led_blue :1;
uint8_t unknown1 :5;
uint8_t frequency; /* 00=1000, 01=125, 02=250, 03=500 */
struct logitech_g300_resolution dpi_levels[LOGITECH_G300_NUM_DPI];
uint8_t unknown; /* dpi index for shift, but something else too */
uint8_t unknown2; /* dpi index for shift, but something else too */
struct logitech_g300_button buttons[LOGITECH_G300_BUTTON_MAX + 1];
} __attribute__((packed));
@@ -373,6 +376,25 @@ logitech_g300_read_button(struct ratbag_button *button)
}
}
static void
logitech_g300_read_led(struct ratbag_led *led)
{
struct ratbag_profile *profile = led->profile;
struct ratbag_device *device = profile->device;
struct logitech_g300_data *drv_data = device->drv_data;
struct logitech_g300_profile_data *pdata;
struct logitech_g300_profile_report *profile_report;
pdata = &drv_data->profile_data[profile->index];
profile_report = &pdata->report;
led->type = RATBAG_LED_TYPE_SIDE;
led->mode = RATBAG_LED_ON;
led->color.red = profile_report->led_red * 255;
led->color.green = profile_report->led_green * 255;
led->color.blue = profile_report->led_blue * 255;
}
static int
logitech_g300_test_hidraw(struct ratbag_device *device)
{
@@ -439,6 +461,8 @@ logitech_g300_write_profile(struct ratbag_profile *profile)
struct logitech_g300_profile_data *pdata;
struct logitech_g300_profile_report *report;
struct ratbag_button *button;
struct ratbag_led *led;
uint8_t *buf;
unsigned int hz, i;
int rc;
@@ -479,6 +503,17 @@ logitech_g300_write_profile(struct ratbag_profile *profile)
}
}
list_for_each(led, &profile->leds, link) {
if (!led->dirty)
continue;
/* Clamp the 8 bit colors to 1 bit */
report->led_red = led->color.red > 127;
report->led_green = led->color.green > 127;
report->led_blue = led->color.blue > 127;
}
buf = (uint8_t*)report;
rc = ratbag_hidraw_raw_request(device, report->id,
@@ -533,4 +568,5 @@ struct ratbag_driver logitech_g300_driver = {
.commit = logitech_g300_commit,
.set_active_profile = logitech_g300_set_active_profile,
.read_button = logitech_g300_read_button,
.read_led = logitech_g300_read_led,
};