VisionRunner: Add stop() function to stop a runForever() loop. (#826)

This was previously possible in Java with Thread.interrupt(), but provide
the same function in both C++ and Java.

Fixes #444.
This commit is contained in:
Peter Johnson
2017-12-10 20:58:14 -08:00
committed by GitHub
parent d2e7a90f41
commit 217b1a2259
3 changed files with 21 additions and 3 deletions

View File

@@ -21,7 +21,9 @@ using namespace frc;
* @param videoSource the video source to use to supply images for the pipeline
*/
VisionRunnerBase::VisionRunnerBase(cs::VideoSource videoSource)
: m_image(std::make_unique<cv::Mat>()), m_cvSink("VisionRunner CvSink") {
: m_image(std::make_unique<cv::Mat>()),
m_cvSink("VisionRunner CvSink"),
m_enabled(true) {
m_cvSink.SetSource(videoSource);
}
@@ -70,7 +72,12 @@ void VisionRunnerBase::RunForever() {
"thread");
return;
}
while (true) {
while (m_enabled) {
RunOnce();
}
}
/**
* Stop a RunForever() loop.
*/
void VisionRunnerBase::Stop() { m_enabled = false; }