2021-04-04 21:04:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <libusb-1.0/libusb.h>
|
|
|
|
|
#include <hidapi/hidapi.h>
|
|
|
|
|
|
2021-04-09 20:48:59 +01:00
|
|
|
/*
|
|
|
|
|
* The code below was extracted from the HIDAPI library. Third-party license may apply here.
|
|
|
|
|
*
|
|
|
|
|
* https://github.com/signal11/hidapi
|
|
|
|
|
*/
|
2021-06-22 23:52:31 +01:00
|
|
|
struct hid_device_
|
|
|
|
|
{
|
2021-04-09 20:33:24 +01:00
|
|
|
// Handle to the actual device.
|
2021-04-04 21:04:12 +01:00
|
|
|
libusb_device_handle* device_handle;
|
|
|
|
|
|
2021-04-09 20:33:24 +01:00
|
|
|
// Endpoint information
|
2021-04-04 21:04:12 +01:00
|
|
|
int input_endpoint;
|
|
|
|
|
int output_endpoint;
|
|
|
|
|
int input_ep_max_packet_size;
|
|
|
|
|
|
2021-04-09 20:33:24 +01:00
|
|
|
// The interface number of the HID
|
2021-04-04 21:04:12 +01:00
|
|
|
int interface;
|
|
|
|
|
|
2021-04-09 20:33:24 +01:00
|
|
|
// Indexes of Strings
|
2021-04-04 21:04:12 +01:00
|
|
|
int manufacturer_index;
|
|
|
|
|
int product_index;
|
|
|
|
|
int serial_index;
|
|
|
|
|
|
2021-04-09 20:33:24 +01:00
|
|
|
// Whether blocking reads are used
|
|
|
|
|
int blocking; // boolean
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2021-04-09 20:33:24 +01:00
|
|
|
// Read thread objects
|
2021-04-04 21:04:12 +01:00
|
|
|
pthread_t thread;
|
2021-04-09 20:33:24 +01:00
|
|
|
pthread_mutex_t mutex; // Protects input_reports
|
2021-04-04 21:04:12 +01:00
|
|
|
pthread_cond_t condition;
|
2021-04-09 20:33:24 +01:00
|
|
|
pthread_barrier_t barrier; // Ensures correct startup sequence
|
2021-04-04 21:04:12 +01:00
|
|
|
int shutdown_thread;
|
|
|
|
|
int cancelled;
|
|
|
|
|
struct libusb_transfer* transfer;
|
|
|
|
|
|
2021-04-09 20:33:24 +01:00
|
|
|
// List of received input reports.
|
2021-04-04 21:04:12 +01:00
|
|
|
struct input_report* input_reports;
|
|
|
|
|
};
|