diff --git a/deploy/hyperion.tar.gz.REMOVED.git-id b/deploy/hyperion.tar.gz.REMOVED.git-id index a48b195a..288cb926 100644 --- a/deploy/hyperion.tar.gz.REMOVED.git-id +++ b/deploy/hyperion.tar.gz.REMOVED.git-id @@ -1 +1 @@ -e80ba1bef0cc5983a767b293f0c5915c2535a47f \ No newline at end of file +ab3338d1164469e008bd9635c817659b6e528a1f \ No newline at end of file diff --git a/include/utils/Sleep.h b/include/utils/Sleep.h new file mode 100644 index 00000000..a2c55815 --- /dev/null +++ b/include/utils/Sleep.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +class Sleep : protected QThread { +public: + static inline void msleep(unsigned long msecs) { + QThread::msleep(msecs); + } +}; diff --git a/libsrc/leddevice/LedDeviceAdalight.cpp b/libsrc/leddevice/LedDeviceAdalight.cpp index f19bb4be..47c09278 100644 --- a/libsrc/leddevice/LedDeviceAdalight.cpp +++ b/libsrc/leddevice/LedDeviceAdalight.cpp @@ -11,8 +11,8 @@ // hyperion local includes #include "LedDeviceAdalight.h" -LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate) : - LedRs232Device(outputDevice, baudrate), +LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) : + LedRs232Device(outputDevice, baudrate, delayAfterConnect_ms), _ledBuffer(0), _timer() { diff --git a/libsrc/leddevice/LedDeviceAdalight.h b/libsrc/leddevice/LedDeviceAdalight.h index 30e7bfb7..3621c5ca 100644 --- a/libsrc/leddevice/LedDeviceAdalight.h +++ b/libsrc/leddevice/LedDeviceAdalight.h @@ -23,7 +23,7 @@ public: /// @param outputDevice The name of the output device (eg '/dev/ttyS0') /// @param baudrate The used baudrate for writing to the output device /// - LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate); + LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms); /// /// Writes the led color values to the led-device diff --git a/libsrc/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index 71aeda06..76eb0137 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -43,8 +43,9 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig) { const std::string output = deviceConfig["output"].asString(); const unsigned rate = deviceConfig["rate"].asInt(); + const int delay_ms = deviceConfig["delayAfterConnect"].asInt(); - LedDeviceAdalight* deviceAdalight = new LedDeviceAdalight(output, rate); + LedDeviceAdalight* deviceAdalight = new LedDeviceAdalight(output, rate, delay_ms); deviceAdalight->open(); device = deviceAdalight; diff --git a/libsrc/leddevice/LedRs232Device.cpp b/libsrc/leddevice/LedRs232Device.cpp index 6bc3560b..c8c185a4 100644 --- a/libsrc/leddevice/LedRs232Device.cpp +++ b/libsrc/leddevice/LedRs232Device.cpp @@ -9,11 +9,13 @@ // Local Hyperion includes #include "LedRs232Device.h" +#include "utils/Sleep.h" -LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate) : - mDeviceName(outputDevice), - mBaudRate_Hz(baudrate), +LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) : + _deviceName(outputDevice), + _baudRate_Hz(baudrate), + _delayAfterConnect_ms(delayAfterConnect_ms), _rs232Port() { // empty @@ -31,10 +33,15 @@ int LedRs232Device::open() { try { - std::cout << "Opening UART: " << mDeviceName << std::endl; - _rs232Port.setPort(mDeviceName); - _rs232Port.setBaudrate(mBaudRate_Hz); + std::cout << "Opening UART: " << _deviceName << std::endl; + _rs232Port.setPort(_deviceName); + _rs232Port.setBaudrate(_baudRate_Hz); _rs232Port.open(); + + if (_delayAfterConnect_ms > 0) + { + Sleep::msleep(_delayAfterConnect_ms); + } } catch (const std::exception& e) { diff --git a/libsrc/leddevice/LedRs232Device.h b/libsrc/leddevice/LedRs232Device.h index 856a80fe..f8154581 100644 --- a/libsrc/leddevice/LedRs232Device.h +++ b/libsrc/leddevice/LedRs232Device.h @@ -18,7 +18,7 @@ public: /// @param[in] outputDevice The name of the output device (eg '/etc/ttyS0') /// @param[in] baudrate The used baudrate for writing to the output device /// - LedRs232Device(const std::string& outputDevice, const unsigned baudrate); + LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms = 0); /// /// Destructor of the LedDevice; closes the output device if it is open @@ -45,9 +45,13 @@ protected: private: /// The name of the output device - const std::string mDeviceName; + const std::string _deviceName; + /// The used baudrate of the output device - const int mBaudRate_Hz; + const int _baudRate_Hz; + + /// Sleep after the connect before continuing + const int _delayAfterConnect_ms; /// The RS232 serial-device serial::Serial _rs232Port; diff --git a/libsrc/utils/CMakeLists.txt b/libsrc/utils/CMakeLists.txt index 52094a61..b1f0709e 100644 --- a/libsrc/utils/CMakeLists.txt +++ b/libsrc/utils/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(hyperion-utils ${CURRENT_HEADER_DIR}/ColorRgba.h ${CURRENT_SOURCE_DIR}/ColorRgba.cpp ${CURRENT_HEADER_DIR}/Image.h + ${CURRENT_HEADER_DIR}/Sleep.h ${CURRENT_HEADER_DIR}/HsvTransform.h ${CURRENT_SOURCE_DIR}/HsvTransform.cpp