2015-11-08 16:26:55 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
// libusb include
|
|
|
|
#include <hidapi/hidapi.h>
|
|
|
|
|
|
|
|
// Leddevice includes
|
|
|
|
#include <leddevice/LedDevice.h>
|
|
|
|
|
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
/// The ProviderHID implements an abstract base-class for LedDevices using an HID-device.
|
2015-11-08 16:26:55 +01:00
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
class ProviderHID : public LedDevice
|
2015-11-08 16:26:55 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
///
|
2016-08-23 20:07:12 +02:00
|
|
|
/// Constructs specific LedDevice
|
2015-11-08 16:26:55 +01:00
|
|
|
///
|
2016-08-23 20:07:12 +02:00
|
|
|
/// @param deviceConfig json device config
|
2015-11-08 16:26:55 +01:00
|
|
|
///
|
2016-10-08 08:14:36 +02:00
|
|
|
ProviderHID();
|
2015-11-08 16:26:55 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Destructor of the LedDevice; closes the output device if it is open
|
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
virtual ~ProviderHID();
|
2015-11-08 16:26:55 +01:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
|
|
|
/// Sets configuration
|
|
|
|
///
|
|
|
|
/// @param deviceConfig the json device config
|
|
|
|
/// @return true if success
|
2016-10-08 08:14:36 +02:00
|
|
|
virtual bool init(const Json::Value &deviceConfig);
|
2016-08-23 20:07:12 +02:00
|
|
|
|
2015-11-08 16:26:55 +01:00
|
|
|
///
|
|
|
|
/// Opens and configures the output device
|
|
|
|
///
|
|
|
|
/// @return Zero on succes else negative
|
|
|
|
///
|
|
|
|
int open();
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Writes the given bytes to the HID-device and
|
|
|
|
*
|
|
|
|
* @param[in[ size The length of the data
|
|
|
|
* @param[in] data The data
|
|
|
|
*
|
|
|
|
* @return Zero on succes else negative
|
|
|
|
*/
|
|
|
|
int writeBytes(const unsigned size, const uint8_t *data);
|
|
|
|
|
|
|
|
// HID VID and PID
|
2016-08-23 20:07:12 +02:00
|
|
|
unsigned short _VendorId;
|
|
|
|
unsigned short _ProductId;
|
2016-09-23 08:49:22 +02:00
|
|
|
bool _useFeature;
|
2015-11-08 16:26:55 +01:00
|
|
|
|
|
|
|
/// libusb device handle
|
|
|
|
hid_device * _deviceHandle;
|
|
|
|
|
|
|
|
/// Sleep after the connect before continuing
|
2016-08-23 20:07:12 +02:00
|
|
|
int _delayAfterConnect_ms;
|
2015-11-08 16:26:55 +01:00
|
|
|
|
|
|
|
bool _blockedForDelay;
|
2016-08-23 20:07:12 +02:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
/// Unblock the device after a connection delay
|
|
|
|
void unblockAfterDelay();
|
2015-11-08 16:26:55 +01:00
|
|
|
};
|