forked from PhotonVision/photonvision
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor program configuration broadcast hashmap spaghetti (PhotonVis…
…ion#1592) WAS: we used raw hash-maps to encode program state S/B: we use Jackson to do this encoding for us for free. We have Objects, and we should use them to represent structured data. --------- Co-authored-by: Craig Schardt <crschardt@fastem.com>
- Loading branch information
Showing
13 changed files
with
296 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...-core/src/main/java/org/photonvision/common/dataflow/websocket/UICameraConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (C) Photon Vision. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.photonvision.common.dataflow.websocket; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import org.photonvision.vision.calibration.UICameraCalibrationCoefficients; | ||
import org.photonvision.vision.camera.QuirkyCamera; | ||
|
||
public class UICameraConfiguration { | ||
@SuppressWarnings("unused") | ||
public double fov; | ||
|
||
public String nickname; | ||
public String uniqueName; | ||
public HashMap<String, Object> currentPipelineSettings; | ||
public int currentPipelineIndex; | ||
public List<String> pipelineNicknames; | ||
public HashMap<Integer, HashMap<String, Object>> videoFormatList; | ||
public int outputStreamPort; | ||
public int inputStreamPort; | ||
public List<UICameraCalibrationCoefficients> calibrations; | ||
public boolean isFovConfigurable = true; | ||
public QuirkyCamera cameraQuirks; | ||
public boolean isCSICamera; | ||
public double minExposureRaw; | ||
public double maxExposureRaw; | ||
public double minWhiteBalanceTemp; | ||
public double maxWhiteBalanceTemp; | ||
} |
49 changes: 49 additions & 0 deletions
49
photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UIGeneralSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (C) Photon Vision. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.photonvision.common.dataflow.websocket; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class UIGeneralSettings { | ||
public UIGeneralSettings( | ||
String version, | ||
String gpuAcceleration, | ||
boolean mrCalWorking, | ||
Map<String, ArrayList<String>> availableModels, | ||
List<String> supportedBackends, | ||
String hardwareModel, | ||
String hardwarePlatform) { | ||
this.version = version; | ||
this.gpuAcceleration = gpuAcceleration; | ||
this.mrCalWorking = mrCalWorking; | ||
this.availableModels = availableModels; | ||
this.supportedBackends = supportedBackends; | ||
this.hardwareModel = hardwareModel; | ||
this.hardwarePlatform = hardwarePlatform; | ||
} | ||
|
||
public String version; | ||
public String gpuAcceleration; | ||
public boolean mrCalWorking; | ||
public Map<String, ArrayList<String>> availableModels; | ||
public List<String> supportedBackends; | ||
public String hardwareModel; | ||
public String hardwarePlatform; | ||
} |
28 changes: 28 additions & 0 deletions
28
photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UILightingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (C) Photon Vision. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.photonvision.common.dataflow.websocket; | ||
|
||
public class UILightingConfig { | ||
public UILightingConfig(int brightness, boolean supported) { | ||
this.brightness = brightness; | ||
this.supported = supported; | ||
} | ||
|
||
public int brightness = 0; | ||
public boolean supported = true; | ||
} |
34 changes: 34 additions & 0 deletions
34
photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UINetConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) Photon Vision. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.photonvision.common.dataflow.websocket; | ||
|
||
import java.util.List; | ||
import org.photonvision.common.configuration.NetworkConfig; | ||
import org.photonvision.common.networking.NetworkUtils.NMDeviceInfo; | ||
|
||
public class UINetConfig extends NetworkConfig { | ||
public UINetConfig( | ||
NetworkConfig config, List<NMDeviceInfo> networkInterfaceNames, boolean networkingDisabled) { | ||
super(config); | ||
this.networkInterfaceNames = networkInterfaceNames; | ||
this.networkingDisabled = networkingDisabled; | ||
} | ||
|
||
public List<NMDeviceInfo> networkInterfaceNames; | ||
public boolean networkingDisabled; | ||
} |
69 changes: 69 additions & 0 deletions
69
...-core/src/main/java/org/photonvision/common/dataflow/websocket/UIPhotonConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) Photon Vision. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.photonvision.common.dataflow.websocket; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.photonvision.PhotonVersion; | ||
import org.photonvision.common.configuration.NeuralNetworkModelManager; | ||
import org.photonvision.common.configuration.PhotonConfiguration; | ||
import org.photonvision.common.hardware.Platform; | ||
import org.photonvision.common.networking.NetworkManager; | ||
import org.photonvision.common.networking.NetworkUtils; | ||
import org.photonvision.mrcal.MrCalJNILoader; | ||
import org.photonvision.raspi.LibCameraJNILoader; | ||
import org.photonvision.vision.processes.VisionModule; | ||
import org.photonvision.vision.processes.VisionModuleManager; | ||
|
||
public class UIPhotonConfiguration { | ||
public List<UICameraConfiguration> cameraSettings; | ||
public UIProgramSettings settings; | ||
|
||
public UIPhotonConfiguration( | ||
UIProgramSettings settings, List<UICameraConfiguration> cameraSettings) { | ||
this.cameraSettings = cameraSettings; | ||
this.settings = settings; | ||
} | ||
|
||
public static UIPhotonConfiguration programStateToUi(PhotonConfiguration c) { | ||
return new UIPhotonConfiguration( | ||
new UIProgramSettings( | ||
new UINetConfig( | ||
c.getNetworkConfig(), | ||
NetworkUtils.getAllActiveWiredInterfaces(), | ||
NetworkManager.getInstance().networkingIsDisabled), | ||
new UILightingConfig( | ||
c.getHardwareSettings().ledBrightnessPercentage, | ||
!c.getHardwareConfig().ledPins.isEmpty()), | ||
new UIGeneralSettings( | ||
PhotonVersion.versionString, | ||
// TODO add support for other types of GPU accel | ||
LibCameraJNILoader.isSupported() ? "Zerocopy Libcamera Working" : "", | ||
MrCalJNILoader.getInstance().isLoaded(), | ||
NeuralNetworkModelManager.getInstance().getModels(), | ||
NeuralNetworkModelManager.getInstance().getSupportedBackends(), | ||
c.getHardwareConfig().deviceName.isEmpty() | ||
? Platform.getHardwareModel() | ||
: c.getHardwareConfig().deviceName, | ||
Platform.getPlatformName()), | ||
c.getApriltagFieldLayout()), | ||
VisionModuleManager.getInstance().getModules().stream() | ||
.map(VisionModule::toUICameraConfig) | ||
.collect(Collectors.toList())); | ||
} | ||
} |
Oops, something went wrong.