mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
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:
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user