Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 4c04035

Browse files
committed
Added functionality to disable the embedded v4l2 grabber when a higher priority source is active
1 parent 698a22a commit 4c04035

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

deploy/hyperion.tar.gz

-290 Bytes
Binary file not shown.

include/grabber/V4L2Wrapper.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#pragma once
22

3+
// Qt includes
4+
#include <QTimer>
5+
36
// Hyperion includes
47
#include <hyperion/Hyperion.h>
58
#include <hyperion/ImageProcessor.h>
@@ -44,6 +47,8 @@ public slots:
4447
private slots:
4548
void newFrame(const Image<ColorRgb> & image);
4649

50+
void checkSources();
51+
4752
private:
4853
/// The timeout of the led colors [ms]
4954
const int _timeout_ms;
@@ -62,4 +67,7 @@ private slots:
6267

6368
/// The list with computed led colors
6469
std::vector<ColorRgb> _ledColors;
70+
71+
/// Timer which tests if a higher priority source is active
72+
QTimer _timer;
6573
};

libsrc/grabber/v4l2/V4L2Grabber.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ V4L2Grabber::V4L2Grabber(const std::string & device,
7272
V4L2Grabber::~V4L2Grabber()
7373
{
7474
// stop if the grabber was not stopped
75-
if (_streamNotifier != nullptr && _streamNotifier->isEnabled()) {
76-
stop();
77-
}
78-
75+
stop();
7976
uninit_device();
8077
close_device();
8178
}
@@ -103,14 +100,22 @@ void V4L2Grabber::setSignalThreshold(double redSignalThreshold, double greenSign
103100

104101
void V4L2Grabber::start()
105102
{
106-
_streamNotifier->setEnabled(true);
107-
start_capturing();
103+
if (_streamNotifier != nullptr && !_streamNotifier->isEnabled())
104+
{
105+
_streamNotifier->setEnabled(true);
106+
start_capturing();
107+
std::cout << "V4L2 grabber started" << std::endl;
108+
}
108109
}
109110

110111
void V4L2Grabber::stop()
111112
{
112-
stop_capturing();
113-
_streamNotifier->setEnabled(false);
113+
if (_streamNotifier != nullptr && _streamNotifier->isEnabled())
114+
{
115+
stop_capturing();
116+
_streamNotifier->setEnabled(false);
117+
std::cout << "V4L2 grabber stopped" << std::endl;
118+
}
114119
}
115120

116121
void V4L2Grabber::open_device()
@@ -142,6 +147,7 @@ void V4L2Grabber::open_device()
142147

143148
// create the notifier for when a new frame is available
144149
_streamNotifier = new QSocketNotifier(_fileDescriptor, QSocketNotifier::Read);
150+
_streamNotifier->setEnabled(false);
145151
connect(_streamNotifier, SIGNAL(activated(int)), this, SLOT(read_frame()));
146152
}
147153

libsrc/grabber/v4l2/V4L2Wrapper.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
2828
pixelDecimation),
2929
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
3030
_hyperion(hyperion),
31-
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0})
31+
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}),
32+
_timer()
3233
{
3334
// set the signal detection threshold of the grabber
3435
_grabber.setSignalThreshold(
@@ -52,6 +53,13 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
5253
this, SIGNAL(emitColors(int,std::vector<ColorRgb>,int)),
5354
_hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int)),
5455
Qt::QueuedConnection);
56+
57+
// setup the higher prio source checker
58+
// this will disable the v4l2 grabber when a source with hisher priority is active
59+
_timer.setInterval(500);
60+
_timer.setSingleShot(false);
61+
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(checkSources()));
62+
_timer.start();
5563
}
5664

5765
V4L2Wrapper::~V4L2Wrapper()
@@ -88,3 +96,20 @@ void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
8896
emit emitColors(_priority, _ledColors, _timeout_ms);
8997
}
9098

99+
void V4L2Wrapper::checkSources()
100+
{
101+
QList<int> activePriorities = _hyperion->getActivePriorities();
102+
103+
for (int x : activePriorities)
104+
{
105+
if (x < _priority)
106+
{
107+
// found a higher priority source: grabber should be disabled
108+
_grabber.stop();
109+
return;
110+
}
111+
}
112+
113+
// no higher priority source was found: grabber should be enabled
114+
_grabber.start();
115+
}

0 commit comments

Comments
 (0)