[hal, wpilib] Remove DigitalSource and AnalogTrigger (#7753)

This commit is contained in:
Thad House
2025-01-30 18:58:21 -08:00
committed by GitHub
parent 7533b323d1
commit 6e704370b3
63 changed files with 7 additions and 2994 deletions

View File

@@ -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 {
/**
* <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:58</i><br>
* enum values
*/
public interface AnalogTriggerType {
/** <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:54</i> */
int kInWindow = 0;
/** <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:55</i> */
int kState = 1;
/** <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:56</i> */
int kRisingPulse = 2;
/** <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:57</i> */
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.
*
* <p>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.
*
* <p>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.
*
* <p>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.
*
* <p>If the value is true, then the averaged value is selected for the analog trigger, otherwise
* the immediate value is used.
*
* <p>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.
*
* <p>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.
*
* <p>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.
*
* <p>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.
*
* <p>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() {}
}

View File

@@ -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.
*

View File

@@ -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() {}
}

View File

@@ -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"

View File

@@ -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

View File

@@ -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 <jni.h>
#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"

View File

@@ -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 <stdint.h>
#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
/** @} */

View File

@@ -6,7 +6,6 @@
#include <stdint.h>
#include "hal/AnalogTrigger.h"
#include "hal/Types.h"
/**

View File

@@ -4,7 +4,6 @@
#pragma once
#include "hal/AnalogTrigger.h"
#include "hal/Types.h"
/**

View File

@@ -6,7 +6,6 @@
#include <stdint.h>
#include "hal/AnalogTrigger.h"
#include "hal/Types.h"
/**

View File

@@ -7,7 +7,6 @@
#include <stdint.h>
#include "hal/AnalogInput.h"
#include "hal/AnalogTrigger.h"
#include "hal/CAN.h"
#include "hal/CANAPI.h"
#include "hal/CTREPCM.h"

View File

@@ -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.
*

View File

@@ -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

View File

@@ -28,7 +28,4 @@ struct AnalogPort {
extern IndexedHandleResource<HAL_AnalogInputHandle, hal::AnalogPort,
kNumAnalogInputs, HAL_HandleEnum::AnalogInput>*
analogInputHandles;
int32_t GetAnalogTriggerInputIndex(HAL_AnalogTriggerHandle handle,
int32_t* status);
} // namespace hal

View File

@@ -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<HAL_AnalogTriggerHandle, AnalogTrigger,
kNumAnalogTriggers, HAL_HandleEnum::AnalogTrigger>*
analogTriggerHandles;
namespace hal::init {
void InitializeAnalogTrigger() {
static LimitedHandleResource<HAL_AnalogTriggerHandle, AnalogTrigger,
kNumAnalogTriggers,
HAL_HandleEnum::AnalogTrigger>
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<uint8_t>(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"

View File

@@ -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;
}

View File

@@ -9,7 +9,6 @@
#include <string>
#include "PortsInternal.h"
#include "hal/AnalogTrigger.h"
#include "hal/handles/DigitalHandleResource.h"
namespace hal {
@@ -58,17 +57,6 @@ extern DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
kNumDigitalChannels + kNumPWMHeaders>*
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.

View File

@@ -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();

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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<HALSIM_AnalogTriggerMode>(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"

View File

@@ -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<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{0};
SimDataValue<double, HAL_MakeDouble, GetTriggerLowerBoundName>
triggerLowerBound{0};
SimDataValue<double, HAL_MakeDouble, GetTriggerUpperBoundName>
triggerUpperBound{0};
SimDataValue<HALSIM_AnalogTriggerMode, MakeTriggerModeValue,
GetTriggerModeName>
triggerMode{static_cast<HALSIM_AnalogTriggerMode>(0)};
std::atomic<int32_t> inputPort;
virtual void ResetData();
};
extern AnalogTriggerData* SimAnalogTriggerData;
} // namespace hal

View File

@@ -4,7 +4,6 @@
#include <hal/simulation/AddressableLEDData.h>
#include <hal/simulation/AnalogInData.h>
#include <hal/simulation/AnalogTriggerData.h>
#include <hal/simulation/CTREPCMData.h>
#include <hal/simulation/CanData.h>
#include <hal/simulation/DIOData.h>
@@ -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++) {

View File

@@ -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 <memory>
#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"

View File

@@ -50,7 +50,6 @@ void InitializeHAL() {
InitializeREVPH();
InitializeAddressableLED();
InitializeAnalogInput();
InitializeAnalogTrigger();
InitializeCAN();
InitializeCANAPI();
InitializeConstants();

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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"

View File

@@ -130,10 +130,6 @@
<Bug pattern="URF_UNREAD_FIELD" />
<Class name="edu.wpi.first.wpilibj.ADIS16470_IMU" />
</Match>
<Match>
<Bug pattern="URF_UNREAD_FIELD" />
<Class name="edu.wpi.first.wpilibj.AnalogTrigger" />
</Match>
<Match>
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
</Match>

View File

@@ -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 <memory>
#include <utility>
#include <hal/AnalogTrigger.h>
#include <hal/FRCUsageReporting.h>
#include <wpi/NullDeleter.h>
#include <wpi/sendable/SendableRegistry.h>
#include "frc/AnalogInput.h"
#include "frc/DutyCycle.h"
#include "frc/Errors.h"
using namespace frc;
AnalogTrigger::AnalogTrigger(int channel)
: AnalogTrigger(std::make_shared<AnalogInput>(channel)) {
m_ownsAnalog = true;
wpi::SendableRegistry::AddChild(this, m_analogInput.get());
}
AnalogTrigger::AnalogTrigger(AnalogInput& input)
: AnalogTrigger{{&input, wpi::NullDeleter<AnalogInput>{}}} {}
AnalogTrigger::AnalogTrigger(AnalogInput* input)
: AnalogTrigger{{input, wpi::NullDeleter<AnalogInput>{}}} {}
AnalogTrigger::AnalogTrigger(std::shared_ptr<AnalogInput> 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<DutyCycle>{}}} {}
AnalogTrigger::AnalogTrigger(DutyCycle* input)
: AnalogTrigger{{input, wpi::NullDeleter<DutyCycle>{}}} {}
AnalogTrigger::AnalogTrigger(std::shared_ptr<DutyCycle> 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<AnalogTriggerOutput> AnalogTrigger::CreateOutput(
AnalogTriggerType type) const {
return std::shared_ptr<AnalogTriggerOutput>(
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;
}
}

View File

@@ -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 <hal/AnalogTrigger.h>
#include <hal/FRCUsageReporting.h>
#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<HAL_AnalogTriggerType>(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<uint8_t>(outputType) + 1);
}

View File

@@ -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<AnalogTriggerType>(0);
}
bool DigitalInput::IsAnalogTrigger() const {
return false;
}
void DigitalInput::SetSimDevice(HAL_SimDeviceHandle device) {
HAL_SetDIOSimDevice(m_handle, device);
}

View File

@@ -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<AnalogTriggerType>(0);
}
bool DigitalOutput::IsAnalogTrigger() const {
return false;
}
int DigitalOutput::GetChannel() const {
return m_channel;
}

View File

@@ -14,7 +14,6 @@
#include <wpi/StackTrace.h>
#include <wpi/sendable/SendableBuilder.h>
#include "frc/DigitalSource.h"
#include "frc/Errors.h"
#include "frc/SensorUtil.h"

View File

@@ -11,7 +11,6 @@
#include <wpi/sendable/SendableBuilder.h>
#include "frc/DigitalInput.h"
#include "frc/DigitalSource.h"
#include "frc/DutyCycle.h"
#include "frc/MathUtil.h"

View File

@@ -12,7 +12,6 @@
#include <wpi/StackTrace.h>
#include <wpi/sendable/SendableBuilder.h>
#include "frc/DigitalSource.h"
#include "frc/Errors.h"
using namespace frc;

View File

@@ -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 <memory>
#include <stdexcept>
#include <hal/simulation/AnalogTriggerData.h>
#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<CallbackStore> AnalogTriggerSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
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<CallbackStore>
AnalogTriggerSim::RegisterTriggerLowerBoundCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
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<CallbackStore>
AnalogTriggerSim::RegisterTriggerUpperBoundCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
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);
}

View File

@@ -27,8 +27,6 @@ namespace frc {
*/
class AnalogInput : public wpi::Sendable,
public wpi::SendableHelper<AnalogInput> {
friend class AnalogTrigger;
public:
/**
* Construct an analog input.

View File

@@ -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 <memory>
#include <hal/AnalogTrigger.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/AnalogTriggerOutput.h"
namespace frc {
class AnalogInput;
class DutyCycle;
class AnalogTrigger : public wpi::Sendable,
public wpi::SendableHelper<AnalogTrigger> {
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<AnalogInput> 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> 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<AnalogTriggerOutput> CreateOutput(
AnalogTriggerType type) const;
void InitSendable(wpi::SendableBuilder& builder) override;
private:
int GetSourceChannel() const;
std::shared_ptr<AnalogInput> m_analogInput;
std::shared_ptr<DutyCycle> m_dutyCycle;
hal::Handle<HAL_AnalogTriggerHandle, HAL_CleanAnalogTrigger> m_trigger;
bool m_ownsAnalog = false;
};
} // namespace frc

View File

@@ -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 <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#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<AnalogTriggerOutput> {
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

View File

@@ -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

View File

@@ -8,8 +8,6 @@
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#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<DigitalInput> {
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.

View File

@@ -10,8 +10,6 @@
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#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<DigitalOutput> {
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.

View File

@@ -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 <hal/Types.h>
#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

View File

@@ -13,9 +13,6 @@
#include <wpi/sendable/SendableHelper.h>
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<DutyCycle> {
friend class AnalogTrigger;
public:
/**
* Constructs a DutyCycle input from a smartio channel.

View File

@@ -15,7 +15,6 @@
namespace frc {
class DutyCycle;
class DigitalSource;
/**
* Class for supporting duty cycle/PWM encoders, such as the US Digital MA3 with

View File

@@ -14,9 +14,6 @@
#include "frc/CounterBase.h"
namespace frc {
class DigitalSource;
/**
* Class to read quad encoders.
*

View File

@@ -17,8 +17,6 @@
#include "EdgeConfiguration.h"
namespace frc {
class DigitalSource;
/**
* Tachometer for getting rotational speed from a device.
*

View File

@@ -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

View File

@@ -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 <memory>
#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<CallbackStore> 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<CallbackStore> 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<CallbackStore> 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

View File

@@ -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 <gtest/gtest.h>
#include <hal/HAL.h>
#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

View File

@@ -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;

View File

@@ -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);
}
}
}

View File

@@ -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.
*
* <p>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.
*
* <p>The InWindow output indicates whether the analog signal is inside the range defined by the
* limits.
*
* <p>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.
*
* <p>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) {}
}

View File

@@ -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.
*

View File

@@ -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;
}
}

View File

@@ -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() {}
}

View File

@@ -15,7 +15,7 @@ import edu.wpi.first.util.sendable.SendableRegistry;
* Class to read a duty cycle PWM input.
*
* <p>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.
*
* <p>These can be combined as the input of an AnalogTrigger to a Counter in order to implement
* rollover checking.

View File

@@ -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);
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}
}
}