From 6fafb23a3fd9db1aace41c95fdd89885e17e80b2 Mon Sep 17 00:00:00 2001 From: johan Date: Sat, 22 Mar 2014 15:35:25 +0100 Subject: [PATCH] Added functionality to disable the embedded v4l2 grabber when a higher priority source is active Former-commit-id: 4c0403584093a1fac29d16b502773c3ed11a13a9 --- deploy/hyperion.tar.gz.REMOVED.git-id | 2 +- include/grabber/V4L2Wrapper.h | 8 ++++++++ libsrc/grabber/v4l2/V4L2Grabber.cpp | 22 ++++++++++++++-------- libsrc/grabber/v4l2/V4L2Wrapper.cpp | 27 ++++++++++++++++++++++++++- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/deploy/hyperion.tar.gz.REMOVED.git-id b/deploy/hyperion.tar.gz.REMOVED.git-id index 3c26a2f2..006b5960 100644 --- a/deploy/hyperion.tar.gz.REMOVED.git-id +++ b/deploy/hyperion.tar.gz.REMOVED.git-id @@ -1 +1 @@ -90bef144811aa3c3db8620622b57e76f699f0121 \ No newline at end of file +3581784ce307344c0a79870314e269117fd139b3 \ No newline at end of file diff --git a/include/grabber/V4L2Wrapper.h b/include/grabber/V4L2Wrapper.h index 99159186..49958a15 100644 --- a/include/grabber/V4L2Wrapper.h +++ b/include/grabber/V4L2Wrapper.h @@ -1,5 +1,8 @@ #pragma once +// Qt includes +#include + // Hyperion includes #include #include @@ -44,6 +47,8 @@ signals: private slots: void newFrame(const Image & image); + void checkSources(); + private: /// The timeout of the led colors [ms] const int _timeout_ms; @@ -62,4 +67,7 @@ private: /// The list with computed led colors std::vector _ledColors; + + /// Timer which tests if a higher priority source is active + QTimer _timer; }; diff --git a/libsrc/grabber/v4l2/V4L2Grabber.cpp b/libsrc/grabber/v4l2/V4L2Grabber.cpp index 526f5754..42b527db 100644 --- a/libsrc/grabber/v4l2/V4L2Grabber.cpp +++ b/libsrc/grabber/v4l2/V4L2Grabber.cpp @@ -72,10 +72,7 @@ V4L2Grabber::V4L2Grabber(const std::string & device, V4L2Grabber::~V4L2Grabber() { // stop if the grabber was not stopped - if (_streamNotifier != nullptr && _streamNotifier->isEnabled()) { - stop(); - } - + stop(); uninit_device(); close_device(); } @@ -103,14 +100,22 @@ void V4L2Grabber::setSignalThreshold(double redSignalThreshold, double greenSign void V4L2Grabber::start() { - _streamNotifier->setEnabled(true); - start_capturing(); + if (_streamNotifier != nullptr && !_streamNotifier->isEnabled()) + { + _streamNotifier->setEnabled(true); + start_capturing(); + std::cout << "V4L2 grabber started" << std::endl; + } } void V4L2Grabber::stop() { - stop_capturing(); - _streamNotifier->setEnabled(false); + if (_streamNotifier != nullptr && _streamNotifier->isEnabled()) + { + stop_capturing(); + _streamNotifier->setEnabled(false); + std::cout << "V4L2 grabber stopped" << std::endl; + } } void V4L2Grabber::open_device() @@ -142,6 +147,7 @@ void V4L2Grabber::open_device() // create the notifier for when a new frame is available _streamNotifier = new QSocketNotifier(_fileDescriptor, QSocketNotifier::Read); + _streamNotifier->setEnabled(false); connect(_streamNotifier, SIGNAL(activated(int)), this, SLOT(read_frame())); } diff --git a/libsrc/grabber/v4l2/V4L2Wrapper.cpp b/libsrc/grabber/v4l2/V4L2Wrapper.cpp index 9a8f450d..860cc555 100644 --- a/libsrc/grabber/v4l2/V4L2Wrapper.cpp +++ b/libsrc/grabber/v4l2/V4L2Wrapper.cpp @@ -28,7 +28,8 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device, pixelDecimation), _processor(ImageProcessorFactory::getInstance().newImageProcessor()), _hyperion(hyperion), - _ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}) + _ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}), + _timer() { // set the signal detection threshold of the grabber _grabber.setSignalThreshold( @@ -52,6 +53,13 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device, this, SIGNAL(emitColors(int,std::vector,int)), _hyperion, SLOT(setColors(int,std::vector,int)), Qt::QueuedConnection); + + // setup the higher prio source checker + // this will disable the v4l2 grabber when a source with hisher priority is active + _timer.setInterval(500); + _timer.setSingleShot(false); + QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(checkSources())); + _timer.start(); } V4L2Wrapper::~V4L2Wrapper() @@ -88,3 +96,20 @@ void V4L2Wrapper::newFrame(const Image &image) emit emitColors(_priority, _ledColors, _timeout_ms); } +void V4L2Wrapper::checkSources() +{ + QList activePriorities = _hyperion->getActivePriorities(); + + for (int x : activePriorities) + { + if (x < _priority) + { + // found a higher priority source: grabber should be disabled + _grabber.stop(); + return; + } + } + + // no higher priority source was found: grabber should be enabled + _grabber.start(); +}