diff --git a/src/Makefile.am b/src/Makefile.am index 759b17b7..05459d49 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,6 +6,7 @@ include_HEADERS = \ libratbag_la_SOURCES = \ debug.h \ driver-etekcity.c \ + driver-logitech-unifying.c \ hidpp10.c \ hidpp10.h \ libratbag.c \ diff --git a/src/driver-logitech-unifying.c b/src/driver-logitech-unifying.c new file mode 100644 index 00000000..d8fab88a --- /dev/null +++ b/src/driver-logitech-unifying.c @@ -0,0 +1,180 @@ +/* + * M705 button 6 toggler. + * + * Copyright 2013 Benjamin Tissoires + * Copyright 2013 Red Hat, Inc + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Based on the HID++ 1.0 documentation provided by Nestor Lopez Casado at: + * https://drive.google.com/folderview?id=0BxbRzx7vEV7eWmgwazJ3NUFfQ28&usp=sharing + */ + +#include "config.h" + +#include +#include +#include +#include +#include + +#include "hidpp10.h" + +#include "libratbag-private.h" +#include "libratbag-hidraw.h" + +struct unifying_data { + struct hidpp10_device *dev; +}; + +static void +unifying_read_button(struct ratbag_button *button) +{ +} + +static int +unifying_write_button(struct ratbag_button *button) +{ + struct ratbag_device *device = button->device; + struct unifying_data *data = ratbag_get_drv_data(device); + struct hidpp10_device *dev = data->dev; + + /* FIXME: this only toggles button 6 */ + + /* M705 with FW RR 17.01 - build 0017 */ + if (dev->fw_major == 0x17 && + dev->fw_minor == 0x01 && + dev->build == 0x0015) + hidpp10_toggle_individual_feature(device->hidraw_fd, + dev, + FEATURE_BIT_R0_SPECIAL_BUTTON_FUNCTION, + -1); + return -1; +} + +static int +unifying_has_capability(const struct ratbag_device *device, enum ratbag_capability cap) +{ + return 0; +} + +static int +unifying_current_profile(struct ratbag_device *device) +{ + return -1; +} + +static int +unifying_set_current_profile(struct ratbag_device *device, unsigned int index) +{ + return -1; +} + +static void +unifying_read_profile(struct ratbag_profile *profile, unsigned int index) +{ +} + +static int +unifying_write_profile(struct ratbag_profile *profile) +{ + return -1; +} + +static int +unifying_probe(struct ratbag_device *device, const struct ratbag_id id) +{ + int rc; + struct unifying_data *drv_data; + struct hidpp10_device dev; + + rc = ratbag_open_hidraw(device); + if (rc) { + log_error(device->ratbag, + "Can't open corresponding hidraw node: '%s' (%d)\n", + strerror(-rc), + rc); + return -ENODEV; + } + + drv_data = zalloc(sizeof(*drv_data)); + if (!drv_data) + return -ENODEV; + + rc = hidpp10_get_device_from_wpid(device->hidraw_fd, + id.id.product, + &dev); + if (rc) { + log_error(device->ratbag, + "Failed to get HID++1.0 device for %s\n", + device->name); + goto err; + } + + ratbag_set_drv_data(device, drv_data); + + device->num_profiles = 1; + device->num_buttons = 8; + + return rc; +err: + free(drv_data); + ratbag_set_drv_data(device, NULL); + return rc; +} + +static void +unifying_remove(struct ratbag_device *device) +{ + free(ratbag_get_drv_data(device)); +} + +static const struct ratbag_id unifying_table[] = { + {.id = { .bustype = BUS_USB, + .vendor = USB_VENDOR_ID_LOGITECH, + .product = USB_DEVICE_ID_LOGITECH_M705, + .version = VERSION_ANY }, + .data = 1, + }, + + {.id = { .bustype = BUS_USB, + .vendor = USB_VENDOR_ID_LOGITECH, + .product = USB_DEVICE_ID_LOGITECH_M570, + .version = VERSION_ANY }, + .data = 1, + }, + { }, +}; + +struct ratbag_driver logitech_unifying_driver = { + .name = "Logitech Unifying Receiver", + .table_ids = unifying_table, + .probe = unifying_probe, + .remove = unifying_remove, + .read_profile = unifying_read_profile, + .write_profile = unifying_write_profile, + .get_active_profile = unifying_current_profile, + .set_active_profile = unifying_set_current_profile, + .has_capability = unifying_has_capability, + .read_button = unifying_read_button, + .write_button = unifying_write_button, +}; diff --git a/src/libratbag-private.h b/src/libratbag-private.h index 72e389b4..52bef3cf 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -33,6 +33,7 @@ #define USB_DEVICE_ID_ETEKCITY_SCROLL_ALPHA 0x4011 #define USB_VENDOR_ID_LOGITECH 0x046d #define USB_DEVICE_ID_LOGITECH_M705 0x101b +#define USB_DEVICE_ID_LOGITECH_M570 0x1028 #define USB_DEVICE_ID_UNIFYING_RECEIVER 0xc52b #define USB_DEVICE_ID_UNIFYING_RECEIVER2 0xc532 @@ -252,6 +253,7 @@ void log_msg(struct ratbag *ratbag, /* list of all supported drivers */ struct ratbag_driver etekcity_driver; +struct ratbag_driver logitech_unifying_driver; #endif /* LIBRATBAG_PRIVATE_H */ diff --git a/src/libratbag.c b/src/libratbag.c index 39faeb3a..0e809e09 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -430,6 +430,7 @@ ratbag_create_context(const struct ratbag_interface *interface, ratbag->log_priority = RATBAG_LOG_PRIORITY_INFO; ratbag_register_driver(ratbag, &etekcity_driver); + ratbag_register_driver(ratbag, &logitech_unifying_driver); return ratbag; } diff --git a/uLogitech/src/m705_button6_toggler.c b/uLogitech/src/m705_button6_toggler.c deleted file mode 100644 index 84eac553..00000000 --- a/uLogitech/src/m705_button6_toggler.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * M705 button 6 toggler. - * - * Copyright 2013 Benjamin Tissoires - * Copyright 2013 Red Hat, Inc - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -/* - * Based on the HID++ 1.0 documentation provided by Nestor Lopez Casado at: - * https://drive.google.com/folderview?id=0BxbRzx7vEV7eWmgwazJ3NUFfQ28&usp=sharing - */ - -#include -#include -#include - -#include -#include - -int main(int argc, char **argv) -{ - struct unifying_device dev; - int fd; - int res; - - /* Open the Unifying Receiver. */ - if (argc == 1) - fd = unifying_find_receiver(); - else { - fd = unifying_open_receiver(argv[1]); - if (fd < 0) - perror("Unable to open device"); - } - - if (fd < 0) - return 1; - - res = hidpp10_get_device_from_wpid(fd, 0x101b, &dev); - - if (!res) { - printf("M705 found at index %d: fw RR %02x.%02x, build %04x\n", dev.index, dev.fw_major, dev.fw_minor, dev.build); - - /* M705 with FW RR 17.01 - build 0017 */ - if (dev.fw_major == 0x17 && - dev.fw_minor == 0x01 && - dev.build == 0x0015) - hidpp10_toggle_individual_feature(fd, &dev, FEATURE_BIT_R0_SPECIAL_BUTTON_FUNCTION, -1); - } - - close(fd); - return 0; -}