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

Commit 951b79b

Browse files
committed
Merge branch 'master' of https://github.com/tvdzwan/hyperion
2 parents a65ec1f + 60ec758 commit 951b79b

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

libsrc/leddevice/LedDeviceAmbiLed.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// STL includes
2+
#include <cstring>
3+
#include <cstdio>
4+
#include <iostream>
5+
6+
// hyperion local includes
7+
#include "LedDeviceAmbiLed.h"
8+
9+
LedDeviceAmbiLed::LedDeviceAmbiLed(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
10+
LedRs232Device(outputDevice, baudrate, delayAfterConnect_ms),
11+
_ledBuffer(0),
12+
_timer()
13+
{
14+
// setup the timer
15+
_timer.setSingleShot(false);
16+
_timer.setInterval(5000);
17+
connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds()));
18+
19+
// start the timer
20+
_timer.start();
21+
}
22+
23+
int LedDeviceAmbiLed::write(const std::vector<ColorRgb> & ledValues)
24+
{
25+
if (_ledBuffer.size() == 0)
26+
{
27+
_ledBuffer.resize(1 + 3*ledValues.size());
28+
_ledBuffer[3*ledValues.size()] = 255;
29+
}
30+
31+
// restart the timer
32+
_timer.start();
33+
34+
// write data
35+
memcpy( _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
36+
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
37+
}
38+
39+
int LedDeviceAmbiLed::switchOff()
40+
{
41+
// restart the timer
42+
_timer.start();
43+
44+
// write data
45+
memset(_ledBuffer.data(), 0, _ledBuffer.size()-6);
46+
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
47+
}
48+
49+
void LedDeviceAmbiLed::rewriteLeds()
50+
{
51+
writeBytes(_ledBuffer.size(), _ledBuffer.data());
52+
}

libsrc/leddevice/LedDeviceAmbiLed.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#pragma once
2+
3+
// STL includes
4+
#include <string>
5+
6+
// Qt includes
7+
#include <QTimer>
8+
9+
// hyperion incluse
10+
#include "LedRs232Device.h"
11+
12+
///
13+
/// Implementation of the LedDevice interface for writing to an Adalight led device.
14+
///
15+
class LedDeviceAmbiLed : public LedRs232Device
16+
{
17+
Q_OBJECT
18+
19+
public:
20+
///
21+
/// Constructs the LedDevice for attached Adalight device
22+
///
23+
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
24+
/// @param baudrate The used baudrate for writing to the output device
25+
///
26+
LedDeviceAmbiLed(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms);
27+
28+
///
29+
/// Writes the led color values to the led-device
30+
///
31+
/// @param ledValues The color-value per led
32+
/// @return Zero on succes else negative
33+
///
34+
virtual int write(const std::vector<ColorRgb> & ledValues);
35+
36+
/// Switch the leds off
37+
virtual int switchOff();
38+
39+
private slots:
40+
/// Write the last data to the leds again
41+
void rewriteLeds();
42+
43+
private:
44+
/// The buffer containing the packed RGB values
45+
std::vector<uint8_t> _ledBuffer;
46+
47+
/// Timer object which makes sure that led data is written at a minimum rate
48+
/// The Adalight device will switch off when it does not receive data at least
49+
/// every 15 seconds
50+
QTimer _timer;
51+
};

libsrc/leddevice/LedDeviceFactory.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#endif
2323

2424
#include "LedDeviceAdalight.h"
25+
#include "LedDeviceAmbiLed.h"
2526
#include "LedDeviceLightpack.h"
2627
#include "LedDeviceMultiLightpack.h"
2728
#include "LedDevicePaintpack.h"
@@ -56,6 +57,17 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
5657

5758
device = deviceAdalight;
5859
}
60+
else if (type == "ambiled")
61+
{
62+
const std::string output = deviceConfig["output"].asString();
63+
const unsigned rate = deviceConfig["rate"].asInt();
64+
const int delay_ms = deviceConfig["delayAfterConnect"].asInt();
65+
66+
LedDeviceAmbiLed* deviceAmbiLed = new LedDeviceAmbiLed(output, rate, delay_ms);
67+
deviceAmbiLed->open();
68+
69+
device = deviceAmbiLed;
70+
}
5971
#ifdef ENABLE_SPIDEV
6072
else if (type == "lpd6803" || type == "ldp6803")
6173
{

0 commit comments

Comments
 (0)