2020-07-12 20:27:56 +02:00
|
|
|
#ifndef LEDEVICETINKERFORGE_H
|
|
|
|
#define LEDEVICETINKERFORGE_H
|
2014-03-04 20:38:54 +01:00
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
// Hyperion-Leddevice includes
|
|
|
|
#include <leddevice/LedDevice.h>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <tinkerforge/ip_connection.h>
|
|
|
|
#include <tinkerforge/bricklet_led_strip.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
class LedDeviceTinkerforge : public LedDevice
|
|
|
|
{
|
|
|
|
public:
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Constructs a Tinkerforge 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 LedDeviceTinkerforge(const QJsonObject &deviceConfig);
|
|
|
|
|
2020-08-08 23:12:43 +02:00
|
|
|
~LedDeviceTinkerforge() override;
|
2014-03-04 20:38:54 +01: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
|
2020-02-10 15:21:58 +01:00
|
|
|
static LedDevice* construct(const QJsonObject &deviceConfig);
|
2014-03-04 20:38:54 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Initialise the device's configuration
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @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
|
|
|
|
2014-03-04 20:38:54 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Opens a connection to the master bricklet and the led strip bricklet.
|
2014-03-04 20:38:54 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return Zero on success (i.e. device is ready), else negative
|
2014-03-04 20:38:54 +01:00
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
int open() override;
|
2014-03-04 20:38:54 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Writes the RGB-Color values to the LEDs.
|
2014-03-04 20:38:54 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param[in] ledValues The RGB-color per LED
|
|
|
|
/// @return Zero on success, else negative
|
2014-03-04 20:38:54 +01: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:
|
2014-03-04 20:38:54 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// Writes the data to the LED strip bricklet
|
2014-03-04 20:38:54 +01:00
|
|
|
int transferLedData(LEDStrip *ledstrip, unsigned int index, unsigned int length, uint8_t *redChannel, uint8_t *greenChannel, uint8_t *blueChannel);
|
|
|
|
|
|
|
|
/// The host of the master brick
|
2017-03-04 22:17:42 +01:00
|
|
|
QString _host;
|
2014-03-04 20:38:54 +01:00
|
|
|
|
|
|
|
/// The port of the master brick
|
2016-08-23 20:07:12 +02:00
|
|
|
uint16_t _port;
|
2014-03-04 20:38:54 +01:00
|
|
|
|
|
|
|
/// The uid of the led strip bricklet
|
2017-03-04 22:17:42 +01:00
|
|
|
QString _uid;
|
2014-03-04 20:38:54 +01:00
|
|
|
|
|
|
|
/// The interval/rate
|
2016-08-23 20:07:12 +02:00
|
|
|
unsigned _interval;
|
2014-03-04 20:38:54 +01:00
|
|
|
|
|
|
|
/// ip connection handle
|
|
|
|
IPConnection *_ipConnection;
|
|
|
|
|
|
|
|
/// led strip handle
|
|
|
|
LEDStrip *_ledStrip;
|
|
|
|
|
|
|
|
/// buffer for red channel led data
|
|
|
|
std::vector<uint8_t> _redChannel;
|
|
|
|
|
|
|
|
/// buffer for red channel led data
|
|
|
|
std::vector<uint8_t> _greenChannel;
|
|
|
|
|
|
|
|
/// buffer for red channel led data
|
|
|
|
std::vector<uint8_t> _blueChannel;
|
|
|
|
|
|
|
|
/// buffer size of the color channels
|
|
|
|
unsigned int _colorChannelSize;
|
|
|
|
|
|
|
|
};
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
#endif // LEDEVICETINKERFORGE_H
|