mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added functionality to disable the embedded v4l2 grabber when a higher priority source is active
Former-commit-id: 4c0403584093a1fac29d16b502773c3ed11a13a9
This commit is contained in:
parent
c3ba03e0ee
commit
6fafb23a3f
@ -1 +1 @@
|
|||||||
90bef144811aa3c3db8620622b57e76f699f0121
|
3581784ce307344c0a79870314e269117fd139b3
|
@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
// Hyperion includes
|
// Hyperion includes
|
||||||
#include <hyperion/Hyperion.h>
|
#include <hyperion/Hyperion.h>
|
||||||
#include <hyperion/ImageProcessor.h>
|
#include <hyperion/ImageProcessor.h>
|
||||||
@ -44,6 +47,8 @@ signals:
|
|||||||
private slots:
|
private slots:
|
||||||
void newFrame(const Image<ColorRgb> & image);
|
void newFrame(const Image<ColorRgb> & image);
|
||||||
|
|
||||||
|
void checkSources();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// The timeout of the led colors [ms]
|
/// The timeout of the led colors [ms]
|
||||||
const int _timeout_ms;
|
const int _timeout_ms;
|
||||||
@ -62,4 +67,7 @@ private:
|
|||||||
|
|
||||||
/// The list with computed led colors
|
/// The list with computed led colors
|
||||||
std::vector<ColorRgb> _ledColors;
|
std::vector<ColorRgb> _ledColors;
|
||||||
|
|
||||||
|
/// Timer which tests if a higher priority source is active
|
||||||
|
QTimer _timer;
|
||||||
};
|
};
|
||||||
|
@ -72,10 +72,7 @@ V4L2Grabber::V4L2Grabber(const std::string & device,
|
|||||||
V4L2Grabber::~V4L2Grabber()
|
V4L2Grabber::~V4L2Grabber()
|
||||||
{
|
{
|
||||||
// stop if the grabber was not stopped
|
// stop if the grabber was not stopped
|
||||||
if (_streamNotifier != nullptr && _streamNotifier->isEnabled()) {
|
|
||||||
stop();
|
stop();
|
||||||
}
|
|
||||||
|
|
||||||
uninit_device();
|
uninit_device();
|
||||||
close_device();
|
close_device();
|
||||||
}
|
}
|
||||||
@ -103,14 +100,22 @@ void V4L2Grabber::setSignalThreshold(double redSignalThreshold, double greenSign
|
|||||||
|
|
||||||
void V4L2Grabber::start()
|
void V4L2Grabber::start()
|
||||||
{
|
{
|
||||||
|
if (_streamNotifier != nullptr && !_streamNotifier->isEnabled())
|
||||||
|
{
|
||||||
_streamNotifier->setEnabled(true);
|
_streamNotifier->setEnabled(true);
|
||||||
start_capturing();
|
start_capturing();
|
||||||
|
std::cout << "V4L2 grabber started" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void V4L2Grabber::stop()
|
void V4L2Grabber::stop()
|
||||||
{
|
{
|
||||||
|
if (_streamNotifier != nullptr && _streamNotifier->isEnabled())
|
||||||
|
{
|
||||||
stop_capturing();
|
stop_capturing();
|
||||||
_streamNotifier->setEnabled(false);
|
_streamNotifier->setEnabled(false);
|
||||||
|
std::cout << "V4L2 grabber stopped" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void V4L2Grabber::open_device()
|
void V4L2Grabber::open_device()
|
||||||
@ -142,6 +147,7 @@ void V4L2Grabber::open_device()
|
|||||||
|
|
||||||
// create the notifier for when a new frame is available
|
// create the notifier for when a new frame is available
|
||||||
_streamNotifier = new QSocketNotifier(_fileDescriptor, QSocketNotifier::Read);
|
_streamNotifier = new QSocketNotifier(_fileDescriptor, QSocketNotifier::Read);
|
||||||
|
_streamNotifier->setEnabled(false);
|
||||||
connect(_streamNotifier, SIGNAL(activated(int)), this, SLOT(read_frame()));
|
connect(_streamNotifier, SIGNAL(activated(int)), this, SLOT(read_frame()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
|
|||||||
pixelDecimation),
|
pixelDecimation),
|
||||||
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
||||||
_hyperion(hyperion),
|
_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
|
// set the signal detection threshold of the grabber
|
||||||
_grabber.setSignalThreshold(
|
_grabber.setSignalThreshold(
|
||||||
@ -52,6 +53,13 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
|
|||||||
this, SIGNAL(emitColors(int,std::vector<ColorRgb>,int)),
|
this, SIGNAL(emitColors(int,std::vector<ColorRgb>,int)),
|
||||||
_hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int)),
|
_hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int)),
|
||||||
Qt::QueuedConnection);
|
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()
|
V4L2Wrapper::~V4L2Wrapper()
|
||||||
@ -88,3 +96,20 @@ void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
|
|||||||
emit emitColors(_priority, _ledColors, _timeout_ms);
|
emit emitColors(_priority, _ledColors, _timeout_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void V4L2Wrapper::checkSources()
|
||||||
|
{
|
||||||
|
QList<int> 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();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user