LED Device Features, Fixes and Refactoring (Resubmit PR855) (#875)

* Refactor LedDevices - Initial version
* Small renamings
* Add WLED as own device
* Lpd8806 Remove open() method
* remove dependency on Qt 5.10
* Lpd8806 Remove open() method
* Update WS281x
* Update WS2812SPI
* Add writeBlack for WLED powerOff
* WLED remove extra bracket
* Allow different Nanoleaf panel numbering sequence (Feature req.#827)
* build(deps): bump websocket-extensions from 0.1.3 to 0.1.4 in /docs (#826)
* Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4.
  - [Release notes](https://github.com/faye/websocket-extensions-node/releases)
  - [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md)
  - [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4)
* Fix typos
* Nanoleaf clean-up
* Yeelight support, generalize wizard elements
* Update Yeelight to handle quota in music mode
* Yeelight extend rage for extraTimeDarkness for testing
* Clean-up - Add commentary, Remove development debug statements
* Fix brightnessSwitchOffOnMinimum typo and default value
* Yeelight support restoreOriginalState, additional Fixes
* WLED - Remove UDP-Port, as it is not configurable
* Fix merging issue
* Remove QHostAddress::operator=(const QString&)' is deprecated
* Windows compile errors and (Qt 5.15 deprecation) warnings
* Fix order includes
* LedDeviceFile Support Qt5.7 and greater
* Windows compatibility and other Fixes
* Fix Qt Version compatability
* Rs232 - Resolve portname from unix /dev/ style, fix DMX sub-type support
* Disable WLED Wizard Button (until Wizard is available)
* Yeelight updates
* Add wrong log-type as per #505
* Fixes and Clean-up after clang-tidy report
* Fix udpe131 not enabled for generated CID
* Change timer into dynamic for Qt Thread-Affinity
* Hue clean-up and diyHue workaround
* Updates after review feedback by m-seker
* Add "chrono" includes
This commit is contained in:
LordGrey
2020-07-12 20:27:56 +02:00
committed by GitHub
parent 3b48d8c9d6
commit 7389068a66
125 changed files with 8864 additions and 3217 deletions

View File

@@ -4,7 +4,9 @@ LedDeviceAPA102::LedDeviceAPA102(const QJsonObject &deviceConfig)
: ProviderSpi()
{
_devConfig = deviceConfig;
_deviceReady = false;
_isDeviceReady = false;
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
}
LedDevice* LedDeviceAPA102::construct(const QJsonObject &deviceConfig)
@@ -14,10 +16,12 @@ LedDevice* LedDeviceAPA102::construct(const QJsonObject &deviceConfig)
bool LedDeviceAPA102::init(const QJsonObject &deviceConfig)
{
bool isInitOK = ProviderSpi::init(deviceConfig);
bool isInitOK = false;
if ( isInitOK )
// Initialise sub-class
if ( ProviderSpi::init(deviceConfig) )
{
const unsigned int startFrameSize = 4;
const unsigned int endFrameSize = qMax<unsigned int>(((_ledCount + 15) / 16), 4);
const unsigned int APAbufferSize = (_ledCount * 4) + startFrameSize + endFrameSize;
@@ -27,6 +31,9 @@ bool LedDeviceAPA102::init(const QJsonObject &deviceConfig)
_ledBuffer[1] = 0x00;
_ledBuffer[2] = 0x00;
_ledBuffer[3] = 0x00;
isInitOK = true;
}
return isInitOK;
}

View File

@@ -1,4 +1,5 @@
#pragma once
#ifndef LEDEVICEAPA102_H
#define LEDEVICEAPA102_H
// hyperion includes
#include "ProviderSpi.h"
@@ -9,26 +10,39 @@
class LedDeviceAPA102 : public ProviderSpi
{
public:
///
/// Constructs specific LedDevice
/// @brief Constructs an APA102 LED-device
///
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceAPA102(const QJsonObject &deviceConfig);
/// constructs leddevice
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
///
static LedDevice* construct(const QJsonObject &deviceConfig);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool init(const QJsonObject &deviceConfig) override;
private:
///
/// Writes the led color values to the led-device
/// @brief Initialise the device's configuration
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
virtual int write(const std::vector<ColorRgb> &ledValues) override;
virtual bool init(const QJsonObject &deviceConfig) override;
///
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> & ledValues) override;
};
#endif // LEDEVICEAPA102_H

View File

@@ -46,9 +46,12 @@ LedDeviceAPA104::LedDeviceAPA104(const QJsonObject &deviceConfig)
}
{
_devConfig = deviceConfig;
_deviceReady = false;
_isDeviceReady = false;
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
}
LedDevice* LedDeviceAPA104::construct(const QJsonObject &deviceConfig)
{
return new LedDeviceAPA104(deviceConfig);
@@ -58,12 +61,16 @@ bool LedDeviceAPA104::init(const QJsonObject &deviceConfig)
{
_baudRate_Hz = 2235000;
bool isInitOK = ProviderSpi::init(deviceConfig);
if ( isInitOK )
bool isInitOK = false;
// Initialise sub-class
if ( ProviderSpi::init(deviceConfig) )
{
WarningIf(( _baudRate_Hz < 2000000 || _baudRate_Hz > 2470000 ), _log, "SPI rate %d outside recommended range (2000000 -> 2470000)", _baudRate_Hz);
_ledBuffer.resize(_ledRGBCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00);
isInitOK = true;
}
return isInitOK;
}

View File

@@ -1,6 +1,7 @@
#pragma once
#ifndef LEDEVICEAPA104_H
#define LEDEVICEAPA104_H
// hyperion inclusdes
// hyperion includes
#include "ProviderSpi.h"
///
@@ -9,34 +10,43 @@
class LedDeviceAPA104 : public ProviderSpi
{
public:
///
/// Constructs specific LedDevice
/// @brief Constructs an APA104 LED-device
///
/// @param deviceConfig json device config
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceAPA104(const QJsonObject &deviceConfig);
/// constructs leddevice
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
static LedDevice* construct(const QJsonObject &deviceConfig);
private:
///
/// Sets configuration
/// @brief Initialise the device's configuration
///
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool init(const QJsonObject &deviceConfig) override;
private:
///
/// Writes the led color values to the led-device
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> &ledValues) override;
virtual int write(const std::vector<ColorRgb> & ledValues) override;
const int SPI_BYTES_PER_COLOUR;
const int SPI_FRAME_END_LATCH_BYTES;
uint8_t bitpair_to_byte[4];
};
#endif // LEDEVICEAPA104_H

View File

@@ -4,7 +4,9 @@ LedDeviceLpd6803::LedDeviceLpd6803(const QJsonObject &deviceConfig)
: ProviderSpi()
{
_devConfig = deviceConfig;
_deviceReady = false;
_isDeviceReady = false;
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
}
LedDevice* LedDeviceLpd6803::construct(const QJsonObject &deviceConfig)
@@ -14,12 +16,16 @@ LedDevice* LedDeviceLpd6803::construct(const QJsonObject &deviceConfig)
bool LedDeviceLpd6803::init(const QJsonObject &deviceConfig)
{
bool isInitOK = ProviderSpi::init(deviceConfig);
if ( isInitOK )
bool isInitOK = false;
// Initialise sub-class
if ( ProviderSpi::init(deviceConfig) )
{
unsigned messageLength = 4 + 2*_ledCount + _ledCount/8 + 1;
// Initialise the buffer
_ledBuffer.resize(messageLength, 0x00);
isInitOK = true;
}
return isInitOK;
}

View File

@@ -1,45 +1,55 @@
#pragma once
#ifndef LEDEVICELPD6803_H
#define LEDEVICELPD6803_H
// Local hyperion includes
#include "ProviderSpi.h"
///
/// Implementation of the LedDevice interface for writing to LDP6803 led device.
/// Implementation of the LedDevice interface for writing to LDP6803 LED-device.
///
/// 00000000 00000000 00000000 00000000 1RRRRRGG GGGBBBBB 1RRRRRGG GGGBBBBB ...
/// |---------------------------------| |---------------| |---------------|
/// 32 zeros to start the frame Led1 Led2 ...
/// 32 zeros to start the frame LED1 LED2 ...
///
/// For each led, the first bit is always 1, and then you have 5 bits each for red, green and blue
/// (R, G and B in the above illustration) making 16 bits per led. Total bytes = 4 + (2 x number of
/// leds)
/// (R, G and B in the above illustration) making 16 bits per led. Total bytes = 4 + (2 x number of LEDs)
///
class LedDeviceLpd6803 : public ProviderSpi
{
public:
///
/// Constructs specific LedDevice
/// @brief Constructs a LDP6803 LED-device
///
/// @param deviceConfig json device config
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceLpd6803(const QJsonObject &deviceConfig);
/// constructs leddevice
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
///
static LedDevice* construct(const QJsonObject &deviceConfig);
private:
///
/// Sets configuration
/// @brief Initialise the device's configuration
///
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool init(const QJsonObject &deviceConfig) override;
private:
///
/// Writes the led color values to the led-device
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> &ledValues) override;
virtual int write(const std::vector<ColorRgb> & ledValues) override;
};
#endif // LEDEVICELPD6803_H

View File

@@ -4,7 +4,9 @@ LedDeviceLpd8806::LedDeviceLpd8806(const QJsonObject &deviceConfig)
: ProviderSpi()
{
_devConfig = deviceConfig;
_deviceReady = false;
_isDeviceReady = false;
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
}
LedDevice* LedDeviceLpd8806::construct(const QJsonObject &deviceConfig)
@@ -14,13 +16,18 @@ LedDevice* LedDeviceLpd8806::construct(const QJsonObject &deviceConfig)
bool LedDeviceLpd8806::init(const QJsonObject &deviceConfig)
{
bool isInitOK = ProviderSpi::init(deviceConfig);
bool isInitOK = false;
const unsigned clearSize = _ledCount/32+1;
unsigned messageLength = _ledRGBCount + clearSize;
// Initialise the buffer
_ledBuffer.resize(messageLength, 0x00);
// Initialise sub-class
if ( ProviderSpi::init(deviceConfig) )
{
const unsigned clearSize = _ledCount/32+1;
unsigned messageLength = _ledRGBCount + clearSize;
// Initialise the buffer
_ledBuffer.resize(messageLength, 0x00);
isInitOK = true;
}
return isInitOK;
}

View File

@@ -1,4 +1,5 @@
#pragma once
#ifndef LEDEVICELPD8806_H
#define LEDEVICELPD8806_H
// Local hyperion includes
#include "ProviderSpi.h"
@@ -32,7 +33,7 @@
/// applications. The 'subsequent' rule also means that at least one extra
/// byte must follow the last pixel, in order for the final blue LED to latch.
///
/// To reset the pass-through behavior and begin sending new data to the start
/// To reset the pass-through behaviour and begin sending new data to the start
/// of the strip, a number of zero bytes must be issued (remember, all color
/// data bytes have the high bit set, thus are in the range 128 to 255, so the
/// zero is 'special'). This should be done before each full payload of color
@@ -69,7 +70,7 @@
/// Tested. Confirmed. Fact.
///
///
/// The summary of the story is that the following needs to be writen on the spi-device:
/// The summary of the story is that the following needs to be written on the spi-device:
/// 1RRRRRRR 1GGGGGGG 1BBBBBBB 1RRRRRRR 1GGGGGGG ... ... 1GGGGGGG 1BBBBBBB 00000000 00000000 ...
/// |---------led_1----------| |---------led_2-- -led_n----------| |----clear data--
///
@@ -78,29 +79,39 @@
class LedDeviceLpd8806 : public ProviderSpi
{
public:
///
/// Constructs specific LedDevice
/// @brief Constructs a LDP8806 LED-device
///
/// @param deviceConfig json device config
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceLpd8806(const QJsonObject &deviceConfig);
/// constructs leddevice
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
///
static LedDevice* construct(const QJsonObject &deviceConfig);
private:
///
/// Sets configuration
/// @brief Initialise the device's configuration
///
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool init(const QJsonObject &deviceConfig) override;
private:
///
/// Writes the led color values to the led-device
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> &ledValues) override;
virtual int write(const std::vector<ColorRgb> & ledValues) override;
};
#endif // LEDEVICELPD8806_H

View File

@@ -4,7 +4,9 @@ LedDeviceP9813::LedDeviceP9813(const QJsonObject &deviceConfig)
: ProviderSpi()
{
_devConfig = deviceConfig;
_deviceReady = false;
_isDeviceReady = false;
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
}
LedDevice* LedDeviceP9813::construct(const QJsonObject &deviceConfig)
@@ -14,10 +16,13 @@ LedDevice* LedDeviceP9813::construct(const QJsonObject &deviceConfig)
bool LedDeviceP9813::init(const QJsonObject &deviceConfig)
{
bool isInitOK = ProviderSpi::init(deviceConfig);
if ( isInitOK )
bool isInitOK = false;
// Initialise sub-class
if ( ProviderSpi::init(deviceConfig) )
{
_ledBuffer.resize(_ledCount * 4 + 8, 0x00);
isInitOK = true;
}
return isInitOK;
}

View File

@@ -1,45 +1,54 @@
#pragma once
#ifndef LEDEVICEP9813_H
#define LEDEVICEP9813_H
// hyperion includes
#include "ProviderSpi.h"
///
/// Implementation of the LedDevice interface for writing to P9813 led device.
/// Implementation of the LedDevice interface for writing to P9813 LED-device.
///
class LedDeviceP9813 : public ProviderSpi
{
public:
///
/// Constructs specific LedDevice
/// @brief Constructs a P9813 LED-device
///
/// @param deviceConfig json device config
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceP9813(const QJsonObject &deviceConfig);
/// constructs leddevice
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
static LedDevice* construct(const QJsonObject &deviceConfig);
private:
///
/// Sets configuration
/// @brief Initialise the device's configuration
///
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool init(const QJsonObject &deviceConfig) override;
private:
///
/// Writes the led color values to the led-device
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> &ledValues) override;
virtual int write(const std::vector<ColorRgb> & ledValues) override;
///
/// Calculates the required checksum for one led
/// Calculates the required checksum for one LED
///
/// @param color The color of the led
/// @return The checksum for the led
///
uint8_t calculateChecksum(const ColorRgb & color) const;
};
#endif // LEDEVICEP9813_H

View File

@@ -12,7 +12,9 @@
}
{
_devConfig = deviceConfig;
_deviceReady = false;
_isDeviceReady = false;
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
}
LedDevice* LedDeviceSk6812SPI::construct(const QJsonObject &deviceConfig)
@@ -24,8 +26,10 @@ bool LedDeviceSk6812SPI::init(const QJsonObject &deviceConfig)
{
_baudRate_Hz = 3000000;
bool isInitOK = ProviderSpi::init(deviceConfig);
if ( isInitOK )
bool isInitOK = false;
// Initialise sub-class
if ( ProviderSpi::init(deviceConfig) )
{
QString whiteAlgorithm = deviceConfig["whiteAlgorithm"].toString("white_off");
@@ -44,6 +48,8 @@ bool LedDeviceSk6812SPI::init(const QJsonObject &deviceConfig)
const int SPI_FRAME_END_LATCH_BYTES = 3;
_ledBuffer.resize(_ledRGBWCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00);
isInitOK = true;
}
}
return isInitOK;

View File

@@ -1,39 +1,47 @@
#pragma once
#ifndef LEDEVICESK6812SPI_H
#define LEDEVICESK6812SPI_H
// hyperion includes
#include "ProviderSpi.h"
///
/// Implementation of the LedDevice interface for writing to Sk6801 led device via SPI.
/// Implementation of the LedDevice interface for writing to Sk6801 LED-device via SPI.
///
class LedDeviceSk6812SPI : public ProviderSpi
{
public:
///
/// Constructs specific LedDevice
/// @brief Constructs a Sk6801 LED-device
///
/// @param deviceConfig json device config
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceSk6812SPI(const QJsonObject &deviceConfig);
/// constructs leddevice
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
static LedDevice* construct(const QJsonObject &deviceConfig);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool init(const QJsonObject &deviceConfig) override;
private:
///
/// Writes the led color values to the led-device
/// @brief Initialise the device's configuration
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
virtual int write(const std::vector<ColorRgb> &ledValues) override;
virtual bool init(const QJsonObject &deviceConfig) override;
///
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> & ledValues) override;
RGBW::WhiteAlgorithm _whiteAlgorithm;
@@ -42,3 +50,5 @@ private:
ColorRgbw _temp_rgbw;
};
#endif // LEDEVICESK6812SPI_H

View File

@@ -49,9 +49,12 @@ LedDeviceSk6822SPI::LedDeviceSk6822SPI(const QJsonObject &deviceConfig)
}
{
_devConfig = deviceConfig;
_deviceReady = false;
_isDeviceReady = false;
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
}
LedDevice* LedDeviceSk6822SPI::construct(const QJsonObject &deviceConfig)
{
return new LedDeviceSk6822SPI(deviceConfig);
@@ -61,13 +64,17 @@ bool LedDeviceSk6822SPI::init(const QJsonObject &deviceConfig)
{
_baudRate_Hz = 2230000;
bool isInitOK = ProviderSpi::init(deviceConfig);
if ( isInitOK )
bool isInitOK = false;
// Initialise sub-class
if ( ProviderSpi::init(deviceConfig) )
{
WarningIf(( _baudRate_Hz < 2000000 || _baudRate_Hz > 2460000 ), _log, "SPI rate %d outside recommended range (2000000 -> 2460000)", _baudRate_Hz);
_ledBuffer.resize( (_ledRGBCount * SPI_BYTES_PER_COLOUR) + (_ledCount * SPI_BYTES_WAIT_TIME ) + SPI_FRAME_END_LATCH_BYTES, 0x00);
// Debug(_log, "_ledBuffer.resize(_ledRGBCount:%d * SPI_BYTES_PER_COLOUR:%d) + ( _ledCount:%d * SPI_BYTES_WAIT_TIME:%d ) + SPI_FRAME_END_LATCH_BYTES:%d, 0x00)", _ledRGBCount, SPI_BYTES_PER_COLOUR, _ledCount, SPI_BYTES_WAIT_TIME, SPI_FRAME_END_LATCH_BYTES);
isInitOK = true;
}
return isInitOK;
@@ -93,9 +100,8 @@ int LedDeviceSk6822SPI::write(const std::vector<ColorRgb> &ledValues)
spi_ptr += SPI_BYTES_WAIT_TIME; // the wait between led time is all zeros
}
/*
// debug the whole SPI packet
/*
// debug the whole SPI packet
char debug_line[2048];
int ptr=0;
for (unsigned int i=0; i < _ledBuffer.size(); i++)
@@ -105,14 +111,14 @@ int LedDeviceSk6822SPI::write(const std::vector<ColorRgb> &ledValues)
ptr += snprintf (ptr+debug_line, sizeof(debug_line)-ptr, "%03x: ", i);
}
ptr += snprintf (ptr+debug_line, sizeof(debug_line)-ptr, "%02x ", _ledBuffer.data()[i]);
ptr += snprintf (ptr+debug_line, sizeof(debug_line)-ptr, "%02x ", _ledBuffer.data()[i]);
if ( (i%16 == 15) || ( i == _ledBuffer.size()-1 ) )
{
Debug(_log, debug_line);
ptr = 0;
if ( (i%16 == 15) || ( i == _ledBuffer.size()-1 ) )
{
Debug(_log, debug_line);
ptr = 0;
}
}
}
*/
return writeBytes(_ledBuffer.size(), _ledBuffer.data());

View File

@@ -1,39 +1,47 @@
#pragma once
#ifndef LEDEVICESK6822SPI_H
#define LEDEVICESK6822SPI_H
// hyperion includes
#include "ProviderSpi.h"
///
/// Implementation of the LedDevice interface for writing to Ws2812 led device via spi.
/// Implementation of the LedDevice interface for writing to Sk6822 LED-device via SPI.
///
class LedDeviceSk6822SPI : public ProviderSpi
{
public:
///
/// Constructs specific LedDevice
/// @brief Constructs a Sk6822 LED-device
///
/// @param deviceConfig json device config
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceSk6822SPI(const QJsonObject &deviceConfig);
/// constructs leddevice
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
static LedDevice* construct(const QJsonObject &deviceConfig);
private:
///
/// Sets configuration
/// @brief Initialise the device's configuration
///
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool init(const QJsonObject &deviceConfig) override;
private:
///
/// Writes the led color values to the led-device
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> &ledValues) override;
virtual int write(const std::vector<ColorRgb> & ledValues) override;
const int SPI_BYTES_PER_COLOUR;
const int SPI_BYTES_WAIT_TIME;
@@ -41,3 +49,5 @@ private:
uint8_t bitpair_to_byte[4];
};
#endif // LEDEVICESK6822SPI_H

View File

@@ -4,7 +4,9 @@ LedDeviceWs2801::LedDeviceWs2801(const QJsonObject &deviceConfig)
: ProviderSpi()
{
_devConfig = deviceConfig;
_deviceReady = false;
_isDeviceReady = false;
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
}
LedDevice* LedDeviceWs2801::construct(const QJsonObject &deviceConfig)

View File

@@ -1,4 +1,5 @@
#pragma once
#ifndef LEDEVICEWS2801_H
#define LEDEVICEWS2801_H
// hyperion includes
#include "ProviderSpi.h"
@@ -9,29 +10,38 @@
class LedDeviceWs2801 : public ProviderSpi
{
public:
///
/// Constructs specific LedDevice
/// @brief Constructs a Ws2801 LED-device
///
/// @param deviceConfig json device config
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceWs2801(const QJsonObject &deviceConfig);
/// constructs leddevice
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
static LedDevice* construct(const QJsonObject &deviceConfig);
private:
///
/// Sets configuration
/// @brief Initialise the device's configuration
///
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool init(const QJsonObject &deviceConfig) override;
protected:
///
/// Writes the led color values to the led-device
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> &ledValues) override;
virtual int write(const std::vector<ColorRgb> & ledValues) override;
};
#endif // LEDEVICEWS2801_H

View File

@@ -46,7 +46,9 @@ Reset time is 300uS = 923 bits = 116 bytes
}
{
_devConfig = deviceConfig;
_deviceReady = false;
_isDeviceReady = false;
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
}
LedDevice* LedDeviceWs2812SPI::construct(const QJsonObject &deviceConfig)
@@ -58,13 +60,18 @@ bool LedDeviceWs2812SPI::init(const QJsonObject &deviceConfig)
{
_baudRate_Hz = 2600000;
bool isInitOK = ProviderSpi::init(deviceConfig);
if ( isInitOK )
bool isInitOK = false;
// Initialise sub-class
if ( ProviderSpi::init(deviceConfig) )
{
WarningIf(( _baudRate_Hz < 2106000 || _baudRate_Hz > 3075000 ), _log, "SPI rate %d outside recommended range (2106000 -> 3075000)", _baudRate_Hz);
_ledBuffer.resize(_ledRGBCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00);
isInitOK = true;
}
return isInitOK;
}

View File

@@ -1,42 +1,52 @@
#pragma once
#ifndef LEDEVICEWS2812_H
#define LEDEVICEWS2812_H
// hyperion includes
#include "ProviderSpi.h"
///
/// Implementation of the LedDevice interface for writing to Ws2812 led device via spi.
/// Implementation of the LedDevice interface for writing to Ws2812 led device.
///
class LedDeviceWs2812SPI : public ProviderSpi
{
public:
///
/// Constructs specific LedDevice
/// @brief Constructs a Ws2812 LED-device
///
/// @param deviceConfig json device config
/// @param deviceConfig Device's configuration as JSON-Object
///
explicit LedDeviceWs2812SPI(const QJsonObject &deviceConfig);
/// constructs leddevice
///
/// @brief Constructs the LED-device
///
/// @param[in] deviceConfig Device's configuration as JSON-Object
/// @return LedDevice constructed
static LedDevice* construct(const QJsonObject &deviceConfig);
private:
///
/// Sets configuration
/// @brief Initialise the device's configuration
///
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool init(const QJsonObject &deviceConfig) override;
private:
///
/// Writes the led color values to the led-device
/// @brief Writes the RGB-Color values to the LEDs.
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
/// @param[in] ledValues The RGB-color per LED
/// @return Zero on success, else negative
///
virtual int write(const std::vector<ColorRgb> &ledValues) override;
virtual int write(const std::vector<ColorRgb> & ledValues) override;
const int SPI_BYTES_PER_COLOUR;
const int SPI_FRAME_END_LATCH_BYTES;
uint8_t bitpair_to_byte[4];
};
#endif // LEDEVICEWS2812_H

View File

@@ -33,13 +33,21 @@ ProviderSpi::~ProviderSpi()
bool ProviderSpi::init(const QJsonObject &deviceConfig)
{
bool isInitOK = LedDevice::init(deviceConfig);
bool isInitOK = false;
_deviceName = deviceConfig["output"].toString(_deviceName);
_baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz);
_spiMode = deviceConfig["spimode"].toInt(_spiMode);
_spiDataInvert = deviceConfig["invert"].toBool(_spiDataInvert);
// Initialise sub-class
if ( LedDevice::init(deviceConfig) )
{
_deviceName = deviceConfig["output"].toString(_deviceName);
_baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz);
_spiMode = deviceConfig["spimode"].toInt(_spiMode);
_spiDataInvert = deviceConfig["invert"].toBool(_spiDataInvert);
Debug(_log, "_baudRate_Hz [%d], _latchTime_ms [%d]", _baudRate_Hz, _latchTime_ms);
Debug(_log, "_spiDataInvert [%d], _spiMode [%d]", _spiDataInvert, _spiMode);
isInitOK = true;
}
return isInitOK;
}
@@ -47,77 +55,74 @@ int ProviderSpi::open()
{
int retval = -1;
QString errortext;
_deviceReady = false;
_isDeviceReady = false;
if ( init(_devConfig) )
const int bitsPerWord = 8;
_fid = ::open(QSTRING_CSTR(_deviceName), O_RDWR);
if (_fid < 0)
{
Debug(_log, "_baudRate_Hz [%d], _latchTime_ms [%d]", _baudRate_Hz, _latchTime_ms);
Debug(_log, "_spiDataInvert [%d], _spiMode [%d]", _spiDataInvert, _spiMode);
const int bitsPerWord = 8;
_fid = ::open(QSTRING_CSTR(_deviceName), O_RDWR);
if (_fid < 0)
errortext = QString ("Failed to open device (%1). Error message: %2").arg(_deviceName, strerror(errno));
retval = -1;
}
else
{
if (ioctl(_fid, SPI_IOC_WR_MODE, &_spiMode) == -1 || ioctl(_fid, SPI_IOC_RD_MODE, &_spiMode) == -1)
{
errortext = QString ("Failed to open device (%1). Error message: %2").arg(_deviceName, strerror(errno));
retval = -1;
retval = -2;
}
else
{
if (ioctl(_fid, SPI_IOC_WR_MODE, &_spiMode) == -1 || ioctl(_fid, SPI_IOC_RD_MODE, &_spiMode) == -1)
if (ioctl(_fid, SPI_IOC_WR_BITS_PER_WORD, &bitsPerWord) == -1 || ioctl(_fid, SPI_IOC_RD_BITS_PER_WORD, &bitsPerWord) == -1)
{
retval = -2;
retval = -4;
}
else
{
if (ioctl(_fid, SPI_IOC_WR_BITS_PER_WORD, &bitsPerWord) == -1 || ioctl(_fid, SPI_IOC_RD_BITS_PER_WORD, &bitsPerWord) == -1)
if (ioctl(_fid, SPI_IOC_WR_MAX_SPEED_HZ, &_baudRate_Hz) == -1 || ioctl(_fid, SPI_IOC_RD_MAX_SPEED_HZ, &_baudRate_Hz) == -1)
{
retval = -4;
retval = -6;
}
else
{
if (ioctl(_fid, SPI_IOC_WR_MAX_SPEED_HZ, &_baudRate_Hz) == -1 || ioctl(_fid, SPI_IOC_RD_MAX_SPEED_HZ, &_baudRate_Hz) == -1)
{
retval = -6;
}
else
{
// Everything OK -> enable device
_deviceReady = true;
setEnable(true);
retval = 0;
}
// Everything OK -> enable device
_isDeviceReady = true;
retval = 0;
}
}
if ( retval < 0 )
{
errortext = QString ("Failed to open device (%1). Error Code: %2").arg(_deviceName).arg(retval);
}
}
if ( retval < 0 )
{
this->setInError( errortext );
errortext = QString ("Failed to open device (%1). Error Code: %2").arg(_deviceName).arg(retval);
}
}
if ( retval < 0 )
{
this->setInError( errortext );
}
return retval;
}
void ProviderSpi::close()
int ProviderSpi::close()
{
LedDevice::close();
// LedDevice specific closing activities
int retval = 0;
_isDeviceReady = false;
// Device specific closing activites
// Test, if device requires closing
if ( _fid > -1 )
{
// Close device
if ( ::close(_fid) != 0 )
{
Error( _log, "Failed to close device (%s). Error message: %s", QSTRING_CSTR(_deviceName), strerror(errno) );
retval = -1;
}
}
return retval;
}
int ProviderSpi::writeBytes(const unsigned size, const uint8_t * data)

View File

@@ -41,7 +41,7 @@ public slots:
/// Closes the output device.
/// Includes switching-off the device and stopping refreshes
///
virtual void close() override;
virtual int close() override;
protected:
///
@@ -51,7 +51,7 @@ protected:
/// @param[in[ size The length of the data
/// @param[in] data The data
///
/// @return Zero on succes else negative
/// @return Zero on success, else negative
///
int writeBytes(const unsigned size, const uint8_t *data);