mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Slight style changes to the pull of the P9813 device
Former-commit-id: 77892a5cfbcc4793061d518a761931be26ef842b
This commit is contained in:
parent
cb59a0e951
commit
fd6d247506
@ -54,16 +54,16 @@ if(ENABLE_SPIDEV)
|
|||||||
${CURRENT_SOURCE_DIR}/LedSpiDevice.h
|
${CURRENT_SOURCE_DIR}/LedSpiDevice.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceLpd6803.h
|
${CURRENT_SOURCE_DIR}/LedDeviceLpd6803.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.h
|
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.h
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.h
|
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceP9813.h
|
${CURRENT_SOURCE_DIR}/LedDeviceP9813.h
|
||||||
|
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.h
|
||||||
)
|
)
|
||||||
SET(Leddevice_SOURCES
|
SET(Leddevice_SOURCES
|
||||||
${Leddevice_SOURCES}
|
${Leddevice_SOURCES}
|
||||||
${CURRENT_SOURCE_DIR}/LedSpiDevice.cpp
|
${CURRENT_SOURCE_DIR}/LedSpiDevice.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceLpd6803.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceLpd6803.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceLpd8806.cpp
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp
|
|
||||||
${CURRENT_SOURCE_DIR}/LedDeviceP9813.cpp
|
${CURRENT_SOURCE_DIR}/LedDeviceP9813.cpp
|
||||||
|
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp
|
||||||
)
|
)
|
||||||
endif(ENABLE_SPIDEV)
|
endif(ENABLE_SPIDEV)
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
#ifdef ENABLE_SPIDEV
|
#ifdef ENABLE_SPIDEV
|
||||||
#include "LedDeviceLpd6803.h"
|
#include "LedDeviceLpd6803.h"
|
||||||
#include "LedDeviceLpd8806.h"
|
#include "LedDeviceLpd8806.h"
|
||||||
#include "LedDeviceWs2801.h"
|
|
||||||
#include "LedDeviceP9813.h"
|
#include "LedDeviceP9813.h"
|
||||||
|
#include "LedDeviceWs2801.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "LedDeviceAdalight.h"
|
#include "LedDeviceAdalight.h"
|
||||||
|
@ -13,37 +13,37 @@
|
|||||||
|
|
||||||
LedDeviceP9813::LedDeviceP9813(const std::string& outputDevice, const unsigned baudrate) :
|
LedDeviceP9813::LedDeviceP9813(const std::string& outputDevice, const unsigned baudrate) :
|
||||||
LedSpiDevice(outputDevice, baudrate, 0),
|
LedSpiDevice(outputDevice, baudrate, 0),
|
||||||
mLedCount(0)
|
_ledCount(0)
|
||||||
{
|
{
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
int LedDeviceP9813::write(const std::vector<ColorRgb> &ledValues)
|
int LedDeviceP9813::write(const std::vector<ColorRgb> &ledValues)
|
||||||
{
|
{
|
||||||
mLedCount = ledValues.size();
|
if (_ledCount != ledValues.size())
|
||||||
|
{
|
||||||
const unsigned dataLen = ledValues.size() * 4 + 8;
|
_ledBuf.resize(ledValues.size() * 4 + 8, 0x00);
|
||||||
uint8_t data[dataLen];
|
_ledCount = ledValues.size();
|
||||||
|
|
||||||
memset(data, 0x00, dataLen);
|
|
||||||
|
|
||||||
int j = 4;
|
|
||||||
for (unsigned i = 0; i < mLedCount; i++){
|
|
||||||
data[j++] = calculateChecksum(ledValues[i]);
|
|
||||||
data[j++] = ledValues[i].blue;
|
|
||||||
data[j++] = ledValues[i].green;
|
|
||||||
data[j++] = ledValues[i].red;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeBytes(dataLen, data);
|
uint8_t * dataPtr = _ledBuf.data();
|
||||||
|
for (const ColorRgb & color : ledValues)
|
||||||
|
{
|
||||||
|
*dataPtr++ = calculateChecksum(color);
|
||||||
|
*dataPtr++ = color.blue;
|
||||||
|
*dataPtr++ = color.green;
|
||||||
|
*dataPtr++ = color.red;
|
||||||
|
}
|
||||||
|
|
||||||
|
return writeBytes(_ledBuf.size(), _ledBuf.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
int LedDeviceP9813::switchOff()
|
int LedDeviceP9813::switchOff()
|
||||||
{
|
{
|
||||||
return write(std::vector<ColorRgb>(mLedCount, ColorRgb{0,0,0}));
|
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t LedDeviceP9813::calculateChecksum(const ColorRgb color)
|
uint8_t LedDeviceP9813::calculateChecksum(const ColorRgb & color) const
|
||||||
{
|
{
|
||||||
uint8_t res = 0;
|
uint8_t res = 0;
|
||||||
|
|
||||||
|
@ -35,6 +35,16 @@ public:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
/// the number of leds
|
/// the number of leds
|
||||||
size_t mLedCount;
|
size_t _ledCount;
|
||||||
const uint8_t calculateChecksum(const ColorRgb color);
|
|
||||||
|
/// Buffer for writing/written led data
|
||||||
|
std::vector<uint8_t> _ledBuf;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 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;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user