2020-07-12 20:27:56 +02:00
|
|
|
#ifndef PROVIDERHID_H
|
|
|
|
#define PROVIDERHID_H
|
2015-11-08 16:26:55 +01:00
|
|
|
|
|
|
|
// 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:
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Constructs a HID (USB) LED-device
|
2015-11-08 16:26:55 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param deviceConfig Device's configuration as JSON-Object
|
2015-11-08 16:26:55 +01:00
|
|
|
///
|
2020-08-08 00:21:19 +02:00
|
|
|
ProviderHID(const QJsonObject &deviceConfig);
|
2015-11-08 16:26:55 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Destructor of the LedDevice
|
2015-11-08 16:26:55 +01:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
~ProviderHID() override;
|
2015-11-08 16:26:55 +01:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Discover HIB (USB) devices available (for configuration).
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
/// @param[in] params Parameters used to overwrite discovery default behaviour
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return A JSON structure holding a list of devices found
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
QJsonObject discover(const QJsonObject& params) override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Initialise the device's configuration
|
|
|
|
///
|
|
|
|
/// @param[in] deviceConfig the JSON device configuration
|
|
|
|
/// @return True, if success
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool init(const QJsonObject &deviceConfig) override;
|
2016-08-23 20:07:12 +02:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Opens the output device.
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return Zero on success (i.e. device is ready), else negative
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int open() override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2015-11-08 16:26:55 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Closes the output device.
|
2015-11-08 16:26:55 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return Zero on success (i.e. device is closed), else negative
|
2015-11-08 16:26:55 +01:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int close() override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
|
|
|
/// @brief Write the given bytes to the HID-device
|
|
|
|
///
|
|
|
|
/// @param[in[ size The length of the data
|
|
|
|
/// @param[in] data The data
|
|
|
|
/// @return Zero on success, else negative
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
int writeBytes(unsigned size, const uint8_t *data);
|
2015-11-08 16:26:55 +01:00
|
|
|
|
|
|
|
// 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();
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2015-11-08 16:26:55 +01:00
|
|
|
};
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
#endif // PROVIDERHID_H
|