1
0
forked from drath/libratbag

hidraw: ratbag_hidraw_has_report() can also match the usage and usage page

Add a match against the usage page and the usage.
If we are not interested in this new match, we can just use 0.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
Benjamin Tissoires
2015-10-07 20:12:05 -04:00
parent d95885c52c
commit d5a20efd8b
6 changed files with 50 additions and 9 deletions

View File

@@ -781,7 +781,7 @@ etekcity_probe(struct ratbag_device *device, const struct ratbag_id id)
return -ENODEV;
}
if (!ratbag_hidraw_has_report(device, ETEKCITY_REPORT_ID_KEY_MAPPING)) {
if (!ratbag_hidraw_has_report(device, ETEKCITY_REPORT_ID_KEY_MAPPING, 0, 0)) {
ratbag_close_hidraw(device);
return -ENODEV;
}

View File

@@ -194,7 +194,7 @@ hidpp10drv_fill_from_profile(struct ratbag_device *device, struct hidpp10_device
static int
hidpp10drv_test_hidraw(struct ratbag_device *device)
{
return ratbag_hidraw_has_report(device, REPORT_ID_SHORT);
return ratbag_hidraw_has_report(device, REPORT_ID_SHORT, 0, 0);
}
static int

View File

@@ -434,7 +434,7 @@ hidpp20drv_20_probe(struct ratbag_device *device, const struct ratbag_id id)
static int
hidpp20drv_test_hidraw(struct ratbag_device *device)
{
return ratbag_hidraw_has_report(device, REPORT_ID_LONG);
return ratbag_hidraw_has_report(device, REPORT_ID_LONG, 0, 0);
}
static int

View File

@@ -917,7 +917,7 @@ roccat_probe(struct ratbag_device *device, const struct ratbag_id id)
return -ENODEV;
}
if (!ratbag_hidraw_has_report(device, ROCCAT_REPORT_ID_KEY_MAPPING)) {
if (!ratbag_hidraw_has_report(device, ROCCAT_REPORT_ID_KEY_MAPPING, 0, 0)) {
ratbag_close_hidraw(device);
return -ENODEV;
}

View File

@@ -275,17 +275,53 @@ ratbag_open_hidraw(struct ratbag_device *device)
return __ratbag_find_hidraw(device, hidraw_match_all, false);
}
static inline int
ratbag_hidraw_match_report(struct ratbag_hid_report *report,
unsigned int report_id,
unsigned int usage_page,
unsigned int usage)
{
if (usage && usage != report->usage)
return 0;
if (usage_page && usage_page != report->usage_page)
return 0;
return report->report_id == report_id;
}
int
ratbag_hidraw_has_report(struct ratbag_device *device, unsigned int report_id)
ratbag_hidraw_has_report(struct ratbag_device *device,
unsigned int report_id,
unsigned int usage_page,
unsigned int usage)
{
unsigned i;
if (report_id == 0)
return device->hidraw.reports[0].report_id == report_id;
if (ratbag_hidraw_match_report(&device->hidraw.reports[0],
report_id,
usage_page,
usage)) {
log_debug(device->ratbag,
"found matching report ID (0) with 0x%04x | 0x%04x\n",
device->hidraw.reports[0].usage_page,
device->hidraw.reports[0].usage);
return 1;
}
for (i = 0; i < device->hidraw.num_reports; i++) {
if (device->hidraw.reports[i].report_id == report_id)
if (ratbag_hidraw_match_report(&device->hidraw.reports[i],
report_id,
usage_page,
usage)) {
log_debug(device->ratbag,
"found matching report ID (%d) with 0x%04x | 0x%04x\n",
report_id,
device->hidraw.reports[i].usage_page,
device->hidraw.reports[i].usage);
return 1;
}
}
return 0;

View File

@@ -120,11 +120,16 @@ int ratbag_hidraw_read_input_report(struct ratbag_device *device, uint8_t *buf,
* Tells if a given device has the specified report ID.
*
* @param device the ratbag device which hidraw node is opened
* @param report_id the report ID we inquire about
* @param report_id the report ID we inquire about (0 means no report ID)
* @param usage_page the usage page we want to match with (0 ignores the match)
* @param usage the usage we want to match with (0 ignores the match)
*
* @return 1 if the device has the given report id, 0 otherwise
*/
int
ratbag_hidraw_has_report(struct ratbag_device *device, unsigned int report_id);
ratbag_hidraw_has_report(struct ratbag_device *device,
unsigned int report_id,
unsigned int usage_page,
unsigned int usage);
#endif /* LIBRATBAG_HIDRAW_H */