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