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

@@ -28,6 +28,7 @@ public class VisionRunner<P extends VisionPipeline> {
private final P m_pipeline;
private final Mat m_image = new Mat();
private final Listener<? super P> m_listener;
private volatile boolean m_enabled = true;
/**
* Listener interface for a callback that should run after a pipeline has processed its input.
@@ -107,9 +108,15 @@ public class VisionRunner<P extends VisionPipeline> {
throw new IllegalStateException(
"VisionRunner.runForever() cannot be called from the main robot thread");
}
while (!Thread.interrupted()) {
while (m_enabled && !Thread.interrupted()) {
runOnce();
}
}
/**
* Stop a RunForever() loop.
*/
public void stop() {
m_enabled = false;
}
}