-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
496 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "LedDeviceAPA102_ftdi.h" | ||
|
||
|
||
LedDeviceAPA102_ftdi::LedDeviceAPA102_ftdi(const QJsonObject &deviceConfig) : ProviderFtdi(deviceConfig) | ||
{ | ||
} | ||
|
||
LedDevice *LedDeviceAPA102_ftdi::construct(const QJsonObject &deviceConfig) | ||
{ | ||
return new LedDeviceAPA102_ftdi(deviceConfig); | ||
} | ||
|
||
bool LedDeviceAPA102_ftdi::init(const QJsonObject &deviceConfig) | ||
{ | ||
bool isInitOK = false; | ||
|
||
// Initialise sub-class | ||
if (ProviderFtdi::init(deviceConfig)) | ||
{ | ||
CreateHeader(); | ||
isInitOK = true; | ||
} | ||
return isInitOK; | ||
} | ||
|
||
void LedDeviceAPA102_ftdi::CreateHeader() | ||
{ | ||
const unsigned int startFrameSize = 4; | ||
const unsigned int endFrameSize = qMax<unsigned int>(((_ledCount + 15) / 16), 4); | ||
const unsigned int APAbufferSize = (_ledCount * 4) + startFrameSize + endFrameSize; | ||
|
||
_ledBuffer.resize(0, 0xFF); | ||
_ledBuffer.resize(APAbufferSize, 0xFF); | ||
_ledBuffer[0] = 0x00; | ||
_ledBuffer[1] = 0x00; | ||
_ledBuffer[2] = 0x00; | ||
_ledBuffer[3] = 0x00; | ||
|
||
Debug(_log, "APA102 buffer created. Led's number: %d", _ledCount); | ||
} | ||
|
||
int LedDeviceAPA102_ftdi::write(const std::vector<ColorRgb> &ledValues) | ||
{ | ||
if (_ledCount != ledValues.size()) | ||
{ | ||
Warning(_log, "APA102 led's number has changed (old: %d, new: %d). Rebuilding buffer.", _ledCount, ledValues.size()); | ||
_ledCount = ledValues.size(); | ||
|
||
CreateHeader(); | ||
} | ||
|
||
for (signed iLed = 0; iLed < static_cast<int>(_ledCount); ++iLed) | ||
{ | ||
const ColorRgb &rgb = ledValues[iLed]; | ||
_ledBuffer[4 + iLed * 4 + 0] = 0xFF; | ||
_ledBuffer[4 + iLed * 4 + 1] = rgb.red; | ||
_ledBuffer[4 + iLed * 4 + 2] = rgb.green; | ||
_ledBuffer[4 + iLed * 4 + 3] = rgb.blue; | ||
} | ||
|
||
return writeBytes(_ledBuffer.size(), _ledBuffer.data()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef LEDEVICET_APA102_H | ||
#define LEDEVICET_APA102_H | ||
#include "ProviderFtdi.h" | ||
|
||
class LedDeviceAPA102_ftdi : public ProviderFtdi | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/// | ||
/// @brief Constructs an APA102 LED-device | ||
/// | ||
/// @param deviceConfig Device's configuration as JSON-Object | ||
/// | ||
explicit LedDeviceAPA102_ftdi(const QJsonObject& deviceConfig); | ||
|
||
/// | ||
/// @brief Constructs the LED-device | ||
/// | ||
/// @param[in] deviceConfig Device's configuration as JSON-Object | ||
/// @return LedDevice constructed | ||
static LedDevice* construct(const QJsonObject& deviceConfig); | ||
|
||
private: | ||
|
||
/// | ||
/// @brief Initialise the device's configuration | ||
/// | ||
/// @param[in] deviceConfig the JSON device configuration | ||
/// @return True, if success | ||
/// | ||
bool init(const QJsonObject& deviceConfig) override; | ||
|
||
void CreateHeader(); | ||
|
||
/// | ||
/// @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; | ||
|
||
}; | ||
|
||
#endif // LEDEVICET_APA102_H |
Oops, something went wrong.