Merge remote-tracking branch 'upstream/master' into support_for_philips_hue

Former-commit-id: 86d827f2672adad200399baf4486f0d7ce3b7480
This commit is contained in:
ntim
2015-03-02 12:48:18 +00:00
11 changed files with 189 additions and 23 deletions

View File

@@ -31,6 +31,7 @@ SET(Leddevice_HEADERS
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
${CURRENT_SOURCE_DIR}/LedDeviceAtmo.h
)
SET(Leddevice_SOURCES
@@ -49,6 +50,7 @@ SET(Leddevice_SOURCES
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp
${CURRENT_SOURCE_DIR}/LedDeviceAtmo.cpp
)
if(ENABLE_SPIDEV)

View File

@@ -0,0 +1,38 @@
// STL includes
#include <cstring>
#include <iostream>
// hyperion local includes
#include "LedDeviceAtmo.h"
LedDeviceAtmo::LedDeviceAtmo(const std::string& outputDevice, const unsigned baudrate) :
LedRs232Device(outputDevice, baudrate),
_ledBuffer(4 + 5*3) // 4-byte header, 5 RGB values
{
_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)
{
std::cerr << "AtmoLight: " << ledValues.size() << " channels configured. This should always be 5!" << std::endl;
return 0;
}
// write data
memcpy(4 + _ledBuffer.data(), ledValues.data(), ledValues.size() * sizeof(ColorRgb));
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}
int LedDeviceAtmo::switchOff()
{
memset(4 + _ledBuffer.data(), 0, _ledBuffer.size() - 4);
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}

View File

@@ -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;
};

View File

@@ -32,6 +32,7 @@
#include "LedDeviceHyperionUsbasp.h"
#include "LedDevicePhilipsHue.h"
#include "LedDeviceTpm2.h"
#include "LedDeviceAtmo.h"
#ifdef ENABLE_WS2812BPWM
#include "LedDeviceWS2812b.h"
@@ -211,6 +212,15 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
deviceTpm2->open();
device = deviceTpm2;
}
else if (type == "atmo")
{
const std::string output = deviceConfig["output"].asString();
const unsigned rate = 38400;
LedDeviceAtmo * deviceAtmo = new LedDeviceAtmo(output, rate);
deviceAtmo->open();
device = deviceAtmo;
}
#ifdef ENABLE_WS2812BPWM
else if (type == "ws2812b")
{

View File

@@ -80,11 +80,13 @@ int LedDevicePiBlaster::write(const std::vector<ColorRgb> & ledValues)
return -1;
}
std::vector<int> iPins = {4, 17, 18, 27, 21, 22, 23, 24, 25};
unsigned colorIdx = 0;
for (unsigned iChannel=0; iChannel<8; ++iChannel)
for (std::vector<int>::iterator it = iPins.begin(); it != iPins.end(); ++it)
{
double pwmDutyCycle = 0.0;
switch (_channelAssignment[iChannel])
switch (_channelAssignment[*it])
{
case 'r':
pwmDutyCycle = ledValues[colorIdx].red / 255.0;
@@ -102,7 +104,7 @@ int LedDevicePiBlaster::write(const std::vector<ColorRgb> & ledValues)
continue;
}
fprintf(_fid, "%i=%f\n", iChannel, pwmDutyCycle);
// fprintf(_fid, "%i=%f\n", iChannel, pwmDutyCycle);
fflush(_fid);
}
@@ -117,11 +119,13 @@ int LedDevicePiBlaster::switchOff()
return -1;
}
for (unsigned iChannel=0; iChannel<8; ++iChannel)
std::vector<int> iPins = {4, 17, 18, 21, 22, 23, 24, 25};
for (std::vector<int>::iterator it = iPins.begin(); it != iPins.end(); ++it)
{
if (_channelAssignment[iChannel] != ' ')
if (_channelAssignment[*it] != ' ')
{
fprintf(_fid, "%i=%f\n", iChannel, 0.0);
fprintf(_fid, "%i=%f\n", *it, 0.0);
fflush(_fid);
}
}