diff --git a/include/hyperion/DispmanxWrapper.h b/include/hyperion/DispmanxWrapper.h index 4d9b5649..75f2bf1f 100644 --- a/include/hyperion/DispmanxWrapper.h +++ b/include/hyperion/DispmanxWrapper.h @@ -4,18 +4,30 @@ #include #include -// Forward class declaration -class ImageProcessor; -class DispmanxFrameGrabber; +// Utils includes +#include +// 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 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 _ledColors; + + Hyperion * _hyperion; }; diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index e278bef3..2455d5d0 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -20,7 +20,9 @@ public: ~Hyperion(); - void setValue(int priority, std::vector &ledColors); + unsigned getLedCount() const; + + void setValue(int priority, std::vector &ledColors, const int timeout_ms); private: void applyTransform(std::vector& colors) const; diff --git a/include/utils/jsonschema/JsonSchemaChecker.h b/include/utils/jsonschema/JsonSchemaChecker.h index b76da8f3..18a33fe7 100644 --- a/include/utils/jsonschema/JsonSchemaChecker.h +++ b/include/utils/jsonschema/JsonSchemaChecker.h @@ -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 diff --git a/libsrc/hyperion/DispmanxWrapper.cpp b/libsrc/hyperion/DispmanxWrapper.cpp index 185b96d5..75af522b 100644 --- a/libsrc/hyperion/DispmanxWrapper.cpp +++ b/libsrc/hyperion/DispmanxWrapper.cpp @@ -4,6 +4,7 @@ // Hyperion includes #include +#include #include #include @@ -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(); } diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 182e024e..09363ecb 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -89,7 +89,12 @@ Hyperion::~Hyperion() delete mRedTransform; } -void Hyperion::setValue(int priority, std::vector& ledColors) +unsigned Hyperion::getLedCount() const +{ + return mLedString.leds().size(); +} + +void Hyperion::setValue(int priority, std::vector& ledColors, const int timeout_ms) { // Apply the transform to each led and color-channel for (RgbColor& color : ledColors) diff --git a/src/hyperion-d.cpp b/src/hyperion-d.cpp index 988db273..de05872c 100644 --- a/src/hyperion-d.cpp +++ b/src/hyperion-d.cpp @@ -2,15 +2,33 @@ // QT includes #include +// Json-Schema includes +#include + // Hyperion includes #include +#include 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();