Former-commit-id: 9d968e9388591f446e548c14ec5fcf58d1aba01b
This commit is contained in:
johan 2013-11-13 23:04:07 +01:00
commit 6c33d55468
9 changed files with 264 additions and 12 deletions

View File

@ -1 +1 @@
992962914879591c2740a1b2769269d790284766 ac10479924500e3f83ef3a1887a74a0f53f2b58b

View File

@ -29,6 +29,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/LedDeviceLpd8806.h
${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.h ${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.h
${CURRENT_SOURCE_DIR}/device/LedDeviceLightpack.h ${CURRENT_SOURCE_DIR}/device/LedDeviceLightpack.h
) )
@ -51,6 +52,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/LedDeviceLpd8806.cpp
${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.cpp ${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.cpp
${CURRENT_SOURCE_DIR}/device/LedDeviceLightpack.cpp ${CURRENT_SOURCE_DIR}/device/LedDeviceLightpack.cpp
) )

View File

@ -14,6 +14,7 @@
#include <hyperion/ImageProcessorFactory.h> #include <hyperion/ImageProcessorFactory.h>
#include "device/LedDeviceLpd6803.h" #include "device/LedDeviceLpd6803.h"
#include "device/LedDeviceLpd8806.h"
#include "device/LedDeviceSedu.h" #include "device/LedDeviceSedu.h"
#include "device/LedDeviceTest.h" #include "device/LedDeviceTest.h"
#include "device/LedDeviceWs2801.h" #include "device/LedDeviceWs2801.h"
@ -48,11 +49,21 @@ LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig)
const std::string output = deviceConfig["output"].asString(); const std::string output = deviceConfig["output"].asString();
const unsigned rate = deviceConfig["rate"].asInt(); const unsigned rate = deviceConfig["rate"].asInt();
LedDeviceLdp6803* deviceLdp6803 = new LedDeviceLdp6803(output, rate); LedDeviceLpd6803* deviceLdp6803 = new LedDeviceLpd6803(output, rate);
deviceLdp6803->open(); deviceLdp6803->open();
device = deviceLdp6803; device = deviceLdp6803;
} }
else if (type == "lpd8806" || type == "ldp8806")
{
const std::string output = deviceConfig["output"].asString();
const unsigned rate = deviceConfig["rate"].asInt();
LedDeviceLpd8806* deviceLpd8806 = new LedDeviceLpd8806(output, rate);
deviceLpd8806->open();
device = deviceLpd8806;
}
else if (type == "sedu") else if (type == "sedu")
{ {
const std::string output = deviceConfig["output"].asString(); const std::string output = deviceConfig["output"].asString();

View File

@ -10,14 +10,14 @@
// hyperion local includes // hyperion local includes
#include "LedDeviceLpd6803.h" #include "LedDeviceLpd6803.h"
LedDeviceLdp6803::LedDeviceLdp6803(const std::string& outputDevice, const unsigned baudrate) : LedDeviceLpd6803::LedDeviceLpd6803(const std::string& outputDevice, const unsigned baudrate) :
LedSpiDevice(outputDevice, baudrate), LedSpiDevice(outputDevice, baudrate),
_ledBuffer(0) _ledBuffer(0)
{ {
// empty // empty
} }
int LedDeviceLdp6803::write(const std::vector<ColorRgb> &ledValues) int LedDeviceLpd6803::write(const std::vector<ColorRgb> &ledValues)
{ {
// Reconfigure if the current connfiguration does not match the required configuration // Reconfigure if the current connfiguration does not match the required configuration
if (4 + 2*ledValues.size() != _ledBuffer.size()) if (4 + 2*ledValues.size() != _ledBuffer.size())
@ -43,7 +43,7 @@ int LedDeviceLdp6803::write(const std::vector<ColorRgb> &ledValues)
return 0; return 0;
} }
int LedDeviceLdp6803::switchOff() int LedDeviceLpd6803::switchOff()
{ {
return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0})); return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0}));
} }

View File

@ -14,7 +14,7 @@
/// (R, G and B in the above illustration) making 16 bits per led. Total bytes = 4 + (2 x number of /// (R, G and B in the above illustration) making 16 bits per led. Total bytes = 4 + (2 x number of
/// leds) /// leds)
/// ///
class LedDeviceLdp6803 : public LedSpiDevice class LedDeviceLpd6803 : public LedSpiDevice
{ {
public: public:
/// ///
@ -23,7 +23,7 @@ public:
/// @param[in] outputDevice The name of the output device (eg '/dev/spidev0.0') /// @param[in] outputDevice The name of the output device (eg '/dev/spidev0.0')
/// @param[in] baudrate The used baudrate for writing to the output device /// @param[in] baudrate The used baudrate for writing to the output device
/// ///
LedDeviceLdp6803(const std::string& outputDevice, const unsigned baudrate); LedDeviceLpd6803(const std::string& outputDevice, const unsigned baudrate);
/// ///
/// Writes the led color values to the led-device /// Writes the led color values to the led-device

View File

@ -0,0 +1,54 @@
// STL includes
#include <cstring>
#include <cstdio>
#include <iostream>
// Linux includes
#include <fcntl.h>
#include <sys/ioctl.h>
// hyperion local includes
#include "LedDeviceLpd8806.h"
LedDeviceLpd8806::LedDeviceLpd8806(const std::string& outputDevice, const unsigned baudrate) :
LedSpiDevice(outputDevice, baudrate),
_ledBuffer(0)
{
// empty
}
int LedDeviceLpd8806::write(const std::vector<ColorRgb> &ledValues)
{
const unsigned clearSize = ledValues.size()/32+1;
// Reconfigure if the current connfiguration does not match the required configuration
if (3*ledValues.size() + clearSize != _ledBuffer.size())
{
// Initialise the buffer
_ledBuffer.resize(3*ledValues.size() + clearSize, 0x00);
// Perform an initial reset to start accepting data on the first led
writeBytes(clearSize, _ledBuffer.data());
}
// Copy the colors from the ColorRgb vector to the Ldp8806 data vector
for (unsigned iLed=0; iLed<ledValues.size(); ++iLed)
{
const ColorRgb& rgb = ledValues[iLed];
_ledBuffer[iLed*3] = 0x80 | (rgb.red >> 1);
_ledBuffer[iLed*3+1] = 0x80 | (rgb.green >> 1);
_ledBuffer[iLed*3+2] = 0x80 | (rgb.blue >> 1);
}
// Write the data
if (writeBytes(_ledBuffer.size(), _ledBuffer.data()) < 0)
{
return -1;
}
return 0;
}
int LedDeviceLpd8806::switchOff()
{
return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0}));
}

View File

@ -0,0 +1,103 @@
#pragma once
// Local hyperion incluse
#include "LedSpiDevice.h"
///
/// Implementation of the LedDevice interface for writing to LPD8806 led device.
///
/// The following description is copied from 'adafruit' (github.com/adafruit/LPD8806)
///
/// Clearing up some misconceptions about how the LPD8806 drivers work:
///
/// The LPD8806 is not a FIFO shift register. The first data out controls the
/// LED *closest* to the processor (unlike a typical shift register, where the
/// first data out winds up at the *furthest* LED). Each LED driver 'fills up'
/// with data and then passes through all subsequent bytes until a latch
/// condition takes place. This is actually pretty common among LED drivers.
///
/// All color data bytes have the high bit (128) set, with the remaining
/// seven bits containing a brightness value (0-127). A byte with the high
/// bit clear has special meaning (explained later).
///
/// The rest gets bizarre...
///
/// The LPD8806 does not perform an in-unison latch (which would display the
/// newly-transmitted data all at once). Rather, each individual byte (even
/// the separate G, R, B components of each LED) is latched AS IT ARRIVES...
/// or more accurately, as the first bit of the subsequent byte arrives and
/// is passed through. So the strip actually refreshes at the speed the data
/// is issued, not instantaneously (this can be observed by greatly reducing
/// the data rate). This has implications for POV displays and light painting
/// applications. The 'subsequent' rule also means that at least one extra
/// byte must follow the last pixel, in order for the final blue LED to latch.
///
/// To reset the pass-through behavior and begin sending new data to the start
/// of the strip, a number of zero bytes must be issued (remember, all color
/// data bytes have the high bit set, thus are in the range 128 to 255, so the
/// zero is 'special'). This should be done before each full payload of color
/// values to the strip. Curiously, zero bytes can only travel one meter (32
/// LEDs) down the line before needing backup; the next meter requires an
/// extra zero byte, and so forth. Longer strips will require progressively
/// more zeros. *(see note below)
///
/// In the interest of efficiency, it's possible to combine the former EOD
/// extra latch byte and the latter zero reset...the same data can do double
/// duty, latching the last blue LED while also resetting the strip for the
/// next payload.
///
/// So: reset byte(s) of suitable length are issued once at startup to 'prime'
/// the strip to a known ready state. After each subsequent LED color payload,
/// these reset byte(s) are then issued at the END of each payload, both to
/// latch the last LED and to prep the strip for the start of the next payload
/// (even if that data does not arrive immediately). This avoids a tiny bit
/// of latency as the new color payload can begin issuing immediately on some
/// signal, such as a timer or GPIO trigger.
///
/// Technically these zero byte(s) are not a latch, as the color data (save
/// for the last byte) is already latched. It's a start-of-data marker, or
/// an indicator to clear the thing-that's-not-a-shift-register. But for
/// conversational consistency with other LED drivers, we'll refer to it as
/// a 'latch' anyway.
///
/// This has been validated independently with multiple customers'
/// hardware. Please do not report as a bug or issue pull requests for
/// this. Fewer zeros sometimes gives the *illusion* of working, the first
/// payload will correctly load and latch, but subsequent frames will drop
/// data at the end. The data shortfall won't always be visually apparent
/// depending on the color data loaded on the prior and subsequent frames.
/// Tested. Confirmed. Fact.
///
///
/// The summary of the story is that the following needs to be writen on the spi-device:
/// 1RRRRRRR 1GGGGGGG 1BBBBBBB 1RRRRRRR 1GGGGGGG ... ... 1GGGGGGG 1BBBBBBB 00000000 00000000 ...
/// |---------led_1----------| |---------led_2-- -led_n----------| |----clear data--
///
/// The number of zeroes in the 'clear data' is (#led/32 + 1)bytes (or *8 for bits)
///
class LedDeviceLpd8806 : public LedSpiDevice
{
public:
///
/// Constructs the LedDevice for a string containing leds of the type LPD8806
///
/// @param[in] outputDevice The name of the output device (eg '/dev/spidev0.0')
/// @param[in] baudrate The used baudrate for writing to the output device
///
LedDeviceLpd8806(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

@ -4,7 +4,7 @@ find_package(BCM REQUIRED)
include_directories(${BCM_INCLUDE_DIRS}) include_directories(${BCM_INCLUDE_DIRS})
# Configure the use of QT4 # Configure the use of QT4
find_package(Qt4 COMPONENTS QtTest REQUIRED QUIET) #find_package(Qt4 COMPONENTS QtTest REQUIRED QUIET)
include(${QT_USE_FILE}) include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS}) add_definitions(${QT_DEFINITIONS})
link_directories(${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf) link_directories(${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf)
@ -15,4 +15,5 @@ add_executable(dispmanx2png
target_link_libraries(dispmanx2png target_link_libraries(dispmanx2png
dispmanx-grabber dispmanx-grabber
getoptPlusPlus
${QT_LIBRARIES}) ${QT_LIBRARIES})

View File

@ -1,14 +1,19 @@
// STL includes // STL includes
#include <csignal> #include <csignal>
#include <iomanip>
// QT includes // QT includes
#include <QImage> #include <QImage>
#include <QTest>
// getoptPlusPLus includes
#include <getoptPlusPlus/getoptpp.h>
// Dispmanx grabber includes // Dispmanx grabber includes
#include <dispmanx-grabber/DispmanxFrameGrabber.h> #include <dispmanx-grabber/DispmanxFrameGrabber.h>
using namespace vlofgren;
static bool running = true; static bool running = true;
void signal_handler(int signum) void signal_handler(int signum)
@ -16,13 +21,86 @@ void signal_handler(int signum)
running = false; running = false;
} }
int main() int main(int argc, char** argv)
{ {
signal(SIGTERM, signal_handler); signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler); signal(SIGINT, signal_handler);
int grabFlags = 0;
try
{
// create the option parser and initialize all parameters
OptionsParser optionParser("Simple application to send a command to hyperion using the Json interface");
ParameterSet & parameters = optionParser.getParameters();
QString flagDescr = QString("Set the grab flags of the dispmanx frame grabber [default: 0x%1]").arg(grabFlags, 8, 16, QChar('0'));
StringParameter & argFlags = parameters.add<StringParameter> ('f', "flags", flagDescr.toAscii().constData());
SwitchParameter<> & argList = parameters.add<SwitchParameter<> >('l', "list", "List the possible flags");
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<> >('h', "help", "Show this help message and exit");
// parse all options
optionParser.parse(argc, const_cast<const char **>(argv));
// check if we need to display the usage. exit if we do.
if (argHelp.isSet())
{
optionParser.usage();
return 0;
}
if (argList.isSet())
{
std::cout.width(15);
std::cout.width(10);
std::cout << "Possible DISPMANX flags: " << std::endl;
std::cout << "Name | " << "Value" << std::endl;
std::cout << "--------------------------------| " << "------" << std::endl;
std::cout << "DISPMANX_NO_ROTATE | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_NO_ROTATE << std::endl;
std::cout << "DISPMANX_ROTATE_90 | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_ROTATE_90 << std::endl;
std::cout << "DISPMANX_ROTATE_180 | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_ROTATE_180 << std::endl;
std::cout << "DISPMANX_ROTATE_270 | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_ROTATE_270 << std::endl;
std::cout << "DISPMANX_FLIP_HRIZ | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_FLIP_HRIZ << std::endl;
std::cout << "DISPMANX_FLIP_VERT | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_FLIP_VERT << std::endl;
std::cout << "DISPMANX_SNAPSHOT_NO_YUV | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_SNAPSHOT_NO_YUV << std::endl;
std::cout << "DISPMANX_SNAPSHOT_NO_RGB | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_SNAPSHOT_NO_RGB << std::endl;
std::cout << "DISPMANX_SNAPSHOT_FILL | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_SNAPSHOT_FILL << std::endl;
std::cout << "DISPMANX_SNAPSHOT_SWAP_RED_BLUE | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_SNAPSHOT_SWAP_RED_BLUE << std::endl;
std::cout << "DISPMANX_SNAPSHOT_PACK | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_SNAPSHOT_PACK << std::endl;
return 0;
}
if (argFlags.isSet())
{
QString flagStr = QString::fromStdString(argFlags.getValue());
bool ok = false;
// grabFlags = flagStr.toInt(&ok);
if (flagStr.startsWith("0x"))
{
grabFlags = flagStr.toInt(&ok, 16);
}
else
{
grabFlags = flagStr.toInt(&ok, 10);
}
std::cout << "Resulting flags: " << grabFlags << " (=0x" << std::hex << std::setfill('0') << std::setw(8) << grabFlags << ")" << std::dec << std::endl;
if (!ok)
{
std::cerr << "Failed to parse flags (" << flagStr.toStdString().c_str() << ")" << std::endl;
return -1;
}
}
}
catch (const std::runtime_error & e)
{
// An error occured. Display error and quit
std::cerr << e.what() << std::endl;
return 1;
}
DispmanxFrameGrabber frameGrabber(64, 64); DispmanxFrameGrabber frameGrabber(64, 64);
frameGrabber.setFlags(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL); frameGrabber.setFlags(grabFlags);
unsigned iFrame = 0; unsigned iFrame = 0;
QImage qImage(64, 64, QImage::Format_ARGB32); QImage qImage(64, 64, QImage::Format_ARGB32);
@ -41,7 +119,10 @@ int main()
qImage.save(QString("HYPERION_%3.png").arg(iFrame)); qImage.save(QString("HYPERION_%3.png").arg(iFrame));
++iFrame; ++iFrame;
QTest::qSleep(1000); timespec sleepTime;
sleepTime.tv_sec = 1;
sleepTime.tv_nsec = 0;
nanosleep(&sleepTime, NULL);
} }
return 0; return 0;