Created first draft of 'hyperion-d'.

This commit is contained in:
T. van der Zwan 2013-08-14 08:54:49 +00:00
parent b411b166ae
commit 7bdd10859e
6 changed files with 77 additions and 25 deletions

View File

@ -4,18 +4,30 @@
#include <QObject>
#include <QTimer>
// Forward class declaration
class ImageProcessor;
class DispmanxFrameGrabber;
// Utils includes
#include <utils/RgbColor.h>
// Forward class declaration
class DispmanxFrameGrabber;
class Hyperion;
class ImageProcessor;
///
/// The DispmanxWrapper uses an instance of the DispmanxFrameGrabber to obtain RgbImage's from the
/// displayed content. This RgbImage is processed to a RgbColor for each led and commmited to the
/// attached Hyperion.
///
class DispmanxWrapper: public QObject
{
Q_OBJECT
public:
DispmanxWrapper();
DispmanxWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, Hyperion * hyperion);
virtual ~DispmanxWrapper();
signals:
void ledValues(const unsigned priority, const std::vector<RgbColor> ledColors, const unsigned timeout_ms);
public slots:
void start();
@ -24,9 +36,17 @@ public slots:
void stop();
private:
const int _updateInterval_ms;
const int _timeout_ms;
QTimer _timer;
DispmanxFrameGrabber* _frameGrabber;
ImageProcessor* _processor;
DispmanxFrameGrabber * _frameGrabber;
ImageProcessor * _processor;
std::vector<RgbColor> _ledColors;
Hyperion * _hyperion;
};

View File

@ -20,7 +20,9 @@ public:
~Hyperion();
void setValue(int priority, std::vector<RgbColor> &ledColors);
unsigned getLedCount() const;
void setValue(int priority, std::vector<RgbColor> &ledColors, const int timeout_ms);
private:
void applyTransform(std::vector<RgbColor>& colors) const;

View File

@ -1,11 +1,3 @@
// Copyright (c) 2012 TNO, The Netherlands.
//
// This file contains information proprietary to TNO.
//
// Any disclosure or use of this information or any reproduction of this document or any part thereof for
// other than the specified purpose for which it is intended is expressly prohibited except as TNO may
// otherwise agree to in writing.
#pragma once
// stl includes

View File

@ -4,6 +4,7 @@
// Hyperion includes
#include <hyperion/DispmanxWrapper.h>
#include <hyperion/Hyperion.h>
#include <hyperion/ImageProcessorFactory.h>
#include <hyperion/ImageProcessor.h>
@ -11,39 +12,53 @@
// Local-Hyperion includes
#include "DispmanxFrameGrabber.h"
DispmanxWrapper::DispmanxWrapper() :
DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, Hyperion * hyperion) :
_updateInterval_ms(1000/updateRate_Hz),
_timeout_ms(2 * _updateInterval_ms),
_timer(),
_frameGrabber(new DispmanxFrameGrabber(64, 64)),
_processor(ImageProcessorFactory::getInstance().newImageProcessor())
_frameGrabber(new DispmanxFrameGrabber(grabWidth, grabHeight)),
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
_ledColors(hyperion->getLedCount(), RgbColor::BLACK),
_hyperion(hyperion)
{
_timer.setInterval(100);
// Configure the timer to generate events every n milliseconds
_timer.setInterval(_updateInterval_ms);
_timer.setSingleShot(false);
_processor->setSize(64, 64);
_processor->setSize(grabWidth, grabHeight);
// Connect the QTimer to this
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action()));
}
DispmanxWrapper::~DispmanxWrapper()
{
// Cleanup used resources (ImageProcessor and FrameGrabber)
delete _processor;
delete _frameGrabber;
}
void DispmanxWrapper::start()
{
// Start the timer with the pre configured interval
_timer.start();
}
void DispmanxWrapper::action()
{
qDebug() << "[" << QDateTime::currentDateTimeUtc() << "] Grabbing frame";
RgbImage image(64, 64);
// Obtain reference of the buffer-image used by the processor
RgbImage & image = _processor->image();
// Grab frame into the allocated image
_frameGrabber->grabFrame(image);
//_processor->
_processor->inplace_process(_ledColors);
const int _priority = 100;
_hyperion->setValue(_priority, _ledColors, _timeout_ms);
}
void DispmanxWrapper::stop()
{
// Stop the timer, effectivly stopping the process
_timer.stop();
}

View File

@ -89,7 +89,12 @@ Hyperion::~Hyperion()
delete mRedTransform;
}
void Hyperion::setValue(int priority, std::vector<RgbColor>& ledColors)
unsigned Hyperion::getLedCount() const
{
return mLedString.leds().size();
}
void Hyperion::setValue(int priority, std::vector<RgbColor>& ledColors, const int timeout_ms)
{
// Apply the transform to each led and color-channel
for (RgbColor& color : ledColors)

View File

@ -2,15 +2,33 @@
// QT includes
#include <QCoreApplication>
// Json-Schema includes
#include <utils/jsonschema/JsonFactory.h>
// Hyperion includes
#include <hyperion/DispmanxWrapper.h>
#include <hyperion/Hyperion.h>
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
// Select config and schema file
const std::string homeDir = getenv("RASPILIGHT_HOME");
const std::string schemaFile = homeDir + "/hyperion.schema.json";
const std::string configFile = homeDir + "/hyperion.config.json";
DispmanxWrapper dispmanx;
// Load configuration and check against the schema at the same time
Json::Value config;
if (JsonFactory::load(schemaFile, configFile, config) < 0)
{
std::cerr << "UNABLE TO LOAD CONFIGURATION" << std::endl;
return -1;
}
Hyperion hyperion(config);
DispmanxWrapper dispmanx(64, 64, 10, &hyperion);
dispmanx.start();
app.exec();