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

Commit b313005

Browse files
committed
Changed connection delay to something non-blocking
1 parent 756fae2 commit b313005

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

deploy/hyperion.tar.gz

-420 Bytes
Binary file not shown.

libsrc/leddevice/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ include_directories(
1313

1414
# Group the headers that go through the MOC compiler
1515
SET(Leddevice_QT_HEADERS
16+
${CURRENT_SOURCE_DIR}/LedRs232Device.h
1617
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.h
1718
)
1819

1920
SET(Leddevice_HEADERS
2021
${CURRENT_HEADER_DIR}/LedDevice.h
2122
${CURRENT_HEADER_DIR}/LedDeviceFactory.h
2223

23-
${CURRENT_SOURCE_DIR}/LedRs232Device.h
24-
2524
${CURRENT_SOURCE_DIR}/LedDeviceLightpack.h
2625
${CURRENT_SOURCE_DIR}/LedDeviceMultiLightpack.h
2726
${CURRENT_SOURCE_DIR}/LedDevicePaintpack.h

libsrc/leddevice/LedDeviceAdalight.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
///
1313
/// Implementation of the LedDevice interface for writing to an Adalight led device.
1414
///
15-
class LedDeviceAdalight : public QObject, public LedRs232Device
15+
class LedDeviceAdalight : public LedRs232Device
1616
{
1717
Q_OBJECT
1818

libsrc/leddevice/LedRs232Device.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44
#include <cstdio>
55
#include <iostream>
66

7+
// Qt includes
8+
#include <QTimer>
9+
710
// Serial includes
811
#include <serial/serial.h>
912

1013
// Local Hyperion includes
1114
#include "LedRs232Device.h"
12-
#include "utils/Sleep.h"
13-
1415

1516
LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
1617
_deviceName(outputDevice),
1718
_baudRate_Hz(baudrate),
1819
_delayAfterConnect_ms(delayAfterConnect_ms),
19-
_rs232Port()
20+
_rs232Port(),
21+
_blockedForDelay(false)
2022
{
2123
// empty
2224
}
@@ -40,7 +42,9 @@ int LedRs232Device::open()
4042

4143
if (_delayAfterConnect_ms > 0)
4244
{
43-
Sleep::msleep(_delayAfterConnect_ms);
45+
_blockedForDelay = true;
46+
QTimer::singleShot(_delayAfterConnect_ms, this, SLOT(unblockAfterDelay()));
47+
std::cout << "Device blocked for " << _delayAfterConnect_ms << " ms" << std::endl;
4448
}
4549
}
4650
catch (const std::exception& e)
@@ -54,6 +58,11 @@ int LedRs232Device::open()
5458

5559
int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
5660
{
61+
if (_blockedForDelay)
62+
{
63+
return 0;
64+
}
65+
5766
if (!_rs232Port.isOpen())
5867
{
5968
return -1;
@@ -102,3 +111,9 @@ int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
102111

103112
return 0;
104113
}
114+
115+
void LedRs232Device::unblockAfterDelay()
116+
{
117+
std::cout << "Device unblocked" << std::endl;
118+
_blockedForDelay = false;
119+
}

libsrc/leddevice/LedRs232Device.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <QObject>
4+
35
// Serial includes
46
#include <serial/serial.h>
57

@@ -9,8 +11,10 @@
911
///
1012
/// The LedRs232Device implements an abstract base-class for LedDevices using a RS232-device.
1113
///
12-
class LedRs232Device : public LedDevice
14+
class LedRs232Device : public QObject, public LedDevice
1315
{
16+
Q_OBJECT
17+
1418
public:
1519
///
1620
/// Constructs the LedDevice attached to a RS232-device
@@ -43,6 +47,10 @@ class LedRs232Device : public LedDevice
4347
*/
4448
int writeBytes(const unsigned size, const uint8_t *data);
4549

50+
private slots:
51+
/// Unblock the device after a connection delay
52+
void unblockAfterDelay();
53+
4654
private:
4755
/// The name of the output device
4856
const std::string _deviceName;
@@ -55,4 +63,6 @@ class LedRs232Device : public LedDevice
5563

5664
/// The RS232 serial-device
5765
serial::Serial _rs232Port;
66+
67+
bool _blockedForDelay;
5868
};

0 commit comments

Comments
 (0)