mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-24 01:31:44 +00:00
Fix driver mode settings, sort resolutions (#115)
* Fix DriverMode settings * Update FileVisionSource.java * Sort modes by resolution * Filter duplicated modes * run spotless * Fix calibration bug * run format * aaaaa * Add hardware and platform support * decrease timing sensitivity * Better handle jvm exitg * Make reboot happen immediately * Cleanup restart * Remove debug print * Fix Jackson exploding when deserializing old versions of configs * Add unit test for old config versions * Run format * Add a comment * remove isvendorcam from pipeline manager * oops
This commit is contained in:
@@ -19,14 +19,12 @@ package org.photonvision.common.hardware;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import org.photonvision.common.ProgramStatus;
|
||||
import org.photonvision.common.configuration.ConfigManager;
|
||||
import org.photonvision.common.configuration.HardwareConfig;
|
||||
import org.photonvision.common.dataflow.networktables.NTDataChangeListener;
|
||||
import org.photonvision.common.dataflow.networktables.NetworkTablesManager;
|
||||
import org.photonvision.common.hardware.GPIO.CustomGPIO;
|
||||
import org.photonvision.common.hardware.GPIO.GPIOBase;
|
||||
import org.photonvision.common.hardware.VisionLED.VisionLEDMode;
|
||||
import org.photonvision.common.hardware.metrics.MetricsBase;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
@@ -36,13 +34,17 @@ import org.photonvision.common.util.ShellExec;
|
||||
public class HardwareManager {
|
||||
private static HardwareManager instance;
|
||||
|
||||
private final HashMap<Integer, GPIOBase> VisionLEDs = new HashMap<>();
|
||||
private final ShellExec shellExec = new ShellExec(true, false);
|
||||
private final Logger logger = new Logger(HardwareManager.class, LogGroup.General);
|
||||
|
||||
private final HardwareConfig hardwareConfig;
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private final StatusLED statusLED;
|
||||
|
||||
private final NetworkTableEntry ledModeEntry;
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private final NTDataChangeListener ledModeListener;
|
||||
|
||||
public final VisionLED visionLED;
|
||||
@@ -64,17 +66,34 @@ public class HardwareManager {
|
||||
new VisionLED(
|
||||
hardwareConfig.ledPins,
|
||||
hardwareConfig.ledPWMFrequency,
|
||||
hardwareConfig.ledPWMRange.get(1));
|
||||
(hardwareConfig.ledPWMRange != null && hardwareConfig.ledPWMRange.size() == 2)
|
||||
? hardwareConfig.ledPWMRange.get(1)
|
||||
: 0);
|
||||
|
||||
ledModeEntry = NetworkTablesManager.getInstance().kRootTable.getEntry("ledMode");
|
||||
ledModeEntry.setNumber(VisionLEDMode.VLM_DEFAULT.value);
|
||||
ledModeListener = new NTDataChangeListener(ledModeEntry, visionLED::onLedModeChange);
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(this::onJvmExit));
|
||||
|
||||
// Start hardware metrics thread (Disabled until implemented)
|
||||
// if (Platform.isLinux()) MetricsPublisher.getInstance().startTask();
|
||||
}
|
||||
|
||||
private void onJvmExit() {
|
||||
logger.info("Shutting down...");
|
||||
visionLED.setState(false);
|
||||
}
|
||||
|
||||
public boolean restartDevice() {
|
||||
if (Platform.isRaspberryPi()) {
|
||||
try {
|
||||
return shellExec.executeBashCommand("reboot now") == 0;
|
||||
} catch (IOException e) {
|
||||
logger.error("Could not restart device!", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return shellExec.executeBashCommand(hardwareConfig.restartHardwareCommand) == 0;
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -88,7 +88,7 @@ public enum Platform {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Platform getCurrentPlatform() {
|
||||
public static Platform getCurrentPlatform() {
|
||||
if (RuntimeDetector.isWindows()) {
|
||||
if (RuntimeDetector.is32BitIntel()) return WINDOWS_32;
|
||||
if (RuntimeDetector.is64BitIntel()) return WINDOWS_64;
|
||||
|
||||
Reference in New Issue
Block a user