This repository has been archived by the owner on May 6, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
// STL includes | ||
#include <cstring> | ||
#include <cstdio> | ||
#include <iostream> | ||
|
||
// Linux includes | ||
#include <fcntl.h> | ||
#include <sys/ioctl.h> | ||
|
||
// hyperion local includes | ||
#include "LedDeviceAtmo.h" | ||
|
||
LedDeviceAtmo::LedDeviceAtmo(const std::string& outputDevice, const unsigned baudrate) : | ||
LedRs232Device(outputDevice, baudrate), | ||
_ledBuffer(0) | ||
{ | ||
_ledBuffer.resize(4 + 3*5); | ||
_ledBuffer[0] = 0xFF; // Startbyte | ||
_ledBuffer[1] = 0x00; // StartChannel(Low) | ||
_ledBuffer[2] = 0x00; // StartChannel(High) | ||
_ledBuffer[3] = 0x0F; // Number of Databytes send (always! 15) | ||
} | ||
|
||
int LedDeviceAtmo::write(const std::vector<ColorRgb> &ledValues) | ||
{ | ||
// The protocol is shomehow limited. we always need to send exactly 5 channels + header | ||
// (19 bytes) for the hardware to recognize the data | ||
if (ledValues.size() != 5) | ||
{ | ||
printf("AtmoLight: %d channels configured. This should always be 5!\n", ledValues.size()); | ||
return 0; | ||
} | ||
|
||
// write data | ||
memcpy(4 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3); | ||
return writeBytes(_ledBuffer.size(), _ledBuffer.data()); | ||
} | ||
|
||
int LedDeviceAtmo::switchOff() | ||
{ | ||
memset(4 + _ledBuffer.data(), 0, _ledBuffer.size() - 4); | ||
return writeBytes(_ledBuffer.size(), _ledBuffer.data()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
// STL includes | ||
#include <string> | ||
|
||
// hyperion incluse | ||
#include "LedRs232Device.h" | ||
|
||
/// | ||
/// Implementation of the LedDevice interface for writing to serial device using tpm2 protocol. | ||
/// | ||
class LedDeviceAtmo : public LedRs232Device | ||
{ | ||
public: | ||
/// | ||
/// Constructs the LedDevice for attached serial device using supporting tpm2 protocol | ||
/// All LEDs in the stripe are handled as one frame | ||
/// | ||
/// @param outputDevice The name of the output device (eg '/dev/ttyAMA0') | ||
/// @param baudrate The used baudrate for writing to the output device | ||
/// | ||
LedDeviceAtmo(const std::string& outputDevice, const unsigned baudrate); | ||
|
||
/// | ||
/// Writes the led color values to the led-device | ||
/// | ||
/// @param ledValues The color-value per led | ||
/// @return Zero on succes else negative | ||
/// | ||
virtual int write(const std::vector<ColorRgb> &ledValues); | ||
|
||
/// Switch the leds off | ||
virtual int switchOff(); | ||
|
||
private: | ||
/// The buffer containing the packed RGB values | ||
std::vector<uint8_t> _ledBuffer; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters