mirror of
				https://github.com/hyperion-project/hyperion.ng.git
				synced 2025-03-01 10:33:28 +00: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:
		@@ -1 +1 @@
 | 
			
		||||
90bef144811aa3c3db8620622b57e76f699f0121
 | 
			
		||||
3581784ce307344c0a79870314e269117fd139b3
 | 
			
		||||
@@ -1,5 +1,8 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
// Qt includes
 | 
			
		||||
#include <QTimer>
 | 
			
		||||
 | 
			
		||||
// Hyperion includes
 | 
			
		||||
#include <hyperion/Hyperion.h>
 | 
			
		||||
#include <hyperion/ImageProcessor.h>
 | 
			
		||||
@@ -44,6 +47,8 @@ signals:
 | 
			
		||||
private slots:
 | 
			
		||||
	void newFrame(const Image<ColorRgb> & 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<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()
 | 
			
		||||
{
 | 
			
		||||
	// 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()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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<ColorRgb>,int)),
 | 
			
		||||
				_hyperion, SLOT(setColors(int,std::vector<ColorRgb>,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<ColorRgb> &image)
 | 
			
		||||
	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();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user