From d7a7610917e2555a2836e354cfeb2bd62f17ea5c Mon Sep 17 00:00:00 2001 From: "Cameron (3539)" Date: Thu, 31 Oct 2024 23:13:36 -0400 Subject: [PATCH] Fix videomode is null (#1513) There is a weird edge case at least with arducam/broken arducams/used arducams where cscore will see it when pv starts but not be able to connect to it. If we always read out the "current" video mode instead of null when it is disconnected things will work. If the camera is disconnected while we try to change the video mode when we get the current video mode it will tell us what we wanted to set it to. Then when the camera reconnects it will be in that video mode. --- .../vision/camera/USBCameras/GenericUSBCameraSettables.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java index e601586fb3..8d272d15e2 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java @@ -240,7 +240,8 @@ public void setGain(int gain) { @Override public VideoMode getCurrentVideoMode() { - return camera.isConnected() ? camera.getVideoMode() : null; + return camera + .getVideoMode(); // This returns the current video mode even if the camera is disconnected } @Override @@ -250,7 +251,7 @@ public void setVideoModeInternal(VideoMode videoMode) { logger.error("Got a null video mode! Doing nothing..."); return; } - camera.setVideoMode(videoMode); + if (camera.setVideoMode(videoMode)) logger.debug("Failed to set video mode!"); } catch (Exception e) { logger.error("Failed to set video mode!", e); }