Added a possible delay after connecting an Adalight device

Former-commit-id: 756fae2ebc57455bf6360dc96bf2ae5469460172
This commit is contained in:
johan 2014-05-04 11:31:13 +02:00
parent 8c1f14f8dc
commit 3eb29146dd
8 changed files with 37 additions and 14 deletions

View File

@ -1 +1 @@
e80ba1bef0cc5983a767b293f0c5915c2535a47f
ab3338d1164469e008bd9635c817659b6e528a1f

10
include/utils/Sleep.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include <QThread>
class Sleep : protected QThread {
public:
static inline void msleep(unsigned long msecs) {
QThread::msleep(msecs);
}
};

View File

@ -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()
{

View File

@ -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

View File

@ -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;

View File

@ -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)
{

View File

@ -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;

View File

@ -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