2020-07-12 20:27:56 +02:00
|
|
|
#ifndef LEDEVICELIGHTPACK_H
|
|
|
|
#define LEDEVICELIGHTPACK_H
|
2013-11-13 20:15:53 +01:00
|
|
|
|
|
|
|
// stl includes
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
// libusb include
|
|
|
|
#include <libusb.h>
|
|
|
|
|
|
|
|
// Hyperion includes
|
2013-12-17 19:50:15 +01:00
|
|
|
#include <leddevice/LedDevice.h>
|
2013-11-13 20:15:53 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// LedDevice implementation for a lightpack device (http://code.google.com/p/light-pack/)
|
|
|
|
///
|
|
|
|
class LedDeviceLightpack : public LedDevice
|
|
|
|
{
|
|
|
|
public:
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2013-11-13 20:15:53 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Constructs a Lightpack LED-device
|
2013-11-13 20:15:53 +01:00
|
|
|
///
|
2016-07-13 11:18:12 +02:00
|
|
|
/// @param serialNumber serial output device
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
explicit LedDeviceLightpack(const QString & serialNumber = "");
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Constructs a Lightpack LED-device
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param deviceConfig Device's configuration as JSON-Object
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-02-10 15:21:58 +01:00
|
|
|
explicit LedDeviceLightpack(const QJsonObject &deviceConfig);
|
2016-08-23 20:07:12 +02:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Destructor of the LedDevice
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
~LedDeviceLightpack() override;
|
2016-08-23 20:07:12 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
|
|
|
/// @brief Constructs the LED-device
|
|
|
|
///
|
|
|
|
/// @param[in] deviceConfig Device's configuration as JSON-Object
|
|
|
|
/// @return LedDevice constructed
|
|
|
|
///
|
2016-10-13 21:59:58 +02:00
|
|
|
static LedDevice* construct(const QJsonObject &deviceConfig);
|
2013-11-13 20:15:53 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Initialise the device's configuration
|
2013-11-13 20:15:53 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param[in] deviceConfig the JSON device configuration
|
|
|
|
/// @return True, if success
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool init(const QJsonObject &deviceConfig) override;
|
2013-11-13 20:15:53 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Opens the output device.
|
2013-11-13 20:15:53 +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-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Closes the output device.
|
|
|
|
///
|
|
|
|
/// @return Zero on success (i.e. device is closed), else negative
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int close() override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Power-/turn off the Nanoleaf device.
|
2013-11-13 20:15:53 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return True if success
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool powerOff() override;
|
2013-11-17 15:51:42 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Writes the RGB-Color values to the LEDs.
|
2013-11-17 15:51:42 +01:00
|
|
|
///
|
|
|
|
/// @param[in] ledValues Array of RGB values
|
|
|
|
/// @param[in] size The number of RGB values
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return Zero on success, else negative
|
2013-11-17 15:51:42 +01:00
|
|
|
///
|
|
|
|
int write(const ColorRgb * ledValues, int size);
|
|
|
|
|
2013-11-13 23:16:09 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Get the serial number of the Lightpack
|
2013-11-13 23:16:09 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return Serial Number
|
|
|
|
/// ///
|
2017-03-04 22:17:42 +01:00
|
|
|
const QString & getSerialNumber() const;
|
2013-11-17 15:51:42 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
bool isOpen(){ return _isOpen; }
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
protected:
|
2013-11-13 20:15:53 +01:00
|
|
|
|
2016-09-23 08:49:22 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Writes the RGB-Color values to the LEDs.
|
2016-09-23 08:49:22 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param[in] ledValues The RGB-color per LED
|
|
|
|
/// @return Zero on success, else negative
|
2016-09-23 08:49:22 +02:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int write(const std::vector<ColorRgb> & ledValues) override;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
private:
|
2016-09-23 08:49:22 +02:00
|
|
|
|
2013-11-20 20:54:04 +01:00
|
|
|
///
|
|
|
|
/// Test if the device is a (or the) lightpack we are looking for
|
|
|
|
///
|
|
|
|
/// @return Zero on succes else negative
|
|
|
|
///
|
2017-03-04 22:17:42 +01:00
|
|
|
int testAndOpen(libusb_device * device, const QString & requestedSerialNumber);
|
2013-11-20 20:54:04 +01:00
|
|
|
|
2013-11-13 20:15:53 +01:00
|
|
|
/// write bytes to the device
|
|
|
|
int writeBytes(uint8_t *data, int size);
|
|
|
|
|
|
|
|
/// Disable the internal smoothing on the Lightpack device
|
|
|
|
int disableSmoothing();
|
|
|
|
|
2013-11-17 15:51:42 +01:00
|
|
|
struct Version
|
|
|
|
{
|
|
|
|
int majorVersion;
|
|
|
|
int minorVersion;
|
|
|
|
};
|
|
|
|
|
2013-11-13 20:15:53 +01:00
|
|
|
static libusb_device_handle * openDevice(libusb_device * device);
|
2017-03-04 22:17:42 +01:00
|
|
|
static QString getString(libusb_device * device, int stringDescriptorIndex);
|
2013-11-13 20:15:53 +01:00
|
|
|
|
|
|
|
/// libusb context
|
|
|
|
libusb_context * _libusbContext;
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
/// libusb device
|
|
|
|
libusb_device * _device;
|
|
|
|
|
2013-11-13 20:15:53 +01:00
|
|
|
/// libusb device handle
|
|
|
|
libusb_device_handle * _deviceHandle;
|
|
|
|
|
|
|
|
/// harware bus number
|
|
|
|
int _busNumber;
|
|
|
|
|
|
|
|
/// hardware address number
|
|
|
|
int _addressNumber;
|
|
|
|
|
|
|
|
/// device serial number
|
2017-03-04 22:17:42 +01:00
|
|
|
QString _serialNumber;
|
2013-11-13 20:15:53 +01:00
|
|
|
|
|
|
|
/// firmware version of the device
|
|
|
|
Version _firmwareVersion;
|
|
|
|
|
|
|
|
/// the number of bits per channel
|
|
|
|
int _bitsPerChannel;
|
2020-05-25 21:51:11 +02:00
|
|
|
|
2016-09-23 08:49:22 +02:00
|
|
|
/// count of real hardware leds
|
|
|
|
int _hwLedCount;
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
bool _isOpen;
|
2013-11-13 20:15:53 +01:00
|
|
|
};
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
#endif // LEDEVICELIGHTPACK_H
|