From 5c71e626c7ef7dbbef0dace01888009faf4e6321 Mon Sep 17 00:00:00 2001 From: johan Date: Mon, 11 Nov 2013 21:07:24 +0100 Subject: [PATCH] Adalight device added Former-commit-id: d9b9a146b39ba83fada52de2b6076dde7e44b151 --- config/hyperion.config.json | 10 ++--- deploy/HyperCon.jar.REMOVED.git-id | 2 +- deploy/hyperiond.REMOVED.git-id | 2 +- libsrc/hyperion/CMakeLists.txt | 2 + libsrc/hyperion/Hyperion.cpp | 11 +++++ libsrc/hyperion/device/LedDeviceAdalight.cpp | 42 +++++++++++++++++++ libsrc/hyperion/device/LedDeviceAdalight.h | 37 ++++++++++++++++ libsrc/hyperion/device/LedDeviceSedu.h | 2 +- libsrc/hyperion/device/LedRs232Device.cpp | 6 +-- .../hyperion/hypercon/spec/DeviceConfig.java | 8 ++-- .../hyperion/hypercon/spec/DeviceType.java | 2 + 11 files changed, 109 insertions(+), 15 deletions(-) create mode 100644 libsrc/hyperion/device/LedDeviceAdalight.cpp create mode 100644 libsrc/hyperion/device/LedDeviceAdalight.h diff --git a/config/hyperion.config.json b/config/hyperion.config.json index eac7c282..ed68c2f9 100644 --- a/config/hyperion.config.json +++ b/config/hyperion.config.json @@ -4,10 +4,10 @@ { /// 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', 'lpd6803', 'sedu', 'test' and 'none') - /// * 'output' : The output specification depends on selected device - /// - 'ws2801' this is the device (eg '/dev/spidev0.0 or /dev/ttyS0') - /// - 'test' this is the file used to write test output (eg '/home/pi/hyperion.out') + /// * 'type' : The type of the device or leds (known types for now are 'ws2801', 'lpd6803', 'sedu', + /// 'adalight', 'test' and 'none') + /// * 'output' : The output specification depends on selected device. This can for example be the + /// device specifier or the output file name /// * 'rate' : The baudrate of the output to the device /// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.). "device" : @@ -15,7 +15,7 @@ "name" : "MyPi", "type" : "ws2801", "output" : "/dev/spidev0.0", - "rate" : 1000000, + "rate" : 500000, "colorOrder" : "rgb" }, diff --git a/deploy/HyperCon.jar.REMOVED.git-id b/deploy/HyperCon.jar.REMOVED.git-id index dd3a10e5..49501ee1 100644 --- a/deploy/HyperCon.jar.REMOVED.git-id +++ b/deploy/HyperCon.jar.REMOVED.git-id @@ -1 +1 @@ -1c3031eb536b2af5ced172f1eb071011f705cc86 \ No newline at end of file +f888f2f1ce44fca56ac8c6326c8615849cbd6a5d \ No newline at end of file diff --git a/deploy/hyperiond.REMOVED.git-id b/deploy/hyperiond.REMOVED.git-id index 5f976bed..31be59c9 100644 --- a/deploy/hyperiond.REMOVED.git-id +++ b/deploy/hyperiond.REMOVED.git-id @@ -1 +1 @@ -9e9b710c8305a3445a621d322334a14b6934b87a \ No newline at end of file +992962914879591c2740a1b2769269d790284766 \ No newline at end of file diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index 6b1b424e..08a3a729 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -27,6 +27,7 @@ SET(Hyperion_HEADERS ${CURRENT_SOURCE_DIR}/device/LedDeviceSedu.h ${CURRENT_SOURCE_DIR}/device/LedDeviceWs2801.h ${CURRENT_SOURCE_DIR}/device/LedDeviceLpd6803.h + ${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.h ) SET(Hyperion_SOURCES @@ -47,6 +48,7 @@ SET(Hyperion_SOURCES ${CURRENT_SOURCE_DIR}/device/LedDeviceTest.cpp ${CURRENT_SOURCE_DIR}/device/LedDeviceWs2801.cpp ${CURRENT_SOURCE_DIR}/device/LedDeviceLpd6803.cpp + ${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.cpp ) set(Hyperion_RESOURCES diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index bd906d2d..6aee8267 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -14,6 +14,7 @@ #include "device/LedDeviceSedu.h" #include "device/LedDeviceTest.h" #include "device/LedDeviceWs2801.h" +#include "device/LedDeviceAdalight.h" #include "LinearColorSmoothing.h" @@ -58,6 +59,16 @@ LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig) device = deviceSedu; } + else if (type == "adalight") + { + const std::string output = deviceConfig["output"].asString(); + const unsigned rate = deviceConfig["rate"].asInt(); + + LedDeviceAdalight* deviceAdalight = new LedDeviceAdalight(output, rate); + deviceAdalight->open(); + + device = deviceAdalight; + } else if (type == "test") { const std::string output = deviceConfig["output"].asString(); diff --git a/libsrc/hyperion/device/LedDeviceAdalight.cpp b/libsrc/hyperion/device/LedDeviceAdalight.cpp new file mode 100644 index 00000000..bca44978 --- /dev/null +++ b/libsrc/hyperion/device/LedDeviceAdalight.cpp @@ -0,0 +1,42 @@ + +// STL includes +#include +#include +#include + +// Linux includes +#include +#include + +// hyperion local includes +#include "LedDeviceAdalight.h" + +LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate) : + LedRs232Device(outputDevice, baudrate), + _ledBuffer(0) +{ + // empty +} + +int LedDeviceAdalight::write(const std::vector &ledValues) +{ + if (_ledBuffer.size() == 0) + { + _ledBuffer.resize(6 + 3*ledValues.size()); + _ledBuffer[0] = 'A'; + _ledBuffer[1] = 'd'; + _ledBuffer[2] = 'a'; + _ledBuffer[3] = ((ledValues.size() - 1) >> 8) & 0xFF; // LED count high byte + _ledBuffer[4] = (ledValues.size() - 1) & 0xFF; // LED count low byte + _ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum + } + + memcpy(6 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3); + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} + +int LedDeviceAdalight::switchOff() +{ + memset(6 + _ledBuffer.data(), 0, _ledBuffer.size()-6); + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} diff --git a/libsrc/hyperion/device/LedDeviceAdalight.h b/libsrc/hyperion/device/LedDeviceAdalight.h new file mode 100644 index 00000000..f06b0230 --- /dev/null +++ b/libsrc/hyperion/device/LedDeviceAdalight.h @@ -0,0 +1,37 @@ +#pragma once + +// STL includes +#include + +// hyperion incluse +#include "LedRs232Device.h" + +/// +/// Implementation of the LedDevice interface for writing to an Adalight led device. +/// +class LedDeviceAdalight : public LedRs232Device +{ +public: + /// + /// Constructs the LedDevice for attached Adalight device + /// + /// @param outputDevice The name of the output device (eg '/dev/ttyS0') + /// @param baudrate The used baudrate for writing to the output device + /// + LedDeviceAdalight(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/device/LedDeviceSedu.h b/libsrc/hyperion/device/LedDeviceSedu.h index 37685f6a..9f2e35bf 100644 --- a/libsrc/hyperion/device/LedDeviceSedu.h +++ b/libsrc/hyperion/device/LedDeviceSedu.h @@ -15,7 +15,7 @@ public: /// /// Constructs the LedDevice for attached via SEDU device /// - /// @param outputDevice The name of the output device (eg '/etc/ttyS0') + /// @param outputDevice The name of the output device (eg '/dev/ttyS0') /// @param baudrate The used baudrate for writing to the output device /// LedDeviceSedu(const std::string& outputDevice, const unsigned baudrate); diff --git a/libsrc/hyperion/device/LedRs232Device.cpp b/libsrc/hyperion/device/LedRs232Device.cpp index 9b94e856..efdd296e 100644 --- a/libsrc/hyperion/device/LedRs232Device.cpp +++ b/libsrc/hyperion/device/LedRs232Device.cpp @@ -48,9 +48,9 @@ int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data) return -1; } - //for (int i = 0; i < 20; ++i) - // std::cout << std::hex << (int)data[i] << " "; - //std::cout << std::endl; +// for (int i = 0; i < 20; ++i) +// std::cout << std::hex << (int)data[i] << " "; +// std::cout << std::endl; try { diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java index 78383edc..6f3ed4ce 100644 --- a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java @@ -26,10 +26,10 @@ public class DeviceConfig { strBuf.append("\t/// Device configuration contains the following fields: \n"); strBuf.append("\t/// * 'name' : The user friendly name of the device (only used for display purposes)\n"); - strBuf.append("\t/// * 'type' : The type of the device or leds (known types for now are 'ws2801', 'lpd6803', 'sedu', 'test' and 'none')\n"); - strBuf.append("\t/// * 'output' : The output specification depends on selected device\n"); - strBuf.append("\t/// - 'ws2801' this is the device (eg '/dev/spidev0.0 or /dev/ttyS0')\n"); - strBuf.append("\t/// - 'test' this is the file used to write test output (eg '/home/pi/hyperion.out')\n"); + strBuf.append("\t/// * 'type' : The type of the device or leds (known types for now are 'ws2801', 'lpd6803', 'sedu',\n"); + strBuf.append("\t/// 'adalight', 'test' and 'none')\n"); + strBuf.append("\t/// * 'output' : The output specification depends on selected device. This can for example be the\n"); + strBuf.append("\t/// device specifier or the output file name\n"); strBuf.append("\t/// * 'rate' : The baudrate of the output to the device\n"); strBuf.append("\t/// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.).\n"); diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceType.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceType.java index b41ba206..9d9fe70d 100644 --- a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceType.java +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceType.java @@ -10,6 +10,8 @@ public enum DeviceType { lpd6803("LPD6803"), /** SEDU LED device */ sedu("SEDU"), + /** Adalight device */ + adalight("Adalight"), /** Test device for writing color values to file-output */ test("Test"), /** No device, no output is generated */