mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added a possible delay after connecting an Adalight device
Former-commit-id: 756fae2ebc57455bf6360dc96bf2ae5469460172
This commit is contained in:
parent
8c1f14f8dc
commit
3eb29146dd
@ -1 +1 @@
|
|||||||
e80ba1bef0cc5983a767b293f0c5915c2535a47f
|
ab3338d1164469e008bd9635c817659b6e528a1f
|
10
include/utils/Sleep.h
Normal file
10
include/utils/Sleep.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
class Sleep : protected QThread {
|
||||||
|
public:
|
||||||
|
static inline void msleep(unsigned long msecs) {
|
||||||
|
QThread::msleep(msecs);
|
||||||
|
}
|
||||||
|
};
|
@ -11,8 +11,8 @@
|
|||||||
// hyperion local includes
|
// hyperion local includes
|
||||||
#include "LedDeviceAdalight.h"
|
#include "LedDeviceAdalight.h"
|
||||||
|
|
||||||
LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate) :
|
LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
|
||||||
LedRs232Device(outputDevice, baudrate),
|
LedRs232Device(outputDevice, baudrate, delayAfterConnect_ms),
|
||||||
_ledBuffer(0),
|
_ledBuffer(0),
|
||||||
_timer()
|
_timer()
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,7 @@ public:
|
|||||||
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
|
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
|
||||||
/// @param baudrate The used baudrate for writing to the output device
|
/// @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
|
/// Writes the led color values to the led-device
|
||||||
|
@ -43,8 +43,9 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
|||||||
{
|
{
|
||||||
const std::string output = deviceConfig["output"].asString();
|
const std::string output = deviceConfig["output"].asString();
|
||||||
const unsigned rate = deviceConfig["rate"].asInt();
|
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();
|
deviceAdalight->open();
|
||||||
|
|
||||||
device = deviceAdalight;
|
device = deviceAdalight;
|
||||||
|
@ -9,11 +9,13 @@
|
|||||||
|
|
||||||
// Local Hyperion includes
|
// Local Hyperion includes
|
||||||
#include "LedRs232Device.h"
|
#include "LedRs232Device.h"
|
||||||
|
#include "utils/Sleep.h"
|
||||||
|
|
||||||
|
|
||||||
LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate) :
|
LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
|
||||||
mDeviceName(outputDevice),
|
_deviceName(outputDevice),
|
||||||
mBaudRate_Hz(baudrate),
|
_baudRate_Hz(baudrate),
|
||||||
|
_delayAfterConnect_ms(delayAfterConnect_ms),
|
||||||
_rs232Port()
|
_rs232Port()
|
||||||
{
|
{
|
||||||
// empty
|
// empty
|
||||||
@ -31,10 +33,15 @@ int LedRs232Device::open()
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::cout << "Opening UART: " << mDeviceName << std::endl;
|
std::cout << "Opening UART: " << _deviceName << std::endl;
|
||||||
_rs232Port.setPort(mDeviceName);
|
_rs232Port.setPort(_deviceName);
|
||||||
_rs232Port.setBaudrate(mBaudRate_Hz);
|
_rs232Port.setBaudrate(_baudRate_Hz);
|
||||||
_rs232Port.open();
|
_rs232Port.open();
|
||||||
|
|
||||||
|
if (_delayAfterConnect_ms > 0)
|
||||||
|
{
|
||||||
|
Sleep::msleep(_delayAfterConnect_ms);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@ public:
|
|||||||
/// @param[in] outputDevice The name of the output device (eg '/etc/ttyS0')
|
/// @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[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
|
/// Destructor of the LedDevice; closes the output device if it is open
|
||||||
@ -45,9 +45,13 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/// The name of the output device
|
/// The name of the output device
|
||||||
const std::string mDeviceName;
|
const std::string _deviceName;
|
||||||
|
|
||||||
/// The used baudrate of the output device
|
/// 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
|
/// The RS232 serial-device
|
||||||
serial::Serial _rs232Port;
|
serial::Serial _rs232Port;
|
||||||
|
@ -11,6 +11,7 @@ add_library(hyperion-utils
|
|||||||
${CURRENT_HEADER_DIR}/ColorRgba.h
|
${CURRENT_HEADER_DIR}/ColorRgba.h
|
||||||
${CURRENT_SOURCE_DIR}/ColorRgba.cpp
|
${CURRENT_SOURCE_DIR}/ColorRgba.cpp
|
||||||
${CURRENT_HEADER_DIR}/Image.h
|
${CURRENT_HEADER_DIR}/Image.h
|
||||||
|
${CURRENT_HEADER_DIR}/Sleep.h
|
||||||
|
|
||||||
${CURRENT_HEADER_DIR}/HsvTransform.h
|
${CURRENT_HEADER_DIR}/HsvTransform.h
|
||||||
${CURRENT_SOURCE_DIR}/HsvTransform.cpp
|
${CURRENT_SOURCE_DIR}/HsvTransform.cpp
|
||||||
|
Loading…
Reference in New Issue
Block a user