diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6b6a0570..b8bc6765 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -# Needed for testing non-public components + # Needed for testing non-public components include_directories(../libsrc) if(ENABLE_SPIDEV) @@ -65,4 +65,6 @@ target_link_libraries(test_rs232highspeed if(NOT APPLE AND UNIX) include_directories(/usr/include) add_executable(test_uartHighSpeed TestUartHighSpeed.cpp) + + add_executable(test_nonInvWs2812b TestNonInvWs2812b.cpp) endif() diff --git a/test/TestNonInvWs2812b.cpp b/test/TestNonInvWs2812b.cpp new file mode 100644 index 00000000..05d60b39 --- /dev/null +++ b/test/TestNonInvWs2812b.cpp @@ -0,0 +1,138 @@ + +// STL includes +#include +#include +#include + +std::vector encode(const std::vector & data); +void split(const uint8_t byte, uint8_t & out1, uint8_t & out2); +uint8_t encode(const bool bit1, const bool bit2, const bool bit3); + +void print(uint8_t byte) +{ + for (int i=0; i<8; ++i) + { + if (byte & (1 << i)) + { + std::cout << '1'; + } + else + { + std::cout << '0'; + } + } +} + +int main() +{ + std::vector data(3, 0x55); + + std::vector encData = encode(data); + + for (uint8_t encByte : encData) + { + std::cout << "0 "; + print(encByte); + std::cout << " 1"; + } + std::cout << std::endl; + + + return 0; +} + +std::vector encode(const std::vector & data) +{ + std::vector result; + + uint8_t previousByte = 0x00; + uint8_t nextByte = 0x00; + for (unsigned iData=0; iData "; + print(out2); std::cout << " => "; + out1 &= ~0x0F; + out1 |= (byte & 0x0F) << 4; +// out2 &= ~0xF0; + print(out2); std::cout << " => "; + out2 = (byte & 0xF0) >> 4; + print(out2); std::cout << std::endl; +} + +uint8_t encode(const bool bit1, const bool bit2, const bool bit3) +{ + if (bit2) + { + uint8_t result = 0x19; // 0--1 01 10-1 + if (bit1) result |= 0x02; +// else result &= ~0x02; + + if (bit3) result |= 0x60; +// else result &= ~0x60; + + return result; + } + else + { + uint8_t result = 0x21;// 0x21 (0-10 01 0--1) + if (bit1) result |= 0x06; +// else result &= ~0x06; + + if (bit3) result |= 0x40; +// else result &= ~0x40; + + return result; + } +}