From 6e704370b37c36f02da74a51323c399913663a6f Mon Sep 17 00:00:00 2001 From: Thad House Date: Thu, 30 Jan 2025 18:58:21 -0800 Subject: [PATCH] [hal, wpilib] Remove DigitalSource and AnalogTrigger (#7753) --- .../java/edu/wpi/first/hal/AnalogJNI.java | 158 ---------- .../main/java/edu/wpi/first/hal/PortsJNI.java | 8 - .../hal/simulation/AnalogTriggerDataJNI.java | 44 --- hal/src/main/native/cpp/jni/AnalogJNI.cpp | 184 ----------- hal/src/main/native/cpp/jni/PortsJNI.cpp | 13 - .../jni/simulation/AnalogTriggerDataJNI.cpp | 192 ------------ .../main/native/include/hal/AnalogTrigger.h | 184 ----------- hal/src/main/native/include/hal/Counter.h | 1 - hal/src/main/native/include/hal/DutyCycle.h | 1 - hal/src/main/native/include/hal/Encoder.h | 1 - hal/src/main/native/include/hal/HAL.h | 1 - hal/src/main/native/include/hal/Ports.h | 7 - .../hal/simulation/AnalogTriggerData.h | 64 ---- hal/src/main/native/sim/AnalogInternal.h | 3 - hal/src/main/native/sim/AnalogTrigger.cpp | 286 ------------------ hal/src/main/native/sim/DigitalInternal.cpp | 28 -- hal/src/main/native/sim/DigitalInternal.h | 12 - hal/src/main/native/sim/HAL.cpp | 2 - hal/src/main/native/sim/HALInitializer.h | 2 - hal/src/main/native/sim/Ports.cpp | 3 - hal/src/main/native/sim/PortsInternal.h | 1 - .../native/sim/mockdata/AnalogTriggerData.cpp | 63 ---- .../sim/mockdata/AnalogTriggerDataInternal.h | 36 --- hal/src/main/native/sim/mockdata/Reset.cpp | 5 - .../main/native/systemcore/AnalogTrigger.cpp | 100 ------ hal/src/main/native/systemcore/HAL.cpp | 1 - .../main/native/systemcore/HALInitializer.h | 1 - hal/src/main/native/systemcore/Ports.cpp | 3 - .../main/native/systemcore/PortsInternal.h | 1 - .../systemcore/mockdata/AnalogTriggerData.cpp | 30 -- styleguide/spotbugs-exclude.xml | 4 - wpilibc/src/main/native/cpp/AnalogTrigger.cpp | 132 -------- .../main/native/cpp/AnalogTriggerOutput.cpp | 48 --- wpilibc/src/main/native/cpp/DigitalInput.cpp | 12 - wpilibc/src/main/native/cpp/DigitalOutput.cpp | 12 - wpilibc/src/main/native/cpp/DutyCycle.cpp | 1 - .../src/main/native/cpp/DutyCycleEncoder.cpp | 1 - .../main/native/cpp/counter/UpDownCounter.cpp | 1 - .../cpp/simulation/AnalogTriggerSim.cpp | 89 ------ .../src/main/native/include/frc/AnalogInput.h | 2 - .../main/native/include/frc/AnalogTrigger.h | 194 ------------ .../native/include/frc/AnalogTriggerOutput.h | 106 ------- .../native/include/frc/AnalogTriggerType.h | 21 -- .../main/native/include/frc/DigitalInput.h | 23 +- .../main/native/include/frc/DigitalOutput.h | 23 +- .../main/native/include/frc/DigitalSource.h | 34 --- .../src/main/native/include/frc/DutyCycle.h | 5 - .../native/include/frc/DutyCycleEncoder.h | 1 - wpilibc/src/main/native/include/frc/Encoder.h | 3 - .../native/include/frc/counter/Tachometer.h | 2 - .../include/frc/counter/UpDownCounter.h | 2 - .../include/frc/simulation/AnalogTriggerSim.h | 137 --------- .../cpp/simulation/AnalogTriggerSimTest.cpp | 55 ---- .../cpp/simulation/SimInitializationTest.cpp | 2 - .../edu/wpi/first/wpilibj/AnalogTrigger.java | 198 ------------ .../first/wpilibj/AnalogTriggerOutput.java | 127 -------- .../edu/wpi/first/wpilibj/DigitalInput.java | 34 +-- .../edu/wpi/first/wpilibj/DigitalOutput.java | 34 +-- .../edu/wpi/first/wpilibj/DigitalSource.java | 47 --- .../java/edu/wpi/first/wpilibj/DutyCycle.java | 2 +- .../wpilibj/simulation/AnalogTriggerSim.java | 153 ---------- .../wpi/first/wpilibj/DigitalOutputTest.java | 2 - .../simulation/AnalogTriggerSimTest.java | 59 ---- 63 files changed, 7 insertions(+), 2994 deletions(-) delete mode 100644 hal/src/main/java/edu/wpi/first/hal/simulation/AnalogTriggerDataJNI.java delete mode 100644 hal/src/main/native/cpp/jni/simulation/AnalogTriggerDataJNI.cpp delete mode 100644 hal/src/main/native/include/hal/AnalogTrigger.h delete mode 100644 hal/src/main/native/include/hal/simulation/AnalogTriggerData.h delete mode 100644 hal/src/main/native/sim/AnalogTrigger.cpp delete mode 100644 hal/src/main/native/sim/mockdata/AnalogTriggerData.cpp delete mode 100644 hal/src/main/native/sim/mockdata/AnalogTriggerDataInternal.h delete mode 100644 hal/src/main/native/systemcore/AnalogTrigger.cpp delete mode 100644 hal/src/main/native/systemcore/mockdata/AnalogTriggerData.cpp delete mode 100644 wpilibc/src/main/native/cpp/AnalogTrigger.cpp delete mode 100644 wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp delete mode 100644 wpilibc/src/main/native/cpp/simulation/AnalogTriggerSim.cpp delete mode 100644 wpilibc/src/main/native/include/frc/AnalogTrigger.h delete mode 100644 wpilibc/src/main/native/include/frc/AnalogTriggerOutput.h delete mode 100644 wpilibc/src/main/native/include/frc/AnalogTriggerType.h delete mode 100644 wpilibc/src/main/native/include/frc/DigitalSource.h delete mode 100644 wpilibc/src/main/native/include/frc/simulation/AnalogTriggerSim.h delete mode 100644 wpilibc/src/test/native/cpp/simulation/AnalogTriggerSimTest.cpp delete mode 100644 wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java delete mode 100644 wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java delete mode 100644 wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java delete mode 100644 wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSim.java delete mode 100644 wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSimTest.java diff --git a/hal/src/main/java/edu/wpi/first/hal/AnalogJNI.java b/hal/src/main/java/edu/wpi/first/hal/AnalogJNI.java index 9c97cab286..dc816cda76 100644 --- a/hal/src/main/java/edu/wpi/first/hal/AnalogJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/AnalogJNI.java @@ -8,27 +8,8 @@ package edu.wpi.first.hal; * Analog Input / Output / Trigger JNI Functions. * * @see "hal/AnalogInput.h" - * @see "hal/AnalogTrigger.h" */ public class AnalogJNI extends JNIWrapper { - /** - * native declaration : AthenaJava\target\native\include\HAL\Analog.h:58
- * enum values - */ - public interface AnalogTriggerType { - /** native declaration : AthenaJava\target\native\include\HAL\Analog.h:54 */ - int kInWindow = 0; - - /** native declaration : AthenaJava\target\native\include\HAL\Analog.h:55 */ - int kState = 1; - - /** native declaration : AthenaJava\target\native\include\HAL\Analog.h:56 */ - int kRisingPulse = 2; - - /** native declaration : AthenaJava\target\native\include\HAL\Analog.h:57 */ - int kFallingPulse = 3; - } - /** * Initializes the analog input port using the given port object. * @@ -248,145 +229,6 @@ public class AnalogJNI extends JNIWrapper { */ public static native int getAnalogOffset(int analogPortHandle); - /** - * Initializes an analog trigger. - * - * @param analogInputHandle the analog input to use for triggering - * @return the created analog trigger handle - * @see "HAL_InitializeAnalogTrigger" - */ - public static native int initializeAnalogTrigger(int analogInputHandle); - - /** - * Initializes an analog trigger with a Duty Cycle input. - * - * @param dutyCycleHandle the analog input to use for duty cycle - * @return tbe created analog trigger handle - * @see "HAL_InitializeAnalogTriggerDutyCycle" - */ - public static native int initializeAnalogTriggerDutyCycle(int dutyCycleHandle); - - /** - * Frees an analog trigger. - * - * @param analogTriggerHandle the trigger handle - * @see "HAL_CleanAnalogTrigger" - */ - public static native void cleanAnalogTrigger(int analogTriggerHandle); - - /** - * Sets the raw ADC upper and lower limits of the analog trigger. - * - *

HAL_SetAnalogTriggerLimitsVoltage or HAL_SetAnalogTriggerLimitsDutyCycle is likely better in - * most cases. - * - * @param analogTriggerHandle the trigger handle - * @param lower the lower ADC value - * @param upper the upper ADC value - * @see "HAL_SetAnalogTriggerLimitsRaw" - */ - public static native void setAnalogTriggerLimitsRaw( - int analogTriggerHandle, int lower, int upper); - - /** - * Sets the upper and lower limits of the analog trigger. - * - *

The limits are given as floating point duty cycle values. - * - * @param analogTriggerHandle the trigger handle - * @param lower the lower duty cycle value - * @param higher the upper duty cycle value - * @see "HAL_SetAnalogTriggerLimitsDutyCycle" - */ - public static native void setAnalogTriggerLimitsDutyCycle( - int analogTriggerHandle, double lower, double higher); - - /** - * Sets the upper and lower limits of the analog trigger. - * - *

The limits are given as floating point voltage values. - * - * @param analogTriggerHandle the trigger handle - * @param lower the lower voltage value - * @param upper the upper voltage value - * @see "HAL_SetAnalogTriggerLimitsVoltage" - */ - public static native void setAnalogTriggerLimitsVoltage( - int analogTriggerHandle, double lower, double upper); - - /** - * Configures the analog trigger to use the averaged vs. raw values. - * - *

If the value is true, then the averaged value is selected for the analog trigger, otherwise - * the immediate value is used. - * - *

This is not allowed to be used if filtered mode is set. This is not allowed to be used with - * Duty Cycle based inputs. - * - * @param analogTriggerHandle the trigger handle - * @param useAveragedValue true to use averaged values, false for raw - * @see "HAL_SetAnalogTriggerAveraged" - */ - public static native void setAnalogTriggerAveraged( - int analogTriggerHandle, boolean useAveragedValue); - - /** - * Configures the analog trigger to use a filtered value. - * - *

The analog trigger will operate with a 3 point average rejection filter. This is designed to - * help with 360 degree pot applications for the period where the pot crosses through zero. - * - *

This is not allowed to be used if averaged mode is set. - * - * @param analogTriggerHandle the trigger handle - * @param useFilteredValue true to use filtered values, false for average or raw - * @see "HAL_SetAnalogTriggerFiltered" - */ - public static native void setAnalogTriggerFiltered( - int analogTriggerHandle, boolean useFilteredValue); - - /** - * Returns the InWindow output of the analog trigger. - * - *

True if the analog input is between the upper and lower limits. - * - * @param analogTriggerHandle the trigger handle - * @return the InWindow output of the analog trigger - * @see "HAL_GetAnalogTriggerInWindow" - */ - public static native boolean getAnalogTriggerInWindow(int analogTriggerHandle); - - /** - * Returns the TriggerState output of the analog trigger. - * - *

True if above upper limit. False if below lower limit. If in Hysteresis, maintain previous - * state. - * - * @param analogTriggerHandle the trigger handle - * @return the TriggerState output of the analog trigger - * @see "HAL_GetAnalogTriggerTriggerState" - */ - public static native boolean getAnalogTriggerTriggerState(int analogTriggerHandle); - - /** - * Gets the state of the analog trigger output. - * - * @param analogTriggerHandle the trigger handle - * @param type the type of trigger to trigger on - * @return the state of the analog trigger output - * @see "HAL_GetAnalogTriggerOutput" - */ - public static native boolean getAnalogTriggerOutput(int analogTriggerHandle, int type); - - /** - * Get the FPGA index for the AnalogTrigger. - * - * @param analogTriggerHandle the trigger handle - * @return the FPGA index - * @see "HAL_GetAnalogTriggerFPGAIndex" - */ - public static native int getAnalogTriggerFPGAIndex(int analogTriggerHandle); - /** Utility class. */ private AnalogJNI() {} } diff --git a/hal/src/main/java/edu/wpi/first/hal/PortsJNI.java b/hal/src/main/java/edu/wpi/first/hal/PortsJNI.java index 3841af6c6a..e92c9110c4 100644 --- a/hal/src/main/java/edu/wpi/first/hal/PortsJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/PortsJNI.java @@ -10,14 +10,6 @@ package edu.wpi.first.hal; * @see "hal/Ports.h" */ public class PortsJNI extends JNIWrapper { - /** - * Gets the number of analog triggers in the current system. - * - * @return the number of analog triggers - * @see "HAL_GetNumAnalogTriggers" - */ - public static native int getNumAnalogTriggers(); - /** * Gets the number of analog inputs in the current system. * diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/AnalogTriggerDataJNI.java b/hal/src/main/java/edu/wpi/first/hal/simulation/AnalogTriggerDataJNI.java deleted file mode 100644 index 681e5bd8c7..0000000000 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/AnalogTriggerDataJNI.java +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.hal.simulation; - -import edu.wpi.first.hal.JNIWrapper; - -/** JNI for analog trigger data. */ -public class AnalogTriggerDataJNI extends JNIWrapper { - public static native int registerInitializedCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelInitializedCallback(int index, int uid); - - public static native boolean getInitialized(int index); - - public static native void setInitialized(int index, boolean initialized); - - public static native int registerTriggerLowerBoundCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelTriggerLowerBoundCallback(int index, int uid); - - public static native double getTriggerLowerBound(int index); - - public static native void setTriggerLowerBound(int index, double triggerLowerBound); - - public static native int registerTriggerUpperBoundCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelTriggerUpperBoundCallback(int index, int uid); - - public static native double getTriggerUpperBound(int index); - - public static native void setTriggerUpperBound(int index, double triggerUpperBound); - - public static native void resetData(int index); - - public static native int findForChannel(int channel); - - /** Utility class. */ - private AnalogTriggerDataJNI() {} -} diff --git a/hal/src/main/native/cpp/jni/AnalogJNI.cpp b/hal/src/main/native/cpp/jni/AnalogJNI.cpp index 0312ea0aa8..f3081b877a 100644 --- a/hal/src/main/native/cpp/jni/AnalogJNI.cpp +++ b/hal/src/main/native/cpp/jni/AnalogJNI.cpp @@ -11,7 +11,6 @@ #include "HALUtil.h" #include "edu_wpi_first_hal_AnalogJNI.h" #include "hal/AnalogInput.h" -#include "hal/AnalogTrigger.h" #include "hal/Ports.h" #include "hal/handles/HandlesInternal.h" @@ -305,187 +304,4 @@ Java_edu_wpi_first_hal_AnalogJNI_getAnalogOffset return returnValue; } -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: initializeAnalogTrigger - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogTrigger - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - HAL_AnalogTriggerHandle analogTrigger = - HAL_InitializeAnalogTrigger((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); - return (jint)analogTrigger; -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: initializeAnalogTriggerDutyCycle - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogTriggerDutyCycle - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - HAL_AnalogTriggerHandle analogTrigger = - HAL_InitializeAnalogTriggerDutyCycle((HAL_DutyCycleHandle)id, &status); - CheckStatus(env, status); - return (jint)analogTrigger; -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: cleanAnalogTrigger - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogJNI_cleanAnalogTrigger - (JNIEnv* env, jclass, jint id) -{ - if (id != HAL_kInvalidHandle) { - HAL_CleanAnalogTrigger((HAL_AnalogTriggerHandle)id); - } -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: setAnalogTriggerLimitsRaw - * Signature: (III)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogJNI_setAnalogTriggerLimitsRaw - (JNIEnv* env, jclass, jint id, jint lower, jint upper) -{ - int32_t status = 0; - HAL_SetAnalogTriggerLimitsRaw((HAL_AnalogTriggerHandle)id, lower, upper, - &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: setAnalogTriggerLimitsDutyCycle - * Signature: (IDD)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogJNI_setAnalogTriggerLimitsDutyCycle - (JNIEnv* env, jclass, jint id, jdouble lower, jdouble upper) -{ - int32_t status = 0; - HAL_SetAnalogTriggerLimitsDutyCycle((HAL_AnalogTriggerHandle)id, lower, upper, - &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: setAnalogTriggerLimitsVoltage - * Signature: (IDD)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogJNI_setAnalogTriggerLimitsVoltage - (JNIEnv* env, jclass, jint id, jdouble lower, jdouble upper) -{ - int32_t status = 0; - HAL_SetAnalogTriggerLimitsVoltage((HAL_AnalogTriggerHandle)id, lower, upper, - &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: setAnalogTriggerAveraged - * Signature: (IZ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogJNI_setAnalogTriggerAveraged - (JNIEnv* env, jclass, jint id, jboolean averaged) -{ - int32_t status = 0; - HAL_SetAnalogTriggerAveraged((HAL_AnalogTriggerHandle)id, averaged, &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: setAnalogTriggerFiltered - * Signature: (IZ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogJNI_setAnalogTriggerFiltered - (JNIEnv* env, jclass, jint id, jboolean filtered) -{ - int32_t status = 0; - HAL_SetAnalogTriggerFiltered((HAL_AnalogTriggerHandle)id, filtered, &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: getAnalogTriggerInWindow - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL -Java_edu_wpi_first_hal_AnalogJNI_getAnalogTriggerInWindow - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jboolean val = - HAL_GetAnalogTriggerInWindow((HAL_AnalogTriggerHandle)id, &status); - CheckStatus(env, status); - return val; -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: getAnalogTriggerTriggerState - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL -Java_edu_wpi_first_hal_AnalogJNI_getAnalogTriggerTriggerState - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jboolean val = - HAL_GetAnalogTriggerTriggerState((HAL_AnalogTriggerHandle)id, &status); - CheckStatus(env, status); - return val; -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: getAnalogTriggerOutput - * Signature: (II)Z - */ -JNIEXPORT jboolean JNICALL -Java_edu_wpi_first_hal_AnalogJNI_getAnalogTriggerOutput - (JNIEnv* env, jclass, jint id, jint type) -{ - int32_t status = 0; - jboolean val = HAL_GetAnalogTriggerOutput( - (HAL_AnalogTriggerHandle)id, (HAL_AnalogTriggerType)type, &status); - CheckStatus(env, status); - return val; -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: getAnalogTriggerFPGAIndex - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_AnalogJNI_getAnalogTriggerFPGAIndex - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - auto val = - HAL_GetAnalogTriggerFPGAIndex((HAL_AnalogTriggerHandle)id, &status); - CheckStatus(env, status); - return val; -} - } // extern "C" diff --git a/hal/src/main/native/cpp/jni/PortsJNI.cpp b/hal/src/main/native/cpp/jni/PortsJNI.cpp index c3d153a895..2a86d90e2c 100644 --- a/hal/src/main/native/cpp/jni/PortsJNI.cpp +++ b/hal/src/main/native/cpp/jni/PortsJNI.cpp @@ -13,19 +13,6 @@ using namespace hal; extern "C" { -/* - * Class: edu_wpi_first_hal_PortsJNI - * Method: getNumAnalogTriggers - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_PortsJNI_getNumAnalogTriggers - (JNIEnv* env, jclass) -{ - jint value = HAL_GetNumAnalogTriggers(); - return value; -} - /* * Class: edu_wpi_first_hal_PortsJNI * Method: getNumAnalogInputs diff --git a/hal/src/main/native/cpp/jni/simulation/AnalogTriggerDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/AnalogTriggerDataJNI.cpp deleted file mode 100644 index f7a5147845..0000000000 --- a/hal/src/main/native/cpp/jni/simulation/AnalogTriggerDataJNI.cpp +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include - -#include "CallbackStore.h" -#include "edu_wpi_first_hal_simulation_AnalogTriggerDataJNI.h" -#include "hal/simulation/AnalogTriggerData.h" - -using namespace hal; - -extern "C" { - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: registerInitializedCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_registerInitializedCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback( - env, index, callback, initialNotify, - &HALSIM_RegisterAnalogTriggerInitializedCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: cancelInitializedCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_cancelInitializedCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback(env, handle, index, - &HALSIM_CancelAnalogTriggerInitializedCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: getInitialized - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_getInitialized - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogTriggerInitialized(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: setInitialized - * Signature: (IZ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_setInitialized - (JNIEnv*, jclass, jint index, jboolean value) -{ - HALSIM_SetAnalogTriggerInitialized(index, value); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: registerTriggerLowerBoundCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_registerTriggerLowerBoundCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback( - env, index, callback, initialNotify, - &HALSIM_RegisterAnalogTriggerTriggerLowerBoundCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: cancelTriggerLowerBoundCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_cancelTriggerLowerBoundCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback( - env, handle, index, &HALSIM_CancelAnalogTriggerTriggerLowerBoundCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: getTriggerLowerBound - * Signature: (I)D - */ -JNIEXPORT jdouble JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_getTriggerLowerBound - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogTriggerTriggerLowerBound(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: setTriggerLowerBound - * Signature: (ID)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_setTriggerLowerBound - (JNIEnv*, jclass, jint index, jdouble value) -{ - HALSIM_SetAnalogTriggerTriggerLowerBound(index, value); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: registerTriggerUpperBoundCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_registerTriggerUpperBoundCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback( - env, index, callback, initialNotify, - &HALSIM_RegisterAnalogTriggerTriggerUpperBoundCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: cancelTriggerUpperBoundCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_cancelTriggerUpperBoundCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback( - env, handle, index, &HALSIM_CancelAnalogTriggerTriggerUpperBoundCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: getTriggerUpperBound - * Signature: (I)D - */ -JNIEXPORT jdouble JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_getTriggerUpperBound - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogTriggerTriggerUpperBound(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: setTriggerUpperBound - * Signature: (ID)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_setTriggerUpperBound - (JNIEnv*, jclass, jint index, jdouble value) -{ - HALSIM_SetAnalogTriggerTriggerUpperBound(index, value); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: resetData - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_resetData - (JNIEnv*, jclass, jint index) -{ - HALSIM_ResetAnalogTriggerData(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI - * Method: findForChannel - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_findForChannel - (JNIEnv*, jclass, jint channel) -{ - return HALSIM_FindAnalogTriggerForChannel(channel); -} - -} // extern "C" diff --git a/hal/src/main/native/include/hal/AnalogTrigger.h b/hal/src/main/native/include/hal/AnalogTrigger.h deleted file mode 100644 index 8c470f12a0..0000000000 --- a/hal/src/main/native/include/hal/AnalogTrigger.h +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include - -#include "hal/Types.h" - -/** - * @defgroup hal_analogtrigger Analog Trigger Functions - * @ingroup hal_capi - * @{ - */ - -/** - * The type of analog trigger to trigger on. - */ -HAL_ENUM(HAL_AnalogTriggerType) { - HAL_Trigger_kInWindow = 0, - HAL_Trigger_kState = 1, - HAL_Trigger_kRisingPulse = 2, - HAL_Trigger_kFallingPulse = 3 -}; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Initializes an analog trigger. - * - * @param[in] portHandle the analog input to use for triggering - * @param[out] status Error status variable. 0 on success. - * @return the created analog trigger handle - */ -HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger( - HAL_AnalogInputHandle portHandle, int32_t* status); - -/** - * Initializes an analog trigger with a Duty Cycle input - * - * @param[in] dutyCycleHandle the analog input to use for duty cycle - * @param[out] status Error status variable. 0 on success. - * @return tbe created analog trigger handle - */ -HAL_AnalogTriggerHandle HAL_InitializeAnalogTriggerDutyCycle( - HAL_DutyCycleHandle dutyCycleHandle, int32_t* status); - -/** - * Frees an analog trigger. - * - * @param[in] analogTriggerHandle the trigger handle - */ -void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle); - -/** - * Sets the raw ADC upper and lower limits of the analog trigger. - * - * HAL_SetAnalogTriggerLimitsVoltage or HAL_SetAnalogTriggerLimitsDutyCycle - * is likely better in most cases. - * - * @param[in] analogTriggerHandle the trigger handle - * @param[in] lower the lower ADC value - * @param[in] upper the upper ADC value - * @param[out] status Error status variable. 0 on success. - */ -void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle, - int32_t lower, int32_t upper, - int32_t* status); - -/** - * Sets the upper and lower limits of the analog trigger. - * - * The limits are given as floating point voltage values. - * - * @param[in] analogTriggerHandle the trigger handle - * @param[in] lower the lower voltage value - * @param[in] upper the upper voltage value - * @param[out] status Error status variable. 0 on success. - */ -void HAL_SetAnalogTriggerLimitsVoltage( - HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper, - int32_t* status); - -/** - * Sets the upper and lower limits of the analog trigger. - * - * The limits are given as floating point duty cycle values. - * - * @param[in] analogTriggerHandle the trigger handle - * @param[in] lower the lower duty cycle value - * @param[in] upper the upper duty cycle value - * @param[out] status Error status variable. 0 on success. - */ -void HAL_SetAnalogTriggerLimitsDutyCycle( - HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper, - int32_t* status); - -/** - * Configures the analog trigger to use the averaged vs. raw values. - * - * If the value is true, then the averaged value is selected for the analog - * trigger, otherwise the immediate value is used. - * - * This is not allowed to be used if filtered mode is set. - * This is not allowed to be used with Duty Cycle based inputs. - * - * @param[in] analogTriggerHandle the trigger handle - * @param[in] useAveragedValue true to use averaged values, false for raw - * @param[out] status Error status variable. 0 on success. - */ -void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle, - HAL_Bool useAveragedValue, int32_t* status); - -/** - * Configures the analog trigger to use a filtered value. - * - * The analog trigger will operate with a 3 point average rejection filter. This - * is designed to help with 360 degree pot applications for the period where the - * pot crosses through zero. - * - * This is not allowed to be used if averaged mode is set. - * - * @param[in] analogTriggerHandle the trigger handle - * @param[in] useFilteredValue true to use filtered values, false for average - * or raw - * @param[out] status Error status variable. 0 on success. - */ -void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle, - HAL_Bool useFilteredValue, int32_t* status); - -/** - * Returns the InWindow output of the analog trigger. - * - * True if the analog input is between the upper and lower limits. - * - * @param[in] analogTriggerHandle the trigger handle - * @param[out] status Error status variable. 0 on success. - * @return the InWindow output of the analog trigger - */ -HAL_Bool HAL_GetAnalogTriggerInWindow( - HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status); - -/** - * Returns the TriggerState output of the analog trigger. - * - * True if above upper limit. - * False if below lower limit. - * If in Hysteresis, maintain previous state. - * - * @param[in] analogTriggerHandle the trigger handle - * @param[out] status Error status variable. 0 on success. - * @return the TriggerState output of the analog trigger - */ -HAL_Bool HAL_GetAnalogTriggerTriggerState( - HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status); - -/** - * Gets the state of the analog trigger output. - * - * @param[in] analogTriggerHandle the trigger handle - * @param[in] type the type of trigger to trigger on - * @param[out] status Error status variable. 0 on success. - * @return the state of the analog trigger output - */ -HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle, - HAL_AnalogTriggerType type, - int32_t* status); - -/** - * Get the FPGA index for the AnalogTrigger. - * - * @param[in] analogTriggerHandle the trigger handle - * @param[out] status Error status variable. 0 on success. - * @return the FPGA index - */ -int32_t HAL_GetAnalogTriggerFPGAIndex( - HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status); -#ifdef __cplusplus -} // extern "C" -#endif -/** @} */ diff --git a/hal/src/main/native/include/hal/Counter.h b/hal/src/main/native/include/hal/Counter.h index 7599ba94d7..6f1dc6a3e4 100644 --- a/hal/src/main/native/include/hal/Counter.h +++ b/hal/src/main/native/include/hal/Counter.h @@ -6,7 +6,6 @@ #include -#include "hal/AnalogTrigger.h" #include "hal/Types.h" /** diff --git a/hal/src/main/native/include/hal/DutyCycle.h b/hal/src/main/native/include/hal/DutyCycle.h index 4b9fb4a057..522f2fad02 100644 --- a/hal/src/main/native/include/hal/DutyCycle.h +++ b/hal/src/main/native/include/hal/DutyCycle.h @@ -4,7 +4,6 @@ #pragma once -#include "hal/AnalogTrigger.h" #include "hal/Types.h" /** diff --git a/hal/src/main/native/include/hal/Encoder.h b/hal/src/main/native/include/hal/Encoder.h index 968d1d905e..c12e239d47 100644 --- a/hal/src/main/native/include/hal/Encoder.h +++ b/hal/src/main/native/include/hal/Encoder.h @@ -6,7 +6,6 @@ #include -#include "hal/AnalogTrigger.h" #include "hal/Types.h" /** diff --git a/hal/src/main/native/include/hal/HAL.h b/hal/src/main/native/include/hal/HAL.h index d44470ce73..01af5ea82e 100644 --- a/hal/src/main/native/include/hal/HAL.h +++ b/hal/src/main/native/include/hal/HAL.h @@ -7,7 +7,6 @@ #include #include "hal/AnalogInput.h" -#include "hal/AnalogTrigger.h" #include "hal/CAN.h" #include "hal/CANAPI.h" #include "hal/CTREPCM.h" diff --git a/hal/src/main/native/include/hal/Ports.h b/hal/src/main/native/include/hal/Ports.h index 1d4b385b69..4536b6557d 100644 --- a/hal/src/main/native/include/hal/Ports.h +++ b/hal/src/main/native/include/hal/Ports.h @@ -16,13 +16,6 @@ extern "C" { #endif -/** - * Gets the number of analog triggers in the current system. - * - * @return the number of analog triggers - */ -int32_t HAL_GetNumAnalogTriggers(void); - /** * Gets the number of analog inputs in the current system. * diff --git a/hal/src/main/native/include/hal/simulation/AnalogTriggerData.h b/hal/src/main/native/include/hal/simulation/AnalogTriggerData.h deleted file mode 100644 index fb232a23e6..0000000000 --- a/hal/src/main/native/include/hal/simulation/AnalogTriggerData.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include "hal/Types.h" -#include "hal/simulation/NotifyListener.h" - -enum HALSIM_AnalogTriggerMode : int32_t { - HALSIM_AnalogTriggerUnassigned, - HALSIM_AnalogTriggerFiltered, - HALSIM_AnalogTriggerDutyCycle, - HALSIM_AnalogTriggerAveraged -}; - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t HALSIM_FindAnalogTriggerForChannel(int32_t channel); - -void HALSIM_ResetAnalogTriggerData(int32_t index); -int32_t HALSIM_RegisterAnalogTriggerInitializedCallback( - int32_t index, HAL_NotifyCallback callback, void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogTriggerInitializedCallback(int32_t index, int32_t uid); -HAL_Bool HALSIM_GetAnalogTriggerInitialized(int32_t index); -void HALSIM_SetAnalogTriggerInitialized(int32_t index, HAL_Bool initialized); - -int32_t HALSIM_RegisterAnalogTriggerTriggerLowerBoundCallback( - int32_t index, HAL_NotifyCallback callback, void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogTriggerTriggerLowerBoundCallback(int32_t index, - int32_t uid); -double HALSIM_GetAnalogTriggerTriggerLowerBound(int32_t index); -void HALSIM_SetAnalogTriggerTriggerLowerBound(int32_t index, - double triggerLowerBound); - -int32_t HALSIM_RegisterAnalogTriggerTriggerUpperBoundCallback( - int32_t index, HAL_NotifyCallback callback, void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogTriggerTriggerUpperBoundCallback(int32_t index, - int32_t uid); -double HALSIM_GetAnalogTriggerTriggerUpperBound(int32_t index); -void HALSIM_SetAnalogTriggerTriggerUpperBound(int32_t index, - double triggerUpperBound); - -int32_t HALSIM_RegisterAnalogTriggerTriggerModeCallback( - int32_t index, HAL_NotifyCallback callback, void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogTriggerTriggerModeCallback(int32_t index, int32_t uid); -HALSIM_AnalogTriggerMode HALSIM_GetAnalogTriggerTriggerMode(int32_t index); -void HALSIM_SetAnalogTriggerTriggerMode(int32_t index, - HALSIM_AnalogTriggerMode triggerMode); - -void HALSIM_RegisterAnalogTriggerAllCallbacks(int32_t index, - HAL_NotifyCallback callback, - void* param, - HAL_Bool initialNotify); - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/hal/src/main/native/sim/AnalogInternal.h b/hal/src/main/native/sim/AnalogInternal.h index 89cb3593c3..e065d6da43 100644 --- a/hal/src/main/native/sim/AnalogInternal.h +++ b/hal/src/main/native/sim/AnalogInternal.h @@ -28,7 +28,4 @@ struct AnalogPort { extern IndexedHandleResource* analogInputHandles; - -int32_t GetAnalogTriggerInputIndex(HAL_AnalogTriggerHandle handle, - int32_t* status); } // namespace hal diff --git a/hal/src/main/native/sim/AnalogTrigger.cpp b/hal/src/main/native/sim/AnalogTrigger.cpp deleted file mode 100644 index 92f0397ac4..0000000000 --- a/hal/src/main/native/sim/AnalogTrigger.cpp +++ /dev/null @@ -1,286 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "hal/AnalogTrigger.h" - -#include "AnalogInternal.h" -#include "HALInitializer.h" -#include "PortsInternal.h" -#include "hal/AnalogInput.h" -#include "hal/Errors.h" -#include "hal/handles/HandlesInternal.h" -#include "hal/handles/LimitedHandleResource.h" -#include "mockdata/AnalogInDataInternal.h" -#include "mockdata/AnalogTriggerDataInternal.h" - -namespace { -struct AnalogTrigger { - HAL_AnalogInputHandle analogHandle; - uint8_t index; - HAL_Bool trigState; -}; -} // namespace - -using namespace hal; - -static LimitedHandleResource* - analogTriggerHandles; - -namespace hal::init { -void InitializeAnalogTrigger() { - static LimitedHandleResource - atH; - analogTriggerHandles = &atH; -} -} // namespace hal::init - -int32_t hal::GetAnalogTriggerInputIndex(HAL_AnalogTriggerHandle handle, - int32_t* status) { - auto trigger = analogTriggerHandles->Get(handle); - if (trigger == nullptr) { - *status = HAL_HANDLE_ERROR; - return -1; - } - - auto analog_port = analogInputHandles->Get(trigger->analogHandle); - if (analog_port == nullptr) { - *status = HAL_HANDLE_ERROR; - return -1; - } - - return analog_port->channel; -} - -extern "C" { - -HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger( - HAL_AnalogInputHandle portHandle, int32_t* status) { - hal::init::CheckInit(); - // ensure we are given a valid and active AnalogInput handle - auto analog_port = analogInputHandles->Get(portHandle); - if (analog_port == nullptr) { - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - HAL_AnalogTriggerHandle handle = analogTriggerHandles->Allocate(); - if (handle == HAL_kInvalidHandle) { - *status = NO_AVAILABLE_RESOURCES; - return HAL_kInvalidHandle; - } - auto trigger = analogTriggerHandles->Get(handle); - if (trigger == nullptr) { // would only occur on thread issue - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; - } - trigger->analogHandle = portHandle; - trigger->index = static_cast(getHandleIndex(handle)); - - SimAnalogTriggerData[trigger->index].initialized = true; - SimAnalogTriggerData[trigger->index].inputPort = analog_port->channel; - - trigger->trigState = false; - - return handle; -} - -HAL_AnalogTriggerHandle HAL_InitializeAnalogTriggerDutyCycle( - HAL_DutyCycleHandle dutyCycleHandle, int32_t* status) { - *status = HAL_SIM_NOT_SUPPORTED; - return HAL_kInvalidHandle; -} - -void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle) { - auto trigger = analogTriggerHandles->Get(analogTriggerHandle); - analogTriggerHandles->Free(analogTriggerHandle); - if (trigger == nullptr) { - return; - } - SimAnalogTriggerData[trigger->index].initialized = false; - // caller owns the analog input handle. -} - -static double GetAnalogValueToVoltage( - HAL_AnalogTriggerHandle analogTriggerHandle, int32_t value, - int32_t* status) { - int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogTriggerHandle, status); - int32_t offset = HAL_GetAnalogOffset(analogTriggerHandle, status); - - double voltage = LSBWeight * 1.0e-9 * value - offset * 1.0e-9; - return voltage; -} - -void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle, - int32_t lower, int32_t upper, - int32_t* status) { - auto trigger = analogTriggerHandles->Get(analogTriggerHandle); - if (trigger == nullptr) { - *status = HAL_HANDLE_ERROR; - return; - } - if (lower > upper) { - *status = ANALOG_TRIGGER_LIMIT_ORDER_ERROR; - } - - double trigLower = - GetAnalogValueToVoltage(trigger->analogHandle, lower, status); - if (status != nullptr) { - return; - } - double trigUpper = - GetAnalogValueToVoltage(trigger->analogHandle, upper, status); - if (status != nullptr) { - return; - } - - SimAnalogTriggerData[trigger->index].triggerUpperBound = trigUpper; - SimAnalogTriggerData[trigger->index].triggerLowerBound = trigLower; -} - -void HAL_SetAnalogTriggerLimitsDutyCycle( - HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper, - int32_t* status) { - *status = HAL_SIM_NOT_SUPPORTED; -} - -void HAL_SetAnalogTriggerLimitsVoltage( - HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper, - int32_t* status) { - auto trigger = analogTriggerHandles->Get(analogTriggerHandle); - if (trigger == nullptr) { - *status = HAL_HANDLE_ERROR; - return; - } - if (lower > upper) { - *status = ANALOG_TRIGGER_LIMIT_ORDER_ERROR; - } - - SimAnalogTriggerData[trigger->index].triggerUpperBound = upper; - SimAnalogTriggerData[trigger->index].triggerLowerBound = lower; -} -void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle, - HAL_Bool useAveragedValue, int32_t* status) { - auto trigger = analogTriggerHandles->Get(analogTriggerHandle); - if (trigger == nullptr) { - *status = HAL_HANDLE_ERROR; - return; - } - - AnalogTriggerData* triggerData = &SimAnalogTriggerData[trigger->index]; - - if (triggerData->triggerMode.Get() != HALSIM_AnalogTriggerUnassigned) { - *status = INCOMPATIBLE_STATE; - return; - } - - auto setVal = useAveragedValue ? HALSIM_AnalogTriggerAveraged - : HALSIM_AnalogTriggerUnassigned; - triggerData->triggerMode = setVal; -} - -void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle, - HAL_Bool useFilteredValue, int32_t* status) { - auto trigger = analogTriggerHandles->Get(analogTriggerHandle); - if (trigger == nullptr) { - *status = HAL_HANDLE_ERROR; - return; - } - - AnalogTriggerData* triggerData = &SimAnalogTriggerData[trigger->index]; - - if (triggerData->triggerMode.Get() != HALSIM_AnalogTriggerUnassigned) { - *status = INCOMPATIBLE_STATE; - return; - } - - auto setVal = useFilteredValue ? HALSIM_AnalogTriggerFiltered - : HALSIM_AnalogTriggerUnassigned; - triggerData->triggerMode = setVal; -} - -static double GetTriggerValue(AnalogTrigger* trigger, int32_t* status) { - auto analogIn = analogInputHandles->Get(trigger->analogHandle); - if (analogIn == nullptr) { - // Returning HAL Handle Error, but going to ignore lower down - *status = HAL_HANDLE_ERROR; - return 0.0; - } - - return SimAnalogInData[analogIn->channel].voltage; -} - -HAL_Bool HAL_GetAnalogTriggerInWindow( - HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) { - auto trigger = analogTriggerHandles->Get(analogTriggerHandle); - if (trigger == nullptr) { - *status = HAL_HANDLE_ERROR; - return false; - } - - double voltage = GetTriggerValue(trigger.get(), status); - if (*status == HAL_HANDLE_ERROR) { - // Don't error if analog has been destroyed - *status = 0; - return false; - } - - double trigUpper = SimAnalogTriggerData[trigger->index].triggerUpperBound; - double trigLower = SimAnalogTriggerData[trigger->index].triggerLowerBound; - - return voltage >= trigLower && voltage <= trigUpper; -} -HAL_Bool HAL_GetAnalogTriggerTriggerState( - HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) { - auto trigger = analogTriggerHandles->Get(analogTriggerHandle); - if (trigger == nullptr) { - *status = HAL_HANDLE_ERROR; - return false; - } - - double voltage = GetTriggerValue(trigger.get(), status); - if (*status == HAL_HANDLE_ERROR) { - // Don't error if analog has been destroyed - *status = 0; - return false; - } - - double trigUpper = SimAnalogTriggerData[trigger->index].triggerUpperBound; - double trigLower = SimAnalogTriggerData[trigger->index].triggerLowerBound; - - if (voltage < trigLower) { - trigger->trigState = false; - return false; - } - if (voltage > trigUpper) { - trigger->trigState = true; - return true; - } - return trigger->trigState; -} -HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle, - HAL_AnalogTriggerType type, - int32_t* status) { - if (type == HAL_Trigger_kInWindow) { - return HAL_GetAnalogTriggerInWindow(analogTriggerHandle, status); - } else if (type == HAL_Trigger_kState) { - return HAL_GetAnalogTriggerTriggerState(analogTriggerHandle, status); - } else { - *status = ANALOG_TRIGGER_PULSE_OUTPUT_ERROR; - return false; - } -} - -int32_t HAL_GetAnalogTriggerFPGAIndex( - HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) { - auto trigger = analogTriggerHandles->Get(analogTriggerHandle); - if (trigger == nullptr) { - *status = HAL_HANDLE_ERROR; - return -1; - } - return trigger->index; -} - -} // extern "C" diff --git a/hal/src/main/native/sim/DigitalInternal.cpp b/hal/src/main/native/sim/DigitalInternal.cpp index b7c1d2f2ae..1afe126e04 100644 --- a/hal/src/main/native/sim/DigitalInternal.cpp +++ b/hal/src/main/native/sim/DigitalInternal.cpp @@ -5,7 +5,6 @@ #include "DigitalInternal.h" #include "PortsInternal.h" -#include "hal/AnalogTrigger.h" #include "hal/Errors.h" #include "hal/handles/DigitalHandleResource.h" #include "hal/handles/HandlesInternal.h" @@ -25,33 +24,6 @@ void InitializeDigitalInternal() { } } // namespace init -bool remapDigitalSource(HAL_Handle digitalSourceHandle, - HAL_AnalogTriggerType analogTriggerType, - uint8_t& channel, uint8_t& module, - bool& analogTrigger) { - if (isHandleType(digitalSourceHandle, HAL_HandleEnum::AnalogTrigger)) { - // If handle passed, index is not negative - int32_t index = getHandleIndex(digitalSourceHandle); - channel = (index << 2) + analogTriggerType; - module = channel >> 4; - analogTrigger = true; - return true; - } else if (isHandleType(digitalSourceHandle, HAL_HandleEnum::DIO)) { - int32_t index = getHandleIndex(digitalSourceHandle); - if (index >= kNumDigitalHeaders) { - channel = remapMXPChannel(index); - module = 1; - } else { - channel = index; - module = 0; - } - analogTrigger = false; - return true; - } else { - return false; - } -} - int32_t remapMXPChannel(int32_t channel) { return channel - 10; } diff --git a/hal/src/main/native/sim/DigitalInternal.h b/hal/src/main/native/sim/DigitalInternal.h index 4bca51f11f..e92b10664a 100644 --- a/hal/src/main/native/sim/DigitalInternal.h +++ b/hal/src/main/native/sim/DigitalInternal.h @@ -9,7 +9,6 @@ #include #include "PortsInternal.h" -#include "hal/AnalogTrigger.h" #include "hal/handles/DigitalHandleResource.h" namespace hal { @@ -58,17 +57,6 @@ extern DigitalHandleResource* digitalChannelHandles; -/** - * Remap the digital source channel and set the module. - * - * If it's an analog trigger, determine the module from the high order routing - * channel else do normal digital input remapping based on channel number - * (MXP). - */ -bool remapDigitalSource(HAL_Handle digitalSourceHandle, - HAL_AnalogTriggerType analogTriggerType, - uint8_t& channel, uint8_t& module, bool& analogTrigger); - /** * Map DIO channel numbers from their physical number (10 to 26) to their * position in the bit field. diff --git a/hal/src/main/native/sim/HAL.cpp b/hal/src/main/native/sim/HAL.cpp index 3227d88694..3e000997f4 100644 --- a/hal/src/main/native/sim/HAL.cpp +++ b/hal/src/main/native/sim/HAL.cpp @@ -68,7 +68,6 @@ namespace hal::init { void InitializeHAL() { InitializeAddressableLEDData(); InitializeAnalogInData(); - InitializeAnalogTriggerData(); InitializeCanData(); InitializeCANAPI(); InitializeDigitalPWMData(); @@ -86,7 +85,6 @@ void InitializeHAL() { InitializeAddressableLED(); InitializeAnalogInput(); InitializeAnalogInternal(); - InitializeAnalogTrigger(); InitializeCAN(); InitializeConstants(); InitializeCounter(); diff --git a/hal/src/main/native/sim/HALInitializer.h b/hal/src/main/native/sim/HALInitializer.h index 359bce8542..20779ff0f8 100644 --- a/hal/src/main/native/sim/HALInitializer.h +++ b/hal/src/main/native/sim/HALInitializer.h @@ -18,7 +18,6 @@ inline void CheckInit() { extern void InitializeAddressableLEDData(); extern void InitializeAnalogInData(); -extern void InitializeAnalogTriggerData(); extern void InitializeCanData(); extern void InitializeCANAPI(); extern void InitializeDigitalPWMData(); @@ -37,7 +36,6 @@ extern void InitializeSimDeviceData(); extern void InitializeAddressableLED(); extern void InitializeAnalogInput(); extern void InitializeAnalogInternal(); -extern void InitializeAnalogTrigger(); extern void InitializeCAN(); extern void InitializeConstants(); extern void InitializeCounter(); diff --git a/hal/src/main/native/sim/Ports.cpp b/hal/src/main/native/sim/Ports.cpp index 271c19e903..4cd622085a 100644 --- a/hal/src/main/native/sim/Ports.cpp +++ b/hal/src/main/native/sim/Ports.cpp @@ -13,9 +13,6 @@ void InitializePorts() {} } // namespace hal::init extern "C" { -int32_t HAL_GetNumAnalogTriggers(void) { - return kNumAnalogTriggers; -} int32_t HAL_GetNumAnalogInputs(void) { return kNumAnalogInputs; } diff --git a/hal/src/main/native/sim/PortsInternal.h b/hal/src/main/native/sim/PortsInternal.h index 190573b6ae..e1562fb95e 100644 --- a/hal/src/main/native/sim/PortsInternal.h +++ b/hal/src/main/native/sim/PortsInternal.h @@ -9,7 +9,6 @@ namespace hal { constexpr int32_t kAccelerometers = 1; constexpr int32_t kNumAccumulators = 2; -constexpr int32_t kNumAnalogTriggers = 8; constexpr int32_t kNumAnalogInputs = 8; constexpr int32_t kNumAnalogOutputs = 2; constexpr int32_t kNumCounters = 8; diff --git a/hal/src/main/native/sim/mockdata/AnalogTriggerData.cpp b/hal/src/main/native/sim/mockdata/AnalogTriggerData.cpp deleted file mode 100644 index 72184da476..0000000000 --- a/hal/src/main/native/sim/mockdata/AnalogTriggerData.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "../PortsInternal.h" -#include "AnalogTriggerDataInternal.h" - -using namespace hal; - -namespace hal::init { -void InitializeAnalogTriggerData() { - static AnalogTriggerData satd[kNumAnalogTriggers]; - ::hal::SimAnalogTriggerData = satd; -} -} // namespace hal::init - -AnalogTriggerData* hal::SimAnalogTriggerData; -void AnalogTriggerData::ResetData() { - initialized.Reset(0); - triggerLowerBound.Reset(0); - triggerUpperBound.Reset(0); - triggerMode.Reset(static_cast(0)); -} - -extern "C" { - -int32_t HALSIM_FindAnalogTriggerForChannel(int32_t channel) { - for (int i = 0; i < kNumAnalogTriggers; ++i) { - if (SimAnalogTriggerData[i].initialized && - SimAnalogTriggerData[i].inputPort == channel) { - return i; - } - } - return -1; -} - -void HALSIM_ResetAnalogTriggerData(int32_t index) { - SimAnalogTriggerData[index].ResetData(); -} - -#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \ - HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, AnalogTrigger##CAPINAME, \ - SimAnalogTriggerData, LOWERNAME) - -DEFINE_CAPI(HAL_Bool, Initialized, initialized) -DEFINE_CAPI(double, TriggerLowerBound, triggerLowerBound) -DEFINE_CAPI(double, TriggerUpperBound, triggerUpperBound) -DEFINE_CAPI(HALSIM_AnalogTriggerMode, TriggerMode, triggerMode) - -#define REGISTER(NAME) \ - SimAnalogTriggerData[index].NAME.RegisterCallback(callback, param, \ - initialNotify) - -void HALSIM_RegisterAnalogTriggerAllCallbacks(int32_t index, - HAL_NotifyCallback callback, - void* param, - HAL_Bool initialNotify) { - REGISTER(initialized); - REGISTER(triggerLowerBound); - REGISTER(triggerUpperBound); - REGISTER(triggerMode); -} -} // extern "C" diff --git a/hal/src/main/native/sim/mockdata/AnalogTriggerDataInternal.h b/hal/src/main/native/sim/mockdata/AnalogTriggerDataInternal.h deleted file mode 100644 index 16aab7980b..0000000000 --- a/hal/src/main/native/sim/mockdata/AnalogTriggerDataInternal.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include "hal/simulation/AnalogTriggerData.h" -#include "hal/simulation/SimDataValue.h" - -namespace hal { -class AnalogTriggerData { - HAL_SIMDATAVALUE_DEFINE_NAME(Initialized) - HAL_SIMDATAVALUE_DEFINE_NAME(TriggerLowerBound) - HAL_SIMDATAVALUE_DEFINE_NAME(TriggerUpperBound) - HAL_SIMDATAVALUE_DEFINE_NAME(TriggerMode) - - static LLVM_ATTRIBUTE_ALWAYS_INLINE HAL_Value - MakeTriggerModeValue(HALSIM_AnalogTriggerMode value) { - return HAL_MakeEnum(value); - } - - public: - SimDataValue initialized{0}; - SimDataValue - triggerLowerBound{0}; - SimDataValue - triggerUpperBound{0}; - SimDataValue - triggerMode{static_cast(0)}; - std::atomic inputPort; - - virtual void ResetData(); -}; -extern AnalogTriggerData* SimAnalogTriggerData; -} // namespace hal diff --git a/hal/src/main/native/sim/mockdata/Reset.cpp b/hal/src/main/native/sim/mockdata/Reset.cpp index 0bd9fb12e4..adaab48ba9 100644 --- a/hal/src/main/native/sim/mockdata/Reset.cpp +++ b/hal/src/main/native/sim/mockdata/Reset.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -30,10 +29,6 @@ extern "C" void HALSIM_ResetAllSimData(void) { HALSIM_ResetAnalogInData(i); } - for (int32_t i = 0; i < hal::kNumAnalogTriggers; i++) { - HALSIM_ResetAnalogTriggerData(i); - } - HALSIM_ResetCanData(); for (int32_t i = 0; i < hal::kNumCTREPCMModules; i++) { diff --git a/hal/src/main/native/systemcore/AnalogTrigger.cpp b/hal/src/main/native/systemcore/AnalogTrigger.cpp deleted file mode 100644 index 73773cf11a..0000000000 --- a/hal/src/main/native/systemcore/AnalogTrigger.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "hal/AnalogTrigger.h" - -#include - -#include "HALInitializer.h" -#include "HALInternal.h" -#include "PortsInternal.h" -#include "hal/AnalogInput.h" -#include "hal/DutyCycle.h" -#include "hal/Errors.h" -#include "hal/handles/HandlesInternal.h" -#include "hal/handles/LimitedHandleResource.h" - -using namespace hal; - -namespace hal::init { -void InitializeAnalogTrigger() {} -} // namespace hal::init - -extern "C" { - -HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger( - HAL_AnalogInputHandle portHandle, int32_t* status) { - hal::init::CheckInit(); - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; -} - -HAL_AnalogTriggerHandle HAL_InitializeAnalogTriggerDutyCycle( - HAL_DutyCycleHandle dutyCycleHandle, int32_t* status) { - hal::init::CheckInit(); - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; -} - -void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle) {} - -void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle, - int32_t lower, int32_t upper, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_SetAnalogTriggerLimitsDutyCycle( - HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_SetAnalogTriggerLimitsVoltage( - HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle, - HAL_Bool useAveragedValue, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle, - HAL_Bool useFilteredValue, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -HAL_Bool HAL_GetAnalogTriggerInWindow( - HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return false; -} - -HAL_Bool HAL_GetAnalogTriggerTriggerState( - HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return false; -} - -HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle, - HAL_AnalogTriggerType type, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return false; -} - -int32_t HAL_GetAnalogTriggerFPGAIndex( - HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -} // extern "C" diff --git a/hal/src/main/native/systemcore/HAL.cpp b/hal/src/main/native/systemcore/HAL.cpp index 5680014f38..9739a9e921 100644 --- a/hal/src/main/native/systemcore/HAL.cpp +++ b/hal/src/main/native/systemcore/HAL.cpp @@ -50,7 +50,6 @@ void InitializeHAL() { InitializeREVPH(); InitializeAddressableLED(); InitializeAnalogInput(); - InitializeAnalogTrigger(); InitializeCAN(); InitializeCANAPI(); InitializeConstants(); diff --git a/hal/src/main/native/systemcore/HALInitializer.h b/hal/src/main/native/systemcore/HALInitializer.h index 913743402a..ba0bc0eaf5 100644 --- a/hal/src/main/native/systemcore/HALInitializer.h +++ b/hal/src/main/native/systemcore/HALInitializer.h @@ -21,7 +21,6 @@ extern void InitializeREVPH(); extern void InitializeAddressableLED(); extern void InitializeAnalogInput(); extern void InitializeAnalogInternal(); -extern void InitializeAnalogTrigger(); extern void InitializeCAN(); extern void InitializeCANAPI(); extern void InitializeConstants(); diff --git a/hal/src/main/native/systemcore/Ports.cpp b/hal/src/main/native/systemcore/Ports.cpp index 670f18fdb1..22cc829376 100644 --- a/hal/src/main/native/systemcore/Ports.cpp +++ b/hal/src/main/native/systemcore/Ports.cpp @@ -13,9 +13,6 @@ void InitializePorts() {} } // namespace hal::init extern "C" { -int32_t HAL_GetNumAnalogTriggers(void) { - return kNumAnalogTriggers; -} int32_t HAL_GetNumAnalogInputs(void) { return kNumAnalogInputs; } diff --git a/hal/src/main/native/systemcore/PortsInternal.h b/hal/src/main/native/systemcore/PortsInternal.h index 0fc1c5639c..4d42fa4ec4 100644 --- a/hal/src/main/native/systemcore/PortsInternal.h +++ b/hal/src/main/native/systemcore/PortsInternal.h @@ -10,7 +10,6 @@ namespace hal { constexpr int32_t kNumSmartIo = 5; constexpr int32_t kNumAccumulators = 0; -constexpr int32_t kNumAnalogTriggers = 0; constexpr int32_t kNumAnalogInputs = 8; constexpr int32_t kNumAnalogOutputs = 0; constexpr int32_t kNumCounters = 0; diff --git a/hal/src/main/native/systemcore/mockdata/AnalogTriggerData.cpp b/hal/src/main/native/systemcore/mockdata/AnalogTriggerData.cpp deleted file mode 100644 index af8d7cc53f..0000000000 --- a/hal/src/main/native/systemcore/mockdata/AnalogTriggerData.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "hal/simulation/AnalogTriggerData.h" - -#include "hal/simulation/SimDataValue.h" - -extern "C" { - -int32_t HALSIM_FindAnalogTriggerForChannel(int32_t channel) { - return 0; -} - -void HALSIM_ResetAnalogTriggerData(int32_t index) {} - -#define DEFINE_CAPI(TYPE, CAPINAME, RETURN) \ - HAL_SIMDATAVALUE_STUB_CAPI(TYPE, HALSIM, AnalogTrigger##CAPINAME, RETURN) - -DEFINE_CAPI(HAL_Bool, Initialized, false) -DEFINE_CAPI(double, TriggerLowerBound, 0) -DEFINE_CAPI(double, TriggerUpperBound, 0) -DEFINE_CAPI(HALSIM_AnalogTriggerMode, TriggerMode, - HALSIM_AnalogTriggerUnassigned) - -void HALSIM_RegisterAnalogTriggerAllCallbacks(int32_t index, - HAL_NotifyCallback callback, - void* param, - HAL_Bool initialNotify) {} -} // extern "C" diff --git a/styleguide/spotbugs-exclude.xml b/styleguide/spotbugs-exclude.xml index e371b2386c..401b227ffe 100644 --- a/styleguide/spotbugs-exclude.xml +++ b/styleguide/spotbugs-exclude.xml @@ -130,10 +130,6 @@ - - - - diff --git a/wpilibc/src/main/native/cpp/AnalogTrigger.cpp b/wpilibc/src/main/native/cpp/AnalogTrigger.cpp deleted file mode 100644 index ca441103a0..0000000000 --- a/wpilibc/src/main/native/cpp/AnalogTrigger.cpp +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "frc/AnalogTrigger.h" - -#include -#include - -#include -#include -#include -#include - -#include "frc/AnalogInput.h" -#include "frc/DutyCycle.h" -#include "frc/Errors.h" - -using namespace frc; - -AnalogTrigger::AnalogTrigger(int channel) - : AnalogTrigger(std::make_shared(channel)) { - m_ownsAnalog = true; - wpi::SendableRegistry::AddChild(this, m_analogInput.get()); -} - -AnalogTrigger::AnalogTrigger(AnalogInput& input) - : AnalogTrigger{{&input, wpi::NullDeleter{}}} {} - -AnalogTrigger::AnalogTrigger(AnalogInput* input) - : AnalogTrigger{{input, wpi::NullDeleter{}}} {} - -AnalogTrigger::AnalogTrigger(std::shared_ptr input) - : m_analogInput{std::move(input)} { - int32_t status = 0; - m_trigger = HAL_InitializeAnalogTrigger(m_analogInput->m_port, &status); - FRC_CheckErrorStatus(status, "Channel {}", m_analogInput->GetChannel()); - int index = GetIndex(); - - HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1); - wpi::SendableRegistry::Add(this, "AnalogTrigger", index); -} - -AnalogTrigger::AnalogTrigger(DutyCycle& input) - : AnalogTrigger{{&input, wpi::NullDeleter{}}} {} - -AnalogTrigger::AnalogTrigger(DutyCycle* input) - : AnalogTrigger{{input, wpi::NullDeleter{}}} {} - -AnalogTrigger::AnalogTrigger(std::shared_ptr input) - : m_dutyCycle{input} { - int32_t status = 0; - m_trigger = HAL_InitializeAnalogTriggerDutyCycle(input->m_handle, &status); - FRC_CheckErrorStatus(status, "Channel {}", m_dutyCycle->GetSourceChannel()); - int index = GetIndex(); - - HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1); - wpi::SendableRegistry::Add(this, "AnalogTrigger", index); -} - -void AnalogTrigger::SetLimitsVoltage(double lower, double upper) { - int32_t status = 0; - HAL_SetAnalogTriggerLimitsVoltage(m_trigger, lower, upper, &status); - FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); -} - -void AnalogTrigger::SetLimitsDutyCycle(double lower, double upper) { - int32_t status = 0; - HAL_SetAnalogTriggerLimitsDutyCycle(m_trigger, lower, upper, &status); - FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); -} - -void AnalogTrigger::SetLimitsRaw(int lower, int upper) { - int32_t status = 0; - HAL_SetAnalogTriggerLimitsRaw(m_trigger, lower, upper, &status); - FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); -} - -void AnalogTrigger::SetAveraged(bool useAveragedValue) { - int32_t status = 0; - HAL_SetAnalogTriggerAveraged(m_trigger, useAveragedValue, &status); - FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); -} - -void AnalogTrigger::SetFiltered(bool useFilteredValue) { - int32_t status = 0; - HAL_SetAnalogTriggerFiltered(m_trigger, useFilteredValue, &status); - FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); -} - -int AnalogTrigger::GetIndex() const { - int32_t status = 0; - auto ret = HAL_GetAnalogTriggerFPGAIndex(m_trigger, &status); - FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); - return ret; -} - -bool AnalogTrigger::GetInWindow() { - int32_t status = 0; - bool result = HAL_GetAnalogTriggerInWindow(m_trigger, &status); - FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); - return result; -} - -bool AnalogTrigger::GetTriggerState() { - int32_t status = 0; - bool result = HAL_GetAnalogTriggerTriggerState(m_trigger, &status); - FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel()); - return result; -} - -std::shared_ptr AnalogTrigger::CreateOutput( - AnalogTriggerType type) const { - return std::shared_ptr( - new AnalogTriggerOutput(*this, type)); -} - -void AnalogTrigger::InitSendable(wpi::SendableBuilder& builder) { - if (m_ownsAnalog) { - m_analogInput->InitSendable(builder); - } -} - -int AnalogTrigger::GetSourceChannel() const { - if (m_analogInput) { - return m_analogInput->GetChannel(); - } else if (m_dutyCycle) { - return m_dutyCycle->GetSourceChannel(); - } else { - return -1; - } -} diff --git a/wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp b/wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp deleted file mode 100644 index ccb44b5721..0000000000 --- a/wpilibc/src/main/native/cpp/AnalogTriggerOutput.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "frc/AnalogTriggerOutput.h" - -#include -#include - -#include "frc/AnalogTrigger.h" -#include "frc/AnalogTriggerType.h" -#include "frc/Errors.h" - -using namespace frc; - -bool AnalogTriggerOutput::Get() const { - int32_t status = 0; - bool result = HAL_GetAnalogTriggerOutput( - m_trigger->m_trigger, static_cast(m_outputType), - &status); - FRC_CheckErrorStatus(status, "Get"); - return result; -} - -HAL_Handle AnalogTriggerOutput::GetPortHandleForRouting() const { - return m_trigger->m_trigger; -} - -AnalogTriggerType AnalogTriggerOutput::GetAnalogTriggerTypeForRouting() const { - return m_outputType; -} - -bool AnalogTriggerOutput::IsAnalogTrigger() const { - return true; -} - -int AnalogTriggerOutput::GetChannel() const { - return m_trigger->GetIndex(); -} - -void AnalogTriggerOutput::InitSendable(wpi::SendableBuilder&) {} - -AnalogTriggerOutput::AnalogTriggerOutput(const AnalogTrigger& trigger, - AnalogTriggerType outputType) - : m_trigger(&trigger), m_outputType(outputType) { - HAL_Report(HALUsageReporting::kResourceType_AnalogTriggerOutput, - trigger.GetIndex() + 1, static_cast(outputType) + 1); -} diff --git a/wpilibc/src/main/native/cpp/DigitalInput.cpp b/wpilibc/src/main/native/cpp/DigitalInput.cpp index 4c1474f0d9..5840686cb0 100644 --- a/wpilibc/src/main/native/cpp/DigitalInput.cpp +++ b/wpilibc/src/main/native/cpp/DigitalInput.cpp @@ -42,18 +42,6 @@ bool DigitalInput::Get() const { return value; } -HAL_Handle DigitalInput::GetPortHandleForRouting() const { - return m_handle; -} - -AnalogTriggerType DigitalInput::GetAnalogTriggerTypeForRouting() const { - return static_cast(0); -} - -bool DigitalInput::IsAnalogTrigger() const { - return false; -} - void DigitalInput::SetSimDevice(HAL_SimDeviceHandle device) { HAL_SetDIOSimDevice(m_handle, device); } diff --git a/wpilibc/src/main/native/cpp/DigitalOutput.cpp b/wpilibc/src/main/native/cpp/DigitalOutput.cpp index 3a2ec092ca..b124e06ecb 100644 --- a/wpilibc/src/main/native/cpp/DigitalOutput.cpp +++ b/wpilibc/src/main/native/cpp/DigitalOutput.cpp @@ -60,18 +60,6 @@ bool DigitalOutput::Get() const { return val; } -HAL_Handle DigitalOutput::GetPortHandleForRouting() const { - return m_handle; -} - -AnalogTriggerType DigitalOutput::GetAnalogTriggerTypeForRouting() const { - return static_cast(0); -} - -bool DigitalOutput::IsAnalogTrigger() const { - return false; -} - int DigitalOutput::GetChannel() const { return m_channel; } diff --git a/wpilibc/src/main/native/cpp/DutyCycle.cpp b/wpilibc/src/main/native/cpp/DutyCycle.cpp index 1a5c23dddc..b0ad03adf0 100644 --- a/wpilibc/src/main/native/cpp/DutyCycle.cpp +++ b/wpilibc/src/main/native/cpp/DutyCycle.cpp @@ -14,7 +14,6 @@ #include #include -#include "frc/DigitalSource.h" #include "frc/Errors.h" #include "frc/SensorUtil.h" diff --git a/wpilibc/src/main/native/cpp/DutyCycleEncoder.cpp b/wpilibc/src/main/native/cpp/DutyCycleEncoder.cpp index 5f1eabd60c..4dcf04d543 100644 --- a/wpilibc/src/main/native/cpp/DutyCycleEncoder.cpp +++ b/wpilibc/src/main/native/cpp/DutyCycleEncoder.cpp @@ -11,7 +11,6 @@ #include #include "frc/DigitalInput.h" -#include "frc/DigitalSource.h" #include "frc/DutyCycle.h" #include "frc/MathUtil.h" diff --git a/wpilibc/src/main/native/cpp/counter/UpDownCounter.cpp b/wpilibc/src/main/native/cpp/counter/UpDownCounter.cpp index 508c2bcb5d..e655339301 100644 --- a/wpilibc/src/main/native/cpp/counter/UpDownCounter.cpp +++ b/wpilibc/src/main/native/cpp/counter/UpDownCounter.cpp @@ -12,7 +12,6 @@ #include #include -#include "frc/DigitalSource.h" #include "frc/Errors.h" using namespace frc; diff --git a/wpilibc/src/main/native/cpp/simulation/AnalogTriggerSim.cpp b/wpilibc/src/main/native/cpp/simulation/AnalogTriggerSim.cpp deleted file mode 100644 index 8faba0feff..0000000000 --- a/wpilibc/src/main/native/cpp/simulation/AnalogTriggerSim.cpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "frc/simulation/AnalogTriggerSim.h" - -#include -#include - -#include - -#include "frc/AnalogTrigger.h" - -using namespace frc; -using namespace frc::sim; - -AnalogTriggerSim::AnalogTriggerSim(const AnalogTrigger& analogTrigger) - : m_index{analogTrigger.GetIndex()} {} - -AnalogTriggerSim AnalogTriggerSim::CreateForChannel(int channel) { - int index = HALSIM_FindAnalogTriggerForChannel(channel); - if (index < 0) { - throw std::out_of_range("no analog trigger found for channel"); - } - return AnalogTriggerSim{index}; -} - -AnalogTriggerSim AnalogTriggerSim::CreateForIndex(int index) { - return AnalogTriggerSim{index}; -} - -std::unique_ptr AnalogTriggerSim::RegisterInitializedCallback( - NotifyCallback callback, bool initialNotify) { - auto store = std::make_unique( - m_index, -1, callback, &HALSIM_CancelAnalogTriggerInitializedCallback); - store->SetUid(HALSIM_RegisterAnalogTriggerInitializedCallback( - m_index, &CallbackStoreThunk, store.get(), initialNotify)); - return store; -} - -bool AnalogTriggerSim::GetInitialized() const { - return HALSIM_GetAnalogTriggerInitialized(m_index); -} - -void AnalogTriggerSim::SetInitialized(bool initialized) { - HALSIM_SetAnalogTriggerInitialized(m_index, initialized); -} - -std::unique_ptr -AnalogTriggerSim::RegisterTriggerLowerBoundCallback(NotifyCallback callback, - bool initialNotify) { - auto store = std::make_unique( - m_index, -1, callback, - &HALSIM_CancelAnalogTriggerTriggerLowerBoundCallback); - store->SetUid(HALSIM_RegisterAnalogTriggerTriggerLowerBoundCallback( - m_index, &CallbackStoreThunk, store.get(), initialNotify)); - return store; -} - -double AnalogTriggerSim::GetTriggerLowerBound() const { - return HALSIM_GetAnalogTriggerTriggerLowerBound(m_index); -} - -void AnalogTriggerSim::SetTriggerLowerBound(double triggerLowerBound) { - HALSIM_SetAnalogTriggerTriggerLowerBound(m_index, triggerLowerBound); -} - -std::unique_ptr -AnalogTriggerSim::RegisterTriggerUpperBoundCallback(NotifyCallback callback, - bool initialNotify) { - auto store = std::make_unique( - m_index, -1, callback, - &HALSIM_CancelAnalogTriggerTriggerUpperBoundCallback); - store->SetUid(HALSIM_RegisterAnalogTriggerTriggerUpperBoundCallback( - m_index, &CallbackStoreThunk, store.get(), initialNotify)); - return store; -} - -double AnalogTriggerSim::GetTriggerUpperBound() const { - return HALSIM_GetAnalogTriggerTriggerUpperBound(m_index); -} - -void AnalogTriggerSim::SetTriggerUpperBound(double triggerUpperBound) { - HALSIM_SetAnalogTriggerTriggerUpperBound(m_index, triggerUpperBound); -} - -void AnalogTriggerSim::ResetData() { - HALSIM_ResetAnalogTriggerData(m_index); -} diff --git a/wpilibc/src/main/native/include/frc/AnalogInput.h b/wpilibc/src/main/native/include/frc/AnalogInput.h index 401226036b..f5f27633be 100644 --- a/wpilibc/src/main/native/include/frc/AnalogInput.h +++ b/wpilibc/src/main/native/include/frc/AnalogInput.h @@ -27,8 +27,6 @@ namespace frc { */ class AnalogInput : public wpi::Sendable, public wpi::SendableHelper { - friend class AnalogTrigger; - public: /** * Construct an analog input. diff --git a/wpilibc/src/main/native/include/frc/AnalogTrigger.h b/wpilibc/src/main/native/include/frc/AnalogTrigger.h deleted file mode 100644 index d38ec13107..0000000000 --- a/wpilibc/src/main/native/include/frc/AnalogTrigger.h +++ /dev/null @@ -1,194 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include - -#include -#include -#include -#include - -#include "frc/AnalogTriggerOutput.h" - -namespace frc { - -class AnalogInput; -class DutyCycle; - -class AnalogTrigger : public wpi::Sendable, - public wpi::SendableHelper { - friend class AnalogTriggerOutput; - - public: - /** - * Constructor for an analog trigger given a channel number. - * - * @param channel The channel number on the roboRIO to represent. 0-3 are - * on-board 4-7 are on the MXP port. - */ - explicit AnalogTrigger(int channel); - - /** - * Construct an analog trigger using an existing analog input. - * - * This should be used in the case of sharing an analog channel between the - * trigger and an analog input object. - * - * @param input A reference to the existing AnalogInput object - */ - explicit AnalogTrigger(AnalogInput& input); - - /** - * Construct an analog trigger using an existing analog input. - * - * This should be used in the case of sharing an analog channel between the - * trigger and an analog input object. - * - * @param input A pointer to the existing AnalogInput object - */ - explicit AnalogTrigger(AnalogInput* input); - - /** - * Construct an analog trigger using an existing analog input. - * - * This should be used in the case of sharing an analog channel between the - * trigger and an analog input object. - * - * @param input A shared_ptr to the existing AnalogInput object - */ - explicit AnalogTrigger(std::shared_ptr input); - - /** - * Construct an analog trigger using an existing duty cycle input. - * - * @param dutyCycle A reference to the existing DutyCycle object - */ - explicit AnalogTrigger(DutyCycle& dutyCycle); - - /** - * Construct an analog trigger using an existing duty cycle input. - * - * @param dutyCycle A pointer to the existing DutyCycle object - */ - explicit AnalogTrigger(DutyCycle* dutyCycle); - - /** - * Construct an analog trigger using an existing duty cycle input. - * - * @param dutyCycle A shared_ptr to the existing DutyCycle object - */ - explicit AnalogTrigger(std::shared_ptr dutyCycle); - - AnalogTrigger(AnalogTrigger&&) = default; - AnalogTrigger& operator=(AnalogTrigger&&) = default; - - ~AnalogTrigger() override = default; - - /** - * Set the upper and lower limits of the analog trigger. - * - * The limits are given as floating point voltage values. - * - * @param lower The lower limit of the trigger in Volts. - * @param upper The upper limit of the trigger in Volts. - */ - void SetLimitsVoltage(double lower, double upper); - - /** - * Set the upper and lower duty cycle limits of the analog trigger. - * - * The limits are given as floating point values between 0 and 1. - * - * @param lower The lower limit of the trigger in percentage. - * @param upper The upper limit of the trigger in percentage. - */ - void SetLimitsDutyCycle(double lower, double upper); - - /** - * Set the upper and lower limits of the analog trigger. - * - * The limits are given in ADC codes. If oversampling is used, the units must - * be scaled appropriately. - * - * @param lower The lower limit of the trigger in ADC codes (12-bit values). - * @param upper The upper limit of the trigger in ADC codes (12-bit values). - */ - void SetLimitsRaw(int lower, int upper); - - /** - * Configure the analog trigger to use the averaged vs. raw values. - * - * If the value is true, then the averaged value is selected for the analog - * trigger, otherwise the immediate value is used. - * - * @param useAveragedValue If true, use the Averaged value, otherwise use the - * instantaneous reading - */ - void SetAveraged(bool useAveragedValue); - - /** - * Configure the analog trigger to use a filtered value. - * - * The analog trigger will operate with a 3 point average rejection filter. - * This is designed to help with 360 degree pot applications for the period - * where the pot crosses through zero. - * - * @param useFilteredValue If true, use the 3 point rejection filter, - * otherwise use the unfiltered value - */ - void SetFiltered(bool useFilteredValue); - - /** - * Return the index of the analog trigger. - * - * This is the FPGA index of this analog trigger instance. - * - * @return The index of the analog trigger. - */ - int GetIndex() const; - - /** - * Return the InWindow output of the analog trigger. - * - * True if the analog input is between the upper and lower limits. - * - * @return True if the analog input is between the upper and lower limits. - */ - bool GetInWindow(); - - /** - * Return the TriggerState output of the analog trigger. - * - * True if above upper limit. - * False if below lower limit. - * If in Hysteresis, maintain previous state. - * - * @return True if above upper limit. False if below lower limit. If in - * Hysteresis, maintain previous state. - */ - bool GetTriggerState(); - - /** - * Creates an AnalogTriggerOutput object. - * - * @param type An enum of the type of output object to create. - * @return A pointer to a new AnalogTriggerOutput object. - */ - std::shared_ptr CreateOutput( - AnalogTriggerType type) const; - - void InitSendable(wpi::SendableBuilder& builder) override; - - private: - int GetSourceChannel() const; - - std::shared_ptr m_analogInput; - std::shared_ptr m_dutyCycle; - hal::Handle m_trigger; - bool m_ownsAnalog = false; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/AnalogTriggerOutput.h b/wpilibc/src/main/native/include/frc/AnalogTriggerOutput.h deleted file mode 100644 index fe22403efb..0000000000 --- a/wpilibc/src/main/native/include/frc/AnalogTriggerOutput.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include -#include - -#include "frc/DigitalSource.h" - -namespace frc { - -class AnalogTrigger; - -/** - * Class to represent a specific output from an analog trigger. - * - * This class is used to get the current output value and also as a - * DigitalSource to provide routing of an output to digital subsystems on the - * FPGA such as Counter, Encoder, and Interrupt. - * - * The TriggerState output indicates the primary output value of the trigger. - * If the analog signal is less than the lower limit, the output is false. If - * the analog value is greater than the upper limit, then the output is true. - * If the analog value is in between, then the trigger output state maintains - * its most recent value. - * - * The InWindow output indicates whether or not the analog signal is inside the - * range defined by the limits. - * - * The RisingPulse and FallingPulse outputs detect an instantaneous transition - * from above the upper limit to below the lower limit, and vice versa. These - * pulses represent a rollover condition of a sensor and can be routed to an up - * / down counter or to interrupts. Because the outputs generate a pulse, they - * cannot be read directly. To help ensure that a rollover condition is not - * missed, there is an average rejection filter available that operates on the - * upper 8 bits of a 12 bit number and selects the nearest outlier of 3 samples. - * This will reject a sample that is (due to averaging or sampling) errantly - * between the two limits. This filter will fail if more than one sample in a - * row is errantly in between the two limits. You may see this problem if - * attempting to use this feature with a mechanical rollover sensor, such as a - * 360 degree no-stop potentiometer without signal conditioning, because the - * rollover transition is not sharp / clean enough. Using the averaging engine - * may help with this, but rotational speeds of the sensor will then be limited. - */ -class AnalogTriggerOutput : public DigitalSource, - public wpi::Sendable, - public wpi::SendableHelper { - friend class AnalogTrigger; - - public: - /** - * Get the state of the analog trigger output. - * - * @return The state of the analog trigger output. - */ - bool Get() const; - - // DigitalSource interface - /** - * @return The HAL Handle to the specified source. - */ - HAL_Handle GetPortHandleForRouting() const override; - - /** - * @return The type of analog trigger output to be used. - */ - AnalogTriggerType GetAnalogTriggerTypeForRouting() const override; - - /** - * Is source an AnalogTrigger - */ - bool IsAnalogTrigger() const override; - - /** - * @return The channel of the source. - */ - int GetChannel() const override; - - void InitSendable(wpi::SendableBuilder& builder) override; - - protected: - /** - * Create an object that represents one of the four outputs from an analog - * trigger. - * - * Because this class derives from DigitalSource, it can be passed into - * routing functions for Counter, Encoder, etc. - * - * @param trigger A pointer to the trigger for which this is an output. - * @param outputType An enum that specifies the output on the trigger to - * represent. - */ - AnalogTriggerOutput(const AnalogTrigger& trigger, - AnalogTriggerType outputType); - - private: - // Uses pointer rather than smart pointer because a user can not construct - // an AnalogTriggerOutput themselves and because the AnalogTriggerOutput - // should always be in scope at the same time as an AnalogTrigger. - const AnalogTrigger* m_trigger; - AnalogTriggerType m_outputType; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/AnalogTriggerType.h b/wpilibc/src/main/native/include/frc/AnalogTriggerType.h deleted file mode 100644 index 0db114d598..0000000000 --- a/wpilibc/src/main/native/include/frc/AnalogTriggerType.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -namespace frc { - -/** Defines the state in which the AnalogTrigger triggers. */ -enum class AnalogTriggerType { - /// In window. - kInWindow = 0, - /// State. - kState = 1, - /// Rising Pulse. - kRisingPulse = 2, - /// Falling pulse. - kFallingPulse = 3 -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/DigitalInput.h b/wpilibc/src/main/native/include/frc/DigitalInput.h index b53453855d..2df396ab1f 100644 --- a/wpilibc/src/main/native/include/frc/DigitalInput.h +++ b/wpilibc/src/main/native/include/frc/DigitalInput.h @@ -8,8 +8,6 @@ #include #include -#include "frc/DigitalSource.h" - namespace frc { /** @@ -21,8 +19,7 @@ namespace frc { * as required. This class is only for devices like switches etc. that aren't * implemented anywhere else. */ -class DigitalInput : public DigitalSource, - public wpi::Sendable, +class DigitalInput : public wpi::Sendable, public wpi::SendableHelper { public: /** @@ -46,26 +43,10 @@ class DigitalInput : public DigitalSource, */ bool Get() const; - // Digital Source Interface - /** - * @return The HAL Handle to the specified source. - */ - HAL_Handle GetPortHandleForRouting() const override; - - /** - * @return The type of analog trigger output to be used. 0 for Digitals - */ - AnalogTriggerType GetAnalogTriggerTypeForRouting() const override; - - /** - * Is source an AnalogTrigger - */ - bool IsAnalogTrigger() const override; - /** * @return The GPIO channel number that this object represents. */ - int GetChannel() const override; + int GetChannel() const; /** * Indicates this input is used by a simulated device. diff --git a/wpilibc/src/main/native/include/frc/DigitalOutput.h b/wpilibc/src/main/native/include/frc/DigitalOutput.h index c9db4f6a6f..225e69b282 100644 --- a/wpilibc/src/main/native/include/frc/DigitalOutput.h +++ b/wpilibc/src/main/native/include/frc/DigitalOutput.h @@ -10,8 +10,6 @@ #include #include -#include "frc/DigitalSource.h" - namespace frc { /** @@ -21,8 +19,7 @@ namespace frc { * elsewhere will allocate channels automatically so for those devices it * shouldn't be done here. */ -class DigitalOutput : public DigitalSource, - public wpi::Sendable, +class DigitalOutput : public wpi::Sendable, public wpi::SendableHelper { public: /** @@ -56,26 +53,10 @@ class DigitalOutput : public DigitalSource, */ bool Get() const; - // Digital Source Interface - /** - * @return The HAL Handle to the specified source. - */ - HAL_Handle GetPortHandleForRouting() const override; - - /** - * @return The type of analog trigger output to be used. 0 for Digitals - */ - AnalogTriggerType GetAnalogTriggerTypeForRouting() const override; - - /** - * Is source an AnalogTrigger - */ - bool IsAnalogTrigger() const override; - /** * @return The GPIO channel number that this object represents. */ - int GetChannel() const override; + int GetChannel() const; /** * Output a single pulse on the digital output line. diff --git a/wpilibc/src/main/native/include/frc/DigitalSource.h b/wpilibc/src/main/native/include/frc/DigitalSource.h deleted file mode 100644 index 0dd35d615e..0000000000 --- a/wpilibc/src/main/native/include/frc/DigitalSource.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include - -#include "frc/AnalogTriggerType.h" - -namespace frc { - -/** - * DigitalSource Interface. - * - * The DigitalSource represents all the possible inputs for a counter or a - * quadrature encoder. The source may be either a digital input or an analog - * input. If the caller just provides a channel, then a digital input will be - * constructed and freed when finished for the source. The source can either be - * a digital input or analog trigger but not both. - */ -class DigitalSource { - public: - DigitalSource() = default; - DigitalSource(DigitalSource&&) = default; - DigitalSource& operator=(DigitalSource&&) = default; - - virtual HAL_Handle GetPortHandleForRouting() const = 0; - virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0; - virtual bool IsAnalogTrigger() const = 0; - virtual int GetChannel() const = 0; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/DutyCycle.h b/wpilibc/src/main/native/include/frc/DutyCycle.h index 5733b8df06..a2d426ebb3 100644 --- a/wpilibc/src/main/native/include/frc/DutyCycle.h +++ b/wpilibc/src/main/native/include/frc/DutyCycle.h @@ -13,9 +13,6 @@ #include namespace frc { -class DigitalSource; -class AnalogTrigger; - /** * Class to read a duty cycle PWM input. * @@ -28,8 +25,6 @@ class AnalogTrigger; * */ class DutyCycle : public wpi::Sendable, public wpi::SendableHelper { - friend class AnalogTrigger; - public: /** * Constructs a DutyCycle input from a smartio channel. diff --git a/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h b/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h index 39abf2e03a..399bdddf96 100644 --- a/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h +++ b/wpilibc/src/main/native/include/frc/DutyCycleEncoder.h @@ -15,7 +15,6 @@ namespace frc { class DutyCycle; -class DigitalSource; /** * Class for supporting duty cycle/PWM encoders, such as the US Digital MA3 with diff --git a/wpilibc/src/main/native/include/frc/Encoder.h b/wpilibc/src/main/native/include/frc/Encoder.h index 1e1da52406..dd23ba4942 100644 --- a/wpilibc/src/main/native/include/frc/Encoder.h +++ b/wpilibc/src/main/native/include/frc/Encoder.h @@ -14,9 +14,6 @@ #include "frc/CounterBase.h" namespace frc { - -class DigitalSource; - /** * Class to read quad encoders. * diff --git a/wpilibc/src/main/native/include/frc/counter/Tachometer.h b/wpilibc/src/main/native/include/frc/counter/Tachometer.h index 32754d6d6f..e22defd666 100644 --- a/wpilibc/src/main/native/include/frc/counter/Tachometer.h +++ b/wpilibc/src/main/native/include/frc/counter/Tachometer.h @@ -17,8 +17,6 @@ #include "EdgeConfiguration.h" namespace frc { -class DigitalSource; - /** * Tachometer for getting rotational speed from a device. * diff --git a/wpilibc/src/main/native/include/frc/counter/UpDownCounter.h b/wpilibc/src/main/native/include/frc/counter/UpDownCounter.h index 371748ac7e..4509c50fe3 100644 --- a/wpilibc/src/main/native/include/frc/counter/UpDownCounter.h +++ b/wpilibc/src/main/native/include/frc/counter/UpDownCounter.h @@ -14,8 +14,6 @@ #include "EdgeConfiguration.h" namespace frc { -class DigitalSource; - /** Up Down Counter. * * This class can count edges on a single digital input or count up based on an diff --git a/wpilibc/src/main/native/include/frc/simulation/AnalogTriggerSim.h b/wpilibc/src/main/native/include/frc/simulation/AnalogTriggerSim.h deleted file mode 100644 index 019a9a95ae..0000000000 --- a/wpilibc/src/main/native/include/frc/simulation/AnalogTriggerSim.h +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#pragma once - -#include - -#include "frc/simulation/CallbackStore.h" - -namespace frc { - -class AnalogTrigger; - -namespace sim { - -/** - * Class to control a simulated analog trigger. - */ -class AnalogTriggerSim { - public: - /** - * Constructs from an AnalogTrigger object. - * - * @param analogTrigger AnalogTrigger to simulate - */ - explicit AnalogTriggerSim(const AnalogTrigger& analogTrigger); - - /** - * Creates an AnalogTriggerSim for an analog input channel. - * - * @param channel analog input channel - * @return Simulated object - * @throws std::out_of_range if no AnalogTrigger is configured for that - * channel - */ - static AnalogTriggerSim CreateForChannel(int channel); - - /** - * Creates an AnalogTriggerSim for a simulated index. - * The index is incremented for each simulated AnalogTrigger. - * - * @param index simulator index - * @return Simulated object - */ - static AnalogTriggerSim CreateForIndex(int index); - - /** - * Register a callback on whether the analog trigger is initialized. - * - * @param callback the callback that will be called whenever the analog - * trigger is initialized - * @param initialNotify if true, the callback will be run on the initial value - * @return the CallbackStore object associated with this callback - */ - [[nodiscard]] - std::unique_ptr RegisterInitializedCallback( - NotifyCallback callback, bool initialNotify); - - /** - * Check if this analog trigger has been initialized. - * - * @return true if initialized - */ - bool GetInitialized() const; - - /** - * Change whether this analog trigger has been initialized. - * - * @param initialized the new value - */ - void SetInitialized(bool initialized); - - /** - * Register a callback on the lower bound. - * - * @param callback the callback that will be called whenever the lower bound - * is changed - * @param initialNotify if true, the callback will be run on the initial value - * @return the CallbackStore object associated with this callback - */ - [[nodiscard]] - std::unique_ptr RegisterTriggerLowerBoundCallback( - NotifyCallback callback, bool initialNotify); - - /** - * Get the lower bound. - * - * @return the lower bound - */ - double GetTriggerLowerBound() const; - - /** - * Change the lower bound. - * - * @param triggerLowerBound the new lower bound - */ - void SetTriggerLowerBound(double triggerLowerBound); - - /** - * Register a callback on the upper bound. - * - * @param callback the callback that will be called whenever the upper bound - * is changed - * @param initialNotify if true, the callback will be run on the initial value - * @return the CallbackStore object associated with this callback - */ - [[nodiscard]] - std::unique_ptr RegisterTriggerUpperBoundCallback( - NotifyCallback callback, bool initialNotify); - - /** - * Get the upper bound. - * - * @return the upper bound - */ - double GetTriggerUpperBound() const; - - /** - * Change the upper bound. - * - * @param triggerUpperBound the new upper bound - */ - void SetTriggerUpperBound(double triggerUpperBound); - - /** - * Reset all simulation data for this object. - */ - void ResetData(); - - private: - explicit AnalogTriggerSim(int index) : m_index{index} {} - - int m_index; -}; -} // namespace sim -} // namespace frc diff --git a/wpilibc/src/test/native/cpp/simulation/AnalogTriggerSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/AnalogTriggerSimTest.cpp deleted file mode 100644 index c01f64f64a..0000000000 --- a/wpilibc/src/test/native/cpp/simulation/AnalogTriggerSimTest.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include "frc/simulation/AnalogTriggerSim.h" // NOLINT(build/include_order) - -#include -#include - -#include "callback_helpers/TestCallbackHelpers.h" -#include "frc/AnalogTrigger.h" - -namespace frc::sim { - -TEST(AnalogTriggerSimTest, Initialization) { - HAL_Initialize(500, 0); - - AnalogTriggerSim sim = AnalogTriggerSim::CreateForIndex(0); - EXPECT_FALSE(sim.GetInitialized()); - - BooleanCallback callback; - auto cb = sim.RegisterInitializedCallback(callback.GetCallback(), false); - - AnalogTrigger trigger{0}; - EXPECT_TRUE(sim.GetInitialized()); - EXPECT_TRUE(callback.WasTriggered()); - EXPECT_TRUE(callback.GetLastValue()); -} - -TEST(AnalogTriggerSimTest, TriggerLowerBound) { - HAL_Initialize(500, 0); - - AnalogTrigger trigger{0}; - AnalogTriggerSim sim(trigger); - - DoubleCallback lowerCallback; - DoubleCallback upperCallback; - auto lowerCb = - sim.RegisterTriggerLowerBoundCallback(lowerCallback.GetCallback(), false); - auto upperCb = - sim.RegisterTriggerUpperBoundCallback(upperCallback.GetCallback(), false); - - trigger.SetLimitsVoltage(0.299, 1.91); - - EXPECT_EQ(0.299, sim.GetTriggerLowerBound()); - EXPECT_EQ(1.91, sim.GetTriggerUpperBound()); - - EXPECT_TRUE(lowerCallback.WasTriggered()); - EXPECT_EQ(0.299, lowerCallback.GetLastValue()); - - EXPECT_TRUE(upperCallback.WasTriggered()); - EXPECT_EQ(1.91, upperCallback.GetLastValue()); -} - -} // namespace frc::sim diff --git a/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp b/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp index 7096849e99..9ad63fe0b5 100644 --- a/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp @@ -9,7 +9,6 @@ #include "frc/simulation/AddressableLEDSim.h" #include "frc/simulation/AnalogInputSim.h" -#include "frc/simulation/AnalogTriggerSim.h" #include "frc/simulation/CTREPCMSim.h" #include "frc/simulation/DIOSim.h" #include "frc/simulation/DigitalPWMSim.h" @@ -25,7 +24,6 @@ using namespace frc::sim; TEST(SimInitializationTest, AllInitialize) { HAL_Initialize(500, 0); AnalogInputSim aisim{0}; - EXPECT_THROW(AnalogTriggerSim::CreateForChannel(0), std::out_of_range); EXPECT_THROW(DigitalPWMSim::CreateForChannel(0), std::out_of_range); DIOSim diosim{0}; DriverStationSim dssim; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java deleted file mode 100644 index a205e50336..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.wpilibj; - -import edu.wpi.first.hal.AnalogJNI; -import edu.wpi.first.hal.FRCNetComm.tResourceType; -import edu.wpi.first.hal.HAL; -import edu.wpi.first.hal.util.BoundaryException; -import edu.wpi.first.util.sendable.Sendable; -import edu.wpi.first.util.sendable.SendableBuilder; -import edu.wpi.first.util.sendable.SendableRegistry; -import edu.wpi.first.wpilibj.AnalogTriggerOutput.AnalogTriggerType; -import java.lang.ref.Reference; - -/** Class for creating and configuring Analog Triggers. */ -public class AnalogTrigger implements Sendable, AutoCloseable { - /** Where the analog trigger is attached. */ - protected int m_port; - - private AnalogInput m_analogInput; - - private DutyCycle m_dutyCycle; - - private boolean m_ownsAnalog; - - /** - * Constructor for an analog trigger given a channel number. - * - * @param channel the port to use for the analog trigger - */ - @SuppressWarnings("this-escape") - public AnalogTrigger(final int channel) { - this(new AnalogInput(channel)); - m_ownsAnalog = true; - SendableRegistry.addChild(this, m_analogInput); - } - - /** - * Construct an analog trigger given an analog channel. This should be used in the case of sharing - * an analog channel between the trigger and an analog input object. - * - * @param channel the AnalogInput to use for the analog trigger - */ - @SuppressWarnings("this-escape") - public AnalogTrigger(AnalogInput channel) { - m_analogInput = channel; - - m_port = AnalogJNI.initializeAnalogTrigger(channel.m_port); - - int index = getIndex(); - - HAL.report(tResourceType.kResourceType_AnalogTrigger, index + 1); - SendableRegistry.add(this, "AnalogTrigger", index); - } - - /** - * Construct an analog trigger given a duty cycle input. - * - * @param input the DutyCycle to use for the analog trigger - */ - @SuppressWarnings("this-escape") - public AnalogTrigger(DutyCycle input) { - m_dutyCycle = input; - - m_port = AnalogJNI.initializeAnalogTriggerDutyCycle(input.m_handle); - - int index = getIndex(); - - HAL.report(tResourceType.kResourceType_AnalogTrigger, index + 1); - SendableRegistry.add(this, "AnalogTrigger", index); - } - - @Override - public void close() { - try { - SendableRegistry.remove(this); - AnalogJNI.cleanAnalogTrigger(m_port); - m_port = 0; - if (m_ownsAnalog && m_analogInput != null) { - m_analogInput.close(); - } - } finally { - Reference.reachabilityFence(m_dutyCycle); - } - } - - /** - * Set the upper and lower limits of the analog trigger. The limits are given in ADC codes. If - * oversampling is used, the units must be scaled appropriately. - * - * @param lower the lower raw limit - * @param upper the upper raw limit - */ - public void setLimitsRaw(final int lower, final int upper) { - if (lower > upper) { - throw new BoundaryException("Lower bound is greater than upper"); - } - AnalogJNI.setAnalogTriggerLimitsRaw(m_port, lower, upper); - } - - /** - * Set the upper and lower limits of the analog trigger. The limits are given as floating point - * values between 0 and 1. - * - * @param lower the lower duty cycle limit - * @param upper the upper duty cycle limit - */ - public void setLimitsDutyCycle(double lower, double upper) { - if (lower > upper) { - throw new BoundaryException("Lower bound is greater than upper bound"); - } - AnalogJNI.setAnalogTriggerLimitsDutyCycle(m_port, lower, upper); - } - - /** - * Set the upper and lower limits of the analog trigger. The limits are given as floating point - * voltage values. - * - * @param lower the lower voltage limit - * @param upper the upper voltage limit - */ - public void setLimitsVoltage(double lower, double upper) { - if (lower > upper) { - throw new BoundaryException("Lower bound is greater than upper bound"); - } - AnalogJNI.setAnalogTriggerLimitsVoltage(m_port, lower, upper); - } - - /** - * Configure the analog trigger to use the averaged vs. raw values. If the value is true, then the - * averaged value is selected for the analog trigger, otherwise the immediate value is used. - * - * @param useAveragedValue true to use an averaged value, false otherwise - */ - public void setAveraged(boolean useAveragedValue) { - AnalogJNI.setAnalogTriggerAveraged(m_port, useAveragedValue); - } - - /** - * Configure the analog trigger to use a filtered value. The analog trigger will operate with a 3 - * point average rejection filter. This is designed to help with 360 degree pot applications for - * the period where the pot crosses through zero. - * - * @param useFilteredValue true to use a filtered value, false otherwise - */ - public void setFiltered(boolean useFilteredValue) { - AnalogJNI.setAnalogTriggerFiltered(m_port, useFilteredValue); - } - - /** - * Return the index of the analog trigger. This is the FPGA index of this analog trigger instance. - * - * @return The index of the analog trigger. - */ - public final int getIndex() { - return AnalogJNI.getAnalogTriggerFPGAIndex(m_port); - } - - /** - * Return the InWindow output of the analog trigger. True if the analog input is between the upper - * and lower limits. - * - * @return The InWindow output of the analog trigger. - */ - public boolean getInWindow() { - return AnalogJNI.getAnalogTriggerInWindow(m_port); - } - - /** - * Return the TriggerState output of the analog trigger. True if above upper limit. False if below - * lower limit. If in Hysteresis, maintain previous state. - * - * @return The TriggerState output of the analog trigger. - */ - public boolean getTriggerState() { - return AnalogJNI.getAnalogTriggerTriggerState(m_port); - } - - /** - * Creates an AnalogTriggerOutput object. Gets an output object that can be used for routing. - * Caller is responsible for deleting the AnalogTriggerOutput object. - * - * @param type An enum of the type of output object to create. - * @return A pointer to a new AnalogTriggerOutput object. - */ - public AnalogTriggerOutput createOutput(AnalogTriggerType type) { - return new AnalogTriggerOutput(this, type); - } - - @Override - public void initSendable(SendableBuilder builder) { - if (m_ownsAnalog) { - m_analogInput.initSendable(builder); - } - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java deleted file mode 100644 index 4d459fc2c4..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.wpilibj; - -import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; - -import edu.wpi.first.hal.AnalogJNI; -import edu.wpi.first.hal.FRCNetComm.tResourceType; -import edu.wpi.first.hal.HAL; -import edu.wpi.first.util.sendable.Sendable; -import edu.wpi.first.util.sendable.SendableBuilder; - -/** - * Class to represent a specific output from an analog trigger. This class is used to get the - * current output value and also as a DigitalSource to provide routing of an output to digital - * subsystems on the FPGA such as Counter, Encoder, and Interrupt. - * - *

The TriggerState output indicates the primary output value of the trigger. If the analog - * signal is less than the lower limit, the output is false. If the analog value is greater than the - * upper limit, then the output is true. If the analog value is in between, then the trigger output - * state maintains its most recent value. - * - *

The InWindow output indicates whether the analog signal is inside the range defined by the - * limits. - * - *

The RisingPulse and FallingPulse outputs detect an instantaneous transition from above the - * upper limit to below the lower limit, and vice versa. These pulses represent a rollover condition - * of a sensor and can be routed to an up / down counter or to interrupts. Because the outputs - * generate a pulse, they cannot be read directly. To help ensure that a rollover condition is not - * missed, there is an average rejection filter available that operates on the upper 8 bits of a 12 - * bit number and selects the nearest outlier of 3 samples. This will reject a sample that is (due - * to averaging or sampling) errantly between the two limits. This filter will fail if more than one - * sample in a row is errantly in between the two limits. You may see this problem if attempting to - * use this feature with a mechanical rollover sensor, such as a 360 degree no-stop potentiometer - * without signal conditioning, because the rollover transition is not sharp / clean enough. Using - * the averaging engine may help with this, but rotational speeds of the sensor will then be - * limited. - */ -public class AnalogTriggerOutput extends DigitalSource implements Sendable { - /** Exceptions dealing with improper operation of the Analog trigger output. */ - public static class AnalogTriggerOutputException extends RuntimeException { - /** - * Create a new exception with the given message. - * - * @param message the message to pass with the exception - */ - public AnalogTriggerOutputException(String message) { - super(message); - } - } - - private final AnalogTrigger m_trigger; - private final AnalogTriggerType m_outputType; - - /** - * Create an object that represents one of the four outputs from an analog trigger. - * - *

Because this class derives from DigitalSource, it can be passed into routing functions for - * Counter, Encoder, etc. - * - * @param trigger The trigger for which this is an output. - * @param outputType An enum that specifies the output on the trigger to represent. - */ - public AnalogTriggerOutput(AnalogTrigger trigger, final AnalogTriggerType outputType) { - requireNonNullParam(trigger, "trigger", "AnalogTriggerOutput"); - requireNonNullParam(outputType, "outputType", "AnalogTriggerOutput"); - - m_trigger = trigger; - m_outputType = outputType; - HAL.report( - tResourceType.kResourceType_AnalogTriggerOutput, - trigger.getIndex() + 1, - outputType.value + 1); - } - - /** - * Get the state of the analog trigger output. - * - * @return The state of the analog trigger output. - */ - public boolean get() { - return AnalogJNI.getAnalogTriggerOutput(m_trigger.m_port, m_outputType.value); - } - - @Override - public int getPortHandleForRouting() { - return m_trigger.m_port; - } - - @Override - public int getAnalogTriggerTypeForRouting() { - return m_outputType.value; - } - - @Override - public int getChannel() { - return m_trigger.getIndex(); - } - - @Override - public boolean isAnalogTrigger() { - return true; - } - - /** Defines the state in which the AnalogTrigger triggers. */ - public enum AnalogTriggerType { - /** In window. */ - kInWindow(AnalogJNI.AnalogTriggerType.kInWindow), - /** State. */ - kState(AnalogJNI.AnalogTriggerType.kState), - /** Rising pulse. */ - kRisingPulse(AnalogJNI.AnalogTriggerType.kRisingPulse), - /** Falling pulse. */ - kFallingPulse(AnalogJNI.AnalogTriggerType.kFallingPulse); - - private final int value; - - AnalogTriggerType(int value) { - this.value = value; - } - } - - @Override - public void initSendable(SendableBuilder builder) {} -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java index edd91cdebd..f7d9be4f70 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java @@ -18,7 +18,7 @@ import edu.wpi.first.util.sendable.SendableRegistry; * elsewhere will automatically allocate digital inputs and outputs as required. This class is only * for devices like switches etc. that aren't implemented anywhere else. */ -public class DigitalInput extends DigitalSource implements Sendable { +public class DigitalInput implements AutoCloseable, Sendable { private final int m_channel; private int m_handle; @@ -40,7 +40,6 @@ public class DigitalInput extends DigitalSource implements Sendable { @Override public void close() { - super.close(); SendableRegistry.remove(this); DIOJNI.freeDIOPort(m_handle); m_handle = 0; @@ -61,41 +60,10 @@ public class DigitalInput extends DigitalSource implements Sendable { * * @return The GPIO channel number that this object represents. */ - @Override public int getChannel() { return m_channel; } - /** - * Get the analog trigger type. - * - * @return false - */ - @Override - public int getAnalogTriggerTypeForRouting() { - return 0; - } - - /** - * Is this an analog trigger. - * - * @return true if this is an analog trigger - */ - @Override - public boolean isAnalogTrigger() { - return false; - } - - /** - * Get the HAL Port Handle. - * - * @return The HAL Handle to the specified source. - */ - @Override - public int getPortHandleForRouting() { - return m_handle; - } - /** * Indicates this input is used by a simulated device. * diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java index 87ed908c94..75951b63af 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java @@ -16,7 +16,7 @@ import edu.wpi.first.util.sendable.SendableRegistry; * Class to write digital outputs. This class will write digital outputs. Other devices that are * implemented elsewhere will automatically allocate digital inputs and outputs as required. */ -public class DigitalOutput extends DigitalSource implements Sendable { +public class DigitalOutput implements AutoCloseable, Sendable { private static final int invalidPwmGenerator = 0; private int m_pwmGenerator = invalidPwmGenerator; @@ -42,7 +42,6 @@ public class DigitalOutput extends DigitalSource implements Sendable { @Override public void close() { - super.close(); SendableRegistry.remove(this); // Disable the pwm only if we have allocated it if (m_pwmGenerator != invalidPwmGenerator) { @@ -75,7 +74,6 @@ public class DigitalOutput extends DigitalSource implements Sendable { * * @return The GPIO channel number. */ - @Override public int getChannel() { return m_channel; } @@ -199,34 +197,4 @@ public class DigitalOutput extends DigitalSource implements Sendable { builder.setSmartDashboardType("Digital Output"); builder.addBooleanProperty("Value", this::get, this::set); } - - /** - * Is this an analog trigger. - * - * @return true if this is an analog trigger - */ - @Override - public boolean isAnalogTrigger() { - return false; - } - - /** - * Get the analog trigger type. - * - * @return false - */ - @Override - public int getAnalogTriggerTypeForRouting() { - return 0; - } - - /** - * Get the HAL Port Handle. - * - * @return The HAL Handle to the specified source. - */ - @Override - public int getPortHandleForRouting() { - return m_handle; - } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java deleted file mode 100644 index 494efe95bf..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.wpilibj; - -/** - * DigitalSource Interface. The DigitalSource represents all the possible inputs for a counter or a - * quadrature encoder. The source may be either a digital input or an analog input. If the caller - * just provides a channel, then a digital input will be constructed and freed when finished for the - * source. The source can either be a digital input or analog trigger but not both. - */ -public abstract class DigitalSource implements AutoCloseable { - /** Default constructor. */ - public DigitalSource() {} - - /** - * Returns true if this DigitalSource is an AnalogTrigger. - * - * @return True if this DigitalSource is an AnalogTrigger. - */ - public abstract boolean isAnalogTrigger(); - - /** - * The DigitalSource channel. - * - * @return The DigitalSource channel. - */ - public abstract int getChannel(); - - /** - * If this is an analog trigger. - * - * @return true if this is an analog trigger. - */ - public abstract int getAnalogTriggerTypeForRouting(); - - /** - * The channel routing number. - * - * @return channel routing number - */ - public abstract int getPortHandleForRouting(); - - @Override - public void close() {} -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycle.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycle.java index 22ded084ac..cf8451db76 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycle.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DutyCycle.java @@ -15,7 +15,7 @@ import edu.wpi.first.util.sendable.SendableRegistry; * Class to read a duty cycle PWM input. * *

PWM input signals are specified with a frequency and a ratio of high to low in that frequency. - * There are 8 of these in the roboRIO, and they can be attached to any {@link DigitalSource}. + * There are 8 of these in the roboRIO, and they can be attached to any SmartIO Channel. * *

These can be combined as the input of an AnalogTrigger to a Counter in order to implement * rollover checking. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSim.java deleted file mode 100644 index fbc90e94d2..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSim.java +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.wpilibj.simulation; - -import edu.wpi.first.hal.simulation.AnalogTriggerDataJNI; -import edu.wpi.first.hal.simulation.NotifyCallback; -import edu.wpi.first.wpilibj.AnalogTrigger; -import java.util.NoSuchElementException; - -/** Class to control a simulated analog trigger. */ -public class AnalogTriggerSim { - private final int m_index; - - /** - * Constructs from an AnalogTrigger object. - * - * @param analogTrigger AnalogTrigger to simulate - */ - public AnalogTriggerSim(AnalogTrigger analogTrigger) { - m_index = analogTrigger.getIndex(); - } - - private AnalogTriggerSim(int index) { - m_index = index; - } - - /** - * Creates an AnalogTriggerSim for an analog input channel. - * - * @param channel analog input channel - * @return Simulated object - * @throws NoSuchElementException if no AnalogTrigger is configured for that channel - */ - public static AnalogTriggerSim createForChannel(int channel) { - int index = AnalogTriggerDataJNI.findForChannel(channel); - if (index < 0) { - throw new NoSuchElementException("no analog trigger found for channel " + channel); - } - return new AnalogTriggerSim(index); - } - - /** - * Creates an AnalogTriggerSim for a simulated index. The index is incremented for each simulated - * AnalogTrigger. - * - * @param index simulator index - * @return Simulated object - */ - public static AnalogTriggerSim createForIndex(int index) { - return new AnalogTriggerSim(index); - } - - /** - * Register a callback on whether the analog trigger is initialized. - * - * @param callback the callback that will be called whenever the analog trigger is initialized - * @param initialNotify if true, the callback will be run on the initial value - * @return the {@link CallbackStore} object associated with this callback. - */ - public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { - int uid = AnalogTriggerDataJNI.registerInitializedCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogTriggerDataJNI::cancelInitializedCallback); - } - - /** - * Check if this analog trigger has been initialized. - * - * @return true if initialized - */ - public boolean getInitialized() { - return AnalogTriggerDataJNI.getInitialized(m_index); - } - - /** - * Change whether this analog trigger has been initialized. - * - * @param initialized the new value - */ - public void setInitialized(boolean initialized) { - AnalogTriggerDataJNI.setInitialized(m_index, initialized); - } - - /** - * Register a callback on the lower bound. - * - * @param callback the callback that will be called whenever the lower bound is changed - * @param initialNotify if true, the callback will be run on the initial value - * @return the {@link CallbackStore} object associated with this callback. - */ - public CallbackStore registerTriggerLowerBoundCallback( - NotifyCallback callback, boolean initialNotify) { - int uid = - AnalogTriggerDataJNI.registerTriggerLowerBoundCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogTriggerDataJNI::cancelTriggerLowerBoundCallback); - } - - /** - * Get the lower bound. - * - * @return the lower bound - */ - public double getTriggerLowerBound() { - return AnalogTriggerDataJNI.getTriggerLowerBound(m_index); - } - - /** - * Change the lower bound. - * - * @param triggerLowerBound the new lower bound - */ - public void setTriggerLowerBound(double triggerLowerBound) { - AnalogTriggerDataJNI.setTriggerLowerBound(m_index, triggerLowerBound); - } - - /** - * Register a callback on the upper bound. - * - * @param callback the callback that will be called whenever the upper bound is changed - * @param initialNotify if true, the callback will be run on the initial value - * @return the {@link CallbackStore} object associated with this callback. - */ - public CallbackStore registerTriggerUpperBoundCallback( - NotifyCallback callback, boolean initialNotify) { - int uid = - AnalogTriggerDataJNI.registerTriggerUpperBoundCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogTriggerDataJNI::cancelTriggerUpperBoundCallback); - } - - /** - * Get the upper bound. - * - * @return the upper bound - */ - public double getTriggerUpperBound() { - return AnalogTriggerDataJNI.getTriggerUpperBound(m_index); - } - - /** - * Change the upper bound. - * - * @param triggerUpperBound the new upper bound - */ - public void setTriggerUpperBound(double triggerUpperBound) { - AnalogTriggerDataJNI.setTriggerUpperBound(m_index, triggerUpperBound); - } - - /** Reset all simulation data for this object. */ - public void resetData() { - AnalogTriggerDataJNI.resetData(m_index); - } -} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/DigitalOutputTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/DigitalOutputTest.java index e83b59c907..027af16d59 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/DigitalOutputTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/DigitalOutputTest.java @@ -16,8 +16,6 @@ class DigitalOutputTest { @Test void testDefaultFunctions() { try (DigitalOutput output = new DigitalOutput(0)) { - assertFalse(output.isAnalogTrigger()); - assertEquals(0, output.getAnalogTriggerTypeForRouting()); assertFalse(output.isPulsing()); } } diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSimTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSimTest.java deleted file mode 100644 index 1142914692..0000000000 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSimTest.java +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.wpilibj.simulation; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.AnalogTrigger; -import edu.wpi.first.wpilibj.simulation.testutils.BooleanCallback; -import edu.wpi.first.wpilibj.simulation.testutils.DoubleCallback; -import org.junit.jupiter.api.Test; - -class AnalogTriggerSimTest { - @Test - void testInitialization() { - HAL.initialize(500, 0); - - AnalogTriggerSim sim = AnalogTriggerSim.createForIndex(0); - sim.resetData(); - assertFalse(sim.getInitialized()); - - BooleanCallback callback = new BooleanCallback(); - - try (CallbackStore cb = sim.registerInitializedCallback(callback, false); - AnalogTrigger trigger = new AnalogTrigger(0)) { - assertTrue(sim.getInitialized()); - assertTrue(callback.wasTriggered()); - assertTrue(callback.getSetValue()); - } - } - - @Test - void triggerLowerBoundTest() { - HAL.initialize(500, 0); - - try (AnalogTrigger trigger = new AnalogTrigger(0)) { - AnalogTriggerSim sim = new AnalogTriggerSim(trigger); - DoubleCallback lowerCallback = new DoubleCallback(); - DoubleCallback upperCallback = new DoubleCallback(); - try (CallbackStore lowerCb = sim.registerTriggerLowerBoundCallback(lowerCallback, false); - CallbackStore upperCb = sim.registerTriggerUpperBoundCallback(upperCallback, false)) { - trigger.setLimitsVoltage(0.299, 1.91); - - assertEquals(0.299, sim.getTriggerLowerBound()); - assertEquals(1.91, sim.getTriggerUpperBound()); - - assertTrue(lowerCallback.wasTriggered()); - assertEquals(0.299, lowerCallback.getSetValue()); - - assertTrue(upperCallback.wasTriggered()); - assertEquals(1.91, upperCallback.getSetValue()); - } - } - } -}