mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Modification and additions to test working of ws2812b
Former-commit-id: 2a7eb3cb67c85a4a4042bd0f1a6ea4d58792b1c2
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
|
||||
// Linux includes
|
||||
#include <unistd.h>
|
||||
|
||||
// Local Hyperion-Leddevice includes
|
||||
#include "LedDeviceWs2812b.h"
|
||||
|
||||
@@ -17,15 +20,19 @@ int LedDeviceWs2812b::write(const std::vector<ColorRgb> & ledValues)
|
||||
}
|
||||
|
||||
// Translate the channel of each color to a signal
|
||||
auto bufIt = _ledBuffer.begin();
|
||||
for (const ColorRgb& color : ledValues)
|
||||
for (unsigned iLed=0; iLed<ledValues.size(); ++iLed)
|
||||
{
|
||||
*bufIt++ = _byte2signalTable[color.red];
|
||||
*bufIt++ = _byte2signalTable[color.green];
|
||||
*bufIt++ = _byte2signalTable[color.blue];
|
||||
const ColorRgb & color = ledValues[iLed];
|
||||
|
||||
_ledBuffer[3*iLed] = _byte2signalTable[color.red];
|
||||
_ledBuffer[3*iLed + 1] = _byte2signalTable[color.green];
|
||||
_ledBuffer[3*iLed + 2] = _byte2signalTable[color.blue];
|
||||
}
|
||||
|
||||
return writeBytes(_ledBuffer.size()*sizeof(ByteSignal), reinterpret_cast<uint8_t *>(_ledBuffer.data()));
|
||||
const int result = writeBytes(_ledBuffer.size()*sizeof(ByteSignal), reinterpret_cast<uint8_t *>(_ledBuffer.data()));
|
||||
// Official latch time is 50us (lets give it 50us more)
|
||||
usleep(100);
|
||||
return result;
|
||||
}
|
||||
|
||||
int LedDeviceWs2812b::switchOff()
|
||||
@@ -63,14 +70,29 @@ uint8_t LedDeviceWs2812b::bits2Signal(const bool bit1, const bool bit2) const
|
||||
{
|
||||
// See https://github.com/tvdzwan/hyperion/wiki/Ws2812b for the explanation of the given
|
||||
// translations
|
||||
|
||||
// Encoding scheme 1
|
||||
// 00 1 1000 1100 0 1 0111 0011 0 1 1100 1110 0 0xCE
|
||||
// 01 1 1000 1110 0 1 0111 0001 0 1 1000 1110 0 0x8E
|
||||
// 10 1 1100 1100 0 1 0011 0011 0 1 1100 1100 0 0xCC
|
||||
// 11 1 1100 1110 0 1 0011 0001 0 1 1000 1100 0 0x8C
|
||||
|
||||
// Encoding schem 2
|
||||
// 00 - 1 0000 1000 0 - 1 1111 0111 0 - 1 1110 1111 0 - 0xEF
|
||||
// 01 - 1 0000 1111 0 - 1 1111 0000 0 - 1 0000 1111 0 - 0x0F
|
||||
// 10 - 1 1110 1000 0 - 1 0001 0111 0 - 1 1110 1000 0 - 0xE8
|
||||
// 11 - 1 1110 1111 0 - 1 0001 0000 0 - 1 0000 1000 0 - 0x08
|
||||
|
||||
if (bit1)
|
||||
{
|
||||
if (bit2)
|
||||
{
|
||||
// return 0x08;
|
||||
return 0x8C;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return 0xE8;
|
||||
return 0xCC;
|
||||
}
|
||||
}
|
||||
@@ -78,10 +100,12 @@ uint8_t LedDeviceWs2812b::bits2Signal(const bool bit1, const bool bit2) const
|
||||
{
|
||||
if (bit2)
|
||||
{
|
||||
// return 0x0F;
|
||||
return 0x8E;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return 0xEF;
|
||||
return 0xCE;
|
||||
}
|
||||
}
|
||||
|
@@ -57,6 +57,7 @@ int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
|
||||
|
||||
try
|
||||
{
|
||||
_rs232Port.flushOutput();
|
||||
_rs232Port.write(data, size);
|
||||
_rs232Port.flush();
|
||||
}
|
||||
|
Reference in New Issue
Block a user