diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index b7449729..c63bb95b 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -20,11 +20,13 @@ SET(Hyperion_HEADERS ${CURRENT_SOURCE_DIR}/BlackBorderDetector.h ${CURRENT_SOURCE_DIR}/BlackBorderProcessor.h ${CURRENT_SOURCE_DIR}/ImageToLedsMap.h - ${CURRENT_SOURCE_DIR}/LedSpiDevice.h - ${CURRENT_SOURCE_DIR}/LedRs232Device.h - ${CURRENT_SOURCE_DIR}/LedDeviceTest.h - ${CURRENT_SOURCE_DIR}/LedDeviceWs2801.h - ${CURRENT_SOURCE_DIR}/LedDeviceLdp6803.h + + ${CURRENT_SOURCE_DIR}/device/LedSpiDevice.h + ${CURRENT_SOURCE_DIR}/device/LedRs232Device.h + ${CURRENT_SOURCE_DIR}/device/LedDeviceTest.h + ${CURRENT_SOURCE_DIR}/device/LedDeviceSedu.h + ${CURRENT_SOURCE_DIR}/device/LedDeviceWs2801.h + ${CURRENT_SOURCE_DIR}/device/LedDeviceLdp6803.h ) SET(Hyperion_SOURCES @@ -37,12 +39,14 @@ SET(Hyperion_SOURCES ${CURRENT_SOURCE_DIR}/BlackBorderDetector.cpp ${CURRENT_SOURCE_DIR}/BlackBorderProcessor.cpp ${CURRENT_SOURCE_DIR}/ImageToLedsMap.cpp - ${CURRENT_SOURCE_DIR}/LedSpiDevice.cpp - ${CURRENT_SOURCE_DIR}/LedRs232Device.cpp - ${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp - ${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp - ${CURRENT_SOURCE_DIR}/LedDeviceLdp6803.cpp ${CURRENT_SOURCE_DIR}/LinearColorSmoothing.cpp + + ${CURRENT_SOURCE_DIR}/device/LedSpiDevice.cpp + ${CURRENT_SOURCE_DIR}/device/LedRs232Device.cpp + ${CURRENT_SOURCE_DIR}/device/LedDeviceSedu.cpp + ${CURRENT_SOURCE_DIR}/device/LedDeviceTest.cpp + ${CURRENT_SOURCE_DIR}/device/LedDeviceWs2801.cpp + ${CURRENT_SOURCE_DIR}/device/LedDeviceLdp6803.cpp ) set(Hyperion_RESOURCES diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index d818e651..d9513e96 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -10,9 +10,9 @@ #include #include -#include "LedDeviceLdp6803.h" -#include "LedDeviceTest.h" -#include "LedDeviceWs2801.h" +#include "device/LedDeviceLdp6803.h" +#include "device/LedDeviceTest.h" +#include "device/LedDeviceWs2801.h" #include "LinearColorSmoothing.h" diff --git a/libsrc/hyperion/LedDeviceLdp6803.cpp b/libsrc/hyperion/device/LedDeviceLdp6803.cpp similarity index 100% rename from libsrc/hyperion/LedDeviceLdp6803.cpp rename to libsrc/hyperion/device/LedDeviceLdp6803.cpp diff --git a/libsrc/hyperion/LedDeviceLdp6803.h b/libsrc/hyperion/device/LedDeviceLdp6803.h similarity index 100% rename from libsrc/hyperion/LedDeviceLdp6803.h rename to libsrc/hyperion/device/LedDeviceLdp6803.h diff --git a/libsrc/hyperion/device/LedDeviceSedu.cpp b/libsrc/hyperion/device/LedDeviceSedu.cpp new file mode 100644 index 00000000..02517624 --- /dev/null +++ b/libsrc/hyperion/device/LedDeviceSedu.cpp @@ -0,0 +1,63 @@ + +// STL includes +#include +#include +#include + +// Linux includes +#include +#include + +// hyperion local includes +#include "LedDeviceSedu.h" + +struct FrameSpec +{ + uint8_t id; + size_t size; +}; + +LedDeviceSedu::LedDeviceSedu(const std::string& outputDevice, const unsigned baudrate) : + LedRs232Device(outputDevice, baudrate), + _ledBuffer(0) +{ + // empty +} + +int LedDeviceSedu::write(const std::vector &ledValues) +{ + if (_ledBuffer.size() == 0) + { + std::vector frameSpecs{{0xA0, 96}, {0xA1, 256}, {0xA2, 512}, {0xB0, 768}, {0xB1, 1536}, {0xB2, 3072} }; + + const unsigned reqColorChannels = ledValues.size() * sizeof(RgbColor); + + for (const FrameSpec& frameSpec : frameSpecs) + { + if (reqColorChannels <= frameSpec.size) + { + _ledBuffer.clear(); + _ledBuffer.resize(frameSpec.size + 3, 0); + _ledBuffer[0] = 0x5A; + _ledBuffer[1] = frameSpec.id; + _ledBuffer.back() = 0xA5; + break; + } + } + + if (_ledBuffer.size() == 0) + { + std::cout << "More rgb-channels required then available" << std::endl; + return -1; + } + } + + memcpy(_ledBuffer.data()+2, ledValues.data(), ledValues.size() * sizeof(RgbColor)); + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} + +int LedDeviceSedu::switchOff() +{ + memset(_ledBuffer.data()+2, 0, _ledBuffer.size()-3); + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} diff --git a/libsrc/hyperion/device/LedDeviceSedu.h b/libsrc/hyperion/device/LedDeviceSedu.h new file mode 100644 index 00000000..37685f6a --- /dev/null +++ b/libsrc/hyperion/device/LedDeviceSedu.h @@ -0,0 +1,37 @@ +#pragma once + +// STL includes +#include + +// hyperion incluse +#include "LedRs232Device.h" + +/// +/// Implementation of the LedDevice interface for writing to SEDU led device. +/// +class LedDeviceSedu : public LedRs232Device +{ +public: + /// + /// Constructs the LedDevice for attached via SEDU device + /// + /// @param outputDevice The name of the output device (eg '/etc/ttyS0') + /// @param baudrate The used baudrate for writing to the output device + /// + LedDeviceSedu(const std::string& outputDevice, const unsigned baudrate); + + /// + /// Writes the led color values to the led-device + /// + /// @param ledValues The color-value per led + /// @return Zero on succes else negative + /// + virtual int write(const std::vector &ledValues); + + /// Switch the leds off + virtual int switchOff(); + +private: + /// The buffer containing the packed RGB values + std::vector _ledBuffer; +}; diff --git a/libsrc/hyperion/LedDeviceTest.cpp b/libsrc/hyperion/device/LedDeviceTest.cpp similarity index 100% rename from libsrc/hyperion/LedDeviceTest.cpp rename to libsrc/hyperion/device/LedDeviceTest.cpp diff --git a/libsrc/hyperion/LedDeviceTest.h b/libsrc/hyperion/device/LedDeviceTest.h similarity index 100% rename from libsrc/hyperion/LedDeviceTest.h rename to libsrc/hyperion/device/LedDeviceTest.h diff --git a/libsrc/hyperion/LedDeviceWs2801.cpp b/libsrc/hyperion/device/LedDeviceWs2801.cpp similarity index 100% rename from libsrc/hyperion/LedDeviceWs2801.cpp rename to libsrc/hyperion/device/LedDeviceWs2801.cpp diff --git a/libsrc/hyperion/LedDeviceWs2801.h b/libsrc/hyperion/device/LedDeviceWs2801.h similarity index 100% rename from libsrc/hyperion/LedDeviceWs2801.h rename to libsrc/hyperion/device/LedDeviceWs2801.h diff --git a/libsrc/hyperion/LedRs232Device.cpp b/libsrc/hyperion/device/LedRs232Device.cpp similarity index 100% rename from libsrc/hyperion/LedRs232Device.cpp rename to libsrc/hyperion/device/LedRs232Device.cpp diff --git a/libsrc/hyperion/LedRs232Device.h b/libsrc/hyperion/device/LedRs232Device.h similarity index 100% rename from libsrc/hyperion/LedRs232Device.h rename to libsrc/hyperion/device/LedRs232Device.h diff --git a/libsrc/hyperion/LedSpiDevice.cpp b/libsrc/hyperion/device/LedSpiDevice.cpp similarity index 100% rename from libsrc/hyperion/LedSpiDevice.cpp rename to libsrc/hyperion/device/LedSpiDevice.cpp diff --git a/libsrc/hyperion/LedSpiDevice.h b/libsrc/hyperion/device/LedSpiDevice.h similarity index 100% rename from libsrc/hyperion/LedSpiDevice.h rename to libsrc/hyperion/device/LedSpiDevice.h diff --git a/test/TestSpi.cpp b/test/TestSpi.cpp index 8d28784a..008966d1 100644 --- a/test/TestSpi.cpp +++ b/test/TestSpi.cpp @@ -10,7 +10,7 @@ // Local includes #include -#include "../libsrc/hyperion/LedDeviceWs2801.h" +#include "../libsrc/hyperion/device/LedDeviceWs2801.h" void setColor(char* colorStr) {