Drop unifying src files, use hidpp10 instead

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2015-08-20 13:30:14 +10:00
parent e9230aef5f
commit 279bceb2d7
6 changed files with 24 additions and 197 deletions

View File

@@ -14,9 +14,7 @@ libratbag_la_SOURCES = \
libratbag-hidraw.h \
libratbag-util.c \
libratbag-private.h \
libratbag-util.h \
unifying.h \
unifying.c
libratbag-util.h
libratbag_la_LIBADD = $(LIBUDEV_LIBS)

View File

@@ -175,7 +175,7 @@ out_err:
return ret;
}
int hidpp10_toggle_individual_feature(int fd, struct unifying_device *dev, int feature_bit_r0, int feature_bit_r2) {
int hidpp10_toggle_individual_feature(int fd, struct hidpp10_device *dev, int feature_bit_r0, int feature_bit_r2) {
unsigned idx = dev->index;
union hidpp10_message mode = CMD_ENABLE_INDIVIDUAL_FEATURES(idx, GET_REGISTER_REQ);
int res;
@@ -212,7 +212,7 @@ int hidpp10_disconnect(int fd, int idx) {
}
void hidpp10_list_devices(int fd) {
struct unifying_device dev;
struct hidpp10_device dev;
int i, res;
for (i = 0; i < 6; ++i) {
@@ -224,7 +224,7 @@ void hidpp10_list_devices(int fd) {
}
}
static int hidpp10_get_device_info(int fd, struct unifying_device *dev) {
static int hidpp10_get_device_info(int fd, struct hidpp10_device *dev) {
unsigned idx = dev->index;
union hidpp10_message pairing_information = CMD_PAIRING_INFORMATION(idx, DEVICE_PAIRING_INFORMATION);
union hidpp10_message device_name = CMD_PAIRING_INFORMATION(idx, DEVICE_NAME);
@@ -271,7 +271,7 @@ static int hidpp10_get_device_info(int fd, struct unifying_device *dev) {
return 0;
}
int hidpp10_get_device_from_wpid(int fd, __u16 wpid, struct unifying_device *dev) {
int hidpp10_get_device_from_wpid(int fd, __u16 wpid, struct hidpp10_device *dev) {
int i, res;
for (i = 0; i < 6; i++) {
@@ -288,7 +288,7 @@ int hidpp10_get_device_from_wpid(int fd, __u16 wpid, struct unifying_device *dev
return res;
}
int hidpp10_get_device_from_idx(int fd, int idx, struct unifying_device *dev) {
int hidpp10_get_device_from_idx(int fd, int idx, struct hidpp10_device *dev) {
dev->index = idx;
return hidpp10_get_device_info(fd, dev);
}

View File

@@ -27,7 +27,6 @@
*/
#include <debug.h>
#include <unifying.h>
#ifndef HIDPP_10_H
#define HIDPP_10_H
@@ -140,6 +139,17 @@
} \
}
struct hidpp10_device {
unsigned index;
char name[15];
__u16 wpid;
__u8 report_interval;
__u8 device_type;
__u8 fw_major;
__u8 fw_minor;
__u16 build;
};
struct _hidpp10_message {
__u8 report_id;
__u8 device_idx;
@@ -158,10 +168,10 @@ union hidpp10_message {
int hidpp10_request_command(int fd, union hidpp10_message *msg);
int hidpp10_toggle_individual_feature(int fd, struct unifying_device *dev, int feature_bit_r0, int feature_bit_r2);
int hidpp10_toggle_individual_feature(int fd, struct hidpp10_device *dev, int feature_bit_r0, int feature_bit_r2);
int hidpp10_open_lock(int fd);
int hidpp10_disconnect(int fd, int idx);
void hidpp10_list_devices(int fd);
int hidpp10_get_device_from_wpid(int fd, __u16 wpid, struct unifying_device *dev);
int hidpp10_get_device_from_idx(int fd, int idx, struct unifying_device *dev);
int hidpp10_get_device_from_wpid(int fd, __u16 wpid, struct hidpp10_device *dev);
int hidpp10_get_device_from_idx(int fd, int idx, struct hidpp10_device *dev);
#endif /* HIDPP_10_H */

View File

@@ -31,6 +31,10 @@
#define USB_VENDOR_ID_ETEKCITY 0x1ea7
#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_UNIFYING_RECEIVER 0xc52b
#define USB_DEVICE_ID_UNIFYING_RECEIVER2 0xc532
#define BUS_ANY 0xffff
#define VENDOR_ANY 0xffff

View File

@@ -1,126 +0,0 @@
/*
* Logitech Unifying Receiver library.
*
* Copyright 2013 Benjamin Tissoires <benjamin.tissoires@gmail.com>
* 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 <linux/types.h>
#include <linux/input.h>
#include <linux/hidraw.h>
#include <sys/ioctl.h>
#include <unifying.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#define DEV_DIR "/dev"
#define HIDRAW_DEV_NAME "hidraw"
int unifying_open_receiver(const char *hidraw) {
struct hidraw_devinfo info;
int fd, res;
/* Open the Device with non-blocking reads. */
fd = open(hidraw, O_RDWR);
if (fd < 0) {
perror("Unable to open device");
goto out_err;
}
/* Get Raw Info */
res = ioctl(fd, HIDIOCGRAWINFO, &info);
if (res < 0) {
perror("error while getting info from device");
} else {
/* Check if the device is an Unifying receiver */
if (info.bustype != BUS_USB ||
info.vendor != USB_VENDOR_ID_LOGITECH ||
(info.product != USB_DEVICE_ID_UNIFYING_RECEIVER &&
info.product != USB_DEVICE_ID_UNIFYING_RECEIVER_2))
goto out_err;
}
return fd;
out_err:
if (fd >= 0)
close(fd);
return fd >= 0 ? -1 : fd;
}
/**
* Filter for the AutoDevProbe scandir on /dev.
*
* @param dir The current directory entry provided by scandir.
*
* @return Non-zero if the given directory entry starts with "hidraw", or zero
* otherwise.
*/
static int is_hidraw_device(const struct dirent *dir) {
return strncmp(HIDRAW_DEV_NAME, dir->d_name, 6) == 0;
}
/**
* Scans all /dev/hidraw*, open the first unifying receiver.
*
* @return The hidraw device file descriptor of the first unifying receiver.
*/
int unifying_find_receiver(void) {
struct dirent **namelist;
int fd = -1;
char fname[64];
int i, ndev;
ndev = scandir(DEV_DIR, &namelist, is_hidraw_device, alphasort);
if (ndev <= 0)
return fd;
for (i = 0; i < ndev; i++)
{
if (fd < 0) {
snprintf(fname, sizeof(fname),
"%s/%s", DEV_DIR, namelist[i]->d_name);
fd = unifying_open_receiver(fname);
}
free(namelist[i]);
}
free(namelist);
if (fd >= 0)
printf("Using %s as the Unifying receiver.\n", fname);
else
printf("Unable to find an Unifying receiver.\n");
return fd;
}

View File

@@ -1,59 +0,0 @@
/*
* Logitech Unifying Receiver library - headers file.
*
* Copyright 2013 Benjamin Tissoires <benjamin.tissoires@gmail.com>
* 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
*/
#ifndef UNIFYING_H
#define UNIFYING_H
#define USB_VENDOR_ID_LOGITECH (__u32)0x046d
#define USB_DEVICE_ID_UNIFYING_RECEIVER (__s16)0xc52b
#define USB_DEVICE_ID_UNIFYING_RECEIVER_2 (__s16)0xc532
struct unifying_device {
unsigned index;
char name[15];
__u16 wpid;
__u8 report_interval;
__u8 device_type;
__u8 fw_major;
__u8 fw_minor;
__u16 build;
};
int unifying_open_receiver(const char *hidraw);
/**
* Scans all /dev/hidraw*, open the first unifying receiver.
*
* @return The hidraw device file descriptor of the first unifying receiver.
*/
int unifying_find_receiver(void);
#endif /* UNIFYING_H */