Added functionality to disable the embedded v4l2 grabber when a higher priority source is active

Former-commit-id: 4c0403584093a1fac29d16b502773c3ed11a13a9
This commit is contained in:
johan
2014-03-22 15:35:25 +01:00
parent c3ba03e0ee
commit 6fafb23a3f
4 changed files with 49 additions and 10 deletions

View File

@@ -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();
}