From 0c2bd445f484677bcdb62430bf5ad065eb67392f Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 8 Apr 2014 01:01:29 +0200 Subject: lib/hidpp20: implement hidpp20_get_version --- lib/hidpp20.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lib/hidpp20.c diff --git a/lib/hidpp20.c b/lib/hidpp20.c new file mode 100644 index 0000000..25e7a43 --- /dev/null +++ b/lib/hidpp20.c @@ -0,0 +1,54 @@ +/* + * HID++ 2.0 protocol details. + * + * Copyright (C) 2014 Peter Wu + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include "debug.h" +#include "hidpp.h" +#include "hidpp10.h" +#include "hidpp20.h" + +uint16_t hidpp20_get_version(int fd, uint8_t device_index) +{ + int r; + uint16_t ver = 0; + const uint8_t pingData = 0x14; + HidppMessage req = { + .report_id = HIDPP_SHORT, + .device_index = device_index, + .feature_id = 0x00, + .func = 0x14, + .params = { 0, 0, pingData } + }; + + assert(device_index >= 1 && device_index <= MAX_DEVICES); + + r = hidpp10_request(fd, &req, NULL, NULL); + if (r == 0 && req.params[2] == pingData) { + ver = (req.params[0] << 8) | req.params[1]; + } else if (r == HIDPP_ERR_INVALID_SUBID) { + ver = 0x0100; + } else { + trace_log("[ix=%02x] HID++ version unavailable, error=%i\n", + device_index, r); + } + + return ver; +} -- cgit v1.2.1