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

Commit a1a3c24

Browse files
committed
Merge pull request #253 from aufano/master
Carsten Atmolight support
2 parents 650ce3b + cd543a0 commit a1a3c24

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

libsrc/leddevice/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SET(Leddevice_HEADERS
3131
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
3232
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
3333
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
34+
${CURRENT_SOURCE_DIR}/LedDeviceAtmo.h
3435
)
3536

3637
SET(Leddevice_SOURCES
@@ -49,6 +50,7 @@ SET(Leddevice_SOURCES
4950
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
5051
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
5152
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp
53+
${CURRENT_SOURCE_DIR}/LedDeviceAtmo.cpp
5254
)
5355

5456
if(ENABLE_SPIDEV)

libsrc/leddevice/LedDeviceAtmo.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
// STL includes
3+
#include <cstring>
4+
#include <cstdio>
5+
#include <iostream>
6+
7+
// Linux includes
8+
#include <fcntl.h>
9+
#include <sys/ioctl.h>
10+
11+
// hyperion local includes
12+
#include "LedDeviceAtmo.h"
13+
14+
LedDeviceAtmo::LedDeviceAtmo(const std::string& outputDevice, const unsigned baudrate) :
15+
LedRs232Device(outputDevice, baudrate),
16+
_ledBuffer(0)
17+
{
18+
_ledBuffer.resize(4 + 3*5);
19+
_ledBuffer[0] = 0xFF; // Startbyte
20+
_ledBuffer[1] = 0x00; // StartChannel(Low)
21+
_ledBuffer[2] = 0x00; // StartChannel(High)
22+
_ledBuffer[3] = 0x0F; // Number of Databytes send (always! 15)
23+
}
24+
25+
int LedDeviceAtmo::write(const std::vector<ColorRgb> &ledValues)
26+
{
27+
// The protocol is shomehow limited. we always need to send exactly 5 channels + header
28+
// (19 bytes) for the hardware to recognize the data
29+
if (ledValues.size() != 5)
30+
{
31+
printf("AtmoLight: %d channels configured. This should always be 5!\n", ledValues.size());
32+
return 0;
33+
}
34+
35+
// write data
36+
memcpy(4 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
37+
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
38+
}
39+
40+
int LedDeviceAtmo::switchOff()
41+
{
42+
memset(4 + _ledBuffer.data(), 0, _ledBuffer.size() - 4);
43+
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
44+
}

libsrc/leddevice/LedDeviceAtmo.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
3+
// STL includes
4+
#include <string>
5+
6+
// hyperion incluse
7+
#include "LedRs232Device.h"
8+
9+
///
10+
/// Implementation of the LedDevice interface for writing to serial device using tpm2 protocol.
11+
///
12+
class LedDeviceAtmo : public LedRs232Device
13+
{
14+
public:
15+
///
16+
/// Constructs the LedDevice for attached serial device using supporting tpm2 protocol
17+
/// All LEDs in the stripe are handled as one frame
18+
///
19+
/// @param outputDevice The name of the output device (eg '/dev/ttyAMA0')
20+
/// @param baudrate The used baudrate for writing to the output device
21+
///
22+
LedDeviceAtmo(const std::string& outputDevice, const unsigned baudrate);
23+
24+
///
25+
/// Writes the led color values to the led-device
26+
///
27+
/// @param ledValues The color-value per led
28+
/// @return Zero on succes else negative
29+
///
30+
virtual int write(const std::vector<ColorRgb> &ledValues);
31+
32+
/// Switch the leds off
33+
virtual int switchOff();
34+
35+
private:
36+
/// The buffer containing the packed RGB values
37+
std::vector<uint8_t> _ledBuffer;
38+
};

libsrc/leddevice/LedDeviceFactory.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "LedDeviceHyperionUsbasp.h"
3333
#include "LedDevicePhilipsHue.h"
3434
#include "LedDeviceTpm2.h"
35+
#include "LedDeviceAtmo.h"
3536

3637
#ifdef ENABLE_WS2812BPWM
3738
#include "LedDeviceWS2812b.h"
@@ -211,6 +212,15 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
211212
deviceTpm2->open();
212213
device = deviceTpm2;
213214
}
215+
else if (type == "atmo")
216+
{
217+
const std::string output = deviceConfig["output"].asString();
218+
const unsigned rate = 38400;
219+
220+
LedDeviceAtmo * deviceAtmo = new LedDeviceAtmo(output, rate);
221+
deviceAtmo->open();
222+
device = deviceAtmo;
223+
}
214224
#ifdef ENABLE_WS2812BPWM
215225
else if (type == "ws2812b")
216226
{

0 commit comments

Comments
 (0)