Adalight device added

Former-commit-id: d9b9a146b39ba83fada52de2b6076dde7e44b151
This commit is contained in:
johan 2013-11-11 21:07:24 +01:00
parent 0a6706e177
commit 5c71e626c7
11 changed files with 109 additions and 15 deletions

View File

@ -4,10 +4,10 @@
{ {
/// Device configuration contains the following fields: /// Device configuration contains the following fields:
/// * 'name' : The user friendly name of the device (only used for display purposes) /// * 'name' : The user friendly name of the device (only used for display purposes)
/// * 'type' : The type of the device or leds (known types for now are 'ws2801', 'lpd6803', 'sedu', 'test' and 'none') /// * 'type' : The type of the device or leds (known types for now are 'ws2801', 'lpd6803', 'sedu',
/// * 'output' : The output specification depends on selected device /// 'adalight', 'test' and 'none')
/// - 'ws2801' this is the device (eg '/dev/spidev0.0 or /dev/ttyS0') /// * 'output' : The output specification depends on selected device. This can for example be the
/// - 'test' this is the file used to write test output (eg '/home/pi/hyperion.out') /// device specifier or the output file name
/// * 'rate' : The baudrate of the output to the device /// * 'rate' : The baudrate of the output to the device
/// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.). /// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.).
"device" : "device" :
@ -15,7 +15,7 @@
"name" : "MyPi", "name" : "MyPi",
"type" : "ws2801", "type" : "ws2801",
"output" : "/dev/spidev0.0", "output" : "/dev/spidev0.0",
"rate" : 1000000, "rate" : 500000,
"colorOrder" : "rgb" "colorOrder" : "rgb"
}, },

View File

@ -1 +1 @@
1c3031eb536b2af5ced172f1eb071011f705cc86 f888f2f1ce44fca56ac8c6326c8615849cbd6a5d

View File

@ -1 +1 @@
9e9b710c8305a3445a621d322334a14b6934b87a 992962914879591c2740a1b2769269d790284766

View File

@ -27,6 +27,7 @@ SET(Hyperion_HEADERS
${CURRENT_SOURCE_DIR}/device/LedDeviceSedu.h ${CURRENT_SOURCE_DIR}/device/LedDeviceSedu.h
${CURRENT_SOURCE_DIR}/device/LedDeviceWs2801.h ${CURRENT_SOURCE_DIR}/device/LedDeviceWs2801.h
${CURRENT_SOURCE_DIR}/device/LedDeviceLpd6803.h ${CURRENT_SOURCE_DIR}/device/LedDeviceLpd6803.h
${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.h
) )
SET(Hyperion_SOURCES SET(Hyperion_SOURCES
@ -47,6 +48,7 @@ SET(Hyperion_SOURCES
${CURRENT_SOURCE_DIR}/device/LedDeviceTest.cpp ${CURRENT_SOURCE_DIR}/device/LedDeviceTest.cpp
${CURRENT_SOURCE_DIR}/device/LedDeviceWs2801.cpp ${CURRENT_SOURCE_DIR}/device/LedDeviceWs2801.cpp
${CURRENT_SOURCE_DIR}/device/LedDeviceLpd6803.cpp ${CURRENT_SOURCE_DIR}/device/LedDeviceLpd6803.cpp
${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.cpp
) )
set(Hyperion_RESOURCES set(Hyperion_RESOURCES

View File

@ -14,6 +14,7 @@
#include "device/LedDeviceSedu.h" #include "device/LedDeviceSedu.h"
#include "device/LedDeviceTest.h" #include "device/LedDeviceTest.h"
#include "device/LedDeviceWs2801.h" #include "device/LedDeviceWs2801.h"
#include "device/LedDeviceAdalight.h"
#include "LinearColorSmoothing.h" #include "LinearColorSmoothing.h"
@ -58,6 +59,16 @@ LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig)
device = deviceSedu; device = deviceSedu;
} }
else if (type == "adalight")
{
const std::string output = deviceConfig["output"].asString();
const unsigned rate = deviceConfig["rate"].asInt();
LedDeviceAdalight* deviceAdalight = new LedDeviceAdalight(output, rate);
deviceAdalight->open();
device = deviceAdalight;
}
else if (type == "test") else if (type == "test")
{ {
const std::string output = deviceConfig["output"].asString(); const std::string output = deviceConfig["output"].asString();

View File

@ -0,0 +1,42 @@
// STL includes
#include <cstring>
#include <cstdio>
#include <iostream>
// Linux includes
#include <fcntl.h>
#include <sys/ioctl.h>
// hyperion local includes
#include "LedDeviceAdalight.h"
LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate) :
LedRs232Device(outputDevice, baudrate),
_ledBuffer(0)
{
// empty
}
int LedDeviceAdalight::write(const std::vector<RgbColor> &ledValues)
{
if (_ledBuffer.size() == 0)
{
_ledBuffer.resize(6 + 3*ledValues.size());
_ledBuffer[0] = 'A';
_ledBuffer[1] = 'd';
_ledBuffer[2] = 'a';
_ledBuffer[3] = ((ledValues.size() - 1) >> 8) & 0xFF; // LED count high byte
_ledBuffer[4] = (ledValues.size() - 1) & 0xFF; // LED count low byte
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
}
memcpy(6 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}
int LedDeviceAdalight::switchOff()
{
memset(6 + _ledBuffer.data(), 0, _ledBuffer.size()-6);
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
}

View File

@ -0,0 +1,37 @@
#pragma once
// STL includes
#include <string>
// hyperion incluse
#include "LedRs232Device.h"
///
/// Implementation of the LedDevice interface for writing to an Adalight led device.
///
class LedDeviceAdalight : public LedRs232Device
{
public:
///
/// Constructs the LedDevice for attached Adalight device
///
/// @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);
///
/// 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<RgbColor> &ledValues);
/// Switch the leds off
virtual int switchOff();
private:
/// The buffer containing the packed RGB values
std::vector<uint8_t> _ledBuffer;
};

View File

@ -15,7 +15,7 @@ public:
/// ///
/// Constructs the LedDevice for attached via SEDU device /// Constructs the LedDevice for attached via SEDU device
/// ///
/// @param outputDevice The name of the output device (eg '/etc/ttyS0') /// @param outputDevice The name of the output device (eg '/dev/ttyS0')
/// @param baudrate The used baudrate for writing to the output device /// @param baudrate The used baudrate for writing to the output device
/// ///
LedDeviceSedu(const std::string& outputDevice, const unsigned baudrate); LedDeviceSedu(const std::string& outputDevice, const unsigned baudrate);

View File

@ -48,9 +48,9 @@ int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
return -1; return -1;
} }
//for (int i = 0; i < 20; ++i) // for (int i = 0; i < 20; ++i)
// std::cout << std::hex << (int)data[i] << " "; // std::cout << std::hex << (int)data[i] << " ";
//std::cout << std::endl; // std::cout << std::endl;
try try
{ {

View File

@ -26,10 +26,10 @@ public class DeviceConfig {
strBuf.append("\t/// Device configuration contains the following fields: \n"); strBuf.append("\t/// Device configuration contains the following fields: \n");
strBuf.append("\t/// * 'name' : The user friendly name of the device (only used for display purposes)\n"); strBuf.append("\t/// * 'name' : The user friendly name of the device (only used for display purposes)\n");
strBuf.append("\t/// * 'type' : The type of the device or leds (known types for now are 'ws2801', 'lpd6803', 'sedu', 'test' and 'none')\n"); strBuf.append("\t/// * 'type' : The type of the device or leds (known types for now are 'ws2801', 'lpd6803', 'sedu',\n");
strBuf.append("\t/// * 'output' : The output specification depends on selected device\n"); strBuf.append("\t/// 'adalight', 'test' and 'none')\n");
strBuf.append("\t/// - 'ws2801' this is the device (eg '/dev/spidev0.0 or /dev/ttyS0')\n"); strBuf.append("\t/// * 'output' : The output specification depends on selected device. This can for example be the\n");
strBuf.append("\t/// - 'test' this is the file used to write test output (eg '/home/pi/hyperion.out')\n"); strBuf.append("\t/// device specifier or the output file name\n");
strBuf.append("\t/// * 'rate' : The baudrate of the output to the device\n"); strBuf.append("\t/// * 'rate' : The baudrate of the output to the device\n");
strBuf.append("\t/// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.).\n"); strBuf.append("\t/// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.).\n");

View File

@ -10,6 +10,8 @@ public enum DeviceType {
lpd6803("LPD6803"), lpd6803("LPD6803"),
/** SEDU LED device */ /** SEDU LED device */
sedu("SEDU"), sedu("SEDU"),
/** Adalight device */
adalight("Adalight"),
/** Test device for writing color values to file-output */ /** Test device for writing color values to file-output */
test("Test"), test("Test"),
/** No device, no output is generated */ /** No device, no output is generated */