From be3f3a968ce7fbfa14fc9e78e3d18d81934aff9e Mon Sep 17 00:00:00 2001 From: aufano Date: Wed, 4 Feb 2015 21:49:33 +0100 Subject: [PATCH] Carsten Atmolight support http://ca.rstenpresser.de/index.php/atmo-main.html Former-commit-id: cd543a063af50455e3e92fc9e89c2503bef95188 --- libsrc/leddevice/CMakeLists.txt | 2 ++ libsrc/leddevice/LedDeviceAtmo.cpp | 44 +++++++++++++++++++++++++++ libsrc/leddevice/LedDeviceAtmo.h | 38 +++++++++++++++++++++++ libsrc/leddevice/LedDeviceFactory.cpp | 10 ++++++ 4 files changed, 94 insertions(+) create mode 100644 libsrc/leddevice/LedDeviceAtmo.cpp create mode 100644 libsrc/leddevice/LedDeviceAtmo.h diff --git a/libsrc/leddevice/CMakeLists.txt b/libsrc/leddevice/CMakeLists.txt index 4304c874..26c04d29 100755 --- a/libsrc/leddevice/CMakeLists.txt +++ b/libsrc/leddevice/CMakeLists.txt @@ -30,6 +30,7 @@ SET(Leddevice_HEADERS ${CURRENT_SOURCE_DIR}/LedDeviceTest.h ${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h ${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h + ${CURRENT_SOURCE_DIR}/LedDeviceAtmo.h ) SET(Leddevice_SOURCES @@ -47,6 +48,7 @@ SET(Leddevice_SOURCES ${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp ${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp ${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp + ${CURRENT_SOURCE_DIR}/LedDeviceAtmo.cpp ) if(ENABLE_SPIDEV) diff --git a/libsrc/leddevice/LedDeviceAtmo.cpp b/libsrc/leddevice/LedDeviceAtmo.cpp new file mode 100644 index 00000000..22842233 --- /dev/null +++ b/libsrc/leddevice/LedDeviceAtmo.cpp @@ -0,0 +1,44 @@ + +// STL includes +#include +#include +#include + +// Linux includes +#include +#include + +// hyperion local includes +#include "LedDeviceAtmo.h" + +LedDeviceAtmo::LedDeviceAtmo(const std::string& outputDevice, const unsigned baudrate) : + LedRs232Device(outputDevice, baudrate), + _ledBuffer(0) +{ + _ledBuffer.resize(4 + 3*5); + _ledBuffer[0] = 0xFF; // Startbyte + _ledBuffer[1] = 0x00; // StartChannel(Low) + _ledBuffer[2] = 0x00; // StartChannel(High) + _ledBuffer[3] = 0x0F; // Number of Databytes send (always! 15) +} + +int LedDeviceAtmo::write(const std::vector &ledValues) +{ + // The protocol is shomehow limited. we always need to send exactly 5 channels + header + // (19 bytes) for the hardware to recognize the data + if (ledValues.size() != 5) + { + printf("AtmoLight: %d channels configured. This should always be 5!\n", ledValues.size()); + return 0; + } + + // write data + memcpy(4 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3); + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} + +int LedDeviceAtmo::switchOff() +{ + memset(4 + _ledBuffer.data(), 0, _ledBuffer.size() - 4); + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} diff --git a/libsrc/leddevice/LedDeviceAtmo.h b/libsrc/leddevice/LedDeviceAtmo.h new file mode 100644 index 00000000..f6bf4a44 --- /dev/null +++ b/libsrc/leddevice/LedDeviceAtmo.h @@ -0,0 +1,38 @@ +#pragma once + +// STL includes +#include + +// hyperion incluse +#include "LedRs232Device.h" + +/// +/// Implementation of the LedDevice interface for writing to serial device using tpm2 protocol. +/// +class LedDeviceAtmo : public LedRs232Device +{ +public: + /// + /// Constructs the LedDevice for attached serial device using supporting tpm2 protocol + /// All LEDs in the stripe are handled as one frame + /// + /// @param outputDevice The name of the output device (eg '/dev/ttyAMA0') + /// @param baudrate The used baudrate for writing to the output device + /// + LedDeviceAtmo(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/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index fb602b02..4f8ca2bf 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -30,6 +30,7 @@ #include "LedDeviceHyperionUsbasp.h" #include "LedDevicePhilipsHue.h" #include "LedDeviceTpm2.h" +#include "LedDeviceAtmo.h" #ifdef ENABLE_WS2812BPWM #include "LedDeviceWS2812b.h" @@ -186,6 +187,15 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig) deviceTpm2->open(); device = deviceTpm2; } + else if (type == "atmo") + { + const std::string output = deviceConfig["output"].asString(); + const unsigned rate = 38400; + + LedDeviceAtmo * deviceAtmo = new LedDeviceAtmo(output, rate); + deviceAtmo->open(); + device = deviceAtmo; + } #ifdef ENABLE_WS2812BPWM else if (type == "ws2812b") {