mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-19 00:41:41 +00:00
Don't interact with Libcamera cameras until connected (#2447)
This commit is contained in:
@@ -35,9 +35,19 @@ public abstract class FrameProvider implements Supplier<Frame>, Releasable {
|
||||
cameraPropertiesCached = true;
|
||||
}
|
||||
|
||||
public abstract boolean isConnected();
|
||||
/** Internal provider for if the camera is currently connected. */
|
||||
protected abstract boolean checkCameraConnected();
|
||||
|
||||
public abstract boolean checkCameraConnected();
|
||||
/** Checks if the camera is currently connected. Also handles connection events. */
|
||||
public boolean isConnected() {
|
||||
boolean connected = this.checkCameraConnected();
|
||||
|
||||
if (!cameraPropertiesCached && connected) {
|
||||
onCameraConnected();
|
||||
}
|
||||
|
||||
return connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the camera has connected at some point. This is not if it is currently connected.
|
||||
|
||||
@@ -37,11 +37,6 @@ public class LibcameraGpuFrameProvider extends FrameProvider {
|
||||
|
||||
public LibcameraGpuFrameProvider(LibcameraGpuSettables visionSettables) {
|
||||
this.settables = visionSettables;
|
||||
|
||||
var vidMode = settables.getCurrentVideoMode();
|
||||
settables.setVideoMode(vidMode);
|
||||
this.cameraPropertiesCached =
|
||||
true; // Camera properties are not able to be changed so they are always cached
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,9 +155,13 @@ public class LibcameraGpuFrameProvider extends FrameProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
// To our knowledge the camera is always connected (after boot) with csi cameras
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return checkCameraConnected();
|
||||
protected void onCameraConnected() {
|
||||
logger.info("Camera connected! running callback");
|
||||
|
||||
super.onCameraConnected();
|
||||
|
||||
var vidMode = settables.getCurrentVideoMode();
|
||||
settables.setVideoMode(vidMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,18 +57,6 @@ public class USBFrameProvider extends CpuImageProcessor {
|
||||
this.connectedCallback = connectedCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkCameraConnected() {
|
||||
boolean connected = camera.isConnected();
|
||||
|
||||
if (!cameraPropertiesCached && connected) {
|
||||
logger.info("Camera connected! running callback");
|
||||
onCameraConnected();
|
||||
}
|
||||
|
||||
return connected;
|
||||
}
|
||||
|
||||
final double CSCORE_DEFAULT_FRAME_TIMEOUT = 1.0 / 4.0;
|
||||
|
||||
@Override
|
||||
@@ -145,13 +133,15 @@ public class USBFrameProvider extends CpuImageProcessor {
|
||||
|
||||
@Override
|
||||
public void onCameraConnected() {
|
||||
logger.info("Camera connected! running callback");
|
||||
|
||||
super.onCameraConnected();
|
||||
|
||||
this.connectedCallback.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
public boolean checkCameraConnected() {
|
||||
return camera.isConnected();
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ public class VisionRunner {
|
||||
|
||||
private void update() {
|
||||
// wait for the camera to connect
|
||||
while (!frameSupplier.checkCameraConnected() && !Thread.interrupted()) {
|
||||
while (!frameSupplier.isConnected() && !Thread.interrupted()) {
|
||||
// yield
|
||||
pipelineResultConsumer.accept(new CVPipelineResult(0l, 0, 0, null, new Frame()));
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user