hyperion.ng/libsrc/leddevice/dev_rpi_pwm/LedDeviceWS281x.h
LordGrey 8a785e70c8
LED-Device updates (#1315)
* SPI Fix - Free allocated memory in case of invert

* Remove development statement

* UI updates

* Minor corrections

* Tpm2net Fix - Free allocated memory

* LGTM Finding

* Add config directory and user type to SysInfo

* WS281x - Ensure that device runs with root priviliges

* WS281x - Update DMA defauls as per rpi_ws281x recommendation

* Support Sysinfo for Qt < 5.10

* Address LGTM finding
2021-09-15 10:31:56 +02:00

82 lines
1.8 KiB
C++

#ifndef LEDEVICEWS281X_H
#define LEDEVICEWS281X_H
// LedDevice includes
#include <leddevice/LedDevice.h>
#include <ws2811.h>
///
/// Implementation of the LedDevice interface for writing to WS281x LED-device via pwm.
///
class LedDeviceWS281x : public LedDevice
{
public:
///
/// @brief Constructs an WS281x LED-device
///
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceWS281x(const QJsonObject &deviceConfig);
///
/// @brief Destructor of the LedDevice
///
~LedDeviceWS281x() override;
///
/// @brief Destructor of the LedDevice
///
static LedDevice* construct(const QJsonObject &deviceConfig);
///
/// @brief Discover WS281x devices available (for configuration).
///
/// @param[in] params Parameters used to overwrite discovery default behaviour
///
/// @return A JSON structure holding a list of devices found
///
QJsonObject discover(const QJsonObject& params) override;
protected:
///
/// @brief Initialise the device's configuration
///
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
bool init(const QJsonObject &deviceConfig) override;
///
/// @brief Opens the output device.
///
/// @return Zero on success (i.e. device is ready), else negative
///
int open() override;
///
/// @brief Closes the output device.
///
/// @return Zero on success (i.e. device is closed), else negative
///
int close() override;
///
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
int write(const std::vector<ColorRgb> & ledValues) override;
private:
ws2811_t _led_string;
int _channel;
RGBW::WhiteAlgorithm _whiteAlgorithm;
ColorRgbw _temp_rgbw;
};
#endif // LEDEVICEWS281X_H