2014-03-04 20:38:54 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// 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:
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
|
|
|
/// Constructs specific LedDevice
|
|
|
|
///
|
|
|
|
/// @param deviceConfig json device config
|
|
|
|
///
|
|
|
|
LedDeviceTinkerforge(const Json::Value &deviceConfig);
|
2014-03-04 20:38:54 +01:00
|
|
|
|
|
|
|
virtual ~LedDeviceTinkerforge();
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
|
|
|
/// Sets configuration
|
|
|
|
///
|
|
|
|
/// @param deviceConfig the json device config
|
|
|
|
/// @return true if success
|
|
|
|
bool setConfig(const Json::Value &deviceConfig);
|
|
|
|
|
|
|
|
/// constructs leddevice
|
|
|
|
static LedDevice* construct(const Json::Value &deviceConfig);
|
|
|
|
|
2014-03-04 20:38:54 +01:00
|
|
|
///
|
|
|
|
/// Attempts to open a connection to the master bricklet and the led strip bricklet.
|
|
|
|
///
|
|
|
|
/// @return Zero on succes else negative
|
|
|
|
///
|
|
|
|
int open();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Writes the colors to the led strip bricklet
|
|
|
|
///
|
|
|
|
/// @param ledValues The color value for each led
|
|
|
|
///
|
|
|
|
/// @return Zero on success else negative
|
|
|
|
///
|
|
|
|
virtual int write(const std::vector<ColorRgb> &ledValues);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Switches off the leds
|
|
|
|
///
|
|
|
|
/// @return Zero on success else negative
|
|
|
|
///
|
|
|
|
virtual int switchOff();
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
/// Writes the data to the led strip blicklet
|
|
|
|
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
|
2016-08-23 20:07:12 +02:00
|
|
|
std::string _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
|
2016-08-23 20:07:12 +02:00
|
|
|
std::string _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;
|
|
|
|
|
|
|
|
};
|