Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 756fae2

Browse files
committed
Added a possible delay after connecting an Adalight device
1 parent dadd309 commit 756fae2

File tree

8 files changed

+36
-13
lines changed

8 files changed

+36
-13
lines changed

deploy/hyperion.tar.gz

-88 Bytes
Binary file not shown.

include/utils/Sleep.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include <QThread>
4+
5+
class Sleep : protected QThread {
6+
public:
7+
static inline void msleep(unsigned long msecs) {
8+
QThread::msleep(msecs);
9+
}
10+
};

libsrc/leddevice/LedDeviceAdalight.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// hyperion local includes
1212
#include "LedDeviceAdalight.h"
1313

14-
LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate) :
15-
LedRs232Device(outputDevice, baudrate),
14+
LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
15+
LedRs232Device(outputDevice, baudrate, delayAfterConnect_ms),
1616
_ledBuffer(0),
1717
_timer()
1818
{

libsrc/leddevice/LedDeviceAdalight.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LedDeviceAdalight : public QObject, public LedRs232Device
2323
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
2424
/// @param baudrate The used baudrate for writing to the output device
2525
///
26-
LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate);
26+
LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms);
2727

2828
///
2929
/// Writes the led color values to the led-device

libsrc/leddevice/LedDeviceFactory.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
4343
{
4444
const std::string output = deviceConfig["output"].asString();
4545
const unsigned rate = deviceConfig["rate"].asInt();
46+
const int delay_ms = deviceConfig["delayAfterConnect"].asInt();
4647

47-
LedDeviceAdalight* deviceAdalight = new LedDeviceAdalight(output, rate);
48+
LedDeviceAdalight* deviceAdalight = new LedDeviceAdalight(output, rate, delay_ms);
4849
deviceAdalight->open();
4950

5051
device = deviceAdalight;

libsrc/leddevice/LedRs232Device.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
// Local Hyperion includes
1111
#include "LedRs232Device.h"
12+
#include "utils/Sleep.h"
1213

1314

14-
LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate) :
15-
mDeviceName(outputDevice),
16-
mBaudRate_Hz(baudrate),
15+
LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
16+
_deviceName(outputDevice),
17+
_baudRate_Hz(baudrate),
18+
_delayAfterConnect_ms(delayAfterConnect_ms),
1719
_rs232Port()
1820
{
1921
// empty
@@ -31,10 +33,15 @@ int LedRs232Device::open()
3133
{
3234
try
3335
{
34-
std::cout << "Opening UART: " << mDeviceName << std::endl;
35-
_rs232Port.setPort(mDeviceName);
36-
_rs232Port.setBaudrate(mBaudRate_Hz);
36+
std::cout << "Opening UART: " << _deviceName << std::endl;
37+
_rs232Port.setPort(_deviceName);
38+
_rs232Port.setBaudrate(_baudRate_Hz);
3739
_rs232Port.open();
40+
41+
if (_delayAfterConnect_ms > 0)
42+
{
43+
Sleep::msleep(_delayAfterConnect_ms);
44+
}
3845
}
3946
catch (const std::exception& e)
4047
{

libsrc/leddevice/LedRs232Device.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class LedRs232Device : public LedDevice
1818
/// @param[in] outputDevice The name of the output device (eg '/etc/ttyS0')
1919
/// @param[in] baudrate The used baudrate for writing to the output device
2020
///
21-
LedRs232Device(const std::string& outputDevice, const unsigned baudrate);
21+
LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms = 0);
2222

2323
///
2424
/// Destructor of the LedDevice; closes the output device if it is open
@@ -45,9 +45,13 @@ class LedRs232Device : public LedDevice
4545

4646
private:
4747
/// The name of the output device
48-
const std::string mDeviceName;
48+
const std::string _deviceName;
49+
4950
/// The used baudrate of the output device
50-
const int mBaudRate_Hz;
51+
const int _baudRate_Hz;
52+
53+
/// Sleep after the connect before continuing
54+
const int _delayAfterConnect_ms;
5155

5256
/// The RS232 serial-device
5357
serial::Serial _rs232Port;

libsrc/utils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_library(hyperion-utils
1111
${CURRENT_HEADER_DIR}/ColorRgba.h
1212
${CURRENT_SOURCE_DIR}/ColorRgba.cpp
1313
${CURRENT_HEADER_DIR}/Image.h
14+
${CURRENT_HEADER_DIR}/Sleep.h
1415

1516
${CURRENT_HEADER_DIR}/HsvTransform.h
1617
${CURRENT_SOURCE_DIR}/HsvTransform.cpp

0 commit comments

Comments
 (0)