diff --git a/docs/source/docs/additional-resources/config.md b/docs/source/docs/additional-resources/config.md index 31412ddcaf..fc0e430469 100644 --- a/docs/source/docs/additional-resources/config.md +++ b/docs/source/docs/additional-resources/config.md @@ -22,8 +22,6 @@ The directory structure is outlined below. - Contains images saved with the input/output save commands. - logs - Contains timestamped logs in the format {code}`photonvision-YYYY-MM-D_HH-MM-SS.log`. These timestamps will likely be significantly behind the real time. Coprocessors on the robot have no way to get current time. -- hardwareSettings.json - - Contains hardware settings. Currently this includes only the LED brightness. - networkSettings.json - Contains network settings, including team number (or remote network tables address), static/dynamic settings, and hostname. @@ -45,7 +43,6 @@ A variety of files can be imported back into PhotonVision: - Single Config File - Currently-supported Files - {code}`hardwareConfig.json` - - {code}`hardwareSettings.json` - {code}`networkSettings.json` - Useful for simple hardware or network configuration tasks without overwriting all settings. diff --git a/docs/source/docs/additional-resources/nt-api.md b/docs/source/docs/additional-resources/nt-api.md index e89c26b356..c5322cae11 100644 --- a/docs/source/docs/additional-resources/nt-api.md +++ b/docs/source/docs/additional-resources/nt-api.md @@ -54,17 +54,3 @@ Images are returned as part of the .zip package from the "Export" operation in t :::{warning} If you manage to make calls to these commands faster than 500ms (between calls), additional photos will not be captured. ::: - -### Global Entries - -These entries are global, meaning that they should be called on the main `photonvision` table. - -| Key | Type | Description | -| --------- | ----- | -------------------------------------------------------- | -| `ledMode` | `int` | Sets the LED Mode (-1: default, 0: off, 1: on, 2: blink) | - -:::{warning} -Setting the LED mode to -1 (default) when `multiple` cameras are connected may result in unexpected behavior. {ref}`This is a known limitation of PhotonVision. ` - -Single camera operation should work without issue. -::: diff --git a/docs/source/docs/advanced-installation/sw_install/files/Limelight2+/hardwareConfig.json b/docs/source/docs/advanced-installation/sw_install/files/Limelight2+/hardwareConfig.json index 5465d0d060..dcc5ad3191 100644 --- a/docs/source/docs/advanced-installation/sw_install/files/Limelight2+/hardwareConfig.json +++ b/docs/source/docs/advanced-installation/sw_install/files/Limelight2+/hardwareConfig.json @@ -1,9 +1,5 @@ { "deviceName" : "Limelight 2+", "supportURL" : "https://limelightvision.io", - "ledPins" : [ 13, 18 ], - "ledsCanDim" : true, - "ledPWMRange" : [ 0, 100 ], - "ledPWMFrequency" : 30000, "vendorFOV" : 75.76079874010732 } diff --git a/docs/source/docs/advanced-installation/sw_install/files/Limelight2/hardwareConfig.json b/docs/source/docs/advanced-installation/sw_install/files/Limelight2/hardwareConfig.json index b38176e119..33a276fd53 100644 --- a/docs/source/docs/advanced-installation/sw_install/files/Limelight2/hardwareConfig.json +++ b/docs/source/docs/advanced-installation/sw_install/files/Limelight2/hardwareConfig.json @@ -1,7 +1,5 @@ { "deviceName" : "Limelight 2", "supportURL" : "https://limelightvision.io", - "ledPins" : [ 17, 18 ], - "ledsCanDim" : false, "vendorFOV" : 75.76079874010732 } diff --git a/docs/source/docs/hardware/customhardware.md b/docs/source/docs/hardware/customhardware.md index 43252b7f84..62ab7149da 100644 --- a/docs/source/docs/hardware/customhardware.md +++ b/docs/source/docs/hardware/customhardware.md @@ -2,35 +2,10 @@ ## Configuration -By default, PhotonVision attempts to make minimal assumptions of the hardware it runs on. However, it may be configured to enable custom LED control, branding, and other functionality. +By default, PhotonVision attempts to make minimal assumptions of the hardware it runs on. However, it may be configured to enable branding and other functionality. `hardwareConfig.json` is the location for this configuration. It is included when settings are exported, and can be uploaded as part of a .zip, or on its own. -## LED Support - -For Raspberry-Pi based hardware, PhotonVision can use [PiGPIO](https://abyz.me.uk/rpi/pigpio/) to control IO pins. The mapping of which pins control which LED's is part of the hardware config. The pins are active-high: set high when LED's are commanded on, and set low when commanded off. - -```{eval-rst} -.. tab-set-code:: - .. code-block:: json - - { - "ledPins" : [ 13 ], - "ledSetCommand" : "", - "ledsCanDim" : true, - "ledPWMRange" : [ 0, 100 ], - "ledPWMSetRange" : "", - "ledPWMFrequency" : 0, - "ledDimCommand" : "", - "ledBlinkCommand" : "", - "statusRGBPins" : [ ], - } -``` - -:::{note} -No hardware boards with status RGB LED pins or non-dimming LED's have been tested yet. Please reach out to the development team if these features are desired, they can assist with configuration and testing. -::: - ## Hardware Interaction Commands For Non-Raspberry-Pi hardware, users must provide valid hardware-specific commands for some parts of the UI interaction (including performance metrics, and executing system restarts). @@ -100,15 +75,6 @@ Here is a complete example `hardwareConfig.json`: "deviceName" : "Blinky McBlinkface", "deviceLogoPath" : "", "supportURL" : "https://www.youtube.com/watch?v=b-CvLWbfZhU", - "ledPins" : [2, 13], - "ledSetCommand" : "", - "ledsCanDim" : true, - "ledPWMRange" : [ 0, 100 ], - "ledPWMSetRange" : "", - "ledPWMFrequency" : 0, - "ledDimCommand" : "", - "ledBlinkCommand" : "", - "statusRGBPins" : [ ], "cpuTempCommand" : "", "cpuMemoryCommand" : "", "cpuUtilCommand" : "", diff --git a/docs/source/docs/programming/photonlib/controlling-led.md b/docs/source/docs/programming/photonlib/controlling-led.md deleted file mode 100644 index dfaf9b3b68..0000000000 --- a/docs/source/docs/programming/photonlib/controlling-led.md +++ /dev/null @@ -1,20 +0,0 @@ -# Controlling LEDs - -You can control the vision LEDs of supported hardware via PhotonLib using the `setLED()` method on a `PhotonCamera` instance. In Java and C++, an `VisionLEDMode` enum class is provided to choose values from. These values include, `kOff`, `kOn`, `kBlink`, and `kDefault`. `kDefault` uses the default LED value from the selected pipeline. - -```{eval-rst} -.. tab-set-code:: - .. code-block:: Java - - // Blink the LEDs. - camera.setLED(VisionLEDMode.kBlink); - - .. code-block:: C++ - - // Blink the LEDs. - camera.SetLED(photonlib::VisionLEDMode::kBlink); - - .. code-block:: Python - - # Coming Soon! -``` diff --git a/docs/source/docs/programming/photonlib/index.md b/docs/source/docs/programming/photonlib/index.md index 0e38862d5f..0d3ab67d9e 100644 --- a/docs/source/docs/programming/photonlib/index.md +++ b/docs/source/docs/programming/photonlib/index.md @@ -8,5 +8,4 @@ getting-target-data using-target-data robot-pose-estimator driver-mode-pipeline-index -controlling-led ``` diff --git a/docs/source/docs/troubleshooting/common-errors.md b/docs/source/docs/troubleshooting/common-errors.md index 217d4a6171..cc4e65cf60 100644 --- a/docs/source/docs/troubleshooting/common-errors.md +++ b/docs/source/docs/troubleshooting/common-errors.md @@ -10,12 +10,6 @@ All known issues can be found on our [GitHub page](https://github.com/PhotonVisi Due to an issue with Linux kernels, the drivers for the PS3Eye are no longer supported. If you would still like to use the PS3Eye, you can downgrade your kernel with the following command: `sudo CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt rpi-update 866751bfd023e72bd96a8225cf567e03c334ecc4`. Note: You must be connected to the internet to run the command. -### LED Control - -The logic for controlling LED mode when `multiple cameras are connected` is not fully fleshed out. In its current state, LED control is only enabled when a Pi Camera Module is not in driver mode—meaning a USB camera on its own is unable to control the LEDs. - -For now, if you are using multiple cameras, it is recommended that teams set the value of the NetworkTables entry {code}`photonvision/ledMode` from the robot code to control LED state. - ## Commonly Seen Issues ### Networking Issues diff --git a/photon-client/src/components/settings/DeviceControlCard.vue b/photon-client/src/components/settings/DeviceControlCard.vue index 76783f6dcb..97c66a53d8 100644 --- a/photon-client/src/components/settings/DeviceControlCard.vue +++ b/photon-client/src/components/settings/DeviceControlCard.vue @@ -133,7 +133,6 @@ const openExportSettingsPrompt = () => { enum ImportType { AllSettings, HardwareConfig, - HardwareSettings, NetworkConfig, ApriltagFieldLayout } @@ -151,9 +150,6 @@ const handleSettingsImport = () => { case ImportType.HardwareConfig: settingsEndpoint = "/hardwareConfig"; break; - case ImportType.HardwareSettings: - settingsEndpoint = "/hardwareSettings"; - break; case ImportType.NetworkConfig: settingsEndpoint = "/networkConfig"; break; diff --git a/photon-client/src/components/settings/LEDControlCard.vue b/photon-client/src/components/settings/LEDControlCard.vue deleted file mode 100644 index 9d9f59003d..0000000000 --- a/photon-client/src/components/settings/LEDControlCard.vue +++ /dev/null @@ -1,19 +0,0 @@ - - - diff --git a/photon-client/src/stores/settings/GeneralSettingsStore.ts b/photon-client/src/stores/settings/GeneralSettingsStore.ts index 28b0f7ad03..f0d9f13767 100644 --- a/photon-client/src/stores/settings/GeneralSettingsStore.ts +++ b/photon-client/src/stores/settings/GeneralSettingsStore.ts @@ -1,20 +1,12 @@ import { defineStore } from "pinia"; -import type { - ConfigurableNetworkSettings, - GeneralSettings, - LightingSettings, - MetricData, - NetworkSettings -} from "@/types/SettingTypes"; +import type { ConfigurableNetworkSettings, GeneralSettings, MetricData, NetworkSettings } from "@/types/SettingTypes"; import { NetworkConnectionType } from "@/types/SettingTypes"; -import { useStateStore } from "@/stores/StateStore"; import axios from "axios"; import type { WebsocketSettingsUpdate } from "@/types/WebsocketDataTypes"; interface GeneralSettingsStore { general: GeneralSettings; network: NetworkSettings; - lighting: LightingSettings; metrics: MetricData; currentFieldLayout; } @@ -49,10 +41,6 @@ export const useSettingsStore = defineStore("settings", { ], networkingDisabled: false }, - lighting: { - supported: true, - brightness: 0 - }, metrics: { cpuTemp: undefined, cpuUtil: undefined, @@ -113,23 +101,11 @@ export const useSettingsStore = defineStore("settings", { conflictingHostname: data.general.conflictingHostname || false, conflictingCameras: data.general.conflictingCameras || "" }; - this.lighting = data.lighting; this.network = data.networkSettings; this.currentFieldLayout = data.atfl; }, updateGeneralSettings(payload: Required) { return axios.post("/settings/general", payload); - }, - /** - * Modify the brightness of the LEDs. - * - * @param brightness brightness to set [0, 100] - */ - changeLEDBrightness(brightness: number) { - const payload = { - enabledLEDPercentage: brightness - }; - useStateStore().websocket?.send(payload, true); } } }); diff --git a/photon-client/src/types/PipelineTypes.ts b/photon-client/src/types/PipelineTypes.ts index 1b56311941..955a7517dd 100644 --- a/photon-client/src/types/PipelineTypes.ts +++ b/photon-client/src/types/PipelineTypes.ts @@ -61,7 +61,6 @@ export interface PipelineSettings { offsetDualPointA: { x: number; y: number }; offsetDualPointB: { x: number; y: number }; hsvHue: WebsocketNumberPair | [number, number]; - ledMode: boolean; hueInverted: boolean; outputShowMultipleTargets: boolean; contourSortMode: number; @@ -93,7 +92,6 @@ export type ConfigurablePipelineSettings = Partial< | "cornerDetectionUseConvexHulls" | "offsetDualPointA" | "offsetDualPointB" - | "ledMode" | "offsetSinglePoint" | "offsetDualPointBArea" | "cornerDetectionExactSideCount" @@ -103,7 +101,7 @@ export type ConfigurablePipelineSettings = Partial< // Omitted settings are changed for all pipeline types export const DefaultPipelineSettings: Omit< PipelineSettings, - "cameraGain" | "targetModel" | "ledMode" | "outputShowMultipleTargets" | "cameraExposureRaw" | "pipelineType" + "cameraGain" | "targetModel" | "outputShowMultipleTargets" | "cameraExposureRaw" | "pipelineType" > = { offsetRobotOffsetMode: RobotOffsetPointMode.None, streamingFrameDivisor: 0, @@ -159,7 +157,6 @@ export const DefaultReflectivePipelineSettings: ReflectivePipelineSettings = { ...DefaultPipelineSettings, cameraGain: 20, targetModel: TargetModel.InfiniteRechargeHighGoalOuter, - ledMode: true, outputShowMultipleTargets: false, cameraExposureRaw: 6, pipelineType: PipelineType.Reflective, @@ -190,7 +187,6 @@ export const DefaultColoredShapePipelineSettings: ColoredShapePipelineSettings = ...DefaultPipelineSettings, cameraGain: 75, targetModel: TargetModel.InfiniteRechargeHighGoalOuter, - ledMode: true, outputShowMultipleTargets: false, cameraExposureRaw: 20, pipelineType: PipelineType.ColoredShape, @@ -230,7 +226,6 @@ export const DefaultAprilTagPipelineSettings: AprilTagPipelineSettings = { ...DefaultPipelineSettings, cameraGain: 75, targetModel: TargetModel.AprilTag6p5in_36h11, - ledMode: false, outputShowMultipleTargets: true, cameraExposureRaw: 20, pipelineType: PipelineType.AprilTag, @@ -276,7 +271,6 @@ export const DefaultArucoPipelineSettings: ArucoPipelineSettings = { targetModel: TargetModel.AprilTag6p5in_36h11, cameraExposureRaw: -1, cameraAutoExposure: true, - ledMode: false, pipelineType: PipelineType.Aruco, tagFamily: AprilTagFamily.Family36h11, @@ -309,7 +303,6 @@ export const DefaultObjectDetectionPipelineSettings: ObjectDetectionPipelineSett pipelineType: PipelineType.ObjectDetection, cameraGain: 20, targetModel: TargetModel.InfiniteRechargeHighGoalOuter, - ledMode: true, outputShowMultipleTargets: false, cameraExposureRaw: 6, confidence: 0.9, @@ -328,7 +321,6 @@ export const DefaultCalibration3dPipelineSettings: Calibration3dPipelineSettings pipelineType: PipelineType.ObjectDetection, cameraGain: 20, targetModel: TargetModel.InfiniteRechargeHighGoalOuter, - ledMode: true, outputShowMultipleTargets: false, cameraExposureRaw: 6, drawAllSnapshots: false diff --git a/photon-client/src/types/SettingTypes.ts b/photon-client/src/types/SettingTypes.ts index 693f14fda5..63de68c5ef 100644 --- a/photon-client/src/types/SettingTypes.ts +++ b/photon-client/src/types/SettingTypes.ts @@ -115,11 +115,6 @@ export interface VsmState { allConnectedCameras: PVCameraInfo[]; } -export interface LightingSettings { - supported: boolean; - brightness: number; -} - export enum LogLevel { ERROR = 0, WARN = 1, diff --git a/photon-client/src/types/WebsocketDataTypes.ts b/photon-client/src/types/WebsocketDataTypes.ts index b68fd1df73..0d8aaf9b91 100644 --- a/photon-client/src/types/WebsocketDataTypes.ts +++ b/photon-client/src/types/WebsocketDataTypes.ts @@ -1,7 +1,6 @@ import type { CameraCalibrationResult, GeneralSettings, - LightingSettings, LogLevel, MetricData, NetworkSettings, @@ -20,7 +19,6 @@ export interface WebsocketLogMessage { } export interface WebsocketSettingsUpdate { general: Required; - lighting: Required; networkSettings: NetworkSettings; atfl: AprilTagFieldLayout; } diff --git a/photon-client/src/views/GeneralSettingsView.vue b/photon-client/src/views/GeneralSettingsView.vue index 09a2ae08c4..fb016e9a9d 100644 --- a/photon-client/src/views/GeneralSettingsView.vue +++ b/photon-client/src/views/GeneralSettingsView.vue @@ -3,7 +3,6 @@ import MetricsCard from "@/components/settings/MetricsCard.vue"; import DeviceControlCard from "@/components/settings/DeviceControlCard.vue"; import ObjectDetectionCard from "@/components/settings/ObjectDetectionCard.vue"; import NetworkingCard from "@/components/settings/NetworkingCard.vue"; -import LightingControlCard from "@/components/settings/LEDControlCard.vue"; import { useSettingsStore } from "@/stores/settings/GeneralSettingsStore"; import ApriltagControlCard from "@/components/settings/ApriltagControlCard.vue"; @@ -14,7 +13,6 @@ import ApriltagControlCard from "@/components/settings/ApriltagControlCard.vue"; - diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/ConfigManager.java b/photon-core/src/main/java/org/photonvision/common/configuration/ConfigManager.java index 6f4371302f..3920f1d462 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/ConfigManager.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/ConfigManager.java @@ -42,7 +42,6 @@ public class ConfigManager { private static ConfigManager INSTANCE; public static final String HW_CFG_FNAME = "hardwareConfig.json"; - public static final String HW_SET_FNAME = "hardwareSettings.json"; public static final String NET_SET_FNAME = "networkSettings.json"; final File configDirectoryFile; @@ -311,10 +310,6 @@ public boolean saveUploadedHardwareConfig(Path uploadPath) { return m_provider.saveUploadedHardwareConfig(uploadPath); } - public boolean saveUploadedHardwareSettings(Path uploadPath) { - return m_provider.saveUploadedHardwareSettings(uploadPath); - } - public boolean saveUploadedNetworkConfig(Path uploadPath) { return m_provider.saveUploadedNetworkConfig(uploadPath); } diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/ConfigProvider.java b/photon-core/src/main/java/org/photonvision/common/configuration/ConfigProvider.java index 6e10e5ffc9..df4c77e75c 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/ConfigProvider.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/ConfigProvider.java @@ -36,8 +36,6 @@ public void clearConfig() { public abstract boolean saveUploadedHardwareConfig(Path uploadPath); - public abstract boolean saveUploadedHardwareSettings(Path uploadPath); - public abstract boolean saveUploadedNetworkConfig(Path uploadPath); public abstract boolean saveUploadedAprilTagFieldLayout(Path uploadPath); diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/HardwareConfig.java b/photon-core/src/main/java/org/photonvision/common/configuration/HardwareConfig.java index be053241a9..5a17643121 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/HardwareConfig.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/HardwareConfig.java @@ -18,24 +18,13 @@ package org.photonvision.common.configuration; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import java.util.ArrayList; @JsonIgnoreProperties(ignoreUnknown = true) public record HardwareConfig( String deviceName, String deviceLogoPath, String supportURL, - // LED control - - ArrayList ledPins, - String ledSetCommand, - boolean ledsCanDim, - ArrayList ledBrightnessRange, - String ledDimCommand, - String ledBlinkCommand, - ArrayList statusRGBPins, // Metrics - String cpuTempCommand, String cpuMemoryCommand, String cpuUtilCommand, @@ -54,13 +43,6 @@ public HardwareConfig() { "", // deviceName "", // deviceLogoPath "", // supportURL - new ArrayList<>(), // ledPins - "", // ledSetCommand - false, // ledsCanDim - new ArrayList<>(), // ledBrightnessRange - "", // ledDimCommand - "", // ledBlinkCommand - new ArrayList<>(), // statusRGBPins "", // cpuTempCommand "", // cpuMemoryCommand "", // cpuUtilCommand @@ -92,7 +74,6 @@ public final boolean hasCommandsConfigured() { || cpuUptimeCommand != "" || gpuMemoryCommand != "" || ramUtilCommand != "" - || ledBlinkCommand != "" || gpuMemUsageCommand != "" || diskUsageCommand != ""; } diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/HardwareSettings.java b/photon-core/src/main/java/org/photonvision/common/configuration/HardwareSettings.java deleted file mode 100644 index 91dbc4fc65..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/configuration/HardwareSettings.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.configuration; - -public class HardwareSettings { - public int ledBrightnessPercentage = 100; - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ledBrightnessPercentage; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - HardwareSettings other = (HardwareSettings) obj; - if (ledBrightnessPercentage != other.ledBrightnessPercentage) return false; - return true; - } - - @Override - public String toString() { - return "HardwareSettings [ledBrightnessPercentage=" + ledBrightnessPercentage + "]"; - } -} diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/LegacyConfigProvider.java b/photon-core/src/main/java/org/photonvision/common/configuration/LegacyConfigProvider.java index 6feadcab3b..253c2cc9a6 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/LegacyConfigProvider.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/LegacyConfigProvider.java @@ -46,13 +46,11 @@ class LegacyConfigProvider extends ConfigProvider { private static final Logger logger = new Logger(LegacyConfigProvider.class, LogGroup.General); public static final String HW_CFG_FNAME = "hardwareConfig.json"; - public static final String HW_SET_FNAME = "hardwareSettings.json"; public static final String NET_SET_FNAME = "networkSettings.json"; public static final String ATFL_SET_FNAME = "apriltagFieldLayout.json"; private PhotonConfiguration config; private final File hardwareConfigFile; - private final File hardwareSettingsFile; private final File networkConfigFile; private final File camerasFolder; private final File apriltagFieldLayoutFile; @@ -87,8 +85,6 @@ protected LegacyConfigProvider(Path configDirectoryFile) { this.configDirectoryFile = new File(configDirectoryFile.toUri()); this.hardwareConfigFile = new File(Path.of(configDirectoryFile.toString(), HW_CFG_FNAME).toUri()); - this.hardwareSettingsFile = - new File(Path.of(configDirectoryFile.toString(), HW_SET_FNAME).toUri()); this.networkConfigFile = new File(Path.of(configDirectoryFile.toString(), NET_SET_FNAME).toUri()); this.apriltagFieldLayoutFile = @@ -121,7 +117,6 @@ public void load() { } HardwareConfig hardwareConfig; - HardwareSettings hardwareSettings; NetworkConfig networkConfig; AprilTagFieldLayout atfl = null; @@ -142,23 +137,6 @@ public void load() { hardwareConfig = new HardwareConfig(); } - if (hardwareSettingsFile.exists()) { - try { - hardwareSettings = - JacksonUtils.deserialize(hardwareSettingsFile.toPath(), HardwareSettings.class); - if (hardwareSettings == null) { - logger.error("Could not deserialize hardware settings! Loading defaults"); - hardwareSettings = new HardwareSettings(); - } - } catch (IOException e) { - logger.error("Could not deserialize hardware settings! Loading defaults"); - hardwareSettings = new HardwareSettings(); - } - } else { - logger.info("Hardware settings does not exist! Loading defaults"); - hardwareSettings = new HardwareSettings(); - } - if (networkConfigFile.exists()) { try { networkConfig = JacksonUtils.deserialize(networkConfigFile.toPath(), NetworkConfig.class); @@ -215,7 +193,6 @@ public void load() { this.config = new PhotonConfiguration( hardwareConfig, - hardwareSettings, networkConfig, atfl, new NeuralNetworkPropertyManager(), @@ -232,11 +209,6 @@ public boolean saveToDisk() { } catch (IOException e) { logger.error("Could not save network config!", e); } - try { - JacksonUtils.serialize(hardwareSettingsFile.toPath(), config.getHardwareSettings()); - } catch (IOException e) { - logger.error("Could not save hardware config!", e); - } // save all of our cameras var cameraConfigMap = config.getCameraConfigurations(); @@ -432,10 +404,6 @@ public Path getHardwareConfigFile() { return this.hardwareConfigFile.toPath(); } - public Path getHardwareSettingsFile() { - return this.hardwareSettingsFile.toPath(); - } - public Path getNetworkConfigFile() { return this.networkConfigFile.toPath(); } @@ -449,11 +417,6 @@ public boolean saveUploadedHardwareConfig(Path uploadPath) { return FileUtils.replaceFile(uploadPath, this.getHardwareConfigFile()); } - @Override - public boolean saveUploadedHardwareSettings(Path uploadPath) { - return FileUtils.replaceFile(uploadPath, this.getHardwareSettingsFile()); - } - @Override public boolean saveUploadedNetworkConfig(Path uploadPath) { return FileUtils.replaceFile(uploadPath, this.getNetworkConfigFile()); diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/PhotonConfiguration.java b/photon-core/src/main/java/org/photonvision/common/configuration/PhotonConfiguration.java index 9b01cff12f..9d71250709 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/PhotonConfiguration.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/PhotonConfiguration.java @@ -25,7 +25,6 @@ public class PhotonConfiguration { private final HardwareConfig hardwareConfig; - private final HardwareSettings hardwareSettings; private NetworkConfig networkConfig; private AprilTagFieldLayout atfl; private NeuralNetworkPropertyManager neuralNetworkProperties; @@ -33,28 +32,19 @@ public class PhotonConfiguration { public PhotonConfiguration( HardwareConfig hardwareConfig, - HardwareSettings hardwareSettings, NetworkConfig networkConfig, AprilTagFieldLayout atfl, NeuralNetworkPropertyManager neuralNetworkProperties) { - this( - hardwareConfig, - hardwareSettings, - networkConfig, - atfl, - neuralNetworkProperties, - new HashMap<>()); + this(hardwareConfig, networkConfig, atfl, neuralNetworkProperties, new HashMap<>()); } public PhotonConfiguration( HardwareConfig hardwareConfig, - HardwareSettings hardwareSettings, NetworkConfig networkConfig, AprilTagFieldLayout atfl, NeuralNetworkPropertyManager neuralNetworkProperties, HashMap cameraConfigurations) { this.hardwareConfig = hardwareConfig; - this.hardwareSettings = hardwareSettings; this.networkConfig = networkConfig; this.neuralNetworkProperties = neuralNetworkProperties; this.cameraConfigurations = cameraConfigurations; @@ -64,7 +54,6 @@ public PhotonConfiguration( public PhotonConfiguration() { this( new HardwareConfig(), - new HardwareSettings(), new NetworkConfig(), new AprilTagFieldLayout(List.of(), 0, 0), new NeuralNetworkPropertyManager()); @@ -78,10 +67,6 @@ public NetworkConfig getNetworkConfig() { return networkConfig; } - public HardwareSettings getHardwareSettings() { - return hardwareSettings; - } - public AprilTagFieldLayout getApriltagFieldLayout() { return atfl; } @@ -134,8 +119,6 @@ public boolean removeCameraConfig(String name) { public String toString() { return "PhotonConfiguration [\n hardwareConfig=" + hardwareConfig - + "\n hardwareSettings=" - + hardwareSettings + "\n networkConfig=" + networkConfig + "\n atfl=" diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/SqlConfigProvider.java b/photon-core/src/main/java/org/photonvision/common/configuration/SqlConfigProvider.java index b9c6c17ec8..fec5a7c90a 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/SqlConfigProvider.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/SqlConfigProvider.java @@ -54,7 +54,6 @@ public class SqlConfigProvider extends ConfigProvider { static class GlobalKeys { static final String NETWORK_CONFIG = "networkConfig"; static final String HARDWARE_CONFIG = "hardwareConfig"; - static final String HARDWARE_SETTINGS = "hardwareSettings"; static final String ATFL_CONFIG_FILE = "apriltagFieldLayout"; static final String NEURAL_NETWORK_PROPERTIES = "neuralNetworkProperties"; } @@ -261,7 +260,6 @@ public void load() { synchronized (m_mutex) { HardwareConfig hardwareConfig; - HardwareSettings hardwareSettings; NetworkConfig networkConfig; AprilTagFieldLayout atfl; NeuralNetworkPropertyManager nnProps; @@ -275,15 +273,6 @@ public void load() { hardwareConfig = new HardwareConfig(); } - try { - hardwareSettings = - JacksonUtils.deserialize( - getOneConfigFile(conn, GlobalKeys.HARDWARE_SETTINGS), HardwareSettings.class); - } catch (IOException e) { - logger.error("Could not deserialize hardware settings! Loading defaults", e); - hardwareSettings = new HardwareSettings(); - } - try { networkConfig = JacksonUtils.deserialize( @@ -330,9 +319,7 @@ public void load() { logger.error("SQL Err closing connection while loading: ", e); } - this.config = - new PhotonConfiguration( - hardwareConfig, hardwareSettings, networkConfig, atfl, nnProps, cams); + this.config = new PhotonConfiguration(hardwareConfig, networkConfig, atfl, nnProps, cams); } } @@ -452,7 +439,6 @@ private void addFile(PreparedStatement ps, String key, String value) throws SQLE // on. // Thank you for coming to my TED talk. private boolean skipSavingHWCfg = false; - private boolean skipSavingHWSet = false; private boolean skipSavingNWCfg = false; private boolean skipSavingAPRTG = false; private boolean skipSavingNNProps = false; @@ -468,15 +454,6 @@ private void saveGlobal(Connection conn) { "REPLACE INTO %s (%s, %s) VALUES (?,?);", Tables.GLOBAL, Columns.GLB_FILENAME, Columns.GLB_CONTENTS); - if (!skipSavingHWSet) { - statement1 = conn.prepareStatement(sqlString); - addFile( - statement1, - GlobalKeys.HARDWARE_SETTINGS, - JacksonUtils.serializeToString(config.getHardwareSettings())); - statement1.executeUpdate(); - } - if (!skipSavingNWCfg) { statement2 = conn.prepareStatement(sqlString); addFile( @@ -571,12 +548,6 @@ public boolean saveUploadedHardwareConfig(Path uploadPath) { return saveOneFile(GlobalKeys.HARDWARE_CONFIG, uploadPath); } - @Override - public boolean saveUploadedHardwareSettings(Path uploadPath) { - skipSavingHWSet = true; - return saveOneFile(GlobalKeys.HARDWARE_SETTINGS, uploadPath); - } - @Override public boolean saveUploadedNetworkConfig(Path uploadPath) { skipSavingNWCfg = true; diff --git a/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java b/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java index 003b7d3190..b5e6200570 100644 --- a/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java +++ b/photon-core/src/main/java/org/photonvision/common/dataflow/networktables/NetworkTablesManager.java @@ -39,7 +39,6 @@ import org.photonvision.common.dataflow.DataChangeService; import org.photonvision.common.dataflow.events.OutgoingUIEvent; import org.photonvision.common.dataflow.websocket.UIPhotonConfiguration; -import org.photonvision.common.hardware.HardwareManager; import org.photonvision.common.logging.LogGroup; import org.photonvision.common.logging.LogLevel; import org.photonvision.common.logging.Logger; @@ -158,7 +157,6 @@ public void checkNtConnectState(NetworkTableEvent event) { event.connInfo.remote_port, event.connInfo.protocol_version); logger.error(msg); - HardwareManager.getInstance().setNTConnected(false); getInstance().broadcastConnectedStatus(); } else if (isConnEvent && event.connInfo != null) { @@ -169,7 +167,6 @@ public void checkNtConnectState(NetworkTableEvent event) { event.connInfo.remote_port, event.connInfo.protocol_version); logger.info(msg); - HardwareManager.getInstance().setNTConnected(true); ScriptManager.queueEvent(ScriptEventType.kNTConnected); getInstance().broadcastVersion(); diff --git a/photon-core/src/main/java/org/photonvision/common/dataflow/statusLEDs/StatusLEDConsumer.java b/photon-core/src/main/java/org/photonvision/common/dataflow/statusLEDs/StatusLEDConsumer.java deleted file mode 100644 index 5df3c15250..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/dataflow/statusLEDs/StatusLEDConsumer.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.dataflow.statusLEDs; - -import org.photonvision.common.dataflow.CVPipelineResultConsumer; -import org.photonvision.common.hardware.HardwareManager; -import org.photonvision.vision.pipeline.result.CVPipelineResult; - -public class StatusLEDConsumer implements CVPipelineResultConsumer { - private final String uniqueName; - - public StatusLEDConsumer(String uniqueName) { - this.uniqueName = uniqueName; - } - - @Override - public void accept(CVPipelineResult t) { - HardwareManager.getInstance().setTargetsVisibleStatus(this.uniqueName, t.hasTargets()); - } -} diff --git a/photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UILightingConfig.java b/photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UILightingConfig.java deleted file mode 100644 index 57d5579f54..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UILightingConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 . - */ - -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; -} diff --git a/photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UIPhotonConfiguration.java b/photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UIPhotonConfiguration.java index 003f3f135d..cf1f85de03 100644 --- a/photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UIPhotonConfiguration.java +++ b/photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UIPhotonConfiguration.java @@ -47,9 +47,6 @@ public static UIPhotonConfiguration programStateToUi(PhotonConfiguration c) { 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 diff --git a/photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UIProgramSettings.java b/photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UIProgramSettings.java index 16710a1b7b..af4de6f21c 100644 --- a/photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UIProgramSettings.java +++ b/photon-core/src/main/java/org/photonvision/common/dataflow/websocket/UIProgramSettings.java @@ -21,18 +21,13 @@ public class UIProgramSettings { public UIProgramSettings( - UINetConfig networkSettings, - UILightingConfig lighting, - UIGeneralSettings general, - AprilTagFieldLayout atfl) { + UINetConfig networkSettings, UIGeneralSettings general, AprilTagFieldLayout atfl) { this.networkSettings = networkSettings; - this.lighting = lighting; this.general = general; this.atfl = atfl; } public UINetConfig networkSettings; - public UILightingConfig lighting; public UIGeneralSettings general; public AprilTagFieldLayout atfl; } diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/CustomGPIO.java b/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/CustomGPIO.java deleted file mode 100644 index 36c9d28af3..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/CustomGPIO.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.hardware.GPIO; - -import org.photonvision.common.configuration.HardwareConfig; -import org.photonvision.common.hardware.Platform; - -public class CustomGPIO extends GPIOBase { - private boolean currentState; - private final int port; - - public CustomGPIO(int port) { - this.port = port; - } - - @Override - public void togglePin() { - if (this.port != -1) { - execute( - commands - .get("setState") - .replace("{s}", String.valueOf(!currentState)) - .replace("{p}", String.valueOf(this.port))); - currentState = !currentState; - } - } - - @Override - public int getPinNumber() { - return port; - } - - @Override - public void setStateImpl(boolean state) { - if (this.port != -1) { - execute( - commands - .get("setState") - .replace("{s}", String.valueOf(state)) - .replace("{p}", String.valueOf(port))); - currentState = state; - } - } - - @Override - public boolean shutdown() { - if (this.port != -1) { - execute(commands.get("shutdown")); - return true; - } - return false; - } - - @Override - public boolean getStateImpl() { - return currentState; - } - - @Override - public void blinkImpl(int pulseTimeMillis, int blinks) { - execute( - commands - .get("blink") - .replace("{pulseTime}", String.valueOf(pulseTimeMillis)) - .replace("{blinks}", String.valueOf(blinks)) - .replace("{p}", String.valueOf(this.port))); - } - - @Override - public void setBrightnessImpl(int brightness) { - execute( - commands - .get("dim") - .replace("{p}", String.valueOf(port)) - .replace("{v}", String.valueOf(brightness))); - } - - public static void setConfig(HardwareConfig config) { - if (Platform.isRaspberryPi()) return; - commands.replace("setState", config.ledSetCommand()); - commands.replace("dim", config.ledDimCommand()); - commands.replace("blink", config.ledBlinkCommand()); - } -} diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/GPIOBase.java b/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/GPIOBase.java deleted file mode 100644 index a1d25be98f..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/GPIOBase.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.hardware.GPIO; - -import java.util.Arrays; -import java.util.HashMap; -import org.photonvision.common.logging.LogGroup; -import org.photonvision.common.logging.Logger; -import org.photonvision.common.util.ShellExec; - -public abstract class GPIOBase { - private static final Logger logger = new Logger(GPIOBase.class, LogGroup.General); - private static final ShellExec runCommand = new ShellExec(true, true); - - protected static HashMap commands = - new HashMap<>() { - { - put("setState", ""); - put("shutdown", ""); - put("dim", ""); - put("blink", ""); - } - }; - - protected static String execute(String command) { - try { - runCommand.executeBashCommand(command); - } catch (Exception e) { - logger.error(Arrays.toString(e.getStackTrace())); - return ""; - } - return runCommand.getOutput(); - } - - public abstract int getPinNumber(); - - public void setState(boolean state) { - if (getPinNumber() != -1) { - setStateImpl(state); - } - } - - protected abstract void setStateImpl(boolean state); - - public final void setOff() { - setState(false); - } - - public final void setOn() { - setState(true); - } - - public void togglePin() { - setState(!getStateImpl()); - } - - public abstract boolean shutdown(); - - public final boolean getState() { - if (getPinNumber() != -1) { - return getStateImpl(); - } else return false; - } - - public abstract boolean getStateImpl(); - - public final void blink(int pulseTimeMillis, int blinks) { - if (getPinNumber() != -1) { - blinkImpl(pulseTimeMillis, blinks); - } - } - - protected abstract void blinkImpl(int pulseTimeMillis, int blinks); - - public final void setBrightness(int brightness) { - if (getPinNumber() != -1) { - if (brightness > 100) brightness = 100; - if (brightness < 0) brightness = 0; - setBrightnessImpl(brightness); - } - } - - protected abstract void setBrightnessImpl(int brightness); -} diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioCommand.java b/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioCommand.java deleted file mode 100644 index 4d2c24eecc..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioCommand.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.hardware.GPIO.pi; - -@SuppressWarnings("SpellCheckingInspection") -public enum PigpioCommand { - PCMD_READ(3), // int gpio_read(unsigned gpio) - PCMD_WRITE(4), // int gpio_write(unsigned gpio, unsigned level) - PCMD_WVCLR(27), // int wave_clear(void) - PCMD_WVAG(28), // int wave_add_generic(unsigned numPulses, gpioPulse_t *pulses) - PCMD_WVHLT(33), // int wave_tx_stop(void) - PCMD_WVCRE(49), // int wave_create(void) - PCMD_WVDEL(50), // int wave_delete(unsigned wave_id) - PCMD_WVTX(51), // int wave_tx_send(unsigned wave_id) (once) - PCMD_WVTXR(52), // int wave_tx_send(unsigned wave_id) (repeat) - PCMD_GDC(83), // int get_duty_cycle(unsigned user_gpio) - PCMD_HP(86), // int hardware_pwm(unsigned gpio, unsigned PWMfreq, unsigned PWMduty) - PCMD_WVTXM(100); // int wave_tx_send(unsigned wave_id, unsigned wave_mode) - - public final int value; - - PigpioCommand(int value) { - this.value = value; - } -} diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioException.java b/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioException.java deleted file mode 100644 index 3ad737777d..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioException.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.hardware.GPIO.pi; - -import java.util.HashMap; - -/** - * A class that defines the exceptions that can be thrown by Pigpio. - * - *

Credit to nkolban - * https://github.com/nkolban/jpigpio/blob/master/JPigpio/src/jpigpio/PigpioException.java - */ -@SuppressWarnings({"SpellCheckingInspection", "unused", "RedundantSuppression"}) -public class PigpioException extends Exception { - private int rc = -99999999; - private static final long serialVersionUID = 443595760654129068L; - - public PigpioException() { - super(); - } - - public PigpioException(int rc) { - super(); - this.rc = rc; - } - - public PigpioException(int rc, String msg) { - super(msg); - this.rc = rc; - } - - public PigpioException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { - super(arg0, arg1, arg2, arg3); - } - - public PigpioException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - public PigpioException(String arg0) { - super(arg0); - } - - public PigpioException(Throwable arg0) { - super(arg0); - } - - @Override - public String getMessage() { - return "(" + rc + ") " + getMessageForError(rc); - } - - /** - * Retrieve the error code that was returned by the underlying Pigpio call. - * - * @return The error code that was returned by the underlying Pigpio call. - */ - public int getErrorCode() { - return rc; - } // End of getErrorCode - - // Public constants for the error codes that can be thrown by Pigpio - public static final int PI_INIT_FAILED = -1; // gpioInitialise failed - public static final int PI_BAD_USER_GPIO = -2; // gpio not 0-31 - public static final int PI_BAD_GPIO = -3; // gpio not 0-53 - public static final int PI_BAD_MODE = -4; // mode not 0-7 - public static final int PI_BAD_LEVEL = -5; // level not 0-1 - public static final int PI_BAD_PUD = -6; // pud not 0-2 - public static final int PI_BAD_PULSEWIDTH = -7; // pulsewidth not 0 or 500-2500 - public static final int PI_BAD_DUTYCYCLE = -8; // dutycycle outside set range - public static final int PI_BAD_TIMER = -9; // timer not 0-9 - public static final int PI_BAD_MS = -10; // ms not 10-60000 - public static final int PI_BAD_TIMETYPE = -11; // timetype not 0-1 - public static final int PI_BAD_SECONDS = -12; // seconds < 0 - public static final int PI_BAD_MICROS = -13; // micros not 0-999999 - public static final int PI_TIMER_FAILED = -14; // gpioSetTimerFunc failed - public static final int PI_BAD_WDOG_TIMEOUT = -15; // timeout not 0-60000 - public static final int PI_NO_ALERT_FUNC = -16; // DEPRECATED - public static final int PI_BAD_CLK_PERIPH = -17; // clock peripheral not 0-1 - public static final int PI_BAD_CLK_SOURCE = -18; // DEPRECATED - public static final int PI_BAD_CLK_MICROS = -19; // clock micros not 1, 2, 4, 5, 8, or 10 - public static final int PI_BAD_BUF_MILLIS = -20; // buf millis not 100-10000 - public static final int PI_BAD_DUTYRANGE = -21; // dutycycle range not 25-40000 - public static final int PI_BAD_DUTY_RANGE = -21; // DEPRECATED (use PI_BAD_DUTYRANGE) - public static final int PI_BAD_SIGNUM = -22; // signum not 0-63 - public static final int PI_BAD_PATHNAME = -23; // can't open pathname - public static final int PI_NO_HANDLE = -24; // no handle available - public static final int PI_BAD_HANDLE = -25; // unknown handle - public static final int PI_BAD_IF_FLAGS = -26; // ifFlags > 3 - public static final int PI_BAD_CHANNEL = -27; // DMA channel not 0-14 - public static final int PI_BAD_PRIM_CHANNEL = -27; // DMA primary channel not 0-14 - public static final int PI_BAD_SOCKET_PORT = -28; // socket port not 1024-32000 - public static final int PI_BAD_FIFO_COMMAND = -29; // unrecognized fifo command - public static final int PI_BAD_SECO_CHANNEL = -30; // DMA secondary channel not 0-6 - public static final int PI_NOT_INITIALISED = -31; // function called before gpioInitialise - public static final int PI_INITIALISED = -32; // function called after gpioInitialise - public static final int PI_BAD_WAVE_MODE = -33; // waveform mode not 0-1 - public static final int PI_BAD_CFG_INTERNAL = -34; // bad parameter in gpioCfgInternals call - public static final int PI_BAD_WAVE_BAUD = -35; // baud rate not 50-250K(RX)/50-1M(TX) - public static final int PI_TOO_MANY_PULSES = -36; // waveform has too many pulses - public static final int PI_TOO_MANY_CHARS = -37; // waveform has too many chars - public static final int PI_NOT_SERIAL_GPIO = -38; // no serial read in progress on gpio - public static final int PI_BAD_SERIAL_STRUC = -39; // bad (null) serial structure parameter - public static final int PI_BAD_SERIAL_BUF = -40; // bad (null) serial buf parameter - public static final int PI_NOT_PERMITTED = -41; // gpio operation not permitted - public static final int PI_SOME_PERMITTED = -42; // one or more gpios not permitted - public static final int PI_BAD_WVSC_COMMND = -43; // bad WVSC subcommand - public static final int PI_BAD_WVSM_COMMND = -44; // bad WVSM subcommand - public static final int PI_BAD_WVSP_COMMND = -45; // bad WVSP subcommand - public static final int PI_BAD_PULSELEN = -46; // trigger pulse length not 1-100 - public static final int PI_BAD_SCRIPT = -47; // invalid script - public static final int PI_BAD_SCRIPT_ID = -48; // unknown script id - public static final int PI_BAD_SER_OFFSET = -49; // add serial data offset > 30 minutes - public static final int PI_GPIO_IN_USE = -50; // gpio already in use - public static final int PI_BAD_SERIAL_COUNT = -51; // must read at least a byte at a time - public static final int PI_BAD_PARAM_NUM = -52; // script parameter id not 0-9 - public static final int PI_DUP_TAG = -53; // script has duplicate tag - public static final int PI_TOO_MANY_TAGS = -54; // script has too many tags - public static final int PI_BAD_SCRIPT_CMD = -55; // illegal script command - public static final int PI_BAD_VAR_NUM = -56; // script variable id not 0-149 - public static final int PI_NO_SCRIPT_ROOM = -57; // no more room for scripts - public static final int PI_NO_MEMORY = -58; // can't allocate temporary memory - public static final int PI_SOCK_READ_FAILED = -59; // socket read failed - public static final int PI_SOCK_WRIT_FAILED = -60; // socket write failed - public static final int PI_TOO_MANY_PARAM = -61; // too many script parameters (> 10) - public static final int PI_NOT_HALTED = -62; // script already running or failed - public static final int PI_BAD_TAG = -63; // script has unresolved tag - public static final int PI_BAD_MICS_DELAY = -64; // bad MICS delay (too large) - public static final int PI_BAD_MILS_DELAY = -65; // bad MILS delay (too large) - public static final int PI_BAD_WAVE_ID = -66; // non existent wave id - public static final int PI_TOO_MANY_CBS = -67; // No more CBs for waveform - public static final int PI_TOO_MANY_OOL = -68; // No more OOL for waveform - public static final int PI_EMPTY_WAVEFORM = -69; // attempt to create an empty waveform - public static final int PI_NO_WAVEFORM_ID = -70; // no more waveforms - public static final int PI_I2C_OPEN_FAILED = -71; // can't open I2C device - public static final int PI_SER_OPEN_FAILED = -72; // can't open serial device - public static final int PI_SPI_OPEN_FAILED = -73; // can't open SPI device - public static final int PI_BAD_I2C_BUS = -74; // bad I2C bus - public static final int PI_BAD_I2C_ADDR = -75; // bad I2C address - public static final int PI_BAD_SPI_CHANNEL = -76; // bad SPI channel - public static final int PI_BAD_FLAGS = -77; // bad i2c/spi/ser open flags - public static final int PI_BAD_SPI_SPEED = -78; // bad SPI speed - public static final int PI_BAD_SER_DEVICE = -79; // bad serial device name - public static final int PI_BAD_SER_SPEED = -80; // bad serial baud rate - public static final int PI_BAD_PARAM = -81; // bad i2c/spi/ser parameter - public static final int PI_I2C_WRITE_FAILED = -82; // i2c write failed - public static final int PI_I2C_READ_FAILED = -83; // i2c read failed - public static final int PI_BAD_SPI_COUNT = -84; // bad SPI count - public static final int PI_SER_WRITE_FAILED = -85; // ser write failed - public static final int PI_SER_READ_FAILED = -86; // ser read failed - public static final int PI_SER_READ_NO_DATA = -87; // ser read no data available - public static final int PI_UNKNOWN_COMMAND = -88; // unknown command - public static final int PI_SPI_XFER_FAILED = -89; // spi xfer/read/write failed - public static final int PI_BAD_POINTER = -90; // bad (NULL) pointer - public static final int PI_NO_AUX_SPI = -91; // need a A+/B+/Pi2 for auxiliary SPI - public static final int PI_NOT_PWM_GPIO = -92; // gpio is not in use for PWM - public static final int PI_NOT_SERVO_GPIO = -93; // gpio is not in use for servo pulses - public static final int PI_NOT_HCLK_GPIO = -94; // gpio has no hardware clock - public static final int PI_NOT_HPWM_GPIO = -95; // gpio has no hardware PWM - public static final int PI_BAD_HPWM_FREQ = -96; // hardware PWM frequency not 1-125M - public static final int PI_BAD_HPWM_DUTY = -97; // hardware PWM dutycycle not 0-1M - public static final int PI_BAD_HCLK_FREQ = -98; // hardware clock frequency not 4689-250M - public static final int PI_BAD_HCLK_PASS = -99; // need password to use hardware clock 1 - public static final int PI_HPWM_ILLEGAL = -100; // illegal, PWM in use for main clock - public static final int PI_BAD_DATABITS = -101; // serial data bits not 1-32 - public static final int PI_BAD_STOPBITS = -102; // serial (half) stop bits not 2-8 - public static final int PI_MSG_TOOBIG = -103; // socket/pipe message too big - public static final int PI_BAD_MALLOC_MODE = -104; // bad memory allocation mode - public static final int PI_TOO_MANY_SEGS = -105; // too many I2C transaction parts - public static final int PI_BAD_I2C_SEG = -106; // a combined I2C transaction failed - public static final int PI_BAD_SMBUS_CMD = -107; - public static final int PI_NOT_I2C_GPIO = -108; - public static final int PI_BAD_I2C_WLEN = -109; - public static final int PI_BAD_I2C_RLEN = -110; - public static final int PI_BAD_I2C_CMD = -111; - public static final int PI_BAD_I2C_BAUD = -112; - public static final int PI_CHAIN_LOOP_CNT = -113; - public static final int PI_BAD_CHAIN_LOOP = -114; - public static final int PI_CHAIN_COUNTER = -115; - public static final int PI_BAD_CHAIN_CMD = -116; - public static final int PI_BAD_CHAIN_DELAY = -117; - public static final int PI_CHAIN_NESTING = -118; - public static final int PI_CHAIN_TOO_BIG = -119; - public static final int PI_DEPRECATED = -120; - public static final int PI_BAD_SER_INVERT = -121; - public static final int PI_BAD_EDGE = -122; - public static final int PI_BAD_ISR_INIT = -123; - public static final int PI_BAD_FOREVER = -124; - public static final int PI_BAD_FILTER = -125; - - public static final int PI_PIGIF_ERR_0 = -2000; - public static final int PI_PIGIF_ERR_99 = -2099; - - public static final int PI_CUSTOM_ERR_0 = -3000; - public static final int PI_CUSTOM_ERR_999 = -3999; - - private static final HashMap errorMessages = new HashMap<>(); - - static { - errorMessages.put(PI_INIT_FAILED, "pigpio initialisation failed"); - errorMessages.put(PI_BAD_USER_GPIO, "GPIO not 0-31"); - errorMessages.put(PI_BAD_GPIO, "GPIO not 0-53"); - errorMessages.put(PI_BAD_MODE, "mode not 0-7"); - errorMessages.put(PI_BAD_LEVEL, "level not 0-1"); - errorMessages.put(PI_BAD_PUD, "pud not 0-2"); - errorMessages.put(PI_BAD_PULSEWIDTH, "pulsewidth not 0 or 500-2500"); - errorMessages.put(PI_BAD_DUTYCYCLE, "dutycycle not 0-range (default 255)"); - errorMessages.put(PI_BAD_TIMER, "timer not 0-9"); - errorMessages.put(PI_BAD_MS, "ms not 10-60000"); - errorMessages.put(PI_BAD_TIMETYPE, "timetype not 0-1"); - errorMessages.put(PI_BAD_SECONDS, "seconds < 0"); - errorMessages.put(PI_BAD_MICROS, "micros not 0-999999"); - errorMessages.put(PI_TIMER_FAILED, "gpioSetTimerFunc failed"); - errorMessages.put(PI_BAD_WDOG_TIMEOUT, "timeout not 0-60000"); - errorMessages.put(PI_NO_ALERT_FUNC, "DEPRECATED"); - errorMessages.put(PI_BAD_CLK_PERIPH, "clock peripheral not 0-1"); - errorMessages.put(PI_BAD_CLK_SOURCE, "DEPRECATED"); - errorMessages.put(PI_BAD_CLK_MICROS, "clock micros not 1, 2, 4, 5, 8, or 10"); - errorMessages.put(PI_BAD_BUF_MILLIS, "buf millis not 100-10000"); - errorMessages.put(PI_BAD_DUTYRANGE, "dutycycle range not 25-40000"); - errorMessages.put(PI_BAD_SIGNUM, "signum not 0-63"); - errorMessages.put(PI_BAD_PATHNAME, "can't open pathname"); - errorMessages.put(PI_NO_HANDLE, "no handle available"); - errorMessages.put(PI_BAD_HANDLE, "unknown handle"); - errorMessages.put(PI_BAD_IF_FLAGS, "ifFlags > 3"); - errorMessages.put(PI_BAD_CHANNEL, "DMA channel not 0-14"); - errorMessages.put(PI_BAD_SOCKET_PORT, "socket port not 1024-30000"); - errorMessages.put(PI_BAD_FIFO_COMMAND, "unknown fifo command"); - errorMessages.put(PI_BAD_SECO_CHANNEL, "DMA secondary channel not 0-14"); - errorMessages.put(PI_NOT_INITIALISED, "function called before gpioInitialise"); - errorMessages.put(PI_INITIALISED, "function called after gpioInitialise"); - errorMessages.put(PI_BAD_WAVE_MODE, "waveform mode not 0-1"); - errorMessages.put(PI_BAD_CFG_INTERNAL, "bad parameter in gpioCfgInternals call"); - errorMessages.put(PI_BAD_WAVE_BAUD, "baud rate not 50-250000(RX)/1000000(TX)"); - errorMessages.put(PI_TOO_MANY_PULSES, "waveform has too many pulses"); - errorMessages.put(PI_TOO_MANY_CHARS, "waveform has too many chars"); - errorMessages.put(PI_NOT_SERIAL_GPIO, "no bit bang serial read in progress on GPIO"); - errorMessages.put(PI_NOT_PERMITTED, "no permission to update GPIO"); - errorMessages.put(PI_SOME_PERMITTED, "no permission to update one or more GPIO"); - errorMessages.put(PI_BAD_WVSC_COMMND, "bad WVSC subcommand"); - errorMessages.put(PI_BAD_WVSM_COMMND, "bad WVSM subcommand"); - errorMessages.put(PI_BAD_WVSP_COMMND, "bad WVSP subcommand"); - errorMessages.put(PI_BAD_PULSELEN, "trigger pulse length not 1-100"); - errorMessages.put(PI_BAD_SCRIPT, "invalid script"); - errorMessages.put(PI_BAD_SCRIPT_ID, "unknown script id"); - errorMessages.put(PI_BAD_SER_OFFSET, "add serial data offset > 30 minute"); - errorMessages.put(PI_GPIO_IN_USE, "GPIO already in use"); - errorMessages.put(PI_BAD_SERIAL_COUNT, "must read at least a byte at a time"); - errorMessages.put(PI_BAD_PARAM_NUM, "script parameter id not 0-9"); - errorMessages.put(PI_DUP_TAG, "script has duplicate tag"); - errorMessages.put(PI_TOO_MANY_TAGS, "script has too many tags"); - errorMessages.put(PI_BAD_SCRIPT_CMD, "illegal script command"); - errorMessages.put(PI_BAD_VAR_NUM, "script variable id not 0-149"); - errorMessages.put(PI_NO_SCRIPT_ROOM, "no more room for scripts"); - errorMessages.put(PI_NO_MEMORY, "can't allocate temporary memory"); - errorMessages.put(PI_SOCK_READ_FAILED, "socket read failed"); - errorMessages.put(PI_SOCK_WRIT_FAILED, "socket write failed"); - errorMessages.put(PI_TOO_MANY_PARAM, "too many script parameters (> 10)"); - errorMessages.put(PI_NOT_HALTED, "script already running or failed"); - errorMessages.put(PI_BAD_TAG, "script has unresolved tag"); - errorMessages.put(PI_BAD_MICS_DELAY, "bad MICS delay (too large)"); - errorMessages.put(PI_BAD_MILS_DELAY, "bad MILS delay (too large)"); - errorMessages.put(PI_BAD_WAVE_ID, "non existent wave id"); - errorMessages.put(PI_TOO_MANY_CBS, "No more CBs for waveform"); - errorMessages.put(PI_TOO_MANY_OOL, "No more OOL for waveform"); - errorMessages.put(PI_EMPTY_WAVEFORM, "attempt to create an empty waveform"); - errorMessages.put(PI_NO_WAVEFORM_ID, "No more waveform ids"); - errorMessages.put(PI_I2C_OPEN_FAILED, "can't open I2C device"); - errorMessages.put(PI_SER_OPEN_FAILED, "can't open serial device"); - errorMessages.put(PI_SPI_OPEN_FAILED, "can't open SPI device"); - errorMessages.put(PI_BAD_I2C_BUS, "bad I2C bus"); - errorMessages.put(PI_BAD_I2C_ADDR, "bad I2C address"); - errorMessages.put(PI_BAD_SPI_CHANNEL, "bad SPI channel"); - errorMessages.put(PI_BAD_FLAGS, "bad i2c/spi/ser open flags"); - errorMessages.put(PI_BAD_SPI_SPEED, "bad SPI speed"); - errorMessages.put(PI_BAD_SER_DEVICE, "bad serial device name"); - errorMessages.put(PI_BAD_SER_SPEED, "bad serial baud rate"); - errorMessages.put(PI_BAD_PARAM, "bad i2c/spi/ser parameter"); - errorMessages.put(PI_I2C_WRITE_FAILED, "I2C write failed"); - errorMessages.put(PI_I2C_READ_FAILED, "I2C read failed"); - errorMessages.put(PI_BAD_SPI_COUNT, "bad SPI count"); - errorMessages.put(PI_SER_WRITE_FAILED, "ser write failed"); - errorMessages.put(PI_SER_READ_FAILED, "ser read failed"); - errorMessages.put(PI_SER_READ_NO_DATA, "ser read no data available"); - errorMessages.put(PI_UNKNOWN_COMMAND, "unknown command"); - errorMessages.put(PI_SPI_XFER_FAILED, "SPI xfer/read/write failed"); - errorMessages.put(PI_BAD_POINTER, "bad (NULL) pointer"); - errorMessages.put(PI_NO_AUX_SPI, "no auxiliary SPI on Pi A or B"); - errorMessages.put(PI_NOT_PWM_GPIO, "GPIO is not in use for PWM"); - errorMessages.put(PI_NOT_SERVO_GPIO, "GPIO is not in use for servo pulses"); - errorMessages.put(PI_NOT_HCLK_GPIO, "GPIO has no hardware clock"); - errorMessages.put(PI_NOT_HPWM_GPIO, "GPIO has no hardware PWM"); - errorMessages.put(PI_BAD_HPWM_FREQ, "hardware PWM frequency not 1-125M"); - errorMessages.put(PI_BAD_HPWM_DUTY, "hardware PWM dutycycle not 0-1M"); - errorMessages.put(PI_BAD_HCLK_FREQ, "hardware clock frequency not 4689-250M"); - errorMessages.put(PI_BAD_HCLK_PASS, "need password to use hardware clock 1"); - errorMessages.put(PI_HPWM_ILLEGAL, "illegal, PWM in use for main clock"); - errorMessages.put(PI_BAD_DATABITS, "serial data bits not 1-32"); - errorMessages.put(PI_BAD_STOPBITS, "serial (half) stop bits not 2-8"); - errorMessages.put(PI_MSG_TOOBIG, "socket/pipe message too big"); - errorMessages.put(PI_BAD_MALLOC_MODE, "bad memory allocation mode"); - errorMessages.put(PI_TOO_MANY_SEGS, "too many I2C transaction segments"); - errorMessages.put(PI_BAD_I2C_SEG, "an I2C transaction segment failed"); - errorMessages.put(PI_BAD_SMBUS_CMD, "SMBus command not supported"); - errorMessages.put(PI_NOT_I2C_GPIO, "no bit bang I2C in progress on GPIO"); - errorMessages.put(PI_BAD_I2C_WLEN, "bad I2C write length"); - errorMessages.put(PI_BAD_I2C_RLEN, "bad I2C read length"); - errorMessages.put(PI_BAD_I2C_CMD, "bad I2C command"); - errorMessages.put(PI_BAD_I2C_BAUD, "bad I2C baud rate, not 50-500k"); - errorMessages.put(PI_CHAIN_LOOP_CNT, "bad chain loop count"); - errorMessages.put(PI_BAD_CHAIN_LOOP, "empty chain loop"); - errorMessages.put(PI_CHAIN_COUNTER, "too many chain counters"); - errorMessages.put(PI_BAD_CHAIN_CMD, "bad chain command"); - errorMessages.put(PI_BAD_CHAIN_DELAY, "bad chain delay micros"); - errorMessages.put(PI_CHAIN_NESTING, "chain counters nested too deeply"); - errorMessages.put(PI_CHAIN_TOO_BIG, "chain is too long"); - errorMessages.put(PI_DEPRECATED, "deprecated function removed"); - errorMessages.put(PI_BAD_SER_INVERT, "bit bang serial invert not 0 or 1"); - errorMessages.put(PI_BAD_EDGE, "bad ISR edge value, not 0-2"); - errorMessages.put(PI_BAD_ISR_INIT, "bad ISR initialisation"); - errorMessages.put(PI_BAD_FOREVER, "loop forever must be last chain command"); - errorMessages.put(PI_BAD_FILTER, "bad filter parameter"); - } - - public static String getMessageForError(int errorCode) { - return errorMessages.get(errorCode); - } -} diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioPin.java b/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioPin.java deleted file mode 100644 index 2e0cc6f0c5..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioPin.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.hardware.GPIO.pi; - -import org.photonvision.common.hardware.GPIO.GPIOBase; -import org.photonvision.common.logging.LogGroup; -import org.photonvision.common.logging.Logger; - -public class PigpioPin extends GPIOBase { - public static final Logger logger = new Logger(PigpioPin.class, LogGroup.General); - private static final PigpioSocket piSocket = new PigpioSocket(); - - private final boolean isHardwarePWMPin; - private final int pinNo; - - private boolean hasFailedHardwarePWM; - - public PigpioPin(int pinNo) { - isHardwarePWMPin = pinNo == 12 || pinNo == 13 || pinNo == 17 || pinNo == 18; - this.pinNo = pinNo; - } - - @Override - public int getPinNumber() { - return pinNo; - } - - @Override - protected void setStateImpl(boolean state) { - try { - piSocket.gpioWrite(pinNo, state); - } catch (PigpioException e) { - logger.error("gpioWrite FAIL - " + e.getMessage()); - } - } - - @Override - public boolean shutdown() { - setState(false); - return true; - } - - @Override - public boolean getStateImpl() { - try { - return piSocket.gpioRead(pinNo); - } catch (PigpioException e) { - logger.error("gpioRead FAIL - " + e.getMessage()); - return false; - } - } - - @Override - protected void blinkImpl(int pulseTimeMillis, int blinks) { - try { - piSocket.generateAndSendWaveform(pulseTimeMillis, blinks, pinNo); - } catch (PigpioException e) { - logger.error("Could not set blink - " + e.getMessage()); - } - } - - @Override - protected void setBrightnessImpl(int brightness) { - if (isHardwarePWMPin) { - try { - piSocket.hardwarePWM(pinNo, 22000, (int) (1000000 * (brightness / 100.0))); - } catch (PigpioException e) { - logger.error("Failed to hardPWM - " + e.getMessage()); - } - } else if (!hasFailedHardwarePWM) { - logger.warn( - "Specified pin (" - + pinNo - + ") is not capable of hardware PWM - no action will be taken."); - hasFailedHardwarePWM = true; - } - } -} diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioPulse.java b/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioPulse.java deleted file mode 100644 index 6d0ff0d1ea..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioPulse.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.hardware.GPIO.pi; - -public class PigpioPulse { - int gpioOn; - int gpioOff; - int delayMicros; - - /** - * Initialises a pulse. - * - * @param gpioOn GPIO number to switch on at the start of the pulse. If zero, then no GPIO will be - * switched on. - * @param gpioOff GPIO number to switch off at the start of the pulse. If zero, then no GPIO will - * be switched off. - * @param delayMicros the delay in microseconds before the next pulse. - */ - public PigpioPulse(int gpioOn, int gpioOff, int delayMicros) { - this.gpioOn = gpioOn != 0 ? 1 << gpioOn : 0; - this.gpioOff = gpioOff != 0 ? 1 << gpioOff : 0; - this.delayMicros = delayMicros; - } -} diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioSocket.java b/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioSocket.java deleted file mode 100644 index f495a9d510..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioSocket.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.hardware.GPIO.pi; - -import static org.photonvision.common.hardware.GPIO.pi.PigpioException.*; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import org.photonvision.common.logging.LogGroup; -import org.photonvision.common.logging.Logger; - -@SuppressWarnings({"SpellCheckingInspection", "unused"}) -public class PigpioSocket { - private static final Logger logger = new Logger(PigpioSocket.class, LogGroup.General); - private static final int PIGPIOD_MESSAGE_SIZE = 12; - - private PigpioSocketLock commandSocket; - private int activeWaveformID = -1; - - /** Creates and starts a socket connection to a pigpio daemon on localhost */ - public PigpioSocket() { - this("127.0.0.1", 8888); - } - - /** - * Creates and starts a socket connection to a pigpio daemon on a remote host with the specified - * address and port - * - * @param addr Address of remote pigpio daemon - * @param port Port of remote pigpio daemon - */ - public PigpioSocket(String addr, int port) { - try { - commandSocket = new PigpioSocketLock(addr, port); - } catch (IOException e) { - logger.error("Failed to create or connect to Pigpio Daemon socket", e); - } - } - - /** - * Reconnects to the pigpio daemon - * - * @throws PigpioException on failure - */ - public void reconnect() throws PigpioException { - try { - commandSocket.reconnect(); - } catch (IOException e) { - logger.error("Failed to reconnect to Pigpio Daemon socket", e); - throw new PigpioException("reconnect", e); - } - } - - /** - * Terminates the connection to the pigpio daemon - * - * @throws PigpioException on failure - */ - public void gpioTerminate() throws PigpioException { - try { - commandSocket.terminate(); - } catch (IOException e) { - logger.error("Failed to terminate connection to Pigpio Daemon socket", e); - throw new PigpioException("gpioTerminate", e); - } - } - - /** - * Read the GPIO level - * - * @param pin Pin to read from - * @return Value of the pin - * @throws PigpioException on failure - */ - public boolean gpioRead(int pin) throws PigpioException { - try { - int retCode = commandSocket.sendCmd(PigpioCommand.PCMD_READ.value, pin); - if (retCode < 0) throw new PigpioException(retCode); - return retCode != 0; - } catch (IOException e) { - logger.error("Failed to read GPIO pin: " + pin, e); - throw new PigpioException("gpioRead", e); - } - } - - /** - * Write the GPIO level - * - * @param pin Pin to write to - * @param value Value to write - * @throws PigpioException on failure - */ - public void gpioWrite(int pin, boolean value) throws PigpioException { - try { - int retCode = commandSocket.sendCmd(PigpioCommand.PCMD_WRITE.value, pin, value ? 1 : 0); - if (retCode < 0) throw new PigpioException(retCode); - } catch (IOException e) { - logger.error("Failed to write to GPIO pin: " + pin, e); - throw new PigpioException("gpioWrite", e); - } - } - - /** - * Clears all waveforms and any data added by calls to {@link #waveAddGeneric(ArrayList)} - * - * @throws PigpioException on failure - */ - public void waveClear() throws PigpioException { - try { - int retCode = commandSocket.sendCmd(PigpioCommand.PCMD_WVCLR.value); - if (retCode < 0) throw new PigpioException(retCode); - } catch (IOException e) { - logger.error("Failed to clear waveforms", e); - throw new PigpioException("waveClear", e); - } - } - - /** - * Adds a number of pulses to the current waveform - * - * @param pulses ArrayList of pulses to add - * @return the new total number of pulses in the current waveform - * @throws PigpioException on failure - */ - private int waveAddGeneric(ArrayList pulses) throws PigpioException { - // pigpio wave message format - - // I p1 0 - // I p2 0 - // I p3 pulses * 12 - // ## extension ## - // III on/off/delay * pulses - - if (pulses == null || pulses.isEmpty()) return 0; - - try { - ByteBuffer bb = ByteBuffer.allocate(pulses.size() * 12); - bb.order(ByteOrder.LITTLE_ENDIAN); - for (var pulse : pulses) { - bb.putInt(pulse.gpioOn).putInt(pulse.gpioOff).putInt(pulse.delayMicros); - } - - int retCode = - commandSocket.sendCmd( - PigpioCommand.PCMD_WVAG.value, - 0, - 0, - pulses.size() * PIGPIOD_MESSAGE_SIZE, - bb.array()); - if (retCode < 0) throw new PigpioException(retCode); - - return retCode; - } catch (IOException e) { - logger.error("Failed to add pulse(s) to waveform", e); - throw new PigpioException("waveAddGeneric", e); - } - } - - /** - * Creates pulses and adds them to the current waveform - * - * @param pulseTimeMillis Pulse length in milliseconds - * @param blinks Number of times to pulse. -1 for repeat - * @param pinNo Pin to pulse - */ - private void addBlinkPulsesToWaveform(int pulseTimeMillis, int blinks, int pinNo) { - boolean repeat = blinks == -1; - - if (blinks == 0) return; - - if (repeat) { - blinks = 1; - } - - try { - ArrayList pulses = new ArrayList<>(); - var startPulse = new PigpioPulse(pinNo, 0, pulseTimeMillis * 1000); - var endPulse = new PigpioPulse(0, pinNo, pulseTimeMillis * 1000); - - for (int i = 0; i < blinks; i++) { - pulses.add(startPulse); - pulses.add(endPulse); - } - - waveAddGeneric(pulses); - pulses.clear(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * Generates and sends a waveform to the given pins with the specified parameters. - * - * @param pulseTimeMillis Pulse length in milliseconds - * @param blinks Number of times to pulse. -1 for repeat - * @param pins Pins to pulse - * @throws PigpioException on failure - */ - public void generateAndSendWaveform(int pulseTimeMillis, int blinks, int... pins) - throws PigpioException { - if (pins.length == 0) return; - boolean repeat = blinks == -1; - if (blinks == 0) return; - - // stop any active waves - waveTxStop(); - waveClear(); - - if (activeWaveformID != -1) { - waveDelete(activeWaveformID); - activeWaveformID = -1; - } - - for (int pin : pins) { - addBlinkPulsesToWaveform(pulseTimeMillis, blinks, pin); - } - - int waveformId = waveCreate(); - - if (waveformId >= 0) { - if (repeat) { - waveSendRepeat(waveformId); - } else { - waveSendOnce(waveformId); - } - } else { - logger.error("Failed to send wave: " + getMessageForError(waveformId)); - } - } - - /** - * Stops the transmission of the current waveform - * - * @return success - * @throws PigpioException on failure - */ - public boolean waveTxStop() throws PigpioException { - try { - int retCode = commandSocket.sendCmd(PigpioCommand.PCMD_WVHLT.value); - if (retCode < 0) throw new PigpioException(retCode); - return retCode == 0; - } catch (IOException e) { - logger.error("Failed to stop waveform", e); - throw new PigpioException("waveTxStop", e); - } - } - - /** - * Creates a waveform from the data provided by the prior calls to {@link - * #waveAddGeneric(ArrayList)} Upon success a wave ID greater than or equal to 0 is returned - * - * @return ID of the created waveform - * @throws PigpioException on failure - */ - public int waveCreate() throws PigpioException { - try { - int retCode = commandSocket.sendCmd(PigpioCommand.PCMD_WVCRE.value); - if (retCode < 0) throw new PigpioException(retCode); - return retCode; - } catch (IOException e) { - logger.error("Failed to create new waveform", e); - throw new PigpioException("waveCreate", e); - } - } - - /** - * Deletes the waveform with specified wave ID - * - * @param waveId ID of the waveform to delete - * @throws PigpioException on failure - */ - public void waveDelete(int waveId) throws PigpioException { - try { - int retCode = commandSocket.sendCmd(PigpioCommand.PCMD_WVDEL.value, waveId); - if (retCode < 0) throw new PigpioException(retCode); - } catch (IOException e) { - logger.error("Failed to delete wave: " + waveId, e); - throw new PigpioException("waveDelete", e); - } - } - - /** - * Transmits the waveform with specified wave ID. The waveform is sent once - * - * @param waveId ID of the waveform to transmit - * @return The number of DMA control blocks in the waveform - * @throws PigpioException on failure - */ - public int waveSendOnce(int waveId) throws PigpioException { - try { - int retCode = commandSocket.sendCmd(PigpioCommand.PCMD_WVTX.value, waveId); - if (retCode < 0) throw new PigpioException(retCode); - return retCode; - } catch (IOException e) { - throw new PigpioException("waveSendOnce", e); - } - } - - /** - * Transmits the waveform with specified wave ID. The waveform cycles until cancelled (either by - * the sending of a new waveform or {@link #waveTxStop()} - * - * @param waveId ID of the waveform to transmit - * @return The number of DMA control blocks in the waveform - * @throws PigpioException on failure - */ - public int waveSendRepeat(int waveId) throws PigpioException { - try { - int retCode = commandSocket.sendCmd(PigpioCommand.PCMD_WVTXR.value, waveId); - if (retCode < 0) throw new PigpioException(retCode); - return retCode; - } catch (IOException e) { - throw new PigpioException("waveSendRepeat", e); - } - } - - /** - * Starts hardware PWM on a GPIO at the specified frequency and dutycycle - * - * @param pin GPIO pin to start PWM on - * @param pwmFrequency Frequency to run at (1Hz-125MHz). Frequencies above 30MHz are unlikely to - * work - * @param pwmDuty Duty cycle to run at (0-1,000,000) - * @throws PigpioException on failure - */ - public void hardwarePWM(int pin, int pwmFrequency, int pwmDuty) throws PigpioException { - try { - ByteBuffer bb = ByteBuffer.allocate(4); - bb.order(ByteOrder.LITTLE_ENDIAN); - bb.putInt(pwmDuty); - - int retCode = - commandSocket.sendCmd(PigpioCommand.PCMD_HP.value, pin, pwmFrequency, 4, bb.array()); - if (retCode < 0) throw new PigpioException(retCode); - } catch (IOException e) { - throw new PigpioException("hardwarePWM", e); - } - } -} diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioSocketLock.java b/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioSocketLock.java deleted file mode 100644 index 60e9d9ff39..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/hardware/GPIO/pi/PigpioSocketLock.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.hardware.GPIO.pi; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.net.Socket; -import java.nio.ByteBuffer; - -/** - * Credit to nkolban - * https://github.com/nkolban/jpigpio/blob/master/JPigpio/src/jpigpio/SocketLock.java - */ -final class PigpioSocketLock { - private static final int replyTimeoutMillis = 1000; - - private final String addr; - private final int port; - - private Socket socket; - private DataInputStream in; - private DataOutputStream out; - - public PigpioSocketLock(String addr, int port) throws IOException { - this.addr = addr; - this.port = port; - reconnect(); - } - - public void reconnect() throws IOException { - socket = new Socket(addr, port); - out = new DataOutputStream(socket.getOutputStream()); - in = new DataInputStream(socket.getInputStream()); - } - - public void terminate() throws IOException { - in.close(); - in = null; - - out.flush(); - out.close(); - out = null; - - socket.close(); - socket = null; - } - - public synchronized int sendCmd(int cmd) throws IOException { - byte[] b = {}; - return sendCmd(cmd, 0, 0, 0, b); - } - - public synchronized int sendCmd(int cmd, int p1) throws IOException { - byte[] b = {}; - return sendCmd(cmd, p1, 0, 0, b); - } - - public synchronized int sendCmd(int cmd, int p1, int p2) throws IOException { - byte[] b = {}; - return sendCmd(cmd, p1, p2, 0, b); - } - - public synchronized int sendCmd(int cmd, int p1, int p2, int p3) throws IOException { - byte[] b = {}; - return sendCmd(cmd, p1, p2, p3, b); - } - - /** - * Send extended command to pigpiod and return result code - * - * @param cmd Command to send - * @param p1 Command parameter 1 - * @param p2 Command parameter 2 - * @param p3 Command parameter 3 (usually length of extended data - see paramater ext) - * @param ext Array of bytes containing extended data - * @return Command result code - * @throws IOException in case of network connection error - */ - @SuppressWarnings("UnusedAssignment") - public synchronized int sendCmd(int cmd, int p1, int p2, int p3, byte[] ext) throws IOException { - ByteBuffer bb = ByteBuffer.allocate(16 + ext.length); - - bb.putInt(Integer.reverseBytes(cmd)); - bb.putInt(Integer.reverseBytes(p1)); - bb.putInt(Integer.reverseBytes(p2)); - bb.putInt(Integer.reverseBytes(p3)); - - if (ext.length > 0) { - bb.put(ext); - } - - out.write(bb.array()); - out.flush(); - - int w = replyTimeoutMillis; - int a = in.available(); - - // if by any chance there is no response from pigpiod, then wait up to - // specified timeout - while (w > 0 && a < 16) { - w -= 10; - try { - Thread.sleep(10); - } catch (InterruptedException ignored) { - } - a = in.available(); - } - - // throw exception if response from pigpiod has not arrived yet - if (in.available() < 16) { - throw new IOException( - "Timeout: No response from pigpio daemon within " + replyTimeoutMillis + " ms."); - } - - int resp = Integer.reverseBytes(in.readInt()); // ignore response - resp = Integer.reverseBytes(in.readInt()); // ignore response - resp = Integer.reverseBytes(in.readInt()); // ignore response - resp = Integer.reverseBytes(in.readInt()); // contains error or response - return resp; - } - - /** - * Read all remaining bytes coming from pigpiod - * - * @param data Array to store read bytes. - * @throws IOException if unable to read from network - */ - public void readBytes(byte[] data) throws IOException { - in.readFully(data); - } -} diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/HardwareManager.java b/photon-core/src/main/java/org/photonvision/common/hardware/HardwareManager.java index 8e8035169c..fabaaf73d5 100644 --- a/photon-core/src/main/java/org/photonvision/common/hardware/HardwareManager.java +++ b/photon-core/src/main/java/org/photonvision/common/hardware/HardwareManager.java @@ -17,18 +17,9 @@ package org.photonvision.common.hardware; -import edu.wpi.first.networktables.IntegerPublisher; -import edu.wpi.first.networktables.IntegerSubscriber; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import org.photonvision.common.configuration.ConfigManager; import org.photonvision.common.configuration.HardwareConfig; -import org.photonvision.common.configuration.HardwareSettings; -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.pi.PigpioSocket; import org.photonvision.common.hardware.metrics.MetricsManager; import org.photonvision.common.logging.LogGroup; import org.photonvision.common.logging.Logger; @@ -42,36 +33,19 @@ public class HardwareManager { private final Logger logger = new Logger(HardwareManager.class, LogGroup.General); private final HardwareConfig hardwareConfig; - private final HardwareSettings hardwareSettings; private final MetricsManager metricsManager; - @SuppressWarnings({"FieldCanBeLocal", "unused"}) - private final StatusLED statusLED; - - @SuppressWarnings("FieldCanBeLocal") - private final IntegerSubscriber ledModeRequest; - - private final IntegerPublisher ledModeState; - - @SuppressWarnings({"FieldCanBeLocal", "unused"}) - private final NTDataChangeListener ledModeListener; - - public final VisionLED visionLED; // May be null if no LED is specified - - private final PigpioSocket pigpioSocket; // will be null unless on Raspi - public static HardwareManager getInstance() { if (instance == null) { var conf = ConfigManager.getInstance().getConfig(); - instance = new HardwareManager(conf.getHardwareConfig(), conf.getHardwareSettings()); + instance = new HardwareManager(conf.getHardwareConfig()); } return instance; } - private HardwareManager(HardwareConfig hardwareConfig, HardwareSettings hardwareSettings) { + private HardwareManager(HardwareConfig hardwareConfig) { this.hardwareConfig = hardwareConfig; - this.hardwareSettings = hardwareSettings; this.metricsManager = new MetricsManager(); this.metricsManager.setConfig(hardwareConfig); @@ -79,75 +53,10 @@ private HardwareManager(HardwareConfig hardwareConfig, HardwareSettings hardware TimedTaskManager.getInstance() .addTask("Metrics Publisher", this.metricsManager::publishMetrics, 5000); - ledModeRequest = - NetworkTablesManager.getInstance() - .kRootTable - .getIntegerTopic("ledModeRequest") - .subscribe(-1); - ledModeState = - NetworkTablesManager.getInstance().kRootTable.getIntegerTopic("ledModeState").publish(); - ledModeState.set(VisionLEDMode.kDefault.value); - - CustomGPIO.setConfig(hardwareConfig); - - if (Platform.isRaspberryPi()) { - pigpioSocket = new PigpioSocket(); - } else { - pigpioSocket = null; - } - - statusLED = - hardwareConfig.statusRGBPins().size() == 3 - ? new StatusLED(hardwareConfig.statusRGBPins()) - : null; - - if (statusLED != null) { - TimedTaskManager.getInstance().addTask("StatusLEDUpdate", this::statusLEDUpdate, 150); - } - - var hasBrightnessRange = hardwareConfig.ledBrightnessRange().size() == 2; - visionLED = - hardwareConfig.ledPins().isEmpty() - ? null - : new VisionLED( - hardwareConfig.ledPins(), - hasBrightnessRange ? hardwareConfig.ledBrightnessRange().get(0) : 0, - hasBrightnessRange ? hardwareConfig.ledBrightnessRange().get(1) : 100, - pigpioSocket, - ledModeState::set); - - ledModeListener = - visionLED == null - ? null - : new NTDataChangeListener( - NetworkTablesManager.getInstance().kRootTable.getInstance(), - ledModeRequest, - visionLED::onLedModeChange); - Runtime.getRuntime().addShutdownHook(new Thread(this::onJvmExit)); - - if (visionLED != null) { - visionLED.setBrightness(hardwareSettings.ledBrightnessPercentage); - visionLED.blink(85, 4); // bootup blink - } - - // Start hardware metrics thread (Disabled until implemented) - // if (Platform.isLinux()) MetricsPublisher.getInstance().startTask(); - } - - public void setBrightnessPercent(int percent) { - if (percent != hardwareSettings.ledBrightnessPercentage) { - hardwareSettings.ledBrightnessPercentage = percent; - if (visionLED != null) visionLED.setBrightness(percent); - ConfigManager.getInstance().requestSave(); - logger.info("Setting led brightness to " + percent + "%"); - } } private void onJvmExit() { - logger.info("Shutting down LEDs..."); - if (visionLED != null) visionLED.setState(false); - ConfigManager.getInstance().onJvmExit(); } @@ -168,63 +77,6 @@ public boolean restartDevice() { } } - // API's supporting status LEDs - - private Map pipelineTargets = new HashMap(); - private boolean ntConnected = false; - private boolean systemRunning = false; - private int blinkCounter = 0; - - public void setTargetsVisibleStatus(String uniqueName, boolean hasTargets) { - pipelineTargets.put(uniqueName, hasTargets); - } - - public void setNTConnected(boolean isConnected) { - this.ntConnected = isConnected; - } - - public void setRunning(boolean isRunning) { - this.systemRunning = isRunning; - } - - private void statusLEDUpdate() { - // make blinky - boolean blinky = ((blinkCounter % 3) > 0); - - // check if any pipeline has a visible target - boolean anyTarget = false; - for (var t : this.pipelineTargets.values()) { - if (t) { - anyTarget = true; - } - } - - if (this.systemRunning) { - if (!this.ntConnected) { - if (anyTarget) { - // Blue Flashing - statusLED.setRGB(false, false, blinky); - } else { - // Yellow flashing - statusLED.setRGB(blinky, blinky, false); - } - } else { - if (anyTarget) { - // Blue - statusLED.setRGB(false, false, blinky); - } else { - // blinky green - statusLED.setRGB(false, blinky, false); - } - } - } else { - // Faulted, not running... blinky red - statusLED.setRGB(blinky, false, false); - } - - blinkCounter++; - } - public void publishMetrics() { metricsManager.publishMetrics(); } diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/StatusLED.java b/photon-core/src/main/java/org/photonvision/common/hardware/StatusLED.java deleted file mode 100644 index efef23454e..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/hardware/StatusLED.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.hardware; - -import java.util.List; -import org.photonvision.common.hardware.GPIO.CustomGPIO; -import org.photonvision.common.hardware.GPIO.GPIOBase; -import org.photonvision.common.hardware.GPIO.pi.PigpioPin; - -public class StatusLED { - public final GPIOBase redLED; - public final GPIOBase greenLED; - public final GPIOBase blueLED; - - public StatusLED(List statusLedPins) { - // fill unassigned pins with -1 to disable - if (statusLedPins.size() != 3) { - for (int i = 0; i < 3 - statusLedPins.size(); i++) { - statusLedPins.add(-1); - } - } - - if (Platform.isRaspberryPi()) { - redLED = new PigpioPin(statusLedPins.get(0)); - greenLED = new PigpioPin(statusLedPins.get(1)); - blueLED = new PigpioPin(statusLedPins.get(2)); - } else { - redLED = new CustomGPIO(statusLedPins.get(0)); - greenLED = new CustomGPIO(statusLedPins.get(1)); - blueLED = new CustomGPIO(statusLedPins.get(2)); - } - } - - public void setRGB(boolean r, boolean g, boolean b) { - // Outputs are active-low, so invert the level applied - redLED.setState(!r); - redLED.setBrightness(r ? 0 : 100); - greenLED.setState(!g); - greenLED.setBrightness(g ? 0 : 100); - blueLED.setState(!b); - blueLED.setBrightness(b ? 0 : 100); - } -} diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java b/photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java deleted file mode 100644 index 2a1af50868..0000000000 --- a/photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.hardware; - -import edu.wpi.first.networktables.NetworkTableEvent; -import java.util.ArrayList; -import java.util.List; -import java.util.function.BooleanSupplier; -import java.util.function.Consumer; -import org.photonvision.common.hardware.GPIO.CustomGPIO; -import org.photonvision.common.hardware.GPIO.GPIOBase; -import org.photonvision.common.hardware.GPIO.pi.PigpioException; -import org.photonvision.common.hardware.GPIO.pi.PigpioPin; -import org.photonvision.common.hardware.GPIO.pi.PigpioSocket; -import org.photonvision.common.logging.LogGroup; -import org.photonvision.common.logging.Logger; -import org.photonvision.common.util.TimedTaskManager; -import org.photonvision.common.util.math.MathUtils; - -public class VisionLED { - private static final Logger logger = new Logger(VisionLED.class, LogGroup.VisionModule); - - private final int[] ledPins; - private final List visionLEDs = new ArrayList<>(); - private final int brightnessMin; - private final int brightnessMax; - private final PigpioSocket pigpioSocket; - - private VisionLEDMode currentLedMode = VisionLEDMode.kDefault; - private BooleanSupplier pipelineModeSupplier; - - private int mappedBrightnessPercentage; - - private final Consumer modeConsumer; - - public VisionLED( - List ledPins, - int brightnessMin, - int brightnessMax, - PigpioSocket pigpioSocket, - Consumer visionLEDmode) { - this.brightnessMin = brightnessMin; - this.brightnessMax = brightnessMax; - this.pigpioSocket = pigpioSocket; - this.modeConsumer = visionLEDmode; - this.ledPins = ledPins.stream().mapToInt(i -> i).toArray(); - ledPins.forEach( - pin -> { - if (Platform.isRaspberryPi()) { - visionLEDs.add(new PigpioPin(pin)); - } else { - visionLEDs.add(new CustomGPIO(pin)); - } - }); - pipelineModeSupplier = () -> false; - } - - public void setPipelineModeSupplier(BooleanSupplier pipelineModeSupplier) { - this.pipelineModeSupplier = pipelineModeSupplier; - } - - public void setBrightness(int percentage) { - mappedBrightnessPercentage = MathUtils.map(percentage, 0, 100, brightnessMin, brightnessMax); - setInternal(currentLedMode, false); - } - - public void blink(int pulseLengthMillis, int blinkCount) { - blinkImpl(pulseLengthMillis, blinkCount); - int blinkDuration = pulseLengthMillis * blinkCount * 2; - TimedTaskManager.getInstance() - .addOneShotTask(() -> setInternal(this.currentLedMode, false), blinkDuration + 150); - } - - private void blinkImpl(int pulseLengthMillis, int blinkCount) { - if (Platform.isRaspberryPi()) { - try { - setStateImpl(false); // hack to ensure hardware PWM has stopped before trying to blink - pigpioSocket.generateAndSendWaveform(pulseLengthMillis, blinkCount, ledPins); - } catch (PigpioException e) { - logger.error("Failed to blink!", e); - } catch (NullPointerException e) { - logger.error("Failed to blink, pigpio internal issue!", e); - } - } else { - for (GPIOBase led : visionLEDs) { - led.blink(pulseLengthMillis, blinkCount); - } - } - } - - private void setStateImpl(boolean state) { - if (Platform.isRaspberryPi()) { - try { - // stop any active blink - pigpioSocket.waveTxStop(); - } catch (PigpioException e) { - logger.error("Failed to stop blink!", e); - } catch (NullPointerException e) { - logger.error("Failed to blink, pigpio internal issue!", e); - } - } - try { - // if the user has set an LED brightness other than 100%, use that instead - if (mappedBrightnessPercentage == 100 || !state) { - visionLEDs.forEach((led) -> led.setState(state)); - } else { - visionLEDs.forEach((led) -> led.setBrightness(mappedBrightnessPercentage)); - } - } catch (NullPointerException e) { - logger.error("Failed to blink, pigpio internal issue!", e); - } - } - - public void setState(boolean on) { - setInternal(on ? VisionLEDMode.kOn : VisionLEDMode.kOff, false); - } - - void onLedModeChange(NetworkTableEvent entryNotification) { - var newLedModeRaw = (int) entryNotification.valueData.value.getInteger(); - logger.debug("Got LED mode " + newLedModeRaw); - if (newLedModeRaw != currentLedMode.value) { - VisionLEDMode newLedMode = - switch (newLedModeRaw) { - case -1 -> VisionLEDMode.kDefault; - case 0 -> VisionLEDMode.kOff; - case 1 -> VisionLEDMode.kOn; - case 2 -> VisionLEDMode.kBlink; - default -> { - logger.warn("User supplied invalid LED mode, falling back to Default"); - yield VisionLEDMode.kDefault; - } - }; - setInternal(newLedMode, true); - - if (modeConsumer != null) modeConsumer.accept(newLedMode.value); - } - } - - private void setInternal(VisionLEDMode newLedMode, boolean fromNT) { - var lastLedMode = currentLedMode; - - if (fromNT) { - switch (newLedMode) { - case kDefault -> setStateImpl(pipelineModeSupplier.getAsBoolean()); - case kOff -> setStateImpl(false); - case kOn -> setStateImpl(true); - case kBlink -> blinkImpl(85, -1); - } - currentLedMode = newLedMode; - logger.info( - "Changing LED mode from \"" + lastLedMode.toString() + "\" to \"" + newLedMode + "\""); - } else { - if (currentLedMode == VisionLEDMode.kDefault) { - switch (newLedMode) { - case kDefault -> setStateImpl(pipelineModeSupplier.getAsBoolean()); - case kOff -> setStateImpl(false); - case kOn -> setStateImpl(true); - case kBlink -> blinkImpl(85, -1); - } - } - logger.info("Changing LED internal state to " + newLedMode.toString()); - } - } -} diff --git a/photon-core/src/main/java/org/photonvision/common/scripting/ScriptEventType.java b/photon-core/src/main/java/org/photonvision/common/scripting/ScriptEventType.java index 3fe98bf447..9f9e60970a 100644 --- a/photon-core/src/main/java/org/photonvision/common/scripting/ScriptEventType.java +++ b/photon-core/src/main/java/org/photonvision/common/scripting/ScriptEventType.java @@ -21,8 +21,6 @@ public enum ScriptEventType { kProgramInit("Program Init"), kProgramExit("Program Exit"), kNTConnected("NT Connected"), - kLEDOn("LED On"), - kLEDOff("LED Off"), kEnterDriverMode("Enter Driver Mode"), kExitDriverMode("Exit Driver Mode"), kFoundTarget("Found Target"), diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/FileVisionSource.java b/photon-core/src/main/java/org/photonvision/vision/camera/FileVisionSource.java index 76737fbf20..74fbb18ed8 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/FileVisionSource.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/FileVisionSource.java @@ -87,11 +87,6 @@ public void remakeSettables() { return; } - @Override - public boolean hasLEDs() { - return false; // Assume USB cameras do not have photonvision-controlled LEDs - } - @Override public void release() { frameProvider.release(); diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/TestSource.java b/photon-core/src/main/java/org/photonvision/vision/camera/TestSource.java index d4a5517d58..33bc748465 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/TestSource.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/TestSource.java @@ -111,11 +111,6 @@ public boolean isVendorCamera() { throw new UnsupportedOperationException("Unimplemented method 'isVendorCamera'"); } - @Override - public boolean hasLEDs() { - return false; // Assume USB cameras do not have photonvision-controlled LEDs - } - @Override public void release() { // TODO Auto-generated method stub diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/USBCameraSource.java b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/USBCameraSource.java index b0a4dde81a..f57bd024af 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/USBCameraSource.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/USBCameraSource.java @@ -235,11 +235,6 @@ public boolean isVendorCamera() { return false; // Vendors do not supply USB Cameras } - @Override - public boolean hasLEDs() { - return false; // Assume USB cameras do not have photonvision-controlled LEDs - } - @Override public void release() { CameraServer.removeCamera(camera.getName()); diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/csi/LibcameraGpuSource.java b/photon-core/src/main/java/org/photonvision/vision/camera/csi/LibcameraGpuSource.java index 6fa1223db8..94df1ff9b8 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/csi/LibcameraGpuSource.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/csi/LibcameraGpuSource.java @@ -98,11 +98,6 @@ public boolean isVendorCamera() { return ConfigManager.getInstance().getConfig().getHardwareConfig().hasPresetFOV(); } - @Override - public boolean hasLEDs() { - return (ConfigManager.getInstance().getConfig().getHardwareConfig().ledPins().size() > 0); - } - @Override public void release() { frameProvider.release(); diff --git a/photon-core/src/main/java/org/photonvision/vision/pipeline/AdvancedPipelineSettings.java b/photon-core/src/main/java/org/photonvision/vision/pipeline/AdvancedPipelineSettings.java index 91a71527a0..94332e0e8e 100644 --- a/photon-core/src/main/java/org/photonvision/vision/pipeline/AdvancedPipelineSettings.java +++ b/photon-core/src/main/java/org/photonvision/vision/pipeline/AdvancedPipelineSettings.java @@ -31,10 +31,6 @@ import org.photonvision.vision.target.TargetOrientation; public class AdvancedPipelineSettings extends CVPipelineSettings { - public AdvancedPipelineSettings() { - ledMode = true; - } - public IntegerCouple hsvHue = new IntegerCouple(50, 180); public IntegerCouple hsvSaturation = new IntegerCouple(50, 255); public IntegerCouple hsvValue = new IntegerCouple(50, 255); diff --git a/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipelineSettings.java b/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipelineSettings.java index cede417e23..ce529c5011 100644 --- a/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipelineSettings.java +++ b/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipelineSettings.java @@ -44,7 +44,6 @@ public AprilTagPipelineSettings() { targetModel = TargetModel.kAprilTag6p5in_36h11; cameraExposureRaw = 20; cameraAutoExposure = false; - ledMode = false; } @Override diff --git a/photon-core/src/main/java/org/photonvision/vision/pipeline/ArucoPipelineSettings.java b/photon-core/src/main/java/org/photonvision/vision/pipeline/ArucoPipelineSettings.java index 145f761427..78ef81fefe 100644 --- a/photon-core/src/main/java/org/photonvision/vision/pipeline/ArucoPipelineSettings.java +++ b/photon-core/src/main/java/org/photonvision/vision/pipeline/ArucoPipelineSettings.java @@ -49,6 +49,5 @@ public ArucoPipelineSettings() { targetModel = TargetModel.kAprilTag6p5in_36h11; cameraExposureRaw = 20; cameraAutoExposure = true; - ledMode = false; } } diff --git a/photon-core/src/main/java/org/photonvision/vision/pipeline/CVPipelineSettings.java b/photon-core/src/main/java/org/photonvision/vision/pipeline/CVPipelineSettings.java index a512e1fcf9..b9656b8c99 100644 --- a/photon-core/src/main/java/org/photonvision/vision/pipeline/CVPipelineSettings.java +++ b/photon-core/src/main/java/org/photonvision/vision/pipeline/CVPipelineSettings.java @@ -54,7 +54,6 @@ public class CVPipelineSettings implements Cloneable { public int cameraBlueGain = 20; public int cameraVideoModeIndex = 0; public FrameDivisor streamingFrameDivisor = FrameDivisor.NONE; - public boolean ledMode = false; public boolean inputShouldShow = false; public boolean outputShouldShow = true; @@ -76,7 +75,6 @@ public boolean equals(Object o) { && Double.compare(that.cameraBlueGain, cameraBlueGain) == 0 && Double.compare(that.cameraWhiteBalanceTemp, cameraWhiteBalanceTemp) == 0 && cameraVideoModeIndex == that.cameraVideoModeIndex - && ledMode == that.ledMode && pipelineType == that.pipelineType && inputImageRotationMode == that.inputImageRotationMode && pipelineNickname.equals(that.pipelineNickname) @@ -102,7 +100,6 @@ public int hashCode() { cameraWhiteBalanceTemp, cameraVideoModeIndex, streamingFrameDivisor, - ledMode, inputShouldShow, outputShouldShow); } @@ -143,8 +140,6 @@ public String toString() { + cameraVideoModeIndex + ", streamingFrameDivisor=" + streamingFrameDivisor - + ", ledMode=" - + ledMode + ", inputShouldShow=" + inputShouldShow + ", outputShouldShow=" diff --git a/photon-core/src/main/java/org/photonvision/vision/pipeline/ObjectDetectionPipelineSettings.java b/photon-core/src/main/java/org/photonvision/vision/pipeline/ObjectDetectionPipelineSettings.java index 67428559ad..6a32a238f0 100644 --- a/photon-core/src/main/java/org/photonvision/vision/pipeline/ObjectDetectionPipelineSettings.java +++ b/photon-core/src/main/java/org/photonvision/vision/pipeline/ObjectDetectionPipelineSettings.java @@ -32,7 +32,6 @@ public ObjectDetectionPipelineSettings() { this.outputShowMultipleTargets = true; cameraExposureRaw = 20; cameraAutoExposure = false; - ledMode = false; confidence = .9; nms = .45; model = diff --git a/photon-core/src/main/java/org/photonvision/vision/processes/VisionModule.java b/photon-core/src/main/java/org/photonvision/vision/processes/VisionModule.java index 69fb69870a..98d81d5c9c 100644 --- a/photon-core/src/main/java/org/photonvision/vision/processes/VisionModule.java +++ b/photon-core/src/main/java/org/photonvision/vision/processes/VisionModule.java @@ -34,11 +34,9 @@ import org.photonvision.common.dataflow.DataChangeService.SubscriberHandle; import org.photonvision.common.dataflow.events.OutgoingUIEvent; import org.photonvision.common.dataflow.networktables.NTDataPublisher; -import org.photonvision.common.dataflow.statusLEDs.StatusLEDConsumer; import org.photonvision.common.dataflow.websocket.UICameraConfiguration; import org.photonvision.common.dataflow.websocket.UIDataPublisher; import org.photonvision.common.dataflow.websocket.UIPhotonConfiguration; -import org.photonvision.common.hardware.HardwareManager; import org.photonvision.common.logging.LogGroup; import org.photonvision.common.logging.Logger; import org.photonvision.common.util.SerializationUtils; @@ -79,7 +77,6 @@ public class VisionModule { new LinkedList<>(); private final NTDataPublisher ntConsumer; private final UIDataPublisher uiDataConsumer; - private final StatusLEDConsumer statusLEDsConsumer; protected final QuirkyCamera cameraQuirks; protected TrackedTarget lastPipelineResultBestTarget; @@ -146,11 +143,8 @@ public VisionModule(PipelineManager pipelineManager, VisionSource visionSource) pipelineManager::getDriverMode, this::setDriverMode); uiDataConsumer = new UIDataPublisher(visionSource.getSettables().getConfiguration().uniqueName); - statusLEDsConsumer = - new StatusLEDConsumer(visionSource.getSettables().getConfiguration().uniqueName); addResultConsumer(ntConsumer); addResultConsumer(uiDataConsumer); - addResultConsumer(statusLEDsConsumer); addResultConsumer( (result) -> lastPipelineResultBestTarget = result.hasTargets() ? result.targets.get(0) : null); @@ -165,14 +159,6 @@ public VisionModule(PipelineManager pipelineManager, VisionSource visionSource) visionSource.getSettables().setFOV(fov); } - // Configure LED's if supported by the underlying hardware - if (HardwareManager.getInstance().visionLED != null && this.camShouldControlLEDs()) { - HardwareManager.getInstance() - .visionLED - .setPipelineModeSupplier(() -> pipelineManager.getCurrentPipelineSettings().ledMode); - setVisionLEDs(pipelineManager.getCurrentPipelineSettings().ledMode); - } - saveAndBroadcastAll(); } @@ -324,7 +310,6 @@ public void stop() { outputFrameSaver.close(); changeSubscriberHandle.stop(); - setVisionLEDs(false); } public void setFov(double fov) { @@ -355,7 +340,6 @@ void changePipelineType(int newType) { void setDriverMode(boolean isDriverMode) { pipelineManager.setDriverMode(isDriverMode); - setVisionLEDs(!isDriverMode); setPipeline( isDriverMode ? PipelineManager.DRIVERMODE_INDEX : pipelineManager.getRequestedIndex()); saveAndBroadcastAll(); @@ -486,28 +470,12 @@ boolean setPipeline(int index) { settables.setAutoWhiteBalance(pipelineSettings.cameraAutoWhiteBalance); } - setVisionLEDs(pipelineSettings.ledMode); - settables.getConfiguration().currentPipelineIndex = pipelineManager.getRequestedIndex(); }); return true; } - private boolean camShouldControlLEDs() { - // Heuristic - if the camera has a known FOV or is a piCam, assume it's in use - // for - // vision processing, and should command stuff to the LED's. - // TODO: Make LED control a property of the camera itself and controllable in - // the UI. - return isVendorCamera(); - } - - private void setVisionLEDs(boolean on) { - if (camShouldControlLEDs() && HardwareManager.getInstance().visionLED != null) - HardwareManager.getInstance().visionLED.setState(on); - } - public void saveModule() { ConfigManager.getInstance() .saveModule( diff --git a/photon-core/src/main/java/org/photonvision/vision/processes/VisionSource.java b/photon-core/src/main/java/org/photonvision/vision/processes/VisionSource.java index 034e3f5f0f..877f9e833f 100644 --- a/photon-core/src/main/java/org/photonvision/vision/processes/VisionSource.java +++ b/photon-core/src/main/java/org/photonvision/vision/processes/VisionSource.java @@ -38,7 +38,5 @@ public CameraConfiguration getCameraConfiguration() { public abstract boolean isVendorCamera(); - public abstract boolean hasLEDs(); - public abstract void remakeSettables(); } diff --git a/photon-core/src/test/java/org/photonvision/common/configuration/ConfigTest.java b/photon-core/src/test/java/org/photonvision/common/configuration/ConfigTest.java index 95262912af..944b6c9f1a 100644 --- a/photon-core/src/test/java/org/photonvision/common/configuration/ConfigTest.java +++ b/photon-core/src/test/java/org/photonvision/common/configuration/ConfigTest.java @@ -137,7 +137,7 @@ public static void cleanup() throws IOException { @Test public void testJacksonHandlesOldVersions() throws IOException { var str = - "{\"baseName\":\"aaaaaa\",\"uniqueName\":\"aaaaaa\",\"nickname\":\"aaaaaa\",\"FOV\":70.0,\"path\":\"dev/vid\",\"cameraType\":\"UsbCamera\",\"currentPipelineIndex\":0,\"camPitch\":{\"radians\":0.0},\"calibrations\":[], \"cameraLEDs\":[]}"; + "{\"baseName\":\"aaaaaa\",\"uniqueName\":\"aaaaaa\",\"nickname\":\"aaaaaa\",\"FOV\":70.0,\"path\":\"dev/vid\",\"cameraType\":\"UsbCamera\",\"currentPipelineIndex\":0,\"camPitch\":{\"radians\":0.0},\"calibrations\":[]}"; File tempFile = File.createTempFile("test", ".json"); tempFile.deleteOnExit(); var writer = new FileWriter(tempFile); @@ -153,7 +153,7 @@ public void testJacksonHandlesOldVersions() throws IOException { @Test public void testJacksonAddUSBVIDPID() throws IOException { var str = - "{\"baseName\":\"aaaaaa\",\"uniqueName\":\"aaaaaa\",\"nickname\":\"aaaaaa\",\"FOV\":70.0,\"path\":\"dev/vid\",\"cameraType\":\"UsbCamera\",\"currentPipelineIndex\":0,\"camPitch\":{\"radians\":0.0},\"calibrations\":[], \"usbVID\":3, \"usbPID\":4, \"cameraLEDs\":[]}"; + "{\"baseName\":\"aaaaaa\",\"uniqueName\":\"aaaaaa\",\"nickname\":\"aaaaaa\",\"FOV\":70.0,\"path\":\"dev/vid\",\"cameraType\":\"UsbCamera\",\"currentPipelineIndex\":0,\"camPitch\":{\"radians\":0.0},\"calibrations\":[], \"usbVID\":3, \"usbPID\":4}"; File tempFile = File.createTempFile("test", ".json"); tempFile.deleteOnExit(); var writer = new FileWriter(tempFile); diff --git a/photon-core/src/test/java/org/photonvision/hardware/HardwareConfigTest.java b/photon-core/src/test/java/org/photonvision/hardware/HardwareConfigTest.java index 67822816b2..f3eb82061f 100644 --- a/photon-core/src/test/java/org/photonvision/hardware/HardwareConfigTest.java +++ b/photon-core/src/test/java/org/photonvision/hardware/HardwareConfigTest.java @@ -17,14 +17,12 @@ package org.photonvision.hardware; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import org.junit.jupiter.api.Test; import org.photonvision.common.configuration.HardwareConfig; -import org.photonvision.common.hardware.GPIO.CustomGPIO; import org.photonvision.common.util.TestUtils; public class HardwareConfigTest { @@ -37,8 +35,6 @@ public void loadJson() { assertEquals(config.deviceName(), "PhotonVision"); assertEquals(config.deviceLogoPath(), "photonvision.png"); assertEquals(config.supportURL(), "https://support.photonvision.com"); - assertArrayEquals(config.ledPins().stream().mapToInt(i -> i).toArray(), new int[] {2, 13}); - CustomGPIO.setConfig(config); } catch (IOException e) { e.printStackTrace(); diff --git a/photon-core/src/test/java/org/photonvision/hardware/HardwareManagerTest.java b/photon-core/src/test/java/org/photonvision/hardware/HardwareManagerTest.java deleted file mode 100644 index 6273696058..0000000000 --- a/photon-core/src/test/java/org/photonvision/hardware/HardwareManagerTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.hardware; - -import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Test; -import org.photonvision.common.hardware.GPIO.pi.PigpioException; -import org.photonvision.common.hardware.GPIO.pi.PigpioSocket; -import org.photonvision.common.hardware.HardwareManager; -import org.photonvision.common.hardware.Platform; -import org.photonvision.common.logging.LogGroup; -import org.photonvision.common.logging.Logger; - -public class HardwareManagerTest { - public static final Logger logger = new Logger(HardwareManager.class, LogGroup.General); - - @Test - public void managementTest() throws InterruptedException { - Assumptions.assumeTrue(Platform.isRaspberryPi()); - var socket = new PigpioSocket(); - try { - socket.gpioWrite(18, false); - socket.gpioWrite(13, false); - Thread.sleep(500); - for (int i = 0; i < 1000000; i++) { - int duty = 1000000 - i; - socket.hardwarePWM(18, 1000000, duty); - Thread.sleep(0, 25); - } - } catch (PigpioException e) { - logger.error("error", e); - } - } -} diff --git a/photon-core/src/test/java/org/photonvision/hardware/HardwareTest.java b/photon-core/src/test/java/org/photonvision/hardware/HardwareTest.java index f5fa86cbe5..5e8f54072f 100644 --- a/photon-core/src/test/java/org/photonvision/hardware/HardwareTest.java +++ b/photon-core/src/test/java/org/photonvision/hardware/HardwareTest.java @@ -17,14 +17,8 @@ package org.photonvision.hardware; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.io.IOException; import org.junit.jupiter.api.Test; -import org.photonvision.common.hardware.GPIO.CustomGPIO; -import org.photonvision.common.hardware.GPIO.GPIOBase; -import org.photonvision.common.hardware.GPIO.pi.PigpioPin; import org.photonvision.common.hardware.Platform; import org.photonvision.common.hardware.metrics.MetricsManager; import org.photonvision.common.util.TestUtils; @@ -56,46 +50,4 @@ public void testHardware() { System.out.println("Printing RAM Info: "); System.out.println("Used RAM: : " + mm.getRamUtil() + "MB"); } - - @Test - public void testGPIO() { - GPIOBase gpio; - if (Platform.isRaspberryPi()) { - gpio = new PigpioPin(18); - } else { - gpio = new CustomGPIO(18); - } - - gpio.setOn(); // HIGH - assertTrue(gpio.getState()); - - gpio.setOff(); // LOW - assertFalse(gpio.getState()); - - gpio.togglePin(); // HIGH - assertTrue(gpio.getState()); - - gpio.togglePin(); // LOW - assertFalse(gpio.getState()); - - gpio.setState(true); // HIGH - assertTrue(gpio.getState()); - - gpio.setState(false); // LOW - assertFalse(gpio.getState()); - - var success = gpio.shutdown(); - assertTrue(success); - } - - @Test - public void testBlink() { - if (!Platform.isRaspberryPi()) return; - GPIOBase pwm = new PigpioPin(18); - pwm.blink(125, 3); - var startms = System.currentTimeMillis(); - while (true) { - if (System.currentTimeMillis() - startms > 4500) break; - } - } } diff --git a/photon-core/src/test/java/org/photonvision/vision/processes/VisionModuleManagerTest.java b/photon-core/src/test/java/org/photonvision/vision/processes/VisionModuleManagerTest.java index d718666774..c1285d30bb 100644 --- a/photon-core/src/test/java/org/photonvision/vision/processes/VisionModuleManagerTest.java +++ b/photon-core/src/test/java/org/photonvision/vision/processes/VisionModuleManagerTest.java @@ -81,11 +81,6 @@ public boolean isVendorCamera() { return false; } - @Override - public boolean hasLEDs() { - return false; - } - @Override public void remakeSettables() { return; diff --git a/photon-lib/py/photonlibpy/photonCamera.py b/photon-lib/py/photonlibpy/photonCamera.py index e4b35b4083..9a005243be 100644 --- a/photon-lib/py/photonlibpy/photonCamera.py +++ b/photon-lib/py/photonlibpy/photonCamera.py @@ -15,7 +15,6 @@ ## along with this program. If not, see . ############################################################################### -from enum import Enum from typing import List import hal @@ -31,14 +30,6 @@ from .timesync.timeSyncServer import inst from .version import PHOTONLIB_VERSION # type: ignore[import-untyped] - -class VisionLEDMode(Enum): - kDefault = -1 - kOff = 0 - kOn = 1 - kBlink = 2 - - _lastVersionTimeCheck = 0.0 _VERSION_CHECK_ENABLED = True @@ -90,12 +81,6 @@ def __init__(self, cameraName: str): -1 ) - self._ledModeRequest = photonvision_root_table.getIntegerTopic( - "ledModeRequest" - ).publish() - self._ledModeState = photonvision_root_table.getIntegerTopic( - "ledModeState" - ).subscribe(-1) self.versionEntry = photonvision_root_table.getStringTopic("version").subscribe( "" ) @@ -222,23 +207,6 @@ def setPipelineIndex(self, index: int) -> None: """ self._pipelineIndexRequest.set(index) - def getLEDMode(self) -> VisionLEDMode: - """Returns the current LED mode. - - :returns: The current LED mode. - """ - - mode = self._ledModeState.get() - return VisionLEDMode(mode) - - def setLEDMode(self, led: VisionLEDMode) -> None: - """Sets the LED mode. - - :param led: The mode to set to. - """ - - self._ledModeRequest.set(led.value) - def getName(self) -> str: """Returns the name of the camera. This will return the same value that was given to the constructor as cameraName. diff --git a/photon-lib/src/main/java/org/photonvision/PhotonCamera.java b/photon-lib/src/main/java/org/photonvision/PhotonCamera.java index d1f5d69616..1eb47722c6 100644 --- a/photon-lib/src/main/java/org/photonvision/PhotonCamera.java +++ b/photon-lib/src/main/java/org/photonvision/PhotonCamera.java @@ -51,7 +51,6 @@ import java.util.List; import java.util.Optional; import org.opencv.core.Core; -import org.photonvision.common.hardware.VisionLEDMode; import org.photonvision.common.networktables.PacketSubscriber; import org.photonvision.targeting.PhotonPipelineResult; import org.photonvision.timesync.TimeSyncSingleton; @@ -68,8 +67,8 @@ public class PhotonCamera implements AutoCloseable { BooleanSubscriber driverModeSubscriber; StringSubscriber versionEntry; IntegerEntry inputSaveImgEntry, outputSaveImgEntry; - IntegerPublisher pipelineIndexRequest, ledModeRequest; - IntegerSubscriber pipelineIndexState, ledModeState; + IntegerPublisher pipelineIndexRequest; + IntegerSubscriber pipelineIndexState; IntegerSubscriber heartbeatSubscriber; DoubleArraySubscriber cameraIntrinsicsSubscriber; DoubleArraySubscriber cameraDistortionSubscriber; @@ -86,8 +85,6 @@ public void close() { outputSaveImgEntry.close(); pipelineIndexRequest.close(); pipelineIndexState.close(); - ledModeRequest.close(); - ledModeState.close(); pipelineIndexRequest.close(); cameraIntrinsicsSubscriber.close(); cameraDistortionSubscriber.close(); @@ -154,8 +151,6 @@ public PhotonCamera(NetworkTableInstance instance, String cameraName) { cameraDistortionSubscriber = cameraTable.getDoubleArrayTopic("cameraDistortion").subscribe(null); - ledModeRequest = rootPhotonTable.getIntegerTopic("ledModeRequest").publish(); - ledModeState = rootPhotonTable.getIntegerTopic("ledModeState").subscribe(-1); versionEntry = rootPhotonTable.getStringTopic("version").subscribe(""); // Existing is enough to make this multisubscriber do its thing @@ -412,30 +407,6 @@ public void setPipelineIndex(int index) { pipelineIndexRequest.set(index); } - /** - * Returns the current LED mode. - * - * @return The current LED mode. - */ - public VisionLEDMode getLEDMode() { - int value = (int) ledModeState.get(-1); - return switch (value) { - case 0 -> VisionLEDMode.kOff; - case 1 -> VisionLEDMode.kOn; - case 2 -> VisionLEDMode.kBlink; - default -> VisionLEDMode.kDefault; - }; - } - - /** - * Sets the LED mode. - * - * @param led The mode to set to. - */ - public void setLED(VisionLEDMode led) { - ledModeRequest.set(led.value); - } - /** * Returns the name of the camera. This will return the same value that was given to the * constructor as cameraName. diff --git a/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp b/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp index 6b7f67bc88..729d00a4d3 100644 --- a/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp +++ b/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp @@ -186,8 +186,6 @@ PhotonCamera::PhotonCamera(nt::NetworkTableInstance instance, rootTable->GetIntegerTopic("pipelineIndexRequest").Publish()), pipelineIndexSub( rootTable->GetIntegerTopic("pipelineIndexState").Subscribe(0)), - ledModePub(mainTable->GetIntegerTopic("ledMode").Publish()), - ledModeSub(mainTable->GetIntegerTopic("ledMode").Subscribe(0)), versionEntry(mainTable->GetStringTopic("version").Subscribe("")), cameraIntrinsicsSubscriber( rootTable->GetDoubleArrayTopic("cameraIntrinsics").Subscribe({})), @@ -339,14 +337,6 @@ int PhotonCamera::GetPipelineIndex() const { return static_cast(pipelineIndexSub.Get()); } -LEDMode PhotonCamera::GetLEDMode() const { - return static_cast(static_cast(ledModeSub.Get())); -} - -void PhotonCamera::SetLEDMode(LEDMode mode) { - ledModePub.Set(static_cast(mode)); -} - const std::string_view PhotonCamera::GetCameraName() const { return cameraName; } diff --git a/photon-lib/src/main/native/include/photon/PhotonCamera.h b/photon-lib/src/main/native/include/photon/PhotonCamera.h index 5281bbe747..22f05600d4 100644 --- a/photon-lib/src/main/native/include/photon/PhotonCamera.h +++ b/photon-lib/src/main/native/include/photon/PhotonCamera.h @@ -48,8 +48,6 @@ class Mat; namespace photon { -enum LEDMode : int { kDefault = -1, kOff = 0, kOn = 1, kBlink = 2 }; - /** * Represents a camera that is connected to PhotonVision.ß */ @@ -137,18 +135,6 @@ class PhotonCamera { */ int GetPipelineIndex() const; - /** - * Returns the current LED mode. - * @return The current LED mode. - */ - LEDMode GetLEDMode() const; - - /** - * Sets the LED mode. - * @param led The mode to set to. - */ - void SetLEDMode(LEDMode led); - /** * Returns the name of the camera. * This will return the same value that was given to the constructor as @@ -201,8 +187,6 @@ class PhotonCamera { nt::IntegerSubscriber outputSaveImgSubscriber; nt::IntegerPublisher pipelineIndexPub; nt::IntegerSubscriber pipelineIndexSub; - nt::IntegerPublisher ledModePub; - nt::IntegerSubscriber ledModeSub; nt::StringSubscriber versionEntry; nt::DoubleArraySubscriber cameraIntrinsicsSubscriber; @@ -210,7 +194,6 @@ class PhotonCamera { nt::BooleanSubscriber driverModeSubscriber; nt::BooleanPublisher driverModePublisher; - nt::IntegerSubscriber ledModeSubscriber; nt::IntegerSubscriber heartbeatSubscriber; diff --git a/photon-server/src/main/java/org/photonvision/Main.java b/photon-server/src/main/java/org/photonvision/Main.java index 442fdb6d09..47ffbfb08d 100644 --- a/photon-server/src/main/java/org/photonvision/Main.java +++ b/photon-server/src/main/java/org/photonvision/Main.java @@ -325,7 +325,6 @@ public static void main(String[] args) { VisionSourceManager.getInstance().registerTimedTasks(); logger.info("Starting server..."); - HardwareManager.getInstance().setRunning(true); Server.initialize(DEFAULT_WEBPORT); } } diff --git a/photon-server/src/main/java/org/photonvision/server/DataSocketHandler.java b/photon-server/src/main/java/org/photonvision/server/DataSocketHandler.java index 69bbd92fea..7a29e9b0f9 100644 --- a/photon-server/src/main/java/org/photonvision/server/DataSocketHandler.java +++ b/photon-server/src/main/java/org/photonvision/server/DataSocketHandler.java @@ -38,7 +38,6 @@ import org.photonvision.common.dataflow.DataChangeDestination; import org.photonvision.common.dataflow.DataChangeService; import org.photonvision.common.dataflow.events.IncomingWebSocketEvent; -import org.photonvision.common.hardware.HardwareManager; import org.photonvision.common.logging.LogGroup; import org.photonvision.common.logging.Logger; import org.photonvision.vision.pipeline.PipelineType; @@ -165,9 +164,6 @@ public void onBinaryMessage(WsBinaryMessageContext context) { cameraUniqueName, context)); } - case SMT_CHANGEBRIGHTNESS -> - HardwareManager.getInstance() - .setBrightnessPercent(Integer.parseInt(entryValue.toString())); case SMT_DUPLICATEPIPELINE -> { var pipeIndex = (Integer) entryValue; diff --git a/photon-server/src/main/java/org/photonvision/server/DataSocketMessageType.java b/photon-server/src/main/java/org/photonvision/server/DataSocketMessageType.java index f5222cf371..4e69b0e171 100644 --- a/photon-server/src/main/java/org/photonvision/server/DataSocketMessageType.java +++ b/photon-server/src/main/java/org/photonvision/server/DataSocketMessageType.java @@ -36,7 +36,6 @@ public enum DataSocketMessageType { SMT_SAVEOUTPUTSNAPSHOT("saveOutputSnapshot"), SMT_TAKECALIBRATIONSNAPSHOT("takeCalibrationSnapshot"), SMT_DUPLICATEPIPELINE("duplicatePipeline"), - SMT_CHANGEBRIGHTNESS("enabledLEDPercentage"), SMT_ROBOTOFFSETPOINT("robotOffsetPoint"), SMT_CHANGEPIPELINETYPE("pipelineType"); diff --git a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java index 5d7ce98fef..65ed3f1b1a 100644 --- a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java +++ b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java @@ -186,49 +186,6 @@ public static void onHardwareConfigRequest(Context ctx) { } } - public static void onHardwareSettingsRequest(Context ctx) { - var file = ctx.uploadedFile("data"); - - if (file == null) { - ctx.status(400); - ctx.result( - "No File was sent with the request. Make sure that the hardware settings json is sent at the key 'data'"); - logger.error( - "No File was sent with the request. Make sure that the hardware settings json is sent at the key 'data'"); - return; - } - - if (!file.extension().contains("json")) { - ctx.status(400); - ctx.result( - "The uploaded file was not of type 'json'. The uploaded file should be a .json file."); - logger.error( - "The uploaded file was not of type 'json'. The uploaded file should be a .json file."); - return; - } - - // Create a temp file - var tempFilePath = handleTempFileCreation(file); - - if (tempFilePath.isEmpty()) { - ctx.status(500); - ctx.result("There was an error while creating a temporary copy of the file"); - logger.error("There was an error while creating a temporary copy of the file"); - return; - } - - if (ConfigManager.getInstance().saveUploadedHardwareSettings(tempFilePath.get().toPath())) { - ctx.status(200); - ctx.result("Successfully saved the uploaded hardware settings, rebooting..."); - logger.info("Successfully saved the uploaded hardware settings, rebooting..."); - restartProgram(); - } else { - ctx.status(500); - ctx.result("There was an error while saving the uploaded hardware settings"); - logger.error("There was an error while saving the uploaded hardware settings"); - } - } - public static void onNetworkConfigRequest(Context ctx) { var file = ctx.uploadedFile("data"); diff --git a/photon-server/src/main/java/org/photonvision/server/Server.java b/photon-server/src/main/java/org/photonvision/server/Server.java index b202b85071..7bc1851a18 100644 --- a/photon-server/src/main/java/org/photonvision/server/Server.java +++ b/photon-server/src/main/java/org/photonvision/server/Server.java @@ -118,7 +118,6 @@ private static void start(int port) { app.post("/api/settings", RequestHandler::onSettingsImportRequest); app.get("/api/settings/photonvision_config.zip", RequestHandler::onSettingsExportRequest); app.post("/api/settings/hardwareConfig", RequestHandler::onHardwareConfigRequest); - app.post("/api/settings/hardwareSettings", RequestHandler::onHardwareSettingsRequest); app.post("/api/settings/networkConfig", RequestHandler::onNetworkConfigRequest); app.post("/api/settings/aprilTagFieldLayout", RequestHandler::onAprilTagFieldLayoutRequest); app.post("/api/settings/general", RequestHandler::onGeneralSettingsRequest); diff --git a/photon-targeting/src/main/java/org/photonvision/common/hardware/VisionLEDMode.java b/photon-targeting/src/main/java/org/photonvision/common/hardware/VisionLEDMode.java deleted file mode 100644 index d81a2d8c5b..0000000000 --- a/photon-targeting/src/main/java/org/photonvision/common/hardware/VisionLEDMode.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 . - */ - -package org.photonvision.common.hardware; - -public enum VisionLEDMode { - kDefault(-1), - kOff(0), - kOn(1), - kBlink(2); - - public final int value; - - VisionLEDMode(int value) { - this.value = value; - } - - @Override - public String toString() { - return switch (this) { - case kDefault -> "Default"; - case kOff -> "Off"; - case kOn -> "On"; - case kBlink -> "Blink"; - }; - } -} diff --git a/test-resources/hardware/HardwareConfig.json b/test-resources/hardware/HardwareConfig.json index e4cbdc65c7..373da4c461 100644 --- a/test-resources/hardware/HardwareConfig.json +++ b/test-resources/hardware/HardwareConfig.json @@ -2,12 +2,6 @@ "deviceName": "PhotonVision", "deviceLogoPath": "photonvision.png", "supportURL": "https://support.photonvision.com", - "ledPins" : [2, 13], - "statusRGBPins" : [-1, -1, -1], - "ledSetCommand" : "", - "ledsCanDim" : true, - "ledDimCommand" : "echo 10", - "ledBlinkCommand" : "echo 10", "cpuTempCommand" : "echo 10", "cpuMemoryCommand" : "echo 10", "cpuUtilCommand" : "echo 10",