mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-06 03:31:41 +00:00
Potential fix for multi-camera on Windows
This commit is contained in:
@@ -37,6 +37,45 @@ public class SettingsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Platform {
|
||||||
|
WINDOWS_64("Windows x64"),
|
||||||
|
LINUX_64("Linux x64"),
|
||||||
|
LINUX_RASPBIAN("Linux Raspbian"),
|
||||||
|
LINUX_AARCH64("Linux ARM 64bit"),
|
||||||
|
MACOS_64("Mac OS x64"),
|
||||||
|
UNSUPPORTED("Unsupported Platform");
|
||||||
|
|
||||||
|
public final String value;
|
||||||
|
|
||||||
|
Platform(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Platform getCurrentPlatform() {
|
||||||
|
var osName = System.getProperty("os.name");
|
||||||
|
var osArch = System.getProperty("os.arch");
|
||||||
|
|
||||||
|
if (osName.contains("Windows")) {
|
||||||
|
if (osArch.equals("amd64")) return Platform.WINDOWS_64;
|
||||||
|
return Platform.UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (osName.contains("Linux")) {
|
||||||
|
if (osArch.equals("amd64")) return Platform.LINUX_64;
|
||||||
|
if (osArch.contains("rasp")) return Platform.LINUX_RASPBIAN;
|
||||||
|
if (osArch.contains("aarch")) return Platform.LINUX_64;
|
||||||
|
return Platform.UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (osName.contains("Mac")) {
|
||||||
|
if (osArch.equals("amd64")) return Platform.MACOS_64;
|
||||||
|
return Platform.UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Platform.UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
private static void initGeneralSettings() {
|
private static void initGeneralSettings() {
|
||||||
FileHelper.CheckPath(SettingsPath);
|
FileHelper.CheckPath(SettingsPath);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.chameleonvision.vision.camera;
|
package com.chameleonvision.vision.camera;
|
||||||
|
|
||||||
|
import com.chameleonvision.settings.SettingsManager;
|
||||||
import com.chameleonvision.vision.Pipeline;
|
import com.chameleonvision.vision.Pipeline;
|
||||||
import com.chameleonvision.web.ServerHandler;
|
import com.chameleonvision.web.ServerHandler;
|
||||||
import edu.wpi.cscore.*;
|
import edu.wpi.cscore.*;
|
||||||
@@ -16,6 +17,7 @@ public class Camera {
|
|||||||
private static final int MINIMUM_FPS = 30;
|
private static final int MINIMUM_FPS = 30;
|
||||||
private static final int MINIMUM_WIDTH = 320;
|
private static final int MINIMUM_WIDTH = 320;
|
||||||
private static final int MINIMUM_HEIGHT = 240;
|
private static final int MINIMUM_HEIGHT = 240;
|
||||||
|
private static final int MAX_INIT_MS = 1500;
|
||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String path;
|
public final String path;
|
||||||
@@ -32,6 +34,7 @@ public class Camera {
|
|||||||
private CamVideoMode camVideoMode;
|
private CamVideoMode camVideoMode;
|
||||||
private int currentPipelineIndex;
|
private int currentPipelineIndex;
|
||||||
private HashMap<Integer, Pipeline> pipelines;
|
private HashMap<Integer, Pipeline> pipelines;
|
||||||
|
private long initTimeout;
|
||||||
|
|
||||||
|
|
||||||
public Camera(String cameraName) {
|
public Camera(String cameraName) {
|
||||||
@@ -64,10 +67,19 @@ public class Camera {
|
|||||||
this.pipelines = pipelines;
|
this.pipelines = pipelines;
|
||||||
|
|
||||||
// set up video modes according to minimums
|
// set up video modes according to minimums
|
||||||
while(!UsbCam.isConnected())
|
if (SettingsManager.getCurrentPlatform() == SettingsManager.Platform.WINDOWS_64 && !UsbCam.isConnected()) {
|
||||||
{
|
System.out.print("Waiting on camera... ");
|
||||||
System.out.println("notConnected");//TODO add a time sleep, can wait only so long before giving up
|
initTimeout = System.nanoTime();
|
||||||
}
|
while(!UsbCam.isConnected())
|
||||||
|
{
|
||||||
|
//TODO add a time sleep, can wait only so long before giving up
|
||||||
|
if (((System.nanoTime() - initTimeout) / 1e6 ) >= MAX_INIT_MS) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var initTimeMs = (System.nanoTime() - initTimeout) / 1e6;
|
||||||
|
System.out.printf("Camera initialized in %.2fms\n", initTimeMs);
|
||||||
|
}
|
||||||
availableVideoModes = Arrays.stream(UsbCam.enumerateVideoModes()).filter(v -> v.fps >= MINIMUM_FPS && v.width >= MINIMUM_WIDTH && v.height >= MINIMUM_HEIGHT).toArray(VideoMode[]::new);
|
availableVideoModes = Arrays.stream(UsbCam.enumerateVideoModes()).filter(v -> v.fps >= MINIMUM_FPS && v.width >= MINIMUM_WIDTH && v.height >= MINIMUM_HEIGHT).toArray(VideoMode[]::new);
|
||||||
if (videoModeIndex <= availableVideoModes.length - 1) {
|
if (videoModeIndex <= availableVideoModes.length - 1) {
|
||||||
setCamVideoMode(videoModeIndex, false);
|
setCamVideoMode(videoModeIndex, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user