diff --git a/.travis/travis_build.sh b/.travis/travis_build.sh index e5f514eb..d274d8ff 100755 --- a/.travis/travis_build.sh +++ b/.travis/travis_build.sh @@ -15,7 +15,7 @@ then mkdir build || exit 1 cd build - cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON -Wno-dev .. || exit 2 + cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -Wno-dev .. || exit 2 make -j$procs || exit 3 # make -j$(nproc) package || exit 4 # currently osx(dmg) package creation not implemented fi @@ -25,7 +25,7 @@ if [[ $TRAVIS_OS_NAME == 'linux' ]] then mkdir build || exit 1 cd build - cmake -DPLATFORM=x86-dev -DCMAKE_BUILD_TYPE=Release .. || exit 2 + cmake -DPLATFORM=x86-dev -DCMAKE_BUILD_TYPE=Debug .. || exit 2 make -j$(nproc) || exit 3 make -j$(nproc) package || exit 4 fi diff --git a/.travis/travis_install.sh b/.travis/travis_install.sh index ae7735b4..cb013543 100755 --- a/.travis/travis_install.sh +++ b/.travis/travis_install.sh @@ -1,6 +1,8 @@ #!/bin/bash + # install osx deps for hyperion compile -if [[ $TRAVIS_OS_NAME == 'osx' ]]; then +if [[ $TRAVIS_OS_NAME == 'osx' ]] +then echo "Install OSX deps" time brew update time brew install qt5 || true @@ -10,7 +12,8 @@ if [[ $TRAVIS_OS_NAME == 'osx' ]]; then fi # install linux deps for hyperion compile -if [[ $TRAVIS_OS_NAME == 'linux' ]]; then +if [[ $TRAVIS_OS_NAME == 'linux' ]] +then echo "Install linux deps" sudo apt-get -qq update sudo apt-get install -qq -y qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev doxygen diff --git a/CODING_STYLE.md b/CODING_STYLE.md index a22773c6..1a5d5f07 100644 --- a/CODING_STYLE.md +++ b/CODING_STYLE.md @@ -41,7 +41,7 @@ MyClass::MyClass() : myVarA(0), good: MyClass::MyClass() - : myVarA(0), + : myVarA(0) , myVarB("eee") , myVarC(true) { diff --git a/include/leddevice/LedDevice.h b/include/leddevice/LedDevice.h index f40e809f..f253591c 100644 --- a/include/leddevice/LedDevice.h +++ b/include/leddevice/LedDevice.h @@ -2,14 +2,21 @@ // STL incldues #include - #include +#include // Utility includes #include #include #include #include +#include +#include + +class LedDevice; + +typedef LedDevice* ( *LedDeviceCreateFuncType ) ( const Json::Value& ); +typedef std::map LedDeviceRegistry; /// /// Interface (pure virtual base class) for LedDevices. @@ -44,6 +51,10 @@ public: /// virtual int open(); + static int addToDeviceMap(std::string name, LedDeviceCreateFuncType funcPtr); + static const LedDeviceRegistry& getDeviceMap(); + static void setActiveDevice(std::string dev); + static std::string activeDevice() { return _activeDevice; }; protected: /// The common Logger instance for all LedDevices Logger * _log; @@ -53,4 +64,6 @@ protected: /// The buffer containing the packed RGB values std::vector _ledBuffer; + static std::string _activeDevice; + static LedDeviceRegistry _ledDeviceMap; }; diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index aa4cae2a..9cbaf376 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -565,7 +565,6 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile) , _raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), jsonConfig["color"])) , _raw2ledTemperature(createLedColorsTemperature(_ledString.leds().size(), jsonConfig["color"])) , _raw2ledAdjustment(createLedColorsAdjustment(_ledString.leds().size(), jsonConfig["color"])) - , _device(LedDeviceFactory::construct(jsonConfig["device"])) , _effectEngine(nullptr) , _messageForwarder(createMessageForwarder(jsonConfig["forwarder"])) , _jsonConfig(jsonConfig) @@ -575,6 +574,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile) , _hwLedCount(_ledString.leds().size()) , _sourceAutoSelectEnabled(true) { + _device = LedDeviceFactory::construct(jsonConfig["device"]); registerPriority("Off", PriorityMuxer::LOWEST_PRIORITY); if (!_raw2ledAdjustment->verifyAdjustments()) diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index ab497bd4..605b0c6e 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -624,21 +625,31 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const st << std::hex << unsigned(priorityInfo.ledColors.begin()->blue); LEDcolor["HEX Value"].append(hex.str()); - + activeLedColors.append(LEDcolor); } } } + // get available led devices + info["ledDevices"]["active"] = LedDevice::activeDevice(); + info["ledDevices"]["available"] = Json::Value(Json::arrayValue); + for ( auto dev: LedDevice::getDeviceMap()) + { + info["ledDevices"]["available"].append(dev.first); + } + + // Add Hyperion Version, build time - Json::Value & version = info["hyperion"] = Json::Value(Json::arrayValue); + //Json::Value & version = + info["hyperion"] = Json::Value(Json::arrayValue); Json::Value ver; ver["jsonrpc_version"] = HYPERION_JSON_VERSION; ver["version"] = HYPERION_VERSION; - ver["build"] = HYPERION_BUILD_ID; - ver["time"] = __DATE__ " " __TIME__; + ver["build"] = HYPERION_BUILD_ID; + ver["time"] = __DATE__ " " __TIME__; - version.append(ver); + info["hyperion"].append(ver); // send the result sendMessage(result); @@ -941,7 +952,7 @@ void JsonClientConnection::handleConfigSetCommand(const Json::Value &message, co sendSuccessReply(command, tan); } } else - sendErrorReply("Error while parsing json: Message size " + message.size(), command, tan); + sendErrorReply("Error while parsing json: Message size " + std::to_string(message.size()), command, tan); } void JsonClientConnection::handleComponentStateCommand(const Json::Value& message, const std::string &command, const int tan) diff --git a/libsrc/leddevice/CMakeLists.txt b/libsrc/leddevice/CMakeLists.txt index 2efcca56..2061f34f 100755 --- a/libsrc/leddevice/CMakeLists.txt +++ b/libsrc/leddevice/CMakeLists.txt @@ -34,13 +34,12 @@ SET(Leddevice_HEADERS ${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.h ${CURRENT_SOURCE_DIR}/LedDeviceSedu.h ${CURRENT_SOURCE_DIR}/LedDeviceFile.h - ${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h - ${CURRENT_SOURCE_DIR}/LedDeviceUdp.h ${CURRENT_SOURCE_DIR}/LedDeviceUdpRaw.h ${CURRENT_SOURCE_DIR}/LedDeviceUdpE131.h ${CURRENT_SOURCE_DIR}/LedUdpDevice.h ${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h ${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h + ${CURRENT_SOURCE_DIR}/LedDeviceTpm2net.h ${CURRENT_SOURCE_DIR}/LedDeviceAtmo.h ) @@ -62,13 +61,13 @@ SET(Leddevice_SOURCES ${CURRENT_SOURCE_DIR}/LedDeviceSedu.cpp ${CURRENT_SOURCE_DIR}/LedDeviceFile.cpp ${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.cpp - ${CURRENT_SOURCE_DIR}/LedDeviceUdp.cpp ${CURRENT_SOURCE_DIR}/LedDeviceUdpRaw.cpp ${CURRENT_SOURCE_DIR}/LedDeviceUdpE131.cpp ${CURRENT_SOURCE_DIR}/LedUdpDevice.cpp ${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp ${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp ${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp + ${CURRENT_SOURCE_DIR}/LedDeviceTpm2net.cpp ${CURRENT_SOURCE_DIR}/LedDeviceAtmo.cpp ) @@ -131,7 +130,13 @@ if(ENABLE_TINKERFORGE) ) endif() +set(LedDevice_RESOURCES + ${CURRENT_SOURCE_DIR}/LedDeviceSchemas.qrc +) + QT5_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS}) +qt5_add_resources(LedDevice_RESOURCES_RCC ${LedDevice_RESOURCES} OPTIONS "-no-compress") + add_library(leddevice @@ -139,13 +144,14 @@ add_library(leddevice ${Leddevice_QT_HEADERS} ${Leddevice_HEADERS_MOC} ${Leddevice_SOURCES} + ${LedDevice_RESOURCES} + ${LedDevice_RESOURCES_RCC} ) qt5_use_modules(leddevice Network SerialPort) target_link_libraries(leddevice hyperion-utils -# serialport ${LIBUSB_1_LIBRARIES} #apt-get install libusb-1.0-0-dev ${CMAKE_THREAD_LIBS_INIT} ${QT_LIBRARIES} diff --git a/libsrc/leddevice/LedDevice.cpp b/libsrc/leddevice/LedDevice.cpp index 11381238..e38a7d81 100644 --- a/libsrc/leddevice/LedDevice.cpp +++ b/libsrc/leddevice/LedDevice.cpp @@ -1,5 +1,8 @@ #include +LedDeviceRegistry LedDevice::_ledDeviceMap = LedDeviceRegistry(); +std::string LedDevice::_activeDevice = ""; + LedDevice::LedDevice() : QObject() , _log(Logger::getInstance("LedDevice")) @@ -9,8 +12,24 @@ LedDevice::LedDevice() { } +// dummy implemention int LedDevice::open() { - //dummy implemention return 0; } + +int LedDevice::addToDeviceMap(std::string name, LedDeviceCreateFuncType funcPtr) +{ + _ledDeviceMap.emplace(name,funcPtr); + return 0; +} + +const LedDeviceRegistry& LedDevice::getDeviceMap() +{ + return _ledDeviceMap; +} + +void LedDevice::setActiveDevice(std::string dev) +{ + _activeDevice = dev; +} \ No newline at end of file diff --git a/libsrc/leddevice/LedDeviceAPA102.cpp b/libsrc/leddevice/LedDeviceAPA102.cpp index 0b2bb1b1..3f2ff87e 100644 --- a/libsrc/leddevice/LedDeviceAPA102.cpp +++ b/libsrc/leddevice/LedDeviceAPA102.cpp @@ -12,9 +12,15 @@ // hyperion local includes #include "LedDeviceAPA102.h" -LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned baudrate) - : LedSpiDevice(outputDevice, baudrate, 500000) +LedDeviceAPA102::LedDeviceAPA102(const Json::Value &deviceConfig) + : LedSpiDevice(deviceConfig) { + _latchTime_ns = 500000; +} + +LedDevice* LedDeviceAPA102::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceAPA102(deviceConfig); } int LedDeviceAPA102::write(const std::vector &ledValues) diff --git a/libsrc/leddevice/LedDeviceAPA102.h b/libsrc/leddevice/LedDeviceAPA102.h index 5eb00514..07271696 100644 --- a/libsrc/leddevice/LedDeviceAPA102.h +++ b/libsrc/leddevice/LedDeviceAPA102.h @@ -5,22 +5,23 @@ // hyperion incluse #include "LedSpiDevice.h" +#include /// /// Implementation of the LedDevice interface for writing to APA102 led device. /// -/// APA102 is -/// class LedDeviceAPA102 : public LedSpiDevice { public: /// - /// Constructs the LedDevice for a string containing leds of the type APA102 + /// Constructs specific LedDevice /// - /// @param outputDevice The name of the output device (eg '/dev/spidev.0.0') - /// @param baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// - LedDeviceAPA102(const std::string& outputDevice, const unsigned baudrate ); + LedDeviceAPA102(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// diff --git a/libsrc/leddevice/LedDeviceAdalight.cpp b/libsrc/leddevice/LedDeviceAdalight.cpp index 880f6690..880417cc 100644 --- a/libsrc/leddevice/LedDeviceAdalight.cpp +++ b/libsrc/leddevice/LedDeviceAdalight.cpp @@ -10,9 +10,10 @@ // hyperion local includes #include "LedDeviceAdalight.h" +#include -LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) - : LedRs232Device(outputDevice, baudrate, delayAfterConnect_ms) +LedDeviceAdalight::LedDeviceAdalight(const Json::Value &deviceConfig) + : LedRs232Device(deviceConfig) , _timer() { // setup the timer @@ -24,6 +25,11 @@ LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsi _timer.start(); } +LedDevice* LedDeviceAdalight::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceAdalight(deviceConfig); +} + int LedDeviceAdalight::write(const std::vector & ledValues) { if (_ledBuffer.size() == 0) diff --git a/libsrc/leddevice/LedDeviceAdalight.h b/libsrc/leddevice/LedDeviceAdalight.h index 2f8aab60..e3f647a5 100644 --- a/libsrc/leddevice/LedDeviceAdalight.h +++ b/libsrc/leddevice/LedDeviceAdalight.h @@ -18,12 +18,14 @@ class LedDeviceAdalight : public LedRs232Device public: /// - /// Constructs the LedDevice for attached Adalight device + /// Constructs specific LedDevice /// - /// @param outputDevice The name of the output device (eg '/dev/ttyS0') - /// @param baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// - LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms); + LedDeviceAdalight(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device @@ -46,3 +48,4 @@ protected: /// every 15 seconds QTimer _timer; }; + diff --git a/libsrc/leddevice/LedDeviceAdalightApa102.cpp b/libsrc/leddevice/LedDeviceAdalightApa102.cpp index c72cbc3b..ccc273a2 100644 --- a/libsrc/leddevice/LedDeviceAdalightApa102.cpp +++ b/libsrc/leddevice/LedDeviceAdalightApa102.cpp @@ -11,11 +11,17 @@ // hyperion local includes #include "LedDeviceAdalightApa102.h" -LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) - : LedDeviceAdalight(outputDevice, baudrate, delayAfterConnect_ms) +LedDeviceAdalightApa102::LedDeviceAdalightApa102(const Json::Value &deviceConfig) + : LedDeviceAdalight(deviceConfig) { } +LedDevice* LedDeviceAdalightApa102::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceAdalightApa102(deviceConfig); +} + + //comparing to ws2801 adalight, the following changes were needed: // 1- differnt data frame (4 bytes instead of 3) // 2 - in order to accomodate point 1 above, number of leds sent to adalight is increased by 1/3rd diff --git a/libsrc/leddevice/LedDeviceAdalightApa102.h b/libsrc/leddevice/LedDeviceAdalightApa102.h index dfdd99c2..d452d771 100644 --- a/libsrc/leddevice/LedDeviceAdalightApa102.h +++ b/libsrc/leddevice/LedDeviceAdalightApa102.h @@ -20,7 +20,10 @@ public: /// @param outputDevice The name of the output device (eg '/dev/ttyS0') /// @param baudrate The used baudrate for writing to the output device /// - LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms); + LedDeviceAdalightApa102(const Json::Value &deviceConfig); + + /// create leddevice when type in config is set to this type + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device @@ -33,3 +36,4 @@ public: /// Switch the leds off virtual int switchOff(); }; + diff --git a/libsrc/leddevice/LedDeviceAtmo.cpp b/libsrc/leddevice/LedDeviceAtmo.cpp index 74d7f044..d4878aff 100644 --- a/libsrc/leddevice/LedDeviceAtmo.cpp +++ b/libsrc/leddevice/LedDeviceAtmo.cpp @@ -1,8 +1,8 @@ // hyperion local includes #include "LedDeviceAtmo.h" -LedDeviceAtmo::LedDeviceAtmo(const std::string& outputDevice, const unsigned baudrate) - : LedRs232Device(outputDevice, baudrate) +LedDeviceAtmo::LedDeviceAtmo(const Json::Value &deviceConfig) + : LedRs232Device(deviceConfig) { _ledBuffer.resize(4 + 5*3); // 4-byte header, 5 RGB values _ledBuffer[0] = 0xFF; // Startbyte @@ -11,6 +11,12 @@ LedDeviceAtmo::LedDeviceAtmo(const std::string& outputDevice, const unsigned bau _ledBuffer[3] = 0x0F; // Number of Databytes send (always! 15) } +LedDevice* LedDeviceAtmo::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceAtmo(deviceConfig); +} + + int LedDeviceAtmo::write(const std::vector &ledValues) { // The protocol is shomehow limited. we always need to send exactly 5 channels + header diff --git a/libsrc/leddevice/LedDeviceAtmo.h b/libsrc/leddevice/LedDeviceAtmo.h index 85f05c6e..18ccfd5d 100644 --- a/libsrc/leddevice/LedDeviceAtmo.h +++ b/libsrc/leddevice/LedDeviceAtmo.h @@ -13,13 +13,14 @@ 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 + /// Constructs specific LedDevice /// - /// @param outputDevice The name of the output device (eg '/dev/ttyAMA0') - /// @param baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// - LedDeviceAtmo(const std::string& outputDevice, const unsigned baudrate); + LedDeviceAtmo(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceAtmoOrb.cpp b/libsrc/leddevice/LedDeviceAtmoOrb.cpp index 28fc48d1..79c339a1 100644 --- a/libsrc/leddevice/LedDeviceAtmoOrb.cpp +++ b/libsrc/leddevice/LedDeviceAtmoOrb.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -15,23 +16,10 @@ AtmoOrbLight::AtmoOrbLight(unsigned int id) { // Not implemented } -LedDeviceAtmoOrb::LedDeviceAtmoOrb( - const std::string &output, - bool useOrbSmoothing, - int transitiontime, - int skipSmoothingDiff, - int port, - int numLeds, - std::vector orbIds) +LedDeviceAtmoOrb::LedDeviceAtmoOrb(const Json::Value &deviceConfig) : LedDevice() - , _multicastGroup(output.c_str()) - , _useOrbSmoothing(useOrbSmoothing) - , _transitiontime(transitiontime) - , _skipSmoothingDiff(skipSmoothingDiff) - , _multiCastGroupPort(port) - , _numLeds(numLeds) - , _orbIds(orbIds) { + setConfig(deviceConfig); _manager = new QNetworkAccessManager(); _groupAddress = QHostAddress(_multicastGroup); @@ -41,6 +29,44 @@ LedDeviceAtmoOrb::LedDeviceAtmoOrb( joinedMulticastgroup = _udpSocket->joinMulticastGroup(_groupAddress); } +bool LedDeviceAtmoOrb::setConfig(const Json::Value &deviceConfig) +{ + _multicastGroup = deviceConfig["output"].asString().c_str(); + _useOrbSmoothing = deviceConfig.get("useOrbSmoothing", false).asBool(); + _transitiontime = deviceConfig.get("transitiontime", 0).asInt(); + _skipSmoothingDiff = deviceConfig.get("skipSmoothingDiff", 0).asInt(); + _multiCastGroupPort = deviceConfig.get("port", 49692).asInt(); + _numLeds = deviceConfig.get("numLeds", 24).asInt(); + + const std::string orbId = deviceConfig["orbIds"].asString(); + _orbIds.clear(); + + // If we find multiple Orb ids separate them and add to list + const std::string separator (","); + if (orbId.find(separator) != std::string::npos) + { + std::stringstream ss(orbId); + std::vector output; + unsigned int i; + while (ss >> i) + { + _orbIds.push_back(i); + if (ss.peek() == ',' || ss.peek() == ' ') ss.ignore(); + } + } + else + { + _orbIds.push_back(atoi(orbId.c_str())); + } + + return true; +} + +LedDevice* LedDeviceAtmoOrb::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceAtmoOrb(deviceConfig); +} + int LedDeviceAtmoOrb::write(const std::vector &ledValues) { // If not in multicast group return diff --git a/libsrc/leddevice/LedDeviceAtmoOrb.h b/libsrc/leddevice/LedDeviceAtmoOrb.h index d11127f1..e76fe067 100644 --- a/libsrc/leddevice/LedDeviceAtmoOrb.h +++ b/libsrc/leddevice/LedDeviceAtmoOrb.h @@ -45,20 +45,21 @@ public: bool joinedMulticastgroup; /// - /// Constructs the device. + /// Constructs specific LedDevice /// - /// @param output is the multicast address of Orbs - /// @param transitiontime is optional and not used at the moment - /// @param useOrbSmoothing use Orbs own (external) smoothing algorithm (default: false) - /// @param skipSmoothingDiff minimal color (0-255) difference to override smoothing so that if current and previously received colors are higher than set dif we override smoothing - /// @param port is the multicast port. - /// @param numLeds is the total amount of leds per Orb - /// @param array containing orb ids + /// @param deviceConfig json device config /// - LedDeviceAtmoOrb(const std::string &output, bool useOrbSmoothing = - false, int transitiontime = 0, int skipSmoothingDiff = 0, int port = 49692, int numLeds = 24, - std::vector orbIds = std::vector()); + LedDeviceAtmoOrb(const Json::Value &deviceConfig); + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Destructor of this device /// diff --git a/libsrc/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index 3257904e..b4baa439 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -3,6 +3,7 @@ #include #include #include +#include // Build configuration #include @@ -10,6 +11,7 @@ // Leddevice includes #include #include +#include // Local Leddevice includes #ifdef ENABLE_SPIDEV @@ -35,7 +37,7 @@ #include "LedDeviceSedu.h" #include "LedDeviceFile.h" #include "LedDeviceFadeCandy.h" -#include "LedDeviceUdp.h" +#include "LedDeviceTpm2net.h" #include "LedDeviceUdpRaw.h" #include "LedDeviceUdpE131.h" #include "LedDeviceHyperionUsbasp.h" @@ -63,281 +65,81 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig) std::string type = deviceConfig.get("type", "UNSPECIFIED").asString(); std::transform(type.begin(), type.end(), type.begin(), ::tolower); + // rs232 devices + LedDevice::addToDeviceMap("adalight" , LedDeviceAdalight::construct); + LedDevice::addToDeviceMap("adalightapa102", LedDeviceAdalightApa102::construct); + LedDevice::addToDeviceMap("sedu" , LedDeviceSedu::construct); + LedDevice::addToDeviceMap("tpm2" , LedDeviceTpm2::construct); + LedDevice::addToDeviceMap("atmo" , LedDeviceAtmo::construct); + LedDevice::addToDeviceMap("fadecandy" , LedDeviceFadeCandy::construct); + + // spi devices + #ifdef ENABLE_SPIDEV + LedDevice::addToDeviceMap("apa102" , LedDeviceAPA102::construct); + LedDevice::addToDeviceMap("lpd6803" , LedDeviceLpd6803::construct); + LedDevice::addToDeviceMap("lpd8806" , LedDeviceLpd8806::construct); + LedDevice::addToDeviceMap("p9813" , LedDeviceP9813::construct); + LedDevice::addToDeviceMap("ws2801" , LedDeviceWs2801::construct); + LedDevice::addToDeviceMap("ws2812spi" , LedDeviceWs2812SPI::construct); + LedDevice::addToDeviceMap("sk6812rgbw-spi", LedDeviceSk6812SPI::construct); + #endif + + // pwm devices + #ifdef ENABLE_WS2812BPWM + LedDevice::addToDeviceMap("ws2812b", LedDeviceWS2812b::construct); + #endif + #ifdef ENABLE_WS281XPWM + LedDevice::addToDeviceMap("ws281x", LedDeviceWS281x::construct); + #endif + + // network lights + LedDevice::addToDeviceMap("tmp2net", LedDeviceTpm2net::construct); + LedDevice::addToDeviceMap("udpraw", LedDeviceUdpRaw::construct); + LedDevice::addToDeviceMap("e131", LedDeviceUdpE131::construct); + #ifdef ENABLE_TINKERFORGE + LedDevice::addToDeviceMap("tinkerforge", LedDeviceTinkerforge::construct); + #endif + LedDevice::addToDeviceMap("philipshue", LedDevicePhilipsHue::construct); + LedDevice::addToDeviceMap("atmoorb", LedDeviceAtmoOrb::construct); + + // direct usb + LedDevice::addToDeviceMap("hyperion-usbasp", LedDeviceHyperionUsbasp::construct); + LedDevice::addToDeviceMap("rawhid", LedDeviceRawHID::construct); + LedDevice::addToDeviceMap("paintpack", LedDevicePaintpack::construct); + LedDevice::addToDeviceMap("lightpack", LedDeviceLightpack::construct); + LedDevice::addToDeviceMap("multi-lightpack", LedDeviceMultiLightpack::construct); + + // other + LedDevice::addToDeviceMap("file", LedDeviceFile::construct); + LedDevice::addToDeviceMap("piblaster", LedDevicePiBlaster::construct); + + const LedDeviceRegistry& devList = LedDevice::getDeviceMap(); LedDevice* device = nullptr; try { - if (false) {} - else if (type == "adalight") + for ( auto dev: devList) { - device = new LedDeviceAdalight( - deviceConfig["output"].asString(), - deviceConfig["rate"].asInt(), - deviceConfig.get("delayAfterConnect",500).asInt() - ); - } - else if (type == "adalightapa102") - { - device = new LedDeviceAdalightApa102( - deviceConfig["output"].asString(), - deviceConfig["rate"].asInt(), - deviceConfig.get("delayAfterConnect",500).asInt() - ); - } - #ifdef ENABLE_SPIDEV - else if (type == "lpd6803" || type == "ldp6803") - { - device = new LedDeviceLpd6803( - deviceConfig["output"].asString(), - deviceConfig["rate"].asInt() - ); - } - else if (type == "lpd8806" || type == "ldp8806") - { - device = new LedDeviceLpd8806( - deviceConfig["output"].asString(), - deviceConfig["rate"].asInt() - ); - } - else if (type == "p9813") - { - device = new LedDeviceP9813( - deviceConfig["output"].asString(), - deviceConfig["rate"].asInt() - ); - } - else if (type == "apa102") - { - device = new LedDeviceAPA102( - deviceConfig["output"].asString(), - deviceConfig["rate"].asInt() - ); - } - else if (type == "ws2801" || type == "lightberry") - { - device = new LedDeviceWs2801( - deviceConfig["output"].asString(), - deviceConfig["rate"].asInt(), - deviceConfig.get("latchtime",500000).asInt(), - deviceConfig.get("spimode",0).asInt(), - deviceConfig.get("invert",false).asBool() - ); - } - else if (type == "ws2812spi") - { - device = new LedDeviceWs2812SPI( - deviceConfig["output"].asString(), - deviceConfig.get("rate",2857143).asInt(), - deviceConfig.get("spimode",0).asInt(), - deviceConfig.get("invert",false).asBool() - ); - } - else if (type == "sk6812rgbw-spi") - { - device = new LedDeviceSk6812SPI( - deviceConfig["output"].asString(), - deviceConfig.get("rate",2857143).asInt(), - deviceConfig.get("white_algorithm","").asString(), - deviceConfig.get("spimode",0).asInt(), - deviceConfig.get("invert",false).asBool() - ); - } - #endif - #ifdef ENABLE_TINKERFORGE - else if (type=="tinkerforge") - { - device = new LedDeviceTinkerforge( - deviceConfig.get("output", "127.0.0.1").asString(), - deviceConfig.get("port", 4223).asInt(), - deviceConfig["uid"].asString(), - deviceConfig["rate"].asInt() - ); - - } - #endif - else if (type == "rawhid") - { - const int delay_ms = deviceConfig["delayAfterConnect"].asInt(); - auto VendorIdString = deviceConfig.get("VID", "0x2341").asString(); - auto ProductIdString = deviceConfig.get("PID", "0x8036").asString(); - - // Convert HEX values to integer - auto VendorId = std::stoul(VendorIdString, nullptr, 16); - auto ProductId = std::stoul(ProductIdString, nullptr, 16); - - device = new LedDeviceRawHID(VendorId, ProductId, delay_ms); - } - else if (type == "lightpack") - { - device = new LedDeviceLightpack( - deviceConfig.get("output", "").asString() - ); - } - else if (type == "multi-lightpack") - { - device = new LedDeviceMultiLightpack(); - } - else if (type == "paintpack") - { - const int delay_ms = deviceConfig["delayAfterConnect"].asInt(); - auto VendorIdString = deviceConfig.get("VID", "0x0EBF").asString(); - auto ProductIdString = deviceConfig.get("PID", "0x0025").asString(); - - // Convert HEX values to integer - auto VendorId = std::stoul(VendorIdString, nullptr, 16); - auto ProductId = std::stoul(ProductIdString, nullptr, 16); - - device = new LedDevicePaintpack(VendorId, ProductId, delay_ms); - } - else if (type == "piblaster") - { - const std::string output = deviceConfig.get("output", "").asString(); - const std::string assignment = deviceConfig.get("assignment", "").asString(); - const Json::Value gpioMapping = deviceConfig.get("gpiomap", Json::nullValue); - - if (! assignment.empty()) + if (dev.first == type) { - throw std::runtime_error("Piblaster: The piblaster configuration syntax has changed in this version."); + device = dev.second(deviceConfig); + LedDevice::setActiveDevice(dev.first); + Info(log,"LedDevice '%s' configured.", dev.first.c_str()); + break; } - if (gpioMapping.isNull()) - { - throw std::runtime_error("Piblaster: no gpiomap defined."); - } - device = new LedDevicePiBlaster(output, gpioMapping); } - else if (type == "sedu") - { - device = new LedDeviceSedu( - deviceConfig["output"].asString(), - deviceConfig["rate"].asInt() - ); - } - else if (type == "hyperion-usbasp-ws2801") - { - device = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2801); - } - else if (type == "hyperion-usbasp-ws2812") - { - device = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2812); - } - else if (type == "philipshue") - { - const std::string output = deviceConfig["output"].asString(); - const std::string username = deviceConfig.get("username", "newdeveloper").asString(); - const bool switchOffOnBlack = deviceConfig.get("switchOffOnBlack", true).asBool(); - const int transitiontime = deviceConfig.get("transitiontime", 1).asInt(); - std::vector lightIds; - for (Json::Value::ArrayIndex i = 0; i < deviceConfig["lightIds"].size(); i++) { - lightIds.push_back(deviceConfig["lightIds"][i].asInt()); - } - device = new LedDevicePhilipsHue(output, username, switchOffOnBlack, transitiontime, lightIds); - } - else if (type == "atmoorb") - { - const std::string output = deviceConfig["output"].asString(); - const bool useOrbSmoothing = deviceConfig.get("useOrbSmoothing", false).asBool(); - const int transitiontime = deviceConfig.get("transitiontime", 1).asInt(); - const int skipSmoothingDiff = deviceConfig.get("skipSmoothingDiff", 0).asInt(); - const int port = deviceConfig.get("port", 1).asInt(); - const int numLeds = deviceConfig.get("numLeds", 1).asInt(); - const std::string orbId = deviceConfig["orbIds"].asString(); - std::vector orbIds; - - // If we find multiple Orb ids separate them and add to list - const std::string separator (","); - if (orbId.find(separator) != std::string::npos) { - std::stringstream ss(orbId); - std::vector output; - unsigned int i; - while (ss >> i) { - orbIds.push_back(i); - if (ss.peek() == ',' || ss.peek() == ' ') - ss.ignore(); - } - } - else - { - orbIds.push_back(atoi(orbId.c_str())); - } - - device = new LedDeviceAtmoOrb(output, useOrbSmoothing, transitiontime, skipSmoothingDiff, port, numLeds, orbIds); - } - else if (type == "fadecandy") - { - device = new LedDeviceFadeCandy(deviceConfig); - } - else if (type == "udp") - { - device = new LedDeviceUdp( - deviceConfig["output"].asString(), - deviceConfig["protocol"].asInt(), - deviceConfig["maxpacket"].asInt() - ); - } - else if (type == "udpraw") - { - device = new LedDeviceUdpRaw( - deviceConfig["output"].asString(), - deviceConfig.get("latchtime",500000).asInt() - ); - } - else if (type == "e131") - { - device = new LedDeviceUdpE131( - deviceConfig["output"].asString(), - deviceConfig.get("latchtime",104000).asInt(), - deviceConfig.get("universe",1).asInt() - ); - } - else if (type == "tpm2") - { - device = new LedDeviceTpm2( - deviceConfig["output"].asString(), - deviceConfig["rate"].asInt() - ); - } - else if (type == "atmo") - { - device = new LedDeviceAtmo( - deviceConfig["output"].asString(), - 38400 - ); - } - #ifdef ENABLE_WS2812BPWM - else if (type == "ws2812b") - { - device = new LedDeviceWS2812b(); - } - #endif - #ifdef ENABLE_WS281XPWM - else if (type == "ws281x") - { - device = new LedDeviceWS281x( - deviceConfig.get("gpio", 18).asInt(), - deviceConfig.get("leds", 256).asInt(), - deviceConfig.get("freq", (Json::UInt)800000ul).asInt(), - deviceConfig.get("dmanum", 5).asInt(), - deviceConfig.get("pwmchannel", 0).asInt(), - deviceConfig.get("invert", 0).asInt(), - deviceConfig.get("rgbw", 0).asInt(), - deviceConfig.get("white_algorithm","").asString() - ); - } - #endif - else if (type == "file") - { - device = new LedDeviceFile( deviceConfig.get("output", "/dev/null").asString() ); - } - else + + if (device == nullptr) { Error(log, "Dummy device used, because configured device '%s' is unknown", type.c_str() ); throw std::runtime_error("unknown device"); } } - catch(std::exception e) + catch(std::exception& e) { Error(log, "Dummy device used, because configured device '%s' throws error '%s'", type.c_str(), e.what()); - device = new LedDeviceFile( "/dev/null" ); + const Json::Value dummyDeviceConfig; + device = LedDeviceFile::construct(Json::nullValue); } device->open(); diff --git a/libsrc/leddevice/LedDeviceFadeCandy.cpp b/libsrc/leddevice/LedDeviceFadeCandy.cpp index f71d02c9..671bde35 100644 --- a/libsrc/leddevice/LedDeviceFadeCandy.cpp +++ b/libsrc/leddevice/LedDeviceFadeCandy.cpp @@ -1,6 +1,6 @@ #include "LedDeviceFadeCandy.h" -static const signed MAX_NUM_LEDS = 10000; // OPC can handle 21845 leds - in theory, fadecandy device should handle 10000 leds +static const signed MAX_NUM_LEDS = 10000; // OPC can handle 21845 leds - in theory, fadecandy device should handle 10000 leds static const unsigned OPC_SET_PIXELS = 0; // OPC command codes static const unsigned OPC_SYS_EX = 255; // OPC command codes static const unsigned OPC_HEADER_SIZE = 4; // OPC header size @@ -10,13 +10,6 @@ LedDeviceFadeCandy::LedDeviceFadeCandy(const Json::Value &deviceConfig) : LedDevice() { setConfig(deviceConfig); - _opc_data.resize( OPC_HEADER_SIZE ); - _opc_data[0] = _channel; - _opc_data[1] = OPC_SET_PIXELS; - _opc_data[2] = 0; - _opc_data[3] = 0; - - } @@ -25,8 +18,16 @@ LedDeviceFadeCandy::~LedDeviceFadeCandy() _client.close(); } +LedDevice* LedDeviceFadeCandy::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceFadeCandy(deviceConfig); +} + + bool LedDeviceFadeCandy::setConfig(const Json::Value &deviceConfig) { + _client.close(); + _host = deviceConfig.get("output", "127.0.0.1").asString(); _port = deviceConfig.get("port", 7890).asInt(); _channel = deviceConfig.get("channel", 0).asInt(); @@ -49,6 +50,12 @@ bool LedDeviceFadeCandy::setConfig(const Json::Value &deviceConfig) _whitePoint_b = whitePointConfig[2].asDouble(); } + _opc_data.resize( OPC_HEADER_SIZE ); + _opc_data[0] = _channel; + _opc_data[1] = OPC_SET_PIXELS; + _opc_data[2] = 0; + _opc_data[3] = 0; + return true; } diff --git a/libsrc/leddevice/LedDeviceFadeCandy.h b/libsrc/leddevice/LedDeviceFadeCandy.h index 7a534cee..cd55958c 100644 --- a/libsrc/leddevice/LedDeviceFadeCandy.h +++ b/libsrc/leddevice/LedDeviceFadeCandy.h @@ -7,7 +7,6 @@ // Leddevice includes #include -#include /// /// Implementation of the LedDevice interface for sending to @@ -48,6 +47,9 @@ public: /// virtual ~LedDeviceFadeCandy(); + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); + /// /// Sets configuration /// @@ -66,7 +68,6 @@ public: /// Switch the leds off virtual int switchOff(); - private: QTcpSocket _client; std::string _host; @@ -115,3 +116,4 @@ private: void sendFadeCandyConfiguration(); }; + diff --git a/libsrc/leddevice/LedDeviceFile.cpp b/libsrc/leddevice/LedDeviceFile.cpp index 3f60b40b..93ad3022 100644 --- a/libsrc/leddevice/LedDeviceFile.cpp +++ b/libsrc/leddevice/LedDeviceFile.cpp @@ -2,16 +2,32 @@ // Local-Hyperion includes #include "LedDeviceFile.h" -LedDeviceFile::LedDeviceFile(const std::string& output) +LedDeviceFile::LedDeviceFile(const Json::Value &deviceConfig) : LedDevice() - , _ofs( output.empty() ? "/dev/null" : output.c_str()) { - // empty + setConfig(deviceConfig); } LedDeviceFile::~LedDeviceFile() { - // empty +} + +LedDevice* LedDeviceFile::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceFile(deviceConfig); +} + +bool LedDeviceFile::setConfig(const Json::Value &deviceConfig) +{ + if ( _ofs.is_open() ) + { + _ofs.close(); + } + + std::string fileName = deviceConfig.get("output","/dev/null").asString(); + _ofs.open( fileName.c_str() ); + + return true; } int LedDeviceFile::write(const std::vector & ledValues) diff --git a/libsrc/leddevice/LedDeviceFile.h b/libsrc/leddevice/LedDeviceFile.h index ef7a54f7..282a7110 100644 --- a/libsrc/leddevice/LedDeviceFile.h +++ b/libsrc/leddevice/LedDeviceFile.h @@ -14,15 +14,27 @@ class LedDeviceFile : public LedDevice { public: /// - /// Constructs the test-device, which opens an output stream to the file + /// Constructs specific LedDevice /// - LedDeviceFile(const std::string& output); + /// @param deviceConfig json device config + /// + LedDeviceFile(const Json::Value &deviceConfig); /// /// Destructor of this test-device /// virtual ~LedDeviceFile(); + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); + + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + virtual bool setConfig(const Json::Value &deviceConfig); + /// /// Writes the given led-color values to the output stream /// diff --git a/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp b/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp index add361a9..f3aa6aaa 100644 --- a/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp +++ b/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp @@ -11,12 +11,12 @@ uint16_t LedDeviceHyperionUsbasp::_usbProductId = 0x05dc; std::string LedDeviceHyperionUsbasp::_usbProductDescription = "Hyperion led controller"; -LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(uint8_t writeLedsCommand) +LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(const Json::Value &deviceConfig) : LedDevice() - , _writeLedsCommand(writeLedsCommand) , _libusbContext(nullptr) , _deviceHandle(nullptr) { + setConfig(deviceConfig); } LedDeviceHyperionUsbasp::~LedDeviceHyperionUsbasp() @@ -37,6 +37,25 @@ LedDeviceHyperionUsbasp::~LedDeviceHyperionUsbasp() } } +bool LedDeviceHyperionUsbasp::setConfig(const Json::Value &deviceConfig) +{ + std::string ledType = deviceConfig.get("output", "ws2801").asString(); + if (ledType != "ws2801" && ledType != "ws2812") + { + throw std::runtime_error("HyperionUsbasp: invalid output; must be 'ws2801' or 'ws2812'."); + } + + _writeLedsCommand = (ledType == "ws2801") ? CMD_WRITE_WS2801 : CMD_WRITE_WS2812; + + return true; +} + +LedDevice* LedDeviceHyperionUsbasp::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceHyperionUsbasp(deviceConfig); +} + + int LedDeviceHyperionUsbasp::open() { int error; diff --git a/libsrc/leddevice/LedDeviceHyperionUsbasp.h b/libsrc/leddevice/LedDeviceHyperionUsbasp.h index 1471f1bd..7e9d0da2 100644 --- a/libsrc/leddevice/LedDeviceHyperionUsbasp.h +++ b/libsrc/leddevice/LedDeviceHyperionUsbasp.h @@ -24,9 +24,21 @@ public: }; /// - /// Constructs the LedDeviceLightpack + /// Constructs specific LedDevice /// - LedDeviceHyperionUsbasp(uint8_t writeLedsCommand); + /// @param deviceConfig json device config + /// + LedDeviceHyperionUsbasp(const Json::Value &deviceConfig); + + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Destructor of the LedDevice; closes the output device if it is open @@ -70,7 +82,7 @@ private: private: /// command to write the leds - const uint8_t _writeLedsCommand; + uint8_t _writeLedsCommand; /// libusb context libusb_context * _libusbContext; diff --git a/libsrc/leddevice/LedDeviceLightpack.cpp b/libsrc/leddevice/LedDeviceLightpack.cpp index 43fc6fd3..80677244 100644 --- a/libsrc/leddevice/LedDeviceLightpack.cpp +++ b/libsrc/leddevice/LedDeviceLightpack.cpp @@ -45,6 +45,12 @@ LedDeviceLightpack::LedDeviceLightpack(const std::string & serialNumber) _ledCount = -1; } +LedDeviceLightpack::LedDeviceLightpack(const Json::Value &deviceConfig) + : LedDeviceLightpack() +{ + setConfig(deviceConfig); +} + LedDeviceLightpack::~LedDeviceLightpack() { if (_deviceHandle != nullptr) @@ -63,6 +69,18 @@ LedDeviceLightpack::~LedDeviceLightpack() } } +bool LedDeviceLightpack::setConfig(const Json::Value &deviceConfig) +{ + _serialNumber = deviceConfig.get("output", "").asString(); + + return true; +} + +LedDevice* LedDeviceLightpack::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceLightpack(deviceConfig); +} + int LedDeviceLightpack::open() { int error; diff --git a/libsrc/leddevice/LedDeviceLightpack.h b/libsrc/leddevice/LedDeviceLightpack.h index 9c2f48b6..8c530094 100644 --- a/libsrc/leddevice/LedDeviceLightpack.h +++ b/libsrc/leddevice/LedDeviceLightpack.h @@ -23,6 +23,22 @@ public: /// @param serialNumber serial output device /// LedDeviceLightpack(const std::string & serialNumber = ""); + /// + /// Constructs specific LedDevice + /// + /// @param deviceConfig json device config + /// + LedDeviceLightpack(const Json::Value &deviceConfig); + + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Destructor of the LedDevice; closes the output device if it is open diff --git a/libsrc/leddevice/LedDeviceLpd6803.cpp b/libsrc/leddevice/LedDeviceLpd6803.cpp index 53f26950..13ca4d93 100644 --- a/libsrc/leddevice/LedDeviceLpd6803.cpp +++ b/libsrc/leddevice/LedDeviceLpd6803.cpp @@ -10,11 +10,16 @@ // hyperion local includes #include "LedDeviceLpd6803.h" -LedDeviceLpd6803::LedDeviceLpd6803(const std::string& outputDevice, const unsigned baudrate) - : LedSpiDevice(outputDevice, baudrate) +LedDeviceLpd6803::LedDeviceLpd6803(const Json::Value &deviceConfig) + : LedSpiDevice(deviceConfig) { } +LedDevice* LedDeviceLpd6803::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceLpd6803(deviceConfig); +} + int LedDeviceLpd6803::write(const std::vector &ledValues) { unsigned messageLength = 4 + 2*ledValues.size() + ledValues.size()/8 + 1; diff --git a/libsrc/leddevice/LedDeviceLpd6803.h b/libsrc/leddevice/LedDeviceLpd6803.h index 3ec28ed5..9ed64125 100644 --- a/libsrc/leddevice/LedDeviceLpd6803.h +++ b/libsrc/leddevice/LedDeviceLpd6803.h @@ -18,12 +18,14 @@ class LedDeviceLpd6803 : public LedSpiDevice { public: /// - /// Constructs the LedDevice for a string containing leds of the type LDP6803 + /// Constructs specific LedDevice /// - /// @param[in] outputDevice The name of the output device (eg '/dev/spidev0.0') - /// @param[in] baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// - LedDeviceLpd6803(const std::string& outputDevice, const unsigned baudrate); + LedDeviceLpd6803(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceLpd8806.cpp b/libsrc/leddevice/LedDeviceLpd8806.cpp index 62cc8e36..ba096c98 100644 --- a/libsrc/leddevice/LedDeviceLpd8806.cpp +++ b/libsrc/leddevice/LedDeviceLpd8806.cpp @@ -10,10 +10,14 @@ // hyperion local includes #include "LedDeviceLpd8806.h" -LedDeviceLpd8806::LedDeviceLpd8806(const std::string& outputDevice, const unsigned baudrate) - : LedSpiDevice(outputDevice, baudrate) +LedDeviceLpd8806::LedDeviceLpd8806(const Json::Value &deviceConfig) + : LedSpiDevice(deviceConfig) { - // empty +} + +LedDevice* LedDeviceLpd8806::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceLpd8806(deviceConfig); } int LedDeviceLpd8806::write(const std::vector &ledValues) diff --git a/libsrc/leddevice/LedDeviceLpd8806.h b/libsrc/leddevice/LedDeviceLpd8806.h index 114747b3..ca87f3e2 100644 --- a/libsrc/leddevice/LedDeviceLpd8806.h +++ b/libsrc/leddevice/LedDeviceLpd8806.h @@ -79,12 +79,14 @@ class LedDeviceLpd8806 : public LedSpiDevice { public: /// - /// Constructs the LedDevice for a string containing leds of the type LPD8806 + /// Constructs specific LedDevice /// - /// @param[in] outputDevice The name of the output device (eg '/dev/spidev0.0') - /// @param[in] baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// - LedDeviceLpd8806(const std::string& outputDevice, const unsigned baudrate); + LedDeviceLpd8806(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceMultiLightpack.cpp b/libsrc/leddevice/LedDeviceMultiLightpack.cpp index 1104f5bf..2092bcb1 100644 --- a/libsrc/leddevice/LedDeviceMultiLightpack.cpp +++ b/libsrc/leddevice/LedDeviceMultiLightpack.cpp @@ -17,7 +17,7 @@ bool compareLightpacks(LedDeviceLightpack * lhs, LedDeviceLightpack * rhs) return lhs->getSerialNumber() < rhs->getSerialNumber(); } -LedDeviceMultiLightpack::LedDeviceMultiLightpack() +LedDeviceMultiLightpack::LedDeviceMultiLightpack(const Json::Value &) : LedDevice() , _lightpacks() { @@ -31,6 +31,11 @@ LedDeviceMultiLightpack::~LedDeviceMultiLightpack() } } +LedDevice* LedDeviceMultiLightpack::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceMultiLightpack(deviceConfig); +} + int LedDeviceMultiLightpack::open() { // retrieve a list with Lightpack serials diff --git a/libsrc/leddevice/LedDeviceMultiLightpack.h b/libsrc/leddevice/LedDeviceMultiLightpack.h index 65e0d1d6..858e9cd9 100644 --- a/libsrc/leddevice/LedDeviceMultiLightpack.h +++ b/libsrc/leddevice/LedDeviceMultiLightpack.h @@ -20,15 +20,20 @@ class LedDeviceMultiLightpack : public LedDevice { public: /// - /// Constructs the LedDeviceMultiLightpack + /// Constructs specific LedDevice /// - LedDeviceMultiLightpack(); + /// @param deviceConfig json device config + /// + LedDeviceMultiLightpack(const Json::Value &); /// /// Destructor of the LedDevice; closes the output device if it is open /// virtual ~LedDeviceMultiLightpack(); + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); + /// /// Opens and configures the output device7 /// diff --git a/libsrc/leddevice/LedDeviceP9813.cpp b/libsrc/leddevice/LedDeviceP9813.cpp index d3142465..9e3e5a40 100644 --- a/libsrc/leddevice/LedDeviceP9813.cpp +++ b/libsrc/leddevice/LedDeviceP9813.cpp @@ -11,10 +11,14 @@ // hyperion local includes #include "LedDeviceP9813.h" -LedDeviceP9813::LedDeviceP9813(const std::string& outputDevice, const unsigned baudrate) - : LedSpiDevice(outputDevice, baudrate, 0) +LedDeviceP9813::LedDeviceP9813(const Json::Value &deviceConfig) + : LedSpiDevice(deviceConfig) { - // empty +} + +LedDevice* LedDeviceP9813::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceP9813(deviceConfig); } int LedDeviceP9813::write(const std::vector &ledValues) diff --git a/libsrc/leddevice/LedDeviceP9813.h b/libsrc/leddevice/LedDeviceP9813.h index 97fba0e0..54236d2e 100644 --- a/libsrc/leddevice/LedDeviceP9813.h +++ b/libsrc/leddevice/LedDeviceP9813.h @@ -13,12 +13,14 @@ class LedDeviceP9813 : public LedSpiDevice { public: /// - /// Constructs the LedDevice for a string containing leds of the type P9813 + /// Constructs specific LedDevice /// - /// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0') - /// @param baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// - LedDeviceP9813(const std::string& outputDevice, const unsigned baudrate); + LedDeviceP9813(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDevicePaintpack.cpp b/libsrc/leddevice/LedDevicePaintpack.cpp index b97665e8..b27126f5 100644 --- a/libsrc/leddevice/LedDevicePaintpack.cpp +++ b/libsrc/leddevice/LedDevicePaintpack.cpp @@ -3,12 +3,16 @@ #include "LedDevicePaintpack.h" // Use out report HID device -LedDevicePaintpack::LedDevicePaintpack(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms) - : LedHIDDevice(VendorId, ProductId, delayAfterConnect_ms, false) +LedDevicePaintpack::LedDevicePaintpack(const Json::Value &deviceConfig) + : LedHIDDevice(deviceConfig) { - // empty + _useFeature = false; } +LedDevice* LedDevicePaintpack::construct(const Json::Value &deviceConfig) +{ + return new LedDevicePaintpack(deviceConfig); +} int LedDevicePaintpack::write(const std::vector & ledValues) { diff --git a/libsrc/leddevice/LedDevicePaintpack.h b/libsrc/leddevice/LedDevicePaintpack.h index d535c262..cdfaac83 100644 --- a/libsrc/leddevice/LedDevicePaintpack.h +++ b/libsrc/leddevice/LedDevicePaintpack.h @@ -12,10 +12,15 @@ class LedDevicePaintpack : public LedHIDDevice { public: - /** - * Constructs the paintpack device - */ - LedDevicePaintpack(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms); + /// + /// Constructs specific LedDevice + /// + /// @param deviceConfig json device config + /// + LedDevicePaintpack(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the RGB-Color values to the leds. diff --git a/libsrc/leddevice/LedDevicePhilipsHue.cpp b/libsrc/leddevice/LedDevicePhilipsHue.cpp index c5db336b..66652946 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.cpp +++ b/libsrc/leddevice/LedDevicePhilipsHue.cpp @@ -164,14 +164,11 @@ CiColor PhilipsHueLight::rgbToCiColor(float red, float green, float blue) return xy; } -LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::string& username, bool switchOffOnBlack, int transitiontime, std::vector lightIds) +LedDevicePhilipsHue::LedDevicePhilipsHue(const Json::Value &deviceConfig) : LedDevice() - , host(output.c_str()) - , username(username.c_str()) - , switchOffOnBlack(switchOffOnBlack) - , transitiontime(transitiontime) - , lightIds(lightIds) { + setConfig(deviceConfig); + manager = new QNetworkAccessManager(); timer.setInterval(3000); timer.setSingleShot(true); @@ -183,6 +180,26 @@ LedDevicePhilipsHue::~LedDevicePhilipsHue() delete manager; } +bool LedDevicePhilipsHue::setConfig(const Json::Value &deviceConfig) +{ + host = deviceConfig["output"].asString().c_str(); + username = deviceConfig.get("username", "newdeveloper").asString().c_str(); + switchOffOnBlack = deviceConfig.get("switchOffOnBlack", true).asBool(); + transitiontime = deviceConfig.get("transitiontime", 1).asInt(); + lightIds.clear(); + for (Json::Value::ArrayIndex i = 0; i < deviceConfig["lightIds"].size(); i++) + { + lightIds.push_back(deviceConfig["lightIds"][i].asInt()); + } + + return true; +} + +LedDevice* LedDevicePhilipsHue::construct(const Json::Value &deviceConfig) +{ + return new LedDevicePhilipsHue(deviceConfig); +} + int LedDevicePhilipsHue::write(const std::vector & ledValues) { // Save light states if not done before. diff --git a/libsrc/leddevice/LedDevicePhilipsHue.h b/libsrc/leddevice/LedDevicePhilipsHue.h index 3b60bb69..5d374a24 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.h +++ b/libsrc/leddevice/LedDevicePhilipsHue.h @@ -115,22 +115,27 @@ class LedDevicePhilipsHue: public LedDevice { public: /// - /// Constructs the device. + /// Constructs specific LedDevice /// - /// @param output the ip address of the bridge - /// @param username username of the hue bridge (default: newdeveloper) - /// @param switchOffOnBlack kill lights for black (default: false) - /// @param transitiontime the time duration a light change takes in multiples of 100 ms (default: 400 ms). - /// @param lightIds light ids of the lights to control if not starting at one in ascending order. + /// @param deviceConfig json device config /// - LedDevicePhilipsHue(const std::string& output, const std::string& username = "newdeveloper", bool switchOffOnBlack = - false, int transitiontime = 1, std::vector lightIds = std::vector()); + LedDevicePhilipsHue(const Json::Value &deviceConfig); /// /// Destructor of this device /// virtual ~LedDevicePhilipsHue(); + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); + /// /// Sends the given led-color values via put request to the hue system /// diff --git a/libsrc/leddevice/LedDevicePiBlaster.cpp b/libsrc/leddevice/LedDevicePiBlaster.cpp index 072a5be8..b4775ee0 100644 --- a/libsrc/leddevice/LedDevicePiBlaster.cpp +++ b/libsrc/leddevice/LedDevicePiBlaster.cpp @@ -13,11 +13,9 @@ // Local LedDevice includes #include "LedDevicePiBlaster.h" -LedDevicePiBlaster::LedDevicePiBlaster(const std::string & deviceName, const Json::Value & gpioMapping) - : _deviceName(deviceName) - , _fid(nullptr) +LedDevicePiBlaster::LedDevicePiBlaster(const Json::Value &deviceConfig) + : _fid(nullptr) { - signal(SIGPIPE, SIG_IGN); // initialise the mapping tables @@ -32,7 +30,31 @@ LedDevicePiBlaster::LedDevicePiBlaster(const std::string & deviceName, const Jso _gpio_to_color[i] = 'z'; } -// walk through the json config and populate the mapping tables + setConfig(deviceConfig); +} + +LedDevicePiBlaster::~LedDevicePiBlaster() +{ + // Close the device (if it is opened) + if (_fid != nullptr) + { + fclose(_fid); + _fid = nullptr; + } +} + + +bool LedDevicePiBlaster::setConfig(const Json::Value &deviceConfig) +{ + _deviceName = deviceConfig.get("output", "").asString(); + Json::Value gpioMapping = deviceConfig.get("gpiomap", Json::nullValue); + + if (gpioMapping.isNull()) + { + throw std::runtime_error("Piblaster: no gpiomap defined."); + } + + // walk through the json config and populate the mapping tables for (const Json::Value& gpioMap : gpioMapping) { const int gpio = gpioMap.get("gpio",-1).asInt(); @@ -47,16 +69,12 @@ LedDevicePiBlaster::LedDevicePiBlaster(const std::string & deviceName, const Jso Warning( _log, "IGNORING gpio %d ledindex %d color %c", gpio,ledindex, ledcolor[0]); } } + return true; } -LedDevicePiBlaster::~LedDevicePiBlaster() +LedDevice* LedDevicePiBlaster::construct(const Json::Value &deviceConfig) { - // Close the device (if it is opened) - if (_fid != nullptr) - { - fclose(_fid); - _fid = nullptr; - } + return new LedDevicePiBlaster(deviceConfig); } int LedDevicePiBlaster::open() diff --git a/libsrc/leddevice/LedDevicePiBlaster.h b/libsrc/leddevice/LedDevicePiBlaster.h index b61bc0b3..d1189e5b 100644 --- a/libsrc/leddevice/LedDevicePiBlaster.h +++ b/libsrc/leddevice/LedDevicePiBlaster.h @@ -14,15 +14,24 @@ class LedDevicePiBlaster : public LedDevice { public: /// - /// Constructs the PiBlaster device which writes to the indicated device and for the assigned - /// channels - /// @param deviceName The name of the output device - /// @param gpioMapping The RGB-Channel assignment json object + /// Constructs specific LedDevice /// - LedDevicePiBlaster(const std::string & deviceName, const Json::Value & gpioMapping); + /// @param deviceConfig json device config + /// + LedDevicePiBlaster(const Json::Value &deviceConfig); virtual ~LedDevicePiBlaster(); + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); + /// /// Attempts to open the piblaster-device. This will only succeed if the device is not yet open /// and the device is available. @@ -50,7 +59,7 @@ public: private: /// The name of the output device (very likely '/dev/pi-blaster') - const std::string _deviceName; + std::string _deviceName; int _gpio_to_led[64]; char _gpio_to_color[64]; diff --git a/libsrc/leddevice/LedDeviceRawHID.cpp b/libsrc/leddevice/LedDeviceRawHID.cpp index 5fd1b5ba..13a4b10d 100644 --- a/libsrc/leddevice/LedDeviceRawHID.cpp +++ b/libsrc/leddevice/LedDeviceRawHID.cpp @@ -12,10 +12,12 @@ #include "LedDeviceRawHID.h" // Use feature report HID device -LedDeviceRawHID::LedDeviceRawHID(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms) - : LedHIDDevice(VendorId, ProductId, delayAfterConnect_ms, true) +LedDeviceRawHID::LedDeviceRawHID(const Json::Value &deviceConfig) + : LedHIDDevice(deviceConfig) , _timer() { + _useFeature = true; + // setup the timer _timer.setSingleShot(false); _timer.setInterval(5000); @@ -25,6 +27,11 @@ LedDeviceRawHID::LedDeviceRawHID(const unsigned short VendorId, const unsigned s _timer.start(); } +LedDevice* LedDeviceRawHID::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceRawHID(deviceConfig); +} + int LedDeviceRawHID::write(const std::vector & ledValues) { // Resize buffer if required diff --git a/libsrc/leddevice/LedDeviceRawHID.h b/libsrc/leddevice/LedDeviceRawHID.h index d0a8e04c..6e2d63ae 100644 --- a/libsrc/leddevice/LedDeviceRawHID.h +++ b/libsrc/leddevice/LedDeviceRawHID.h @@ -18,9 +18,14 @@ class LedDeviceRawHID : public LedHIDDevice public: /// - /// Constructs the LedDevice for attached RawHID device + /// Constructs specific LedDevice /// - LedDeviceRawHID(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms); + /// @param deviceConfig json device config + /// + LedDeviceRawHID(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceSchemas.qrc b/libsrc/leddevice/LedDeviceSchemas.qrc new file mode 100644 index 00000000..4e7f956d --- /dev/null +++ b/libsrc/leddevice/LedDeviceSchemas.qrc @@ -0,0 +1,31 @@ + + + schemas/schema-adalightapa102.json + schemas/schema-adalight.json + schemas/schema-apa102.json + schemas/schema-atmo.json + schemas/schema-atmoorb.json + schemas/schema-e131.json + schemas/schema-fadecandy.json + schemas/schema-file.json + schemas/schema-hyperion-usbasp.json + schemas/schema-lightpack.json + schemas/schema-lpd6803.json + schemas/schema-lpd8806.json + schemas/schema-multi-lightpack.json + schemas/schema-p9813.json + schemas/schema-paintpack.json + schemas/schema-philipshue.json + schemas/schema-piblaster.json + schemas/schema-rawhid.json + schemas/schema-sedu.json + schemas/schema-sk6812rgbw-spi.json + schemas/schema-tinkerforge.json + schemas/schema-tmp2net.json + schemas/schema-tpm2.json + schemas/schema-udpraw.json + schemas/schema-ws2801.json + schemas/schema-ws2812spi.json + schemas/schema-ws281x.json + + diff --git a/libsrc/leddevice/LedDeviceSedu.cpp b/libsrc/leddevice/LedDeviceSedu.cpp index 7293dd27..54a4e216 100644 --- a/libsrc/leddevice/LedDeviceSedu.cpp +++ b/libsrc/leddevice/LedDeviceSedu.cpp @@ -17,12 +17,17 @@ struct FrameSpec size_t size; }; -LedDeviceSedu::LedDeviceSedu(const std::string& outputDevice, const unsigned baudrate) - : LedRs232Device(outputDevice, baudrate) +LedDeviceSedu::LedDeviceSedu(const Json::Value &deviceConfig) + : LedRs232Device(deviceConfig) { // empty } +LedDevice* LedDeviceSedu::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceSedu(deviceConfig); +} + int LedDeviceSedu::write(const std::vector &ledValues) { if (_ledBuffer.size() == 0) diff --git a/libsrc/leddevice/LedDeviceSedu.h b/libsrc/leddevice/LedDeviceSedu.h index dda0a58d..e83ccceb 100644 --- a/libsrc/leddevice/LedDeviceSedu.h +++ b/libsrc/leddevice/LedDeviceSedu.h @@ -13,12 +13,14 @@ class LedDeviceSedu : public LedRs232Device { public: /// - /// Constructs the LedDevice for attached via SEDU device + /// Constructs specific LedDevice /// - /// @param outputDevice The name of the output device (eg '/dev/ttyS0') - /// @param baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// - LedDeviceSedu(const std::string& outputDevice, const unsigned baudrate); + LedDeviceSedu(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceSk6812SPI.cpp b/libsrc/leddevice/LedDeviceSk6812SPI.cpp index 0c5dc3c2..6e25a69d 100644 --- a/libsrc/leddevice/LedDeviceSk6812SPI.cpp +++ b/libsrc/leddevice/LedDeviceSk6812SPI.cpp @@ -11,10 +11,8 @@ // hyperion local includes #include "LedDeviceSk6812SPI.h" -LedDeviceSk6812SPI::LedDeviceSk6812SPI(const std::string& outputDevice, const unsigned baudrate, const std::string& whiteAlgorithm, - const int spiMode, const bool spiDataInvert) - : LedSpiDevice(outputDevice, baudrate, 0, spiMode, spiDataInvert) - , _whiteAlgorithm(whiteAlgorithm) +LedDeviceSk6812SPI::LedDeviceSk6812SPI(const Json::Value &deviceConfig) + : LedSpiDevice(deviceConfig) , bitpair_to_byte { 0b10001000, 0b10001100, @@ -23,7 +21,21 @@ LedDeviceSk6812SPI::LedDeviceSk6812SPI(const std::string& outputDevice, const un } { - Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str()); + setConfig(deviceConfig); + Debug( _log, "whiteAlgorithm : %s", _whiteAlgorithm.c_str()); +} + +LedDevice* LedDeviceSk6812SPI::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceSk6812SPI(deviceConfig); +} + +bool LedDeviceSk6812SPI::setConfig(const Json::Value &deviceConfig) +{ + LedSpiDevice::setConfig(deviceConfig); + _whiteAlgorithm = deviceConfig.get("white_algorithm","").asString(); + + return true; } int LedDeviceSk6812SPI::write(const std::vector &ledValues) diff --git a/libsrc/leddevice/LedDeviceSk6812SPI.h b/libsrc/leddevice/LedDeviceSk6812SPI.h index d547d367..2f79d26d 100644 --- a/libsrc/leddevice/LedDeviceSk6812SPI.h +++ b/libsrc/leddevice/LedDeviceSk6812SPI.h @@ -13,15 +13,22 @@ class LedDeviceSk6812SPI : public LedSpiDevice { public: /// - /// Constructs the LedDevice for a string containing leds of the type Sk6812SPI + /// Constructs specific LedDevice /// - /// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0') - /// @param baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// + LedDeviceSk6812SPI(const Json::Value &deviceConfig); - LedDeviceSk6812SPI(const std::string& outputDevice, const unsigned baudrate, - const std::string& whiteAlgorithm, const int spiMode, const bool spiDataInvert); + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + /// /// Writes the led color values to the led-device /// diff --git a/libsrc/leddevice/LedDeviceTinkerforge.cpp b/libsrc/leddevice/LedDeviceTinkerforge.cpp index 972762eb..59ffaf37 100644 --- a/libsrc/leddevice/LedDeviceTinkerforge.cpp +++ b/libsrc/leddevice/LedDeviceTinkerforge.cpp @@ -9,17 +9,13 @@ static const unsigned MAX_NUM_LEDS = 320; static const unsigned MAX_NUM_LEDS_SETTABLE = 16; -LedDeviceTinkerforge::LedDeviceTinkerforge(const std::string & host, uint16_t port, const std::string & uid, const unsigned interval) +LedDeviceTinkerforge::LedDeviceTinkerforge(const Json::Value &deviceConfig) : LedDevice() - , _host(host) - , _port(port) - , _uid(uid) - , _interval(interval) , _ipConnection(nullptr) , _ledStrip(nullptr) , _colorChannelSize(0) { - // empty + setConfig(deviceConfig); } LedDeviceTinkerforge::~LedDeviceTinkerforge() @@ -35,6 +31,21 @@ LedDeviceTinkerforge::~LedDeviceTinkerforge() delete _ledStrip; } +bool LedDeviceTinkerforge::setConfig(const Json::Value &deviceConfig) +{ + _host = deviceConfig.get("output", "127.0.0.1").asString(); + _port = deviceConfig.get("port", 4223).asInt(); + _uid = deviceConfig["uid"].asString(); + _interval = deviceConfig["rate"].asInt(); + + return true; +} + +LedDevice* LedDeviceTinkerforge::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceTinkerforge(deviceConfig); +} + int LedDeviceTinkerforge::open() { // Check if connection is already createds diff --git a/libsrc/leddevice/LedDeviceTinkerforge.h b/libsrc/leddevice/LedDeviceTinkerforge.h index 95f43332..4f3c6dc7 100644 --- a/libsrc/leddevice/LedDeviceTinkerforge.h +++ b/libsrc/leddevice/LedDeviceTinkerforge.h @@ -16,11 +16,25 @@ extern "C" { class LedDeviceTinkerforge : public LedDevice { public: - - LedDeviceTinkerforge(const std::string &host, uint16_t port, const std::string &uid, const unsigned interval); + /// + /// Constructs specific LedDevice + /// + /// @param deviceConfig json device config + /// + LedDeviceTinkerforge(const Json::Value &deviceConfig); virtual ~LedDeviceTinkerforge(); + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); + /// /// Attempts to open a connection to the master bricklet and the led strip bricklet. /// @@ -50,16 +64,16 @@ private: int transferLedData(LEDStrip *ledstrip, unsigned int index, unsigned int length, uint8_t *redChannel, uint8_t *greenChannel, uint8_t *blueChannel); /// The host of the master brick - const std::string _host; + std::string _host; /// The port of the master brick - const uint16_t _port; + uint16_t _port; /// The uid of the led strip bricklet - const std::string _uid; + std::string _uid; /// The interval/rate - const unsigned _interval; + unsigned _interval; /// ip connection handle IPConnection *_ipConnection; diff --git a/libsrc/leddevice/LedDeviceTpm2.cpp b/libsrc/leddevice/LedDeviceTpm2.cpp index bf816a5c..ab5d9c80 100644 --- a/libsrc/leddevice/LedDeviceTpm2.cpp +++ b/libsrc/leddevice/LedDeviceTpm2.cpp @@ -6,11 +6,16 @@ // hyperion local includes #include "LedDeviceTpm2.h" +#include -LedDeviceTpm2::LedDeviceTpm2(const std::string& outputDevice, const unsigned baudrate) - : LedRs232Device(outputDevice, baudrate) +LedDeviceTpm2::LedDeviceTpm2(const Json::Value &deviceConfig) + : LedRs232Device(deviceConfig) { - // empty +} + +LedDevice* LedDeviceTpm2::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceTpm2(deviceConfig); } int LedDeviceTpm2::write(const std::vector &ledValues) diff --git a/libsrc/leddevice/LedDeviceTpm2.h b/libsrc/leddevice/LedDeviceTpm2.h index f6ff7340..dab57be9 100644 --- a/libsrc/leddevice/LedDeviceTpm2.h +++ b/libsrc/leddevice/LedDeviceTpm2.h @@ -13,13 +13,14 @@ class LedDeviceTpm2 : public LedRs232Device { public: /// - /// Constructs the LedDevice for attached serial device using supporting tpm2 protocol - /// All LEDs in the stripe are handled as one frame + /// Constructs specific LedDevice /// - /// @param outputDevice The name of the output device (eg '/dev/ttyAMA0') - /// @param baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// - LedDeviceTpm2(const std::string& outputDevice, const unsigned baudrate); + LedDeviceTpm2(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceTpm2net.cpp b/libsrc/leddevice/LedDeviceTpm2net.cpp new file mode 100644 index 00000000..5075f188 --- /dev/null +++ b/libsrc/leddevice/LedDeviceTpm2net.cpp @@ -0,0 +1,63 @@ +// STL includes +#include +#include +#include +#include + +// Local-Hyperion includes +#include "LedDeviceTpm2net.h" + + +LedDeviceTpm2net::LedDeviceTpm2net(const Json::Value &deviceConfig) + : LedDevice() + , _socket(this) +{ + setConfig(deviceConfig); +} + +LedDeviceTpm2net::~LedDeviceTpm2net() +{ +} + +bool LedDeviceTpm2net::setConfig(const Json::Value &deviceConfig) +{ + _host = QHostAddress(QString::fromStdString(deviceConfig.get("output", "127.0.0.1").asString())); + _port = deviceConfig.get("port", 65506).asInt(); + + return true; +} + +LedDevice* LedDeviceTpm2net::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceTpm2net(deviceConfig); +} + +int LedDeviceTpm2net::write(const std::vector & ledValues) +{ + if (_ledBuffer.size() == 0) + { + _ledBuffer.resize(7 + 3*ledValues.size()); + _ledBuffer[0] = 0x9c; // block-start byte TPM.NET + _ledBuffer[1] = 0xDA; + _ledBuffer[2] = ((3 * ledValues.size()) >> 8) & 0xFF; // frame size high byte + _ledBuffer[3] = (3 * ledValues.size()) & 0xFF; // frame size low byte + _ledBuffer[4] = 1; // packets number + _ledBuffer[5] = 1; // Number of packets + _ledBuffer[(int)(7 + 3*ledValues.size()-1)] = 0x36; // block-end byte + } + + // write data + memcpy(6 + _ledBuffer.data(), ledValues.data() /*Max 1,490 bytes*/, ledValues.size() * 3); + + _socket.connectToHost(_host, _port); + _socket.write((const char *)_ledBuffer.data()); + _socket.close(); + + return 0; +} + +int LedDeviceTpm2net::switchOff() +{ + memset(6 + _ledBuffer.data(), 0, _ledBuffer.size() - 5); + return 0; +} diff --git a/libsrc/leddevice/LedDeviceTpm2net.h b/libsrc/leddevice/LedDeviceTpm2net.h new file mode 100644 index 00000000..1f3ec05f --- /dev/null +++ b/libsrc/leddevice/LedDeviceTpm2net.h @@ -0,0 +1,53 @@ +#pragma once + +// STL includes +#include +#include +#include +#include +// Leddevice includes +#include + +/// +class LedDeviceTpm2net : public LedDevice +{ +public: + /// + /// Constructs specific LedDevice + /// + /// @param deviceConfig json device config + /// + LedDeviceTpm2net(const Json::Value &deviceConfig); + + virtual ~LedDeviceTpm2net(); + + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); + + /// + /// Writes the given led-color values to the output stream + /// + /// @param ledValues The color-value per led + /// + /// @return Zero on success else negative + /// + virtual int write(const std::vector & ledValues); + + /// Switch the leds off + virtual int switchOff(); + +private: + /// The host of the master brick + QHostAddress _host; + + /// The port of the master brick + uint16_t _port; + QUdpSocket _socket; +}; diff --git a/libsrc/leddevice/LedDeviceUdpE131.cpp b/libsrc/leddevice/LedDeviceUdpE131.cpp index 813a7382..043a5bb4 100644 --- a/libsrc/leddevice/LedDeviceUdpE131.cpp +++ b/libsrc/leddevice/LedDeviceUdpE131.cpp @@ -12,12 +12,25 @@ // hyperion local includes #include "LedDeviceUdpE131.h" -LedDeviceUdpE131::LedDeviceUdpE131(const std::string& outputDevice, const unsigned latchTime, const unsigned universe) - : LedUdpDevice(outputDevice, latchTime) - , _e131_universe(universe) +LedDeviceUdpE131::LedDeviceUdpE131(const Json::Value &deviceConfig) + : LedUdpDevice(deviceConfig) { - // empty + setConfig(deviceConfig); +} + +bool LedDeviceUdpE131::setConfig(const Json::Value &deviceConfig) +{ + LedUdpDevice::setConfig(deviceConfig); + _LatchTime_ns = deviceConfig.get("latchtime",104000).asInt(); + _e131_universe = deviceConfig.get("universe",1).asInt(); + + return true; +} + +LedDevice* LedDeviceUdpE131::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceUdpE131(deviceConfig); } #define CID "hyperion!\0" diff --git a/libsrc/leddevice/LedDeviceUdpE131.h b/libsrc/leddevice/LedDeviceUdpE131.h index 01a6c04f..700adf29 100644 --- a/libsrc/leddevice/LedDeviceUdpE131.h +++ b/libsrc/leddevice/LedDeviceUdpE131.h @@ -100,13 +100,21 @@ class LedDeviceUdpE131 : public LedUdpDevice { public: /// - /// Constructs the LedDevice for sending led colors via udp + /// Constructs specific LedDevice /// - /// @param outputDevice hostname:port - /// @param latchTime + /// @param deviceConfig json device config /// + LedDeviceUdpE131(const Json::Value &deviceConfig); - LedDeviceUdpE131(const std::string& outputDevice, const unsigned latchTime, const unsigned universe); + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// diff --git a/libsrc/leddevice/LedDeviceUdpRaw.cpp b/libsrc/leddevice/LedDeviceUdpRaw.cpp index 3fcb1a64..cbc75bd1 100644 --- a/libsrc/leddevice/LedDeviceUdpRaw.cpp +++ b/libsrc/leddevice/LedDeviceUdpRaw.cpp @@ -11,10 +11,23 @@ // hyperion local includes #include "LedDeviceUdpRaw.h" -LedDeviceUdpRaw::LedDeviceUdpRaw(const std::string& outputDevice, const unsigned latchTime) - : LedUdpDevice(outputDevice, latchTime) +LedDeviceUdpRaw::LedDeviceUdpRaw(const Json::Value &deviceConfig) + : LedUdpDevice(deviceConfig) { - // empty + setConfig(deviceConfig); +} + +bool LedDeviceUdpRaw::setConfig(const Json::Value &deviceConfig) +{ + LedUdpDevice::setConfig(deviceConfig); + _LatchTime_ns = deviceConfig.get("latchtime",500000).asInt(); + + return true; +} + +LedDevice* LedDeviceUdpRaw::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceUdpRaw(deviceConfig); } int LedDeviceUdpRaw::write(const std::vector &ledValues) diff --git a/libsrc/leddevice/LedDeviceUdpRaw.h b/libsrc/leddevice/LedDeviceUdpRaw.h index f56aac01..81f8439b 100644 --- a/libsrc/leddevice/LedDeviceUdpRaw.h +++ b/libsrc/leddevice/LedDeviceUdpRaw.h @@ -13,13 +13,21 @@ class LedDeviceUdpRaw : public LedUdpDevice { public: /// - /// Constructs the LedDevice for sending led colors via udp + /// Constructs specific LedDevice /// - /// @param outputDevice hostname:port - /// @param latchTime + /// @param deviceConfig json device config /// + LedDeviceUdpRaw(const Json::Value &deviceConfig); - LedDeviceUdpRaw(const std::string& outputDevice, const unsigned latchTime); + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceWS2812b.cpp b/libsrc/leddevice/LedDeviceWS2812b.cpp index ca7b8ffa..8df215bf 100644 --- a/libsrc/leddevice/LedDeviceWS2812b.cpp +++ b/libsrc/leddevice/LedDeviceWS2812b.cpp @@ -258,6 +258,11 @@ LedDeviceWS2812b::LedDeviceWS2812b() printf("WS2812b init finished \n"); } +LedDevice* LedDeviceWS2812b::construct(const Json::Value &) +{ + return new LedDeviceWS2812b(); +} + #ifdef WS2812_ASM_OPTI // rotate register, used to move the 1 around :-) diff --git a/libsrc/leddevice/LedDeviceWS2812b.h b/libsrc/leddevice/LedDeviceWS2812b.h index c477296d..041a58e3 100644 --- a/libsrc/leddevice/LedDeviceWS2812b.h +++ b/libsrc/leddevice/LedDeviceWS2812b.h @@ -133,10 +133,24 @@ class LedDeviceWS2812b : public LedDevice { public: /// - /// Constructs the LedDevice for a string containing leds of the type WS2812 + /// Constructs specific LedDevice + /// + /// @param deviceConfig json device config + /// LedDeviceWS2812b(); ~LedDeviceWS2812b(); + + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value&) {}; + + /// constructs leddevice + static LedDevice* construct(const Json::Value &); + /// /// Writes the led color values to the led-device /// diff --git a/libsrc/leddevice/LedDeviceWS281x.cpp b/libsrc/leddevice/LedDeviceWS281x.cpp index 7e49ff39..98e03e11 100644 --- a/libsrc/leddevice/LedDeviceWS281x.cpp +++ b/libsrc/leddevice/LedDeviceWS281x.cpp @@ -4,31 +4,13 @@ #include "LedDeviceWS281x.h" // Constructor -LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, const int dmanum, const int pwmchannel, const int invert, const int rgbw, const std::string& whiteAlgorithm) +LedDeviceWS281x::LedDeviceWS281x(const Json::Value &deviceConfig) : LedDevice() - , _channel(pwmchannel) , _initialized(false) - , _whiteAlgorithm(whiteAlgorithm) { - Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str()); + setConfig(deviceConfig); + Debug( _log, "whiteAlgorithm : %s", _whiteAlgorithm.c_str()); - _led_string.freq = freq; - _led_string.dmanum = dmanum; - if (pwmchannel != 0 && pwmchannel != 1) - { - throw std::runtime_error("WS281x: invalid PWM channel; must be 0 or 1."); - } - _led_string.channel[_channel].gpionum = gpio; - _led_string.channel[_channel].invert = invert; - _led_string.channel[_channel].count = leds; - _led_string.channel[_channel].brightness = 255; - _led_string.channel[_channel].strip_type = ((rgbw == 1) ? SK6812_STRIP_GRBW : WS2811_STRIP_RGB); - - _led_string.channel[!_channel].gpionum = 0; - _led_string.channel[!_channel].invert = invert; - _led_string.channel[!_channel].count = 0; - _led_string.channel[!_channel].brightness = 0; - _led_string.channel[!_channel].strip_type = WS2811_STRIP_RGB; if (ws2811_init(&_led_string) < 0) { throw std::runtime_error("Unable to initialize ws281x library."); @@ -36,6 +18,38 @@ LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t _initialized = true; } +bool LedDeviceWS281x::setConfig(const Json::Value &deviceConfig) +{ + _whiteAlgorithm = deviceConfig.get("white_algorithm","").asString(); + _channel = deviceConfig.get("pwmchannel", 0).asInt(); + if (_channel != 0 && _channel != 1) + { + throw std::runtime_error("WS281x: invalid PWM channel; must be 0 or 1."); + } + + _led_string.freq = deviceConfig.get("freq", (Json::UInt)800000ul).asInt(); + _led_string.dmanum = deviceConfig.get("dmanum", 5).asInt(); + _led_string.channel[_channel].gpionum = deviceConfig.get("gpio", 18).asInt(); + _led_string.channel[_channel].count = deviceConfig.get("leds", 256).asInt(); + _led_string.channel[_channel].invert = deviceConfig.get("invert", 0).asInt(); + _led_string.channel[_channel].strip_type = ((deviceConfig.get("rgbw", 0).asInt() == 1) ? SK6812_STRIP_GRBW : WS2811_STRIP_RGB); + _led_string.channel[_channel].brightness = 255; + + _led_string.channel[!_channel].gpionum = 0; + _led_string.channel[!_channel].invert = _led_string.channel[_channel].invert; + _led_string.channel[!_channel].count = 0; + _led_string.channel[!_channel].brightness = 0; + _led_string.channel[!_channel].strip_type = WS2811_STRIP_RGB; + + return true; +} + +LedDevice* LedDeviceWS281x::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceWS281x(deviceConfig); +} + + // Send new values down the LED chain int LedDeviceWS281x::write(const std::vector &ledValues) { diff --git a/libsrc/leddevice/LedDeviceWS281x.h b/libsrc/leddevice/LedDeviceWS281x.h index 4cb9a0d2..b622981b 100644 --- a/libsrc/leddevice/LedDeviceWS281x.h +++ b/libsrc/leddevice/LedDeviceWS281x.h @@ -7,24 +7,26 @@ class LedDeviceWS281x : public LedDevice { public: /// - /// Constructs the LedDevice for WS281x (one wire 800kHz) + /// Constructs specific LedDevice /// - /// @param gpio The gpio pin to use (BCM chip counting, default is 18) - /// @param leds The number of leds attached to the gpio pin - /// @param freq The target frequency for the data line, default is 800000 - /// @param dmanum The DMA channel to use, default is 5 - /// @param pwmchannel The pwm channel to use - /// @param invert Invert the output line to support an inverting level shifter - /// @param rgbw Send 32 bit rgbw colour data for sk6812 - + /// @param deviceConfig json device config /// - LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, int dmanum, int pwmchannel, int invert, - int rgbw, const std::string& whiteAlgorithm); + LedDeviceWS281x(const Json::Value &deviceConfig); /// /// Destructor of the LedDevice, waits for DMA to complete and then cleans up /// ~LedDeviceWS281x(); + + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceWs2801.cpp b/libsrc/leddevice/LedDeviceWs2801.cpp index 41f2d661..f34e113d 100644 --- a/libsrc/leddevice/LedDeviceWs2801.cpp +++ b/libsrc/leddevice/LedDeviceWs2801.cpp @@ -11,11 +11,14 @@ // hyperion local includes #include "LedDeviceWs2801.h" -LedDeviceWs2801::LedDeviceWs2801(const std::string& outputDevice, const unsigned baudrate, const unsigned latchTime, - const int spiMode, const bool spiDataInvert) - : LedSpiDevice(outputDevice, baudrate, latchTime, spiMode, spiDataInvert) +LedDeviceWs2801::LedDeviceWs2801(const Json::Value &deviceConfig) + : LedSpiDevice(deviceConfig) { - // empty +} + +LedDevice* LedDeviceWs2801::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceWs2801(deviceConfig); } int LedDeviceWs2801::write(const std::vector &ledValues) diff --git a/libsrc/leddevice/LedDeviceWs2801.h b/libsrc/leddevice/LedDeviceWs2801.h index 0703bdf7..a7afee5f 100644 --- a/libsrc/leddevice/LedDeviceWs2801.h +++ b/libsrc/leddevice/LedDeviceWs2801.h @@ -13,17 +13,14 @@ class LedDeviceWs2801 : public LedSpiDevice { public: /// - /// Constructs the LedDevice for a string containing leds of the type Ws2801 + /// Constructs specific LedDevice /// - /// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0') - /// @param baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// + LedDeviceWs2801(const Json::Value &deviceConfig); - LedDeviceWs2801(const std::string& outputDevice, - const unsigned baudrate, - const unsigned latchTime, - const int spiMode, - const bool spiDataInvert); + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceWs2812SPI.cpp b/libsrc/leddevice/LedDeviceWs2812SPI.cpp index 3b3751e3..5fbd2134 100644 --- a/libsrc/leddevice/LedDeviceWs2812SPI.cpp +++ b/libsrc/leddevice/LedDeviceWs2812SPI.cpp @@ -11,8 +11,8 @@ // hyperion local includes #include "LedDeviceWs2812SPI.h" -LedDeviceWs2812SPI::LedDeviceWs2812SPI(const std::string& outputDevice, const unsigned baudrate, const int spiMode, const bool spiDataInvert) - : LedSpiDevice(outputDevice, baudrate, 0, spiMode, spiDataInvert) +LedDeviceWs2812SPI::LedDeviceWs2812SPI(const Json::Value &deviceConfig) + : LedSpiDevice(deviceConfig) , bitpair_to_byte { 0b10001000, 0b10001100, @@ -20,7 +20,11 @@ LedDeviceWs2812SPI::LedDeviceWs2812SPI(const std::string& outputDevice, const un 0b11001100, } { - // empty +} + +LedDevice* LedDeviceWs2812SPI::construct(const Json::Value &deviceConfig) +{ + return new LedDeviceWs2812SPI(deviceConfig); } int LedDeviceWs2812SPI::write(const std::vector &ledValues) diff --git a/libsrc/leddevice/LedDeviceWs2812SPI.h b/libsrc/leddevice/LedDeviceWs2812SPI.h index eed65c3e..bc1f01b1 100644 --- a/libsrc/leddevice/LedDeviceWs2812SPI.h +++ b/libsrc/leddevice/LedDeviceWs2812SPI.h @@ -13,13 +13,14 @@ class LedDeviceWs2812SPI : public LedSpiDevice { public: /// - /// Constructs the LedDevice for a string containing leds of the type Ws2812SPI + /// Constructs specific LedDevice /// - /// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0') - /// @param baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// - LedDeviceWs2812SPI(const std::string& outputDevice, const unsigned baudrate, - const int spiMode, const bool spiDataInvert); + LedDeviceWs2812SPI(const Json::Value &deviceConfig); + + /// constructs leddevice + static LedDevice* construct(const Json::Value &deviceConfig); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedHIDDevice.cpp b/libsrc/leddevice/LedHIDDevice.cpp index bd3a01bf..f3672e2f 100644 --- a/libsrc/leddevice/LedHIDDevice.cpp +++ b/libsrc/leddevice/LedHIDDevice.cpp @@ -9,15 +9,12 @@ // Local Hyperion includes #include "LedHIDDevice.h" -LedHIDDevice::LedHIDDevice(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms, const bool useFeature) - : _VendorId(VendorId) - , _ProductId(ProductId) - , _useFeature(useFeature) +LedHIDDevice::LedHIDDevice(const Json::Value &deviceConfig) + : _useFeature(false) , _deviceHandle(nullptr) - , _delayAfterConnect_ms(delayAfterConnect_ms) , _blockedForDelay(false) { - // empty + setConfig(deviceConfig); } LedHIDDevice::~LedHIDDevice() @@ -31,6 +28,19 @@ LedHIDDevice::~LedHIDDevice() hid_exit(); } +bool LedHIDDevice::setConfig(const Json::Value &deviceConfig) +{ + _delayAfterConnect_ms = deviceConfig.get("delayAfterConnect", 0 ).asInt(); + auto VendorIdString = deviceConfig.get("VID", "0x2341").asString(); + auto ProductIdString = deviceConfig.get("PID", "0x8036").asString(); + + // Convert HEX values to integer + _VendorId = std::stoul(VendorIdString, nullptr, 16); + _ProductId = std::stoul(ProductIdString, nullptr, 16); + + return true; +} + int LedHIDDevice::open() { // Initialize the usb context diff --git a/libsrc/leddevice/LedHIDDevice.h b/libsrc/leddevice/LedHIDDevice.h index 65c2595e..6db51ac0 100644 --- a/libsrc/leddevice/LedHIDDevice.h +++ b/libsrc/leddevice/LedHIDDevice.h @@ -17,18 +17,24 @@ class LedHIDDevice : public LedDevice public: /// - /// Constructs the LedDevice attached to an HID-device + /// Constructs specific LedDevice /// - /// @param[in] VendorId The USB VID of the output device - /// @param[in] ProductId The USB PID of the output device + /// @param deviceConfig json device config /// - LedHIDDevice(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms = 0, const bool useFeature = false); + LedHIDDevice(const Json::Value &deviceConfig); /// /// Destructor of the LedDevice; closes the output device if it is open /// virtual ~LedHIDDevice(); + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + virtual bool setConfig(const Json::Value &deviceConfig); + /// /// Opens and configures the output device /// @@ -46,21 +52,20 @@ protected: */ int writeBytes(const unsigned size, const uint8_t *data); -private slots: - /// Unblock the device after a connection delay - void unblockAfterDelay(); - -private: // HID VID and PID - const unsigned short _VendorId; - const unsigned short _ProductId; - const bool _useFeature; + unsigned short _VendorId; + unsigned short _ProductId; + bool _useFeature; /// libusb device handle hid_device * _deviceHandle; /// Sleep after the connect before continuing - const int _delayAfterConnect_ms; + int _delayAfterConnect_ms; bool _blockedForDelay; + +private slots: + /// Unblock the device after a connection delay + void unblockAfterDelay(); }; diff --git a/libsrc/leddevice/LedRs232Device.cpp b/libsrc/leddevice/LedRs232Device.cpp index f55ee54b..fea6541f 100644 --- a/libsrc/leddevice/LedRs232Device.cpp +++ b/libsrc/leddevice/LedRs232Device.cpp @@ -9,17 +9,25 @@ // Local Hyperion includes #include "LedRs232Device.h" -LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) - : _deviceName(outputDevice) - , _baudRate_Hz(baudrate) - , _delayAfterConnect_ms(delayAfterConnect_ms) - , _rs232Port(this) +LedRs232Device::LedRs232Device(const Json::Value &deviceConfig) + : _rs232Port(this) , _blockedForDelay(false) , _stateChanged(true) { + setConfig(deviceConfig); connect(&_rs232Port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error(QSerialPort::SerialPortError))); } +bool LedRs232Device::setConfig(const Json::Value &deviceConfig) +{ + closeDevice(); + _deviceName = deviceConfig["output"].asString(); + _baudRate_Hz = deviceConfig["rate"].asInt(); + _delayAfterConnect_ms = deviceConfig.get("delayAfterConnect",250).asInt(); + + return true; +} + void LedRs232Device::error(QSerialPort::SerialPortError error) { if ( error != QSerialPort::NoError ) @@ -59,6 +67,11 @@ void LedRs232Device::error(QSerialPort::SerialPortError error) LedRs232Device::~LedRs232Device() { disconnect(&_rs232Port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error(QSerialPort::SerialPortError))); + closeDevice(); +} + +void LedRs232Device::closeDevice() +{ if (_rs232Port.isOpen()) { _rs232Port.close(); @@ -66,7 +79,6 @@ LedRs232Device::~LedRs232Device() } } - int LedRs232Device::open() { Info(_log, "Opening UART: %s", _deviceName.c_str()); diff --git a/libsrc/leddevice/LedRs232Device.h b/libsrc/leddevice/LedRs232Device.h index 264c2829..d321835d 100644 --- a/libsrc/leddevice/LedRs232Device.h +++ b/libsrc/leddevice/LedRs232Device.h @@ -15,12 +15,18 @@ class LedRs232Device : public LedDevice public: /// - /// Constructs the LedDevice attached to a RS232-device + /// Constructs specific LedDevice /// - /// @param[in] outputDevice The name of the output device (eg '/etc/ttyS0') - /// @param[in] baudrate The used baudrate for writing to the output device + /// @param deviceConfig json device config /// - LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms = 0); + LedRs232Device(const Json::Value &deviceConfig); + + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + virtual bool setConfig(const Json::Value &deviceConfig); /// /// Destructor of the LedDevice; closes the output device if it is open @@ -45,6 +51,8 @@ protected: */ int writeBytes(const unsigned size, const uint8_t *data); + void closeDevice(); + private slots: /// Unblock the device after a connection delay void unblockAfterDelay(); @@ -55,10 +63,10 @@ private: bool tryOpen(); /// The name of the output device - const std::string _deviceName; + std::string _deviceName; /// The used baudrate of the output device - const qint32 _baudRate_Hz; + qint32 _baudRate_Hz; /// Sleep after the connect before continuing int _delayAfterConnect_ms; diff --git a/libsrc/leddevice/LedSpiDevice.cpp b/libsrc/leddevice/LedSpiDevice.cpp index f0ed5b96..7ff12a62 100644 --- a/libsrc/leddevice/LedSpiDevice.cpp +++ b/libsrc/leddevice/LedSpiDevice.cpp @@ -14,14 +14,11 @@ #include -LedSpiDevice::LedSpiDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns, const int spiMode, const bool spiDataInvert) - : _deviceName(outputDevice) - , _baudRate_Hz(baudrate) - , _latchTime_ns(latchTime_ns) +LedSpiDevice::LedSpiDevice(const Json::Value &deviceConfig) + : LedDevice() , _fid(-1) - , _spiMode(spiMode) - , _spiDataInvert(spiDataInvert) { + setConfig(deviceConfig); memset(&_spi, 0, sizeof(_spi)); Debug(_log, "_spiDataInvert %d, _spiMode %d", _spiDataInvert, _spiMode); } @@ -31,6 +28,17 @@ LedSpiDevice::~LedSpiDevice() // close(_fid); } +bool LedSpiDevice::setConfig(const Json::Value &deviceConfig) +{ + _deviceName = deviceConfig.get("output","/dev/spidev.0.0").asString(); + _baudRate_Hz = deviceConfig.get("rate",1000000).asInt(); + _latchTime_ns = deviceConfig.get("latchtime",0).asInt(); + _spiMode = deviceConfig.get("spimode",SPI_MODE_0).asInt(); + _spiDataInvert = deviceConfig.get("invert",false).asBool(); + + return true; +} + int LedSpiDevice::open() { const int bitsPerWord = 8; diff --git a/libsrc/leddevice/LedSpiDevice.h b/libsrc/leddevice/LedSpiDevice.h index 8e27082b..8bc920c3 100644 --- a/libsrc/leddevice/LedSpiDevice.h +++ b/libsrc/leddevice/LedSpiDevice.h @@ -13,16 +13,18 @@ class LedSpiDevice : public LedDevice { public: /// - /// Constructs the LedDevice attached to a SPI-device + /// Constructs specific LedDevice /// - /// @param[in] outputDevice The name of the output device (eg '/dev/spidev.0.0') - /// @param[in] baudrate The used baudrate for writing to the output device - /// @param[in] latchTime_ns The latch-time to latch in the values across the SPI-device (negative - /// means no latch required) [ns] + /// @param deviceConfig json device config /// - LedSpiDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns = -1, - const int spiMode = SPI_MODE_0, const bool spiDataInvert = false); + LedSpiDevice(const Json::Value &deviceConfig); + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + virtual bool setConfig(const Json::Value &deviceConfig); /// /// Destructor of the LedDevice; closes the output device if it is open @@ -48,15 +50,14 @@ protected: /// int writeBytes(const unsigned size, const uint8_t *data); -private: /// The name of the output device - const std::string _deviceName; + std::string _deviceName; /// The used baudrate of the output device - const int _baudRate_Hz; + int _baudRate_Hz; /// The time which the device should be untouched after a write - const int _latchTime_ns; + int _latchTime_ns; /// The File Identifier of the opened output device (or -1 if not opened) int _fid; diff --git a/libsrc/leddevice/LedUdpDevice.cpp b/libsrc/leddevice/LedUdpDevice.cpp index da7a9528..25e6d79b 100644 --- a/libsrc/leddevice/LedUdpDevice.cpp +++ b/libsrc/leddevice/LedUdpDevice.cpp @@ -15,24 +15,12 @@ // Local Hyperion includes #include "LedUdpDevice.h" -LedUdpDevice::LedUdpDevice(const std::string& output, const int latchTime_ns) - : _target(output) - , _LatchTime_ns(latchTime_ns) +LedUdpDevice::LedUdpDevice(const Json::Value &deviceConfig) + : LedDevice() + , _LatchTime_ns(-1) { + setConfig(deviceConfig); _udpSocket = new QUdpSocket(); - QString str = QString::fromStdString(_target); - QStringList str_splitted = str.split(":"); - if (str_splitted.size() != 2) - { - throw("Error parsing hostname:port"); - } - QHostInfo info = QHostInfo::fromName(str_splitted.at(0)); - if (!info.addresses().isEmpty()) - { - // use the first IP address - _address = info.addresses().first(); - } - _port = str_splitted.at(1).toInt(); } LedUdpDevice::~LedUdpDevice() @@ -40,6 +28,19 @@ LedUdpDevice::~LedUdpDevice() _udpSocket->close(); } +bool LedUdpDevice::setConfig(const Json::Value &deviceConfig) +{ + QHostInfo info = QHostInfo::fromName( QString::fromStdString(deviceConfig["output"].asString()) ); + if (info.addresses().isEmpty()) + { + throw("invalid target address"); + } + _address = info.addresses().first(); + _port = deviceConfig["port"].asUInt(); + + return true; +} + int LedUdpDevice::open() { QHostAddress localAddress = QHostAddress::Any; diff --git a/libsrc/leddevice/LedUdpDevice.h b/libsrc/leddevice/LedUdpDevice.h index 27ca481b..d1faa366 100644 --- a/libsrc/leddevice/LedUdpDevice.h +++ b/libsrc/leddevice/LedUdpDevice.h @@ -13,19 +13,24 @@ class LedUdpDevice : public LedDevice { public: /// - /// Constructs the LedDevice sendig data via udp + /// Constructs specific LedDevice /// - /// @param[in] outputDevice string hostname:port - /// @param[in] latchTime_ns The latch-time to latch in the values across the SPI-device (negative - /// means no latch required) [ns] + /// @param deviceConfig json device config /// - LedUdpDevice(const std::string& outputDevice, const int latchTime_ns = -1); + LedUdpDevice(const Json::Value &deviceConfig); /// /// Destructor of the LedDevice; closes the output device if it is open /// virtual ~LedUdpDevice(); + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool setConfig(const Json::Value &deviceConfig); + /// /// Opens and configures the output device /// @@ -45,12 +50,8 @@ protected: /// int writeBytes(const unsigned size, const uint8_t *data); -private: - /// The UDP destination as "host:port" - const std::string _target; - /// The time which the device should be untouched after a write - const int _LatchTime_ns; + int _LatchTime_ns; /// QUdpSocket * _udpSocket; diff --git a/libsrc/leddevice/schemas/schema-adalight.json b/libsrc/leddevice/schemas/schema-adalight.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-adalight.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-adalightapa102.json b/libsrc/leddevice/schemas/schema-adalightapa102.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-adalightapa102.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-apa102.json b/libsrc/leddevice/schemas/schema-apa102.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-apa102.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-atmo.json b/libsrc/leddevice/schemas/schema-atmo.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-atmo.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-atmoorb.json b/libsrc/leddevice/schemas/schema-atmoorb.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-atmoorb.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-e131.json b/libsrc/leddevice/schemas/schema-e131.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-e131.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-fadecandy.json b/libsrc/leddevice/schemas/schema-fadecandy.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-fadecandy.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-file.json b/libsrc/leddevice/schemas/schema-file.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-file.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-hyperion-usbasp.json b/libsrc/leddevice/schemas/schema-hyperion-usbasp.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-hyperion-usbasp.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-lightpack.json b/libsrc/leddevice/schemas/schema-lightpack.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-lightpack.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-lpd6803.json b/libsrc/leddevice/schemas/schema-lpd6803.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-lpd6803.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-lpd8806.json b/libsrc/leddevice/schemas/schema-lpd8806.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-lpd8806.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-multi-lightpack.json b/libsrc/leddevice/schemas/schema-multi-lightpack.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-multi-lightpack.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-p9813.json b/libsrc/leddevice/schemas/schema-p9813.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-p9813.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-paintpack.json b/libsrc/leddevice/schemas/schema-paintpack.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-paintpack.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-philipshue.json b/libsrc/leddevice/schemas/schema-philipshue.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-philipshue.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-piblaster.json b/libsrc/leddevice/schemas/schema-piblaster.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-piblaster.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-rawhid.json b/libsrc/leddevice/schemas/schema-rawhid.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-rawhid.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-sedu.json b/libsrc/leddevice/schemas/schema-sedu.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-sedu.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-sk6812rgbw-spi.json b/libsrc/leddevice/schemas/schema-sk6812rgbw-spi.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-sk6812rgbw-spi.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-tinkerforge.json b/libsrc/leddevice/schemas/schema-tinkerforge.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-tinkerforge.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-tmp2net.json b/libsrc/leddevice/schemas/schema-tmp2net.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-tmp2net.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-tpm2.json b/libsrc/leddevice/schemas/schema-tpm2.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-tpm2.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-udpraw.json b/libsrc/leddevice/schemas/schema-udpraw.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-udpraw.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-ws2801.json b/libsrc/leddevice/schemas/schema-ws2801.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-ws2801.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-ws2812spi.json b/libsrc/leddevice/schemas/schema-ws2812spi.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-ws2812spi.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/libsrc/leddevice/schemas/schema-ws281x.json b/libsrc/leddevice/schemas/schema-ws281x.json new file mode 100644 index 00000000..0bce7984 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-ws281x.json @@ -0,0 +1,7 @@ +{ + "type":"object", + "required":true, + "properties":{ + }, + "additionalProperties": true +} diff --git a/test/TestSpi.cpp b/test/TestSpi.cpp index c8420d41..47aa6627 100644 --- a/test/TestSpi.cpp +++ b/test/TestSpi.cpp @@ -9,9 +9,13 @@ // Local includes #include +#include #include "../libsrc/leddevice/LedDeviceWs2801.h" +Json::Value deviceConfig; + + void setColor(char* colorStr) { ColorRgb color = ColorRgb::BLACK; @@ -54,7 +58,8 @@ void setColor(char* colorStr) unsigned ledCnt = 50; std::vector buff(ledCnt, color); - LedDeviceWs2801 ledDevice("/dev/spidev0.0", 40000, 500000, 0, 0); + + LedDeviceWs2801 ledDevice(deviceConfig); ledDevice.open(); ledDevice.write(buff); } @@ -68,7 +73,7 @@ void doCircle() unsigned ledCnt = 50; std::vector data(ledCnt, ColorRgb::BLACK); - LedDeviceWs2801 ledDevice("/dev/spidev0.0", 40000, 500000, 0, 0); + LedDeviceWs2801 ledDevice(deviceConfig); ledDevice.open(); timespec loopTime; @@ -142,6 +147,10 @@ int main(int argc, char** argv) return -1; } + deviceConfig["output"] = "/dev/spidev0.0"; + deviceConfig["rate"] = 40000; + deviceConfig["latchtime"] = 500000; + if (strncmp("fixed", argv[1], 5) == 0) { setColor(argv[2]); diff --git a/test/testrunner.sh b/test/testrunner.sh index 8c1afa3f..21503b8c 100644 --- a/test/testrunner.sh +++ b/test/testrunner.sh @@ -16,9 +16,11 @@ function exec_test() then echo -e " ... success" (( STATS_SUCCESS++ )) + return 0 else echo -e " ... failed" (( STATS_FAILED++ )) + return 1 fi echo } @@ -31,6 +33,7 @@ echo echo "Hyperion test execution" echo exec_test "hyperiond is executable and show version" bin/hyperiond --version + for cfg in ../config/*json* do exec_test "test $(basename $cfg)" bin/test_configfile $cfg