mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Merge branch 'master' into support_for_philips_hue
Former-commit-id: ee3816fde708fa2f9f9e6ad50ec1e6d2ff552b23
This commit is contained in:
@@ -13,6 +13,7 @@ include_directories(
|
||||
|
||||
# Group the headers that go through the MOC compiler
|
||||
SET(Leddevice_QT_HEADERS
|
||||
${CURRENT_SOURCE_DIR}/LedRs232Device.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAdalight.h
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h
|
||||
)
|
||||
@@ -21,8 +22,6 @@ SET(Leddevice_HEADERS
|
||||
${CURRENT_HEADER_DIR}/LedDevice.h
|
||||
${CURRENT_HEADER_DIR}/LedDeviceFactory.h
|
||||
|
||||
${CURRENT_SOURCE_DIR}/LedRs232Device.h
|
||||
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceLightpack.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceMultiLightpack.h
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePaintpack.h
|
||||
|
@@ -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()
|
||||
{
|
||||
|
@@ -12,7 +12,7 @@
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to an Adalight led device.
|
||||
///
|
||||
class LedDeviceAdalight : public QObject, public LedRs232Device
|
||||
class LedDeviceAdalight : public LedRs232Device
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -14,11 +14,13 @@
|
||||
|
||||
/**
|
||||
* Implementation for the Philips Hue system.
|
||||
*
|
||||
*
|
||||
* To use set the device to "philipshue".
|
||||
* Uses the official Philips Hue API (http://developers.meethue.com).
|
||||
* Framegrabber must be limited to 10 Hz / numer of lights to avoid rate limitation by the hue bridge.
|
||||
* Create a new API user name "newdeveloper" on the bridge (http://developers.meethue.com/gettingstarted.html)
|
||||
*
|
||||
* @author ntim (github)
|
||||
*/
|
||||
class LedDevicePhilipsHue: public QObject, public LedDevice {
|
||||
Q_OBJECT
|
||||
|
@@ -4,17 +4,21 @@
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
// Qt includes
|
||||
#include <QTimer>
|
||||
|
||||
// Serial includes
|
||||
#include <serial/serial.h>
|
||||
|
||||
// Local Hyperion includes
|
||||
#include "LedRs232Device.h"
|
||||
|
||||
|
||||
LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate) :
|
||||
mDeviceName(outputDevice),
|
||||
mBaudRate_Hz(baudrate),
|
||||
_rs232Port()
|
||||
LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
|
||||
_deviceName(outputDevice),
|
||||
_baudRate_Hz(baudrate),
|
||||
_delayAfterConnect_ms(delayAfterConnect_ms),
|
||||
_rs232Port(),
|
||||
_blockedForDelay(false)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
@@ -31,10 +35,17 @@ 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)
|
||||
{
|
||||
_blockedForDelay = true;
|
||||
QTimer::singleShot(_delayAfterConnect_ms, this, SLOT(unblockAfterDelay()));
|
||||
std::cout << "Device blocked for " << _delayAfterConnect_ms << " ms" << std::endl;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
@@ -47,6 +58,11 @@ int LedRs232Device::open()
|
||||
|
||||
int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
|
||||
{
|
||||
if (_blockedForDelay)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_rs232Port.isOpen())
|
||||
{
|
||||
return -1;
|
||||
@@ -95,3 +111,9 @@ int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LedRs232Device::unblockAfterDelay()
|
||||
{
|
||||
std::cout << "Device unblocked" << std::endl;
|
||||
_blockedForDelay = false;
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
// Serial includes
|
||||
#include <serial/serial.h>
|
||||
|
||||
@@ -9,8 +11,10 @@
|
||||
///
|
||||
/// The LedRs232Device implements an abstract base-class for LedDevices using a RS232-device.
|
||||
///
|
||||
class LedRs232Device : public LedDevice
|
||||
class LedRs232Device : public QObject, public LedDevice
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
///
|
||||
/// Constructs the LedDevice attached to a RS232-device
|
||||
@@ -18,7 +22,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
|
||||
@@ -43,12 +47,22 @@ protected:
|
||||
*/
|
||||
int writeBytes(const unsigned size, const uint8_t *data);
|
||||
|
||||
private slots:
|
||||
/// Unblock the device after a connection delay
|
||||
void unblockAfterDelay();
|
||||
|
||||
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;
|
||||
|
||||
bool _blockedForDelay;
|
||||
};
|
||||
|
Reference in New Issue
Block a user