mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Support for driver settings tab
This commit is contained in:
@@ -52,7 +52,7 @@ public class Camera {
|
||||
//Driver mode camera settings
|
||||
public int driverExposure;
|
||||
public int driverBrightness;
|
||||
public boolean isDriver;
|
||||
private boolean isDriver;
|
||||
|
||||
public Camera(String cameraName) {
|
||||
this(cameraName, DEFAULT_FOV);
|
||||
@@ -67,18 +67,18 @@ public class Camera {
|
||||
}
|
||||
|
||||
public Camera(String cameraName, UsbCameraInfo usbCamInfo, double fov, StreamDivisor divisor) {
|
||||
this(cameraName, usbCamInfo, fov, new ArrayList<>(), 0, divisor, DEFAULT_EXPOSURE, DEFAULT_BRIGHTNESS);
|
||||
this(cameraName, usbCamInfo, fov, new ArrayList<>(), 0, divisor, DEFAULT_EXPOSURE, DEFAULT_BRIGHTNESS,false);
|
||||
}
|
||||
|
||||
public Camera(String cameraName, double fov, List<Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness) {
|
||||
this(cameraName, CameraManager.AllUsbCameraInfosByName.get(cameraName), fov, pipelines, videoModeIndex, divisor, driverExposure, driverBrightness);
|
||||
public Camera(String cameraName, double fov, List<Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness,boolean isDriver) {
|
||||
this(cameraName, CameraManager.AllUsbCameraInfosByName.get(cameraName), fov, pipelines, videoModeIndex, divisor, driverExposure, driverBrightness, isDriver);
|
||||
}
|
||||
|
||||
public Camera(String cameraName, double fov, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness) {
|
||||
this(cameraName, fov, new ArrayList<>(), videoModeIndex, divisor, driverExposure, driverBrightness);
|
||||
public Camera(String cameraName, double fov, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness,boolean isDriver) {
|
||||
this(cameraName, fov, new ArrayList<>(), videoModeIndex, divisor, driverExposure, driverBrightness,isDriver);
|
||||
}
|
||||
|
||||
public Camera(String cameraName, UsbCameraInfo usbCamInfo, double fov, List<Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness) {
|
||||
public Camera(String cameraName, UsbCameraInfo usbCamInfo, double fov, List<Pipeline> pipelines, int videoModeIndex, StreamDivisor divisor, int driverExposure, int driverBrightness,boolean isDriver) {
|
||||
FOV = fov;
|
||||
name = cameraName;
|
||||
|
||||
@@ -121,7 +121,9 @@ public class Camera {
|
||||
|
||||
cvSink = cs.getVideo(UsbCam);
|
||||
cvSource = cs.putVideo(name, camVals.ImageWidth, camVals.ImageHeight);
|
||||
isDriver = false;
|
||||
|
||||
//Driver mode settings
|
||||
this.isDriver = isDriver;
|
||||
this.driverBrightness=driverBrightness;
|
||||
this.driverExposure=driverExposure;
|
||||
}
|
||||
@@ -228,18 +230,15 @@ public class Camera {
|
||||
|
||||
public void setDriverMode(boolean state)
|
||||
{
|
||||
Map<String,Integer> data = new HashMap<>();
|
||||
isDriver=state;
|
||||
if(isDriver){
|
||||
UsbCam.setBrightness(driverBrightness);
|
||||
UsbCam.setBrightness(driverBrightness);
|
||||
UsbCam.setBrightness(driverBrightness);//We call setBrightness because it updates after 2 calls
|
||||
UsbCam.setBrightness(driverBrightness);//Check it after we update to 2020 libraries
|
||||
try{UsbCam.setExposureManual(driverExposure);}
|
||||
catch (VideoException e)
|
||||
{
|
||||
System.out.println("Exposure change isnt supported");
|
||||
System.out.println("Exposure change isn't supported");
|
||||
}
|
||||
data.put("brightness",getBrightness());
|
||||
data.put("exposure",driverExposure);
|
||||
}
|
||||
else{
|
||||
UsbCam.setBrightness(getCurrentPipeline().brightness);
|
||||
@@ -247,18 +246,22 @@ public class Camera {
|
||||
try{UsbCam.setExposureManual(getCurrentPipeline().exposure);}
|
||||
catch (VideoException e)
|
||||
{
|
||||
System.out.println("Exposure change isnt supported");
|
||||
System.out.println("Exposure change isn't supported");
|
||||
}
|
||||
data.put("brightness",getBrightness());
|
||||
data.put("exposure",getCurrentPipeline().exposure);
|
||||
}
|
||||
ServerHandler.broadcastMessage(data);
|
||||
}
|
||||
|
||||
public boolean getDriverMode()
|
||||
{
|
||||
return isDriver;
|
||||
}
|
||||
|
||||
public int getBrightness() {
|
||||
return UsbCam.getBrightness();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setBrightness(int brightness) {
|
||||
if (isDriver)
|
||||
driverBrightness=brightness;
|
||||
|
||||
@@ -23,6 +23,7 @@ public class CameraDeserializer implements JsonDeserializer<Camera> {
|
||||
var camName = jsonObj.get("name").getAsString();
|
||||
var camNickname = jsonObj.get("nickname").getAsString();
|
||||
var videoModeIndex = jsonObj.get("resolution").getAsInt();
|
||||
var isDriver = jsonObj.get("isDriver").getAsBoolean();
|
||||
var driverExposure = jsonObj.get("driverExposure").getAsInt();
|
||||
var driverBrightness = jsonObj.get("driverBrightness").getAsInt();
|
||||
var divisor = StreamDivisor.values()[jsonObj.get("streamDivisor").getAsInt()];
|
||||
@@ -38,13 +39,13 @@ public class CameraDeserializer implements JsonDeserializer<Camera> {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
var newCamera = actualPipelines != null ? new Camera(camName, camFOV, actualPipelines, videoModeIndex, divisor, driverExposure, driverBrightness) : new Camera(camName, camFOV, videoModeIndex, divisor, driverExposure, driverBrightness);
|
||||
var newCamera = actualPipelines != null ? new Camera(camName, camFOV, actualPipelines, videoModeIndex, divisor, driverExposure, driverBrightness,isDriver) : new Camera(camName, camFOV, videoModeIndex, divisor, driverExposure, driverBrightness,isDriver);
|
||||
newCamera.setNickname(camNickname != null ? camNickname : "");
|
||||
return newCamera;
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
System.err.println("Error while reading json, value doesnt exist!");
|
||||
System.err.println("Error while reading json, value doesn't exist!");
|
||||
System.err.println("Try to delete the camera settings in settings/cameras/YOURCAMERA.json");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
||||
@@ -16,6 +16,7 @@ public class CameraSerializer implements JsonSerializer<Camera> {
|
||||
obj.add("pipelines", pipelines);
|
||||
obj.addProperty("resolution", camera.getVideoModeIndex());
|
||||
obj.add("camVideoMode", context.serialize(camera.getVideoMode()));
|
||||
obj.add("isDriver",context.serialize(camera.getDriverMode()));
|
||||
obj.add("driverExposure",context.serialize(camera.driverExposure));
|
||||
obj.add("driverBrightness",context.serialize(camera.driverBrightness));
|
||||
return obj;
|
||||
|
||||
@@ -123,7 +123,7 @@ public class VisionProcess implements Runnable {
|
||||
if (currentPipeline.orientation.equals(Orientation.Inverted)) {
|
||||
Core.flip(inputImage, inputImage, -1);
|
||||
}
|
||||
if (ntDriverModeEntry.getBoolean(false)) {
|
||||
if (camera.getDriverMode()) {
|
||||
inputImage.copyTo(outputImage);
|
||||
return pipelineResult;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,13 @@ public class ServerHandler {
|
||||
sendFullSettings();
|
||||
break;
|
||||
}
|
||||
case "driverMode": {
|
||||
for (HashMap.Entry<String, Object> e : ((HashMap<String, Object>) entry.getValue()).entrySet()) {
|
||||
setField(CameraManager.getCurrentCamera(), e.getKey(), e.getValue());
|
||||
}
|
||||
CameraManager.saveCameras();
|
||||
break;
|
||||
}
|
||||
case "cameraSettings": {
|
||||
HashMap camSettings = (HashMap) entry.getValue();
|
||||
CameraManager.getCurrentCamera().setFOV((Number) camSettings.get("fov"));
|
||||
@@ -224,6 +231,19 @@ public class ServerHandler {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
private static HashMap<String, Object> getOrdinalDriver() {
|
||||
HashMap<String, Object> tmp = new HashMap<>();
|
||||
try {
|
||||
var currentCamera = CameraManager.getCurrentCamera();
|
||||
tmp.put("isDriver", currentCamera.getDriverMode());
|
||||
tmp.put("driverBrightness", currentCamera.driverBrightness);
|
||||
tmp.put("driverExposure", currentCamera.driverExposure);
|
||||
} catch (CameraException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public static void sendFullSettings() {
|
||||
//General settings
|
||||
Map<String, Object> fullSettings = new HashMap<>();
|
||||
@@ -231,8 +251,9 @@ public class ServerHandler {
|
||||
fullSettings.put("settings", getOrdinalSettings());
|
||||
fullSettings.put("cameraSettings", getOrdinalCameraSettings());
|
||||
fullSettings.put("cameraList", CameraManager.getAllCameraByNickname());
|
||||
var currentCamera = CameraManager.getCurrentCamera();
|
||||
fullSettings.put("pipeline", getOrdinalPipeline());
|
||||
var currentCamera = CameraManager.getCurrentCamera();
|
||||
fullSettings.put("driverMode",getOrdinalDriver());
|
||||
fullSettings.put("pipelineList", currentCamera.getPipelinesNickname());
|
||||
fullSettings.put("resolutionList", currentCamera.getResolutionList());
|
||||
fullSettings.put("port", currentCamera.getStreamPort());
|
||||
|
||||
Reference in New Issue
Block a user