mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Fixed endianness issue in LDP6803 device
Former-commit-id: 6762890065d791f3ad5f24526f2f735822b451e1
This commit is contained in:
parent
fb23befdee
commit
e5395951a5
@ -4,7 +4,7 @@
|
||||
{
|
||||
/// Device configuration contains the following fields:
|
||||
/// * 'name' : The user friendly name of the device (only used for display purposes)
|
||||
/// * 'type' : The type of the device or leds (known types for now are 'ws2801', 'test' and 'none')
|
||||
/// * 'type' : The type of the device or leds (known types for now are 'ws2801', 'ldp6803', 'test' and 'none')
|
||||
/// * 'output' : The output specification depends on selected device
|
||||
/// - 'ws2801' this is the device (eg '/dev/spidev0.0')
|
||||
/// - 'test' this is the file used to write test output (eg '/home/pi/hyperion.out')
|
||||
|
Binary file not shown.
@ -1 +1 @@
|
||||
e027a9a48c14dcffacb9539ede8ddca32cba2171
|
||||
26d94964cc23d092b4504771bb1c0940e4d6d66e
|
@ -20,31 +20,23 @@ LedDeviceLdp6803::LedDeviceLdp6803(const std::string& outputDevice, const unsign
|
||||
int LedDeviceLdp6803::write(const std::vector<RgbColor> &ledValues)
|
||||
{
|
||||
// Reconfigure if the current connfiguration does not match the required configuration
|
||||
if (ledValues.size() != _ledBuffer.size())
|
||||
if (4 + 2*ledValues.size() != _ledBuffer.size())
|
||||
{
|
||||
// Initialise the buffer with all 'black' values
|
||||
_ledBuffer.resize(ledValues.size() + 2, 0x80);
|
||||
_ledBuffer[0] = 0;
|
||||
_ledBuffer[1] = 0;
|
||||
// Initialise the buffer
|
||||
_ledBuffer.resize(4 + 2*ledValues.size(), 0x00);
|
||||
}
|
||||
|
||||
// Copy the colors from the RgbColor vector to the Ldp6803Rgb vector
|
||||
// Copy the colors from the RgbColor vector to the Ldp6803 data vector
|
||||
for (unsigned iLed=0; iLed<ledValues.size(); ++iLed)
|
||||
{
|
||||
const RgbColor& rgb = ledValues[iLed];
|
||||
|
||||
const char packedRed = rgb.red & 0xf8;
|
||||
const char packedGreen = rgb.green & 0xf8;
|
||||
const char packedBlue = rgb.blue & 0xf8;
|
||||
const unsigned short packedRgb = 0x80 | (packedRed << 7) | (packedGreen << 2) | (packedBlue >> 3);
|
||||
|
||||
_ledBuffer[iLed + 2] = packedRgb;
|
||||
_ledBuffer[4 + 2 * iLed] = 0x80 | ((rgb.red & 0xf8) >> 1) | (rgb.green >> 6);
|
||||
_ledBuffer[5 + 2 * iLed] = ((rgb.green & 0x38) << 2) | (rgb.blue >> 3);
|
||||
}
|
||||
|
||||
// Write the data
|
||||
const unsigned bufCnt = _ledBuffer.size() * sizeof(short);
|
||||
const char * bufPtr = reinterpret_cast<const char *>(_ledBuffer.data());
|
||||
if (latch(bufCnt, bufPtr, 0) < 0)
|
||||
if (writeBytes(_ledBuffer.size(), _ledBuffer.data()) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -6,12 +6,12 @@
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to LDP6803 led device.
|
||||
///
|
||||
/// 00000000 00000000 00000000 00000000 1XXXXXYY YYYZZZZZ 1XXXXXYY YYYZZZZZ ...
|
||||
/// 00000000 00000000 00000000 00000000 1RRRRRGG GGGBBBBB 1RRRRRGG GGGBBBBB ...
|
||||
/// |---------------------------------| |---------------| |---------------|
|
||||
/// 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
|
||||
/// (X, Y and Z in the above illustration) making 16 bits per led. Total bits = 32 + (16 x number of
|
||||
/// (R, G and B in the above illustration) making 16 bits per led. Total bytes = 4 + (2 x number of
|
||||
/// leds)
|
||||
///
|
||||
class LedDeviceLdp6803 : public LedSpiDevice
|
||||
@ -20,7 +20,7 @@ public:
|
||||
///
|
||||
/// Constructs the LedDevice for a string containing leds of the type LDP6803
|
||||
///
|
||||
/// @param[in] outputDevice The name of the output device (eg '/etc/SpiDev.0.0')
|
||||
/// @param[in] outputDevice The name of the output device (eg '/dev/spidev0.0')
|
||||
/// @param[in] baudrate The used baudrate for writing to the output device
|
||||
///
|
||||
LedDeviceLdp6803(const std::string& outputDevice, const unsigned baudrate);
|
||||
@ -38,5 +38,5 @@ public:
|
||||
|
||||
private:
|
||||
/// The buffer containing the packed RGB values
|
||||
std::vector<unsigned short> _ledBuffer;
|
||||
std::vector<uint8_t> _ledBuffer;
|
||||
};
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "LedDeviceWs2801.h"
|
||||
|
||||
LedDeviceWs2801::LedDeviceWs2801(const std::string& outputDevice, const unsigned baudrate) :
|
||||
LedSpiDevice(outputDevice, baudrate),
|
||||
LedSpiDevice(outputDevice, baudrate, 500000),
|
||||
mLedCount(0)
|
||||
{
|
||||
// empty
|
||||
@ -23,10 +23,9 @@ int LedDeviceWs2801::write(const std::vector<RgbColor> &ledValues)
|
||||
mLedCount = ledValues.size();
|
||||
|
||||
const unsigned dataLen = ledValues.size() * sizeof(RgbColor);
|
||||
const char * dataPtr = reinterpret_cast<const char *>(ledValues.data());
|
||||
const uint8_t * dataPtr = reinterpret_cast<const uint8_t *>(ledValues.data());
|
||||
|
||||
const int retVal = latch(dataLen, dataPtr, 500000);
|
||||
return retVal;
|
||||
return writeBytes(dataLen, dataPtr);
|
||||
}
|
||||
|
||||
int LedDeviceWs2801::switchOff()
|
||||
|
@ -12,9 +12,10 @@
|
||||
#include "LedSpiDevice.h"
|
||||
|
||||
|
||||
LedSpiDevice::LedSpiDevice(const std::string& outputDevice, const unsigned baudrate) :
|
||||
LedSpiDevice::LedSpiDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns) :
|
||||
mDeviceName(outputDevice),
|
||||
mBaudRate_Hz(baudrate),
|
||||
mLatchTime_ns(latchTime_ns),
|
||||
mFid(-1)
|
||||
{
|
||||
memset(&spi, 0, sizeof(spi));
|
||||
@ -56,30 +57,28 @@ int LedSpiDevice::open()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LedSpiDevice::latch(const unsigned len, const char * vec, const int latchTime_ns)
|
||||
int LedSpiDevice::writeBytes(const unsigned size, const uint8_t * data)
|
||||
{
|
||||
|
||||
if (mFid < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
spi.tx_buf = __u64(vec);
|
||||
spi.len = __u32(len);
|
||||
spi.tx_buf = __u64(data);
|
||||
spi.len = __u32(size);
|
||||
|
||||
int retVal = ioctl(mFid, SPI_IOC_MESSAGE(1), &spi);
|
||||
|
||||
if (retVal == 0 && latchTime_ns > 0)
|
||||
if (retVal == 0 && mLatchTime_ns > 0)
|
||||
{
|
||||
// The 'latch' time for latching the shifted-value into the leds
|
||||
timespec latchTime;
|
||||
latchTime.tv_sec = 0;
|
||||
latchTime.tv_nsec = latchTime_ns;
|
||||
latchTime.tv_nsec = mLatchTime_ns;
|
||||
|
||||
// Sleep to latch the leds (only if write succesfull)
|
||||
nanosleep(&latchTime, NULL);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
/// @param[in] outputDevice The name of the output device (eg '/etc/SpiDev.0.0')
|
||||
/// @param[in] baudrate The used baudrate for writing to the output device
|
||||
///
|
||||
LedSpiDevice(const std::string& outputDevice, const unsigned baudrate);
|
||||
LedSpiDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns = -1);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the output device if it is open
|
||||
@ -37,20 +37,22 @@ protected:
|
||||
* Writes the given bytes/bits to the SPI-device and sleeps the latch time to ensure that the
|
||||
* values are latched.
|
||||
*
|
||||
* @param[in[ len The length of the data
|
||||
* @param[in] vec The data
|
||||
* @param[in[ size The length of the data
|
||||
* @param[in] data The data
|
||||
* @param[in] latchTime_ns The latch-time to latch in the values across the SPI-device (negative
|
||||
* means no latch required) [ns]
|
||||
*
|
||||
* @return Zero on succes else negative
|
||||
*/
|
||||
int latch(const unsigned len, const char * vec, const int latchTime_ns);
|
||||
int writeBytes(const unsigned size, const uint8_t *data);
|
||||
|
||||
private:
|
||||
/// The name of the output device
|
||||
const std::string mDeviceName;
|
||||
/// The used baudrate of the output device
|
||||
const int mBaudRate_Hz;
|
||||
/// The time which the device should be untouched after a write
|
||||
const int mLatchTime_ns;
|
||||
|
||||
/// The File Identifier of the opened output device (or -1 if not opened)
|
||||
int mFid;
|
||||
|
Loading…
Reference in New Issue
Block a user