diff --git a/hal/src/main/java/org/wpilib/hardware/hal/AnalogInputJNI.java b/hal/src/main/java/org/wpilib/hardware/hal/AnalogInputJNI.java index 1336e4b7e7..dfa5aa3e32 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/AnalogInputJNI.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/AnalogInputJNI.java @@ -55,77 +55,6 @@ public class AnalogInputJNI extends JNIWrapper { */ public static native void setAnalogInputSimDevice(int handle, int device); - /** - * Sets the sample rate. - * - *

This is a global setting for the Athena and effects all channels. - * - * @param samplesPerSecond The number of samples per channel per second. - * @see "HAL_SetAnalogSampleRate" - */ - public static native void setAnalogSampleRate(double samplesPerSecond); - - /** - * Gets the current sample rate. - * - *

This assumes one entry in the scan list. This is a global setting for the Athena and effects - * all channels. - * - * @return Sample rate. - * @see "HAL_GetAnalogSampleRate" - */ - public static native double getAnalogSampleRate(); - - /** - * Sets the number of averaging bits. - * - *

This sets the number of averaging bits. The actual number of averaged samples is 2**bits. - * Use averaging to improve the stability of your measurement at the expense of sampling rate. The - * averaging is done automatically in the FPGA. - * - * @param analogPortHandle Handle to the analog port to configure. - * @param bits Number of bits to average. - * @see "HAL_SetAnalogAverageBits" - */ - public static native void setAnalogAverageBits(int analogPortHandle, int bits); - - /** - * Gets the number of averaging bits. - * - *

This gets the number of averaging bits from the FPGA. The actual number of averaged samples - * is 2**bits. The averaging is done automatically in the FPGA. - * - * @param analogPortHandle Handle to the analog port to use. - * @return Bits to average. - * @see "HAL_GetAnalogAverageBits" - */ - public static native int getAnalogAverageBits(int analogPortHandle); - - /** - * Sets the number of oversample bits. - * - *

This sets the number of oversample bits. The actual number of oversampled values is 2**bits. - * Use oversampling to improve the resolution of your measurements at the expense of sampling - * rate. The oversampling is done automatically in the FPGA. - * - * @param analogPortHandle Handle to the analog port to use. - * @param bits Number of bits to oversample. - * @see "HAL_SetAnalogOversampleBits" - */ - public static native void setAnalogOversampleBits(int analogPortHandle, int bits); - - /** - * Gets the number of oversample bits. - * - *

This gets the number of oversample bits from the FPGA. The actual number of oversampled - * values is 2**bits. The oversampling is done automatically in the FPGA. - * - * @param analogPortHandle Handle to the analog port to use. - * @return Bits to oversample. - * @see "HAL_GetAnalogOversampleBits" - */ - public static native int getAnalogOversampleBits(int analogPortHandle); - /** * Gets a sample straight from the channel on this module. * @@ -139,21 +68,6 @@ public class AnalogInputJNI extends JNIWrapper { */ public static native short getAnalogValue(int analogPortHandle); - /** - * Gets a sample from the output of the oversample and average engine for the channel. - * - *

The sample is 12-bit + the value configured in SetOversampleBits(). The value configured in - * SetAverageBits() will cause this value to be averaged 2**bits number of samples. This is not a - * sliding window. The sample will not change until 2**(OversampleBits + AverageBits) samples have - * been acquired from the module on this channel. Use GetAverageVoltage() to get the analog value - * in calibrated units. - * - * @param analogPortHandle Handle to the analog port to use. - * @return A sample from the oversample and average engine for the channel. - * @see "HAL_GetAnalogAverageValue" - */ - public static native int getAnalogAverageValue(int analogPortHandle); - /** * Converts a voltage to a raw value for a specified channel. * @@ -181,8 +95,7 @@ public class AnalogInputJNI extends JNIWrapper { /** * Gets a scaled sample straight from the channel on this module. * - *

The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() - * and GetOffset(). + *

The value is scaled to units of Volts. * * @param analogPortHandle Handle to the analog port to use. * @return A scaled sample straight from the channel on this module. @@ -190,45 +103,6 @@ public class AnalogInputJNI extends JNIWrapper { */ public static native double getAnalogVoltage(int analogPortHandle); - /** - * Gets a scaled sample from the output of the oversample and average engine for the channel. - * - *

The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() - * and GetOffset(). Using oversampling will cause this value to be higher resolution, but it will - * update more slowly. Using averaging will cause this value to be more stable, but it will update - * more slowly. - * - * @param analogPortHandle Handle to the analog port to use. - * @return A scaled sample from the output of the oversample and average engine for the channel. - * @see "HAL_GetAnalogAverageVoltage" - */ - public static native double getAnalogAverageVoltage(int analogPortHandle); - - /** - * Gets the factory scaling least significant bit weight constant. The least significant bit - * weight constant for the channel that was calibrated in manufacturing and stored in an eeprom in - * the module. - * - *

Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9) - * - * @param analogPortHandle Handle to the analog port to use. - * @return Least significant bit weight. - * @see "HAL_GetAnalogLSBWeight" - */ - public static native int getAnalogLSBWeight(int analogPortHandle); - - /** - * Gets the factory scaling offset constant. The offset constant for the channel that was - * calibrated in manufacturing and stored in an eeprom in the module. - * - *

Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9) - * - * @param analogPortHandle Handle to the analog port to use. - * @return Offset constant. - * @see "HAL_GetAnalogOffset" - */ - public static native int getAnalogOffset(int analogPortHandle); - /** Utility class. */ private AnalogInputJNI() {} } diff --git a/hal/src/main/java/org/wpilib/hardware/hal/ConstantsJNI.java b/hal/src/main/java/org/wpilib/hardware/hal/ConstantsJNI.java deleted file mode 100644 index b5e698bf5d..0000000000 --- a/hal/src/main/java/org/wpilib/hardware/hal/ConstantsJNI.java +++ /dev/null @@ -1,23 +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 org.wpilib.hardware.hal; - -/** - * Constants HAL JNI functions. - * - * @see "wpi/hal/Constants.h" - */ -public class ConstantsJNI extends JNIWrapper { - /** - * Gets the number of FPGA system clock ticks per microsecond. - * - * @return the number of clock ticks per microsecond - * @see "HAL_GetSystemClockTicksPerMicrosecond" - */ - public static native int getSystemClockTicksPerMicrosecond(); - - /** Utility class. */ - private ConstantsJNI() {} -} diff --git a/hal/src/main/java/org/wpilib/hardware/hal/HALUtil.java b/hal/src/main/java/org/wpilib/hardware/hal/HALUtil.java index 0ed4db49e4..928b751aae 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/HALUtil.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/HALUtil.java @@ -25,17 +25,11 @@ public final class HALUtil extends JNIWrapper { /** A parameter is out of range. */ public static final int PARAMETER_OUT_OF_RANGE = -1028; - /** roboRIO 1.0. */ - public static final int RUNTIME_ROBORIO = 0; - - /** roboRIO 2.0. */ - public static final int RUNTIME_ROBORIO_2 = 1; + /** Systemcore runtime. */ + public static final int RUNTIME_SYSTEMCORE = 0; /** Simulation runtime. */ - public static final int RUNTIME_SIMULATION = 2; - - /** Systemcore. */ - public static final int RUNTIME_SYSTEMCORE = 3; + public static final int RUNTIME_SIMULATION = 1; /** * Returns the roboRIO serial number. @@ -72,9 +66,8 @@ public final class HALUtil extends JNIWrapper { * Returns the runtime type of the HAL. * * @return HAL Runtime Type - * @see RUNTIME_ROBORIO - * @see RUNTIME_ROBORIO_2 - * @see RUNTIME_SIMULATION + * @see #RUNTIME_SYSTEMCORE + * @see #RUNTIME_SIMULATION * @see "HAL_GetRuntimeType" */ public static native int getHALRuntimeType(); diff --git a/hal/src/main/java/org/wpilib/hardware/hal/PortsJNI.java b/hal/src/main/java/org/wpilib/hardware/hal/PortsJNI.java index 9435da7b42..14fd760587 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/PortsJNI.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/PortsJNI.java @@ -19,60 +19,12 @@ public class PortsJNI extends JNIWrapper { public static native int getNumCanBuses(); /** - * Gets the number of analog inputs in the current system. + * Gets the number of SmartIo ports in the current system. * - * @return the number of analog inputs - * @see "HAL_GetNumAnalogInputs" + * @return the number of SmartIo + * @see "HAL_GetNumSmartIo" */ - public static native int getNumAnalogInputs(); - - /** - * Gets the number of counters in the current system. - * - * @return the number of counters - * @see "HAL_GetNumCounters" - */ - public static native int getNumCounters(); - - /** - * Gets the number of digital channels in the current system. - * - * @return the number of digital channels - * @see "HAL_GetNumDigitalChannels" - */ - public static native int getNumDigitalChannels(); - - /** - * Gets the number of PWM channels in the current system. - * - * @return the number of PWM channels - * @see "HAL_GetNumPWMChannels" - */ - public static native int getNumPWMChannels(); - - /** - * Gets the number of digital IO PWM outputs in the current system. - * - * @return the number of digital IO PWM outputs - * @see "HAL_GetNumDigitalPWMOutputs" - */ - public static native int getNumDigitalPWMOutputs(); - - /** - * Gets the number of quadrature encoders in the current system. - * - * @return the number of quadrature encoders - * @see "HAL_GetNumEncoders" - */ - public static native int getNumEncoders(); - - /** - * Gets the number of interrupts in the current system. - * - * @return the number of interrupts - * @see "HAL_GetNumInterrupts" - */ - public static native int getNumInterrupts(); + public static native int getNumSmartIo(); /** * Gets the number of PCM modules in the current system. diff --git a/hal/src/main/java/org/wpilib/hardware/hal/simulation/AnalogInDataJNI.java b/hal/src/main/java/org/wpilib/hardware/hal/simulation/AnalogInDataJNI.java index 03d2092c15..9a9eddfcb5 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/simulation/AnalogInDataJNI.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/simulation/AnalogInDataJNI.java @@ -17,24 +17,6 @@ public class AnalogInDataJNI extends JNIWrapper { public static native void setInitialized(int index, boolean initialized); - public static native int registerAverageBitsCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelAverageBitsCallback(int index, int uid); - - public static native int getAverageBits(int index); - - public static native void setAverageBits(int index, int averageBits); - - public static native int registerOversampleBitsCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelOversampleBitsCallback(int index, int uid); - - public static native int getOversampleBits(int index); - - public static native void setOversampleBits(int index, int oversampleBits); - public static native int registerVoltageCallback( int index, NotifyCallback callback, boolean initialNotify); diff --git a/hal/src/main/native/cpp/jni/AnalogInputJNI.cpp b/hal/src/main/native/cpp/jni/AnalogInputJNI.cpp index 0d80c4ba6c..ac58763d7d 100644 --- a/hal/src/main/native/cpp/jni/AnalogInputJNI.cpp +++ b/hal/src/main/native/cpp/jni/AnalogInputJNI.cpp @@ -86,95 +86,6 @@ Java_org_wpilib_hardware_hal_AnalogInputJNI_setAnalogInputSimDevice (HAL_SimDeviceHandle)device); } -/* - * Class: org_wpilib_hardware_hal_AnalogInputJNI - * Method: setAnalogSampleRate - * Signature: (D)V - */ -JNIEXPORT void JNICALL -Java_org_wpilib_hardware_hal_AnalogInputJNI_setAnalogSampleRate - (JNIEnv* env, jclass, jdouble value) -{ - int32_t status = 0; - HAL_SetAnalogSampleRate(value, &status); - CheckStatus(env, status); -} - -/* - * Class: org_wpilib_hardware_hal_AnalogInputJNI - * Method: getAnalogSampleRate - * Signature: ()D - */ -JNIEXPORT jdouble JNICALL -Java_org_wpilib_hardware_hal_AnalogInputJNI_getAnalogSampleRate - (JNIEnv* env, jclass) -{ - int32_t status = 0; - double returnValue = HAL_GetAnalogSampleRate(&status); - CheckStatus(env, status); - return returnValue; -} - -/* - * Class: org_wpilib_hardware_hal_AnalogInputJNI - * Method: setAnalogAverageBits - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_org_wpilib_hardware_hal_AnalogInputJNI_setAnalogAverageBits - (JNIEnv* env, jclass, jint id, jint value) -{ - int32_t status = 0; - HAL_SetAnalogAverageBits((HAL_AnalogInputHandle)id, value, &status); - CheckStatus(env, status); -} - -/* - * Class: org_wpilib_hardware_hal_AnalogInputJNI - * Method: getAnalogAverageBits - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_AnalogInputJNI_getAnalogAverageBits - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jint returnValue = - HAL_GetAnalogAverageBits((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); - return returnValue; -} - -/* - * Class: org_wpilib_hardware_hal_AnalogInputJNI - * Method: setAnalogOversampleBits - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_org_wpilib_hardware_hal_AnalogInputJNI_setAnalogOversampleBits - (JNIEnv* env, jclass, jint id, jint value) -{ - int32_t status = 0; - HAL_SetAnalogOversampleBits((HAL_AnalogInputHandle)id, value, &status); - CheckStatus(env, status); -} - -/* - * Class: org_wpilib_hardware_hal_AnalogInputJNI - * Method: getAnalogOversampleBits - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_AnalogInputJNI_getAnalogOversampleBits - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jint returnValue = - HAL_GetAnalogOversampleBits((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); - return returnValue; -} - /* * Class: org_wpilib_hardware_hal_AnalogInputJNI * Method: getAnalogValue @@ -190,22 +101,6 @@ Java_org_wpilib_hardware_hal_AnalogInputJNI_getAnalogValue return returnValue; } -/* - * Class: org_wpilib_hardware_hal_AnalogInputJNI - * Method: getAnalogAverageValue - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_AnalogInputJNI_getAnalogAverageValue - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jint returnValue = - HAL_GetAnalogAverageValue((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); - return returnValue; -} - /* * Class: org_wpilib_hardware_hal_AnalogInputJNI * Method: getAnalogVoltsToValue @@ -254,52 +149,4 @@ Java_org_wpilib_hardware_hal_AnalogInputJNI_getAnalogVoltage return returnValue; } -/* - * Class: org_wpilib_hardware_hal_AnalogInputJNI - * Method: getAnalogAverageVoltage - * Signature: (I)D - */ -JNIEXPORT jdouble JNICALL -Java_org_wpilib_hardware_hal_AnalogInputJNI_getAnalogAverageVoltage - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jdouble returnValue = - HAL_GetAnalogAverageVoltage((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); - return returnValue; -} - -/* - * Class: org_wpilib_hardware_hal_AnalogInputJNI - * Method: getAnalogLSBWeight - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_AnalogInputJNI_getAnalogLSBWeight - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - - jint returnValue = HAL_GetAnalogLSBWeight((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); - return returnValue; -} - -/* - * Class: org_wpilib_hardware_hal_AnalogInputJNI - * Method: getAnalogOffset - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_AnalogInputJNI_getAnalogOffset - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - - jint returnValue = HAL_GetAnalogOffset((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); - return returnValue; -} - } // extern "C" diff --git a/hal/src/main/native/cpp/jni/ConstantsJNI.cpp b/hal/src/main/native/cpp/jni/ConstantsJNI.cpp deleted file mode 100644 index 01a08fa5cb..0000000000 --- a/hal/src/main/native/cpp/jni/ConstantsJNI.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include - -#include - -#include "HALUtil.hpp" -#include "org_wpilib_hardware_hal_ConstantsJNI.h" -#include "wpi/hal/Constants.h" - -using namespace wpi::hal; - -extern "C" { -/* - * Class: org_wpilib_hardware_hal_ConstantsJNI - * Method: getSystemClockTicksPerMicrosecond - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_ConstantsJNI_getSystemClockTicksPerMicrosecond - (JNIEnv* env, jclass) -{ - jint value = HAL_GetSystemClockTicksPerMicrosecond(); - return value; -} -} // extern "C" diff --git a/hal/src/main/native/cpp/jni/HALUtil.cpp b/hal/src/main/native/cpp/jni/HALUtil.cpp index 721b28f658..27ed2868a0 100644 --- a/hal/src/main/native/cpp/jni/HALUtil.cpp +++ b/hal/src/main/native/cpp/jni/HALUtil.cpp @@ -24,10 +24,6 @@ using namespace wpi::util::java; -static_assert(org_wpilib_hardware_hal_HALUtil_RUNTIME_ROBORIO == - HAL_RUNTIME_ROBORIO); -static_assert(org_wpilib_hardware_hal_HALUtil_RUNTIME_ROBORIO_2 == - HAL_RUNTIME_ROBORIO_2); static_assert(org_wpilib_hardware_hal_HALUtil_RUNTIME_SIMULATION == HAL_RUNTIME_SIMULATION); static_assert(org_wpilib_hardware_hal_HALUtil_RUNTIME_SYSTEMCORE == diff --git a/hal/src/main/native/cpp/jni/PortsJNI.cpp b/hal/src/main/native/cpp/jni/PortsJNI.cpp index f5bb17fe50..33f03d4f79 100644 --- a/hal/src/main/native/cpp/jni/PortsJNI.cpp +++ b/hal/src/main/native/cpp/jni/PortsJNI.cpp @@ -28,92 +28,14 @@ Java_org_wpilib_hardware_hal_PortsJNI_getNumCanBuses /* * Class: org_wpilib_hardware_hal_PortsJNI - * Method: getNumAnalogInputs + * Method: getNumSmartIo * Signature: ()I */ JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_PortsJNI_getNumAnalogInputs +Java_org_wpilib_hardware_hal_PortsJNI_getNumSmartIo (JNIEnv* env, jclass) { - jint value = HAL_GetNumAnalogInputs(); - return value; -} - -/* - * Class: org_wpilib_hardware_hal_PortsJNI - * Method: getNumCounters - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_PortsJNI_getNumCounters - (JNIEnv* env, jclass) -{ - jint value = HAL_GetNumCounters(); - return value; -} - -/* - * Class: org_wpilib_hardware_hal_PortsJNI - * Method: getNumDigitalChannels - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_PortsJNI_getNumDigitalChannels - (JNIEnv* env, jclass) -{ - jint value = HAL_GetNumDigitalChannels(); - return value; -} - -/* - * Class: org_wpilib_hardware_hal_PortsJNI - * Method: getNumPWMChannels - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_PortsJNI_getNumPWMChannels - (JNIEnv* env, jclass) -{ - jint value = HAL_GetNumPWMChannels(); - return value; -} - -/* - * Class: org_wpilib_hardware_hal_PortsJNI - * Method: getNumDigitalPWMOutputs - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_PortsJNI_getNumDigitalPWMOutputs - (JNIEnv* env, jclass) -{ - jint value = HAL_GetNumDigitalPWMOutputs(); - return value; -} - -/* - * Class: org_wpilib_hardware_hal_PortsJNI - * Method: getNumEncoders - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_PortsJNI_getNumEncoders - (JNIEnv* env, jclass) -{ - jint value = HAL_GetNumEncoders(); - return value; -} - -/* - * Class: org_wpilib_hardware_hal_PortsJNI - * Method: getNumInterrupts - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_PortsJNI_getNumInterrupts - (JNIEnv* env, jclass) -{ - jint value = HAL_GetNumInterrupts(); + jint value = HAL_GetNumSmartIo(); return value; } diff --git a/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp index 023e4a7120..21442a5480 100644 --- a/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp +++ b/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp @@ -62,106 +62,6 @@ Java_org_wpilib_hardware_hal_simulation_AnalogInDataJNI_setInitialized HALSIM_SetAnalogInInitialized(index, value); } -/* - * Class: org_wpilib_hardware_hal_simulation_AnalogInDataJNI - * Method: registerAverageBitsCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_simulation_AnalogInDataJNI_registerAverageBitsCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback(env, index, callback, initialNotify, - &HALSIM_RegisterAnalogInAverageBitsCallback); -} - -/* - * Class: org_wpilib_hardware_hal_simulation_AnalogInDataJNI - * Method: cancelAverageBitsCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_org_wpilib_hardware_hal_simulation_AnalogInDataJNI_cancelAverageBitsCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback(env, handle, index, - &HALSIM_CancelAnalogInAverageBitsCallback); -} - -/* - * Class: org_wpilib_hardware_hal_simulation_AnalogInDataJNI - * Method: getAverageBits - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_simulation_AnalogInDataJNI_getAverageBits - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogInAverageBits(index); -} - -/* - * Class: org_wpilib_hardware_hal_simulation_AnalogInDataJNI - * Method: setAverageBits - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_org_wpilib_hardware_hal_simulation_AnalogInDataJNI_setAverageBits - (JNIEnv*, jclass, jint index, jint value) -{ - HALSIM_SetAnalogInAverageBits(index, value); -} - -/* - * Class: org_wpilib_hardware_hal_simulation_AnalogInDataJNI - * Method: registerOversampleBitsCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_simulation_AnalogInDataJNI_registerOversampleBitsCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback(env, index, callback, initialNotify, - &HALSIM_RegisterAnalogInOversampleBitsCallback); -} - -/* - * Class: org_wpilib_hardware_hal_simulation_AnalogInDataJNI - * Method: cancelOversampleBitsCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_org_wpilib_hardware_hal_simulation_AnalogInDataJNI_cancelOversampleBitsCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback(env, handle, index, - &HALSIM_CancelAnalogInOversampleBitsCallback); -} - -/* - * Class: org_wpilib_hardware_hal_simulation_AnalogInDataJNI - * Method: getOversampleBits - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_org_wpilib_hardware_hal_simulation_AnalogInDataJNI_getOversampleBits - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogInOversampleBits(index); -} - -/* - * Class: org_wpilib_hardware_hal_simulation_AnalogInDataJNI - * Method: setOversampleBits - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_org_wpilib_hardware_hal_simulation_AnalogInDataJNI_setOversampleBits - (JNIEnv*, jclass, jint index, jint value) -{ - HALSIM_SetAnalogInOversampleBits(index, value); -} - /* * Class: org_wpilib_hardware_hal_simulation_AnalogInDataJNI * Method: registerVoltageCallback diff --git a/hal/src/main/native/include/wpi/hal/AnalogInput.h b/hal/src/main/native/include/wpi/hal/AnalogInput.h index 4f7ae0193a..2cae53bebf 100644 --- a/hal/src/main/native/include/wpi/hal/AnalogInput.h +++ b/hal/src/main/native/include/wpi/hal/AnalogInput.h @@ -64,83 +64,6 @@ HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel); void HAL_SetAnalogInputSimDevice(HAL_AnalogInputHandle handle, HAL_SimDeviceHandle device); -/** - * Sets the sample rate. - * - * This is a global setting for the Athena and effects all channels. - * - * @param[in] samplesPerSecond The number of samples per channel per second. - * @param[out] status the error code, or 0 for success - */ -void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status); - -/** - * Gets the current sample rate. - * - * This assumes one entry in the scan list. - * This is a global setting for the Athena and effects all channels. - * - * @param[out] status the error code, or 0 for success - * @return Sample rate. - */ -double HAL_GetAnalogSampleRate(int32_t* status); - -/** - * Sets the number of averaging bits. - * - * This sets the number of averaging bits. The actual number of averaged samples - * is 2**bits. Use averaging to improve the stability of your measurement at the - * expense of sampling rate. The averaging is done automatically in the FPGA. - * - * @param[in] analogPortHandle Handle to the analog port to configure. - * @param[in] bits Number of bits to average. - * @param[out] status the error code, or 0 for success - */ -void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle, - int32_t bits, int32_t* status); - -/** - * Gets the number of averaging bits. - * - * This gets the number of averaging bits from the FPGA. The actual number of - * averaged samples is 2**bits. The averaging is done automatically in the FPGA. - * - * @param[in] analogPortHandle Handle to the analog port to use. - * @param[out] status the error code, or 0 for success - * @return Bits to average. - */ -int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle, - int32_t* status); - -/** - * Sets the number of oversample bits. - * - * This sets the number of oversample bits. The actual number of oversampled - * values is 2**bits. Use oversampling to improve the resolution of your - * measurements at the expense of sampling rate. The oversampling is done - * automatically in the FPGA. - * - * @param[in] analogPortHandle Handle to the analog port to use. - * @param[in] bits Number of bits to oversample. - * @param[out] status the error code, or 0 for success - */ -void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle, - int32_t bits, int32_t* status); - -/** - * Gets the number of oversample bits. - * - * This gets the number of oversample bits from the FPGA. The actual number of - * oversampled values is 2**bits. The oversampling is done automatically in the - * FPGA. - * - * @param[in] analogPortHandle Handle to the analog port to use. - * @param[out] status the error code, or 0 for success - * @return Bits to oversample. - */ -int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle, - int32_t* status); - /** * Gets a sample straight from the channel on this module. * @@ -155,24 +78,6 @@ int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle, int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle, int32_t* status); -/** - * Gets a sample from the output of the oversample and average engine for the - * channel. - * - * The sample is 12-bit + the value configured in SetOversampleBits(). - * The value configured in SetAverageBits() will cause this value to be averaged - * 2**bits number of samples. This is not a sliding window. The sample will not - * change until 2**(OversampleBits + AverageBits) samples have been acquired - * from the module on this channel. Use GetAverageVoltage() to get the analog - * value in calibrated units. - * - * @param[in] analogPortHandle Handle to the analog port to use. - * @param[out] status the error code, or 0 for success - * @return A sample from the oversample and average engine for the channel. - */ -int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle, - int32_t* status); - /** * Converts a voltage to a raw value for a specified channel. * @@ -192,8 +97,7 @@ int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle, /** * Gets a scaled sample straight from the channel on this module. * - * The value is scaled to units of Volts using the calibrated scaling data from - * GetLSBWeight() and GetOffset(). + * The value is scaled to units of Volts. * * @param[in] analogPortHandle Handle to the analog port to use. * @param[out] status the error code, or 0 for success @@ -202,51 +106,6 @@ int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle, double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle, int32_t* status); -/** - * Gets a scaled sample from the output of the oversample and average engine for - * the channel. - * - * The value is scaled to units of Volts using the calibrated scaling data from - * GetLSBWeight() and GetOffset(). Using oversampling will cause this value to - * be higher resolution, but it will update more slowly. Using averaging will - * cause this value to be more stable, but it will update more slowly. - * - * @param[in] analogPortHandle Handle to the analog port to use. - * @param[out] status the error code, or 0 for success - * @return A scaled sample from the output of the oversample and average engine - * for the channel. - */ -double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle, - int32_t* status); - -/** - * Gets the factory scaling least significant bit weight constant. - * The least significant bit weight constant for the channel that was calibrated - * in manufacturing and stored in an eeprom in the module. - * - * Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9) - * - * @param[in] analogPortHandle Handle to the analog port to use. - * @param[out] status the error code, or 0 for success - * @return Least significant bit weight. - */ -int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle, - int32_t* status); - -/** - * Gets the factory scaling offset constant. - * The offset constant for the channel that was calibrated in manufacturing and - * stored in an eeprom in the module. - * - * Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9) - * - * @param[in] analogPortHandle Handle to the analog port to use. - * @param[out] status Error status variable. 0 on success. - * @return Offset constant. - */ -int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle, - int32_t* status); - /** * Get the analog voltage from a raw value. * diff --git a/hal/src/main/native/include/wpi/hal/Constants.h b/hal/src/main/native/include/wpi/hal/Constants.h deleted file mode 100644 index c8c731c29d..0000000000 --- a/hal/src/main/native/include/wpi/hal/Constants.h +++ /dev/null @@ -1,28 +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 - -/** - * @defgroup hal_constants Constants Functions - * @ingroup hal_capi - * @{ - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Gets the number of FPGA system clock ticks per microsecond. - * - * @return the number of clock ticks per microsecond - */ -int32_t HAL_GetSystemClockTicksPerMicrosecond(void); -#ifdef __cplusplus -} // extern "C" -#endif -/** @} */ diff --git a/hal/src/main/native/include/wpi/hal/HAL.h b/hal/src/main/native/include/wpi/hal/HAL.h index 0e40d9ffcb..59acf610b5 100644 --- a/hal/src/main/native/include/wpi/hal/HAL.h +++ b/hal/src/main/native/include/wpi/hal/HAL.h @@ -25,14 +25,10 @@ * Runtime type. */ HAL_ENUM(HAL_RuntimeType) { - /** roboRIO 1.0 */ - HAL_RUNTIME_ROBORIO, - /** roboRIO 2.0 */ - HAL_RUNTIME_ROBORIO_2, - /** Simulation runtime */ - HAL_RUNTIME_SIMULATION, - /** Systemcore */ + /** Systemcore runtime */ HAL_RUNTIME_SYSTEMCORE, + /** Simulation runtime */ + HAL_RUNTIME_SIMULATION }; #ifdef __cplusplus diff --git a/hal/src/main/native/include/wpi/hal/Ports.h b/hal/src/main/native/include/wpi/hal/Ports.h index bb5aa318ef..5b5796c54c 100644 --- a/hal/src/main/native/include/wpi/hal/Ports.h +++ b/hal/src/main/native/include/wpi/hal/Ports.h @@ -23,6 +23,13 @@ extern "C" { */ int32_t HAL_GetNumCanBuses(void); +/** + * Gets the number of smart IO channels in the current system. + * + * @return the number of SmartIO + */ +int32_t HAL_GetNumSmartIo(void); + /** * Gets the number of analog inputs in the current system. * diff --git a/hal/src/main/native/include/wpi/hal/simulation/AnalogInData.h b/hal/src/main/native/include/wpi/hal/simulation/AnalogInData.h index 0fa543a840..17132ef3c1 100644 --- a/hal/src/main/native/include/wpi/hal/simulation/AnalogInData.h +++ b/hal/src/main/native/include/wpi/hal/simulation/AnalogInData.h @@ -22,21 +22,6 @@ void HALSIM_SetAnalogInInitialized(int32_t index, HAL_Bool initialized); HAL_SimDeviceHandle HALSIM_GetAnalogInSimDevice(int32_t index); -int32_t HALSIM_RegisterAnalogInAverageBitsCallback(int32_t index, - HAL_NotifyCallback callback, - void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogInAverageBitsCallback(int32_t index, int32_t uid); -int32_t HALSIM_GetAnalogInAverageBits(int32_t index); -void HALSIM_SetAnalogInAverageBits(int32_t index, int32_t averageBits); - -int32_t HALSIM_RegisterAnalogInOversampleBitsCallback( - int32_t index, HAL_NotifyCallback callback, void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogInOversampleBitsCallback(int32_t index, int32_t uid); -int32_t HALSIM_GetAnalogInOversampleBits(int32_t index); -void HALSIM_SetAnalogInOversampleBits(int32_t index, int32_t oversampleBits); - int32_t HALSIM_RegisterAnalogInVoltageCallback(int32_t index, HAL_NotifyCallback callback, void* param, diff --git a/hal/src/main/native/include/wpi/hal/simulation/RoboRioData.h b/hal/src/main/native/include/wpi/hal/simulation/RoboRioData.h index b17a12281f..4d8ca37e17 100644 --- a/hal/src/main/native/include/wpi/hal/simulation/RoboRioData.h +++ b/hal/src/main/native/include/wpi/hal/simulation/RoboRioData.h @@ -18,13 +18,6 @@ extern "C" { #endif void HALSIM_ResetRoboRioData(void); -int32_t HALSIM_RegisterRoboRioFPGAButtonCallback(HAL_NotifyCallback callback, - void* param, - HAL_Bool initialNotify); -void HALSIM_CancelRoboRioFPGAButtonCallback(int32_t uid); -HAL_Bool HALSIM_GetRoboRioFPGAButton(void); -void HALSIM_SetRoboRioFPGAButton(HAL_Bool fPGAButton); - int32_t HALSIM_RegisterRoboRioVInVoltageCallback(HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify); diff --git a/hal/src/main/native/sim/AnalogInput.cpp b/hal/src/main/native/sim/AnalogInput.cpp index 755cef541c..07a414727e 100644 --- a/hal/src/main/native/sim/AnalogInput.cpp +++ b/hal/src/main/native/sim/AnalogInput.cpp @@ -43,7 +43,6 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort( } analog_port->channel = static_cast(channel); - analog_port->isAccumulator = false; SimAnalogInData[channel].initialized = true; SimAnalogInData[channel].simDevice = 0; @@ -80,52 +79,6 @@ void HAL_SetAnalogInputSimDevice(HAL_AnalogInputHandle handle, SimAnalogInData[port->channel].simDevice = device; } -void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) { - // No op -} -double HAL_GetAnalogSampleRate(int32_t* status) { - return kDefaultSampleRate; -} -void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle, - int32_t bits, int32_t* status) { - auto port = analogInputHandles->Get(analogPortHandle); - if (port == nullptr) { - *status = HAL_HANDLE_ERROR; - return; - } - - SimAnalogInData[port->channel].averageBits = bits; -} -int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - auto port = analogInputHandles->Get(analogPortHandle); - if (port == nullptr) { - *status = HAL_HANDLE_ERROR; - return 0; - } - - return SimAnalogInData[port->channel].averageBits; -} -void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle, - int32_t bits, int32_t* status) { - auto port = analogInputHandles->Get(analogPortHandle); - if (port == nullptr) { - *status = HAL_HANDLE_ERROR; - return; - } - - SimAnalogInData[port->channel].oversampleBits = bits; -} -int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - auto port = analogInputHandles->Get(analogPortHandle); - if (port == nullptr) { - *status = HAL_HANDLE_ERROR; - return 0; - } - - return SimAnalogInData[port->channel].oversampleBits; -} int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle, int32_t* status) { auto port = analogInputHandles->Get(analogPortHandle); @@ -137,27 +90,12 @@ int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle, double voltage = SimAnalogInData[port->channel].voltage; return HAL_GetAnalogVoltsToValue(analogPortHandle, voltage, status); } -int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - // No averaging supported - return HAL_GetAnalogValue(analogPortHandle, status); -} + int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle, double voltage, int32_t* status) { - if (voltage > 5.0) { - voltage = 5.0; - *status = VOLTAGE_OUT_OF_RANGE; - } - if (voltage < 0.0) { - voltage = 0.0; - *status = VOLTAGE_OUT_OF_RANGE; - } - int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status); - int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status); - int32_t value = - static_cast((voltage + offset * 1.0e-9) / (LSBWeight * 1.0e-9)); - return value; + return static_cast(voltage * 4095.0 / 3.3); } + double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle, int32_t* status) { auto port = analogInputHandles->Get(analogPortHandle); @@ -171,29 +109,6 @@ double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle, double HAL_GetAnalogValueToVolts(HAL_AnalogInputHandle analogPortHandle, int32_t rawValue, int32_t* status) { - int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status); - int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status); - double voltage = LSBWeight * 1.0e-9 * rawValue - offset * 1.0e-9; - return voltage; -} - -double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - auto port = analogInputHandles->Get(analogPortHandle); - if (port == nullptr) { - *status = HAL_HANDLE_ERROR; - return 0.0; - } - - // No averaging supported - return SimAnalogInData[port->channel].voltage; -} -int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - return 1220703; -} -int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - return 0; + return rawValue / 4095.0 * 3.3; } } // extern "C" diff --git a/hal/src/main/native/sim/AnalogInternal.hpp b/hal/src/main/native/sim/AnalogInternal.hpp index 1a98dcbb1c..4ec25ad5bf 100644 --- a/hal/src/main/native/sim/AnalogInternal.hpp +++ b/hal/src/main/native/sim/AnalogInternal.hpp @@ -13,15 +13,9 @@ #include "wpi/hal/handles/IndexedHandleResource.hpp" namespace wpi::hal { -constexpr int32_t kTimebase = 40000000; ///< 40 MHz clock -constexpr int32_t kDefaultOversampleBits = 0; -constexpr int32_t kDefaultAverageBits = 7; -constexpr double kDefaultSampleRate = 50000.0; -static constexpr uint32_t kAccumulatorChannels[] = {0, 1}; struct AnalogPort { uint8_t channel; - bool isAccumulator; std::string previousAllocation; }; diff --git a/hal/src/main/native/sim/Constants.cpp b/hal/src/main/native/sim/Constants.cpp deleted file mode 100644 index e44fdad764..0000000000 --- a/hal/src/main/native/sim/Constants.cpp +++ /dev/null @@ -1,19 +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 "wpi/hal/Constants.h" - -#include "ConstantsInternal.hpp" - -using namespace wpi::hal; - -namespace wpi::hal::init { -void InitializeConstants() {} -} // namespace wpi::hal::init - -extern "C" { -int32_t HAL_GetSystemClockTicksPerMicrosecond(void) { - return kSystemClockTicksPerMicrosecond; -} -} // extern "C" diff --git a/hal/src/main/native/sim/ConstantsInternal.hpp b/hal/src/main/native/sim/ConstantsInternal.hpp deleted file mode 100644 index 1afdd66979..0000000000 --- a/hal/src/main/native/sim/ConstantsInternal.hpp +++ /dev/null @@ -1,11 +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 - -namespace wpi::hal { -constexpr int32_t kSystemClockTicksPerMicrosecond = 40; -} // namespace wpi::hal diff --git a/hal/src/main/native/sim/HAL.cpp b/hal/src/main/native/sim/HAL.cpp index d41559fa88..30370d5401 100644 --- a/hal/src/main/native/sim/HAL.cpp +++ b/hal/src/main/native/sim/HAL.cpp @@ -86,7 +86,6 @@ void InitializeHAL() { InitializeAnalogInput(); InitializeAnalogInternal(); InitializeCAN(); - InitializeConstants(); InitializeCounter(); InitializeDigitalInternal(); InitializeDIO(); diff --git a/hal/src/main/native/sim/HALInitializer.hpp b/hal/src/main/native/sim/HALInitializer.hpp index 5ac35a0238..4e297b2015 100644 --- a/hal/src/main/native/sim/HALInitializer.hpp +++ b/hal/src/main/native/sim/HALInitializer.hpp @@ -38,7 +38,6 @@ extern void InitializeAlert(); extern void InitializeAnalogInput(); extern void InitializeAnalogInternal(); extern void InitializeCAN(); -extern void InitializeConstants(); extern void InitializeCounter(); extern void InitializeDigitalInternal(); extern void InitializeDIO(); diff --git a/hal/src/main/native/sim/MockHooks.cpp b/hal/src/main/native/sim/MockHooks.cpp index 809745dd87..97d574a61f 100644 --- a/hal/src/main/native/sim/MockHooks.cpp +++ b/hal/src/main/native/sim/MockHooks.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "MockHooksInternal.hpp" diff --git a/hal/src/main/native/sim/PWM.cpp b/hal/src/main/native/sim/PWM.cpp index d34a6febf6..baa8bd0648 100644 --- a/hal/src/main/native/sim/PWM.cpp +++ b/hal/src/main/native/sim/PWM.cpp @@ -4,8 +4,6 @@ #include "wpi/hal/PWM.h" -#include - #include "DigitalInternal.hpp" #include "HALInitializer.hpp" #include "HALInternal.hpp" diff --git a/hal/src/main/native/sim/Ports.cpp b/hal/src/main/native/sim/Ports.cpp index ed2ff23ecc..4971f17123 100644 --- a/hal/src/main/native/sim/Ports.cpp +++ b/hal/src/main/native/sim/Ports.cpp @@ -16,6 +16,9 @@ extern "C" { int32_t HAL_GetNumCanBuses(void) { return kNumCanBuses; } +int32_t HAL_GetNumSmartIo(void) { + return kNumSmartIo; +} int32_t HAL_GetNumAnalogInputs(void) { return kNumAnalogInputs; } diff --git a/hal/src/main/native/sim/PortsInternal.hpp b/hal/src/main/native/sim/PortsInternal.hpp index 8a339392c3..1c8aab4381 100644 --- a/hal/src/main/native/sim/PortsInternal.hpp +++ b/hal/src/main/native/sim/PortsInternal.hpp @@ -9,6 +9,7 @@ namespace wpi::hal { constexpr int32_t kNumCanBuses = 5; constexpr int32_t kAccelerometers = 1; +constexpr int32_t kNumSmartIo = 6; constexpr int32_t kNumAccumulators = 2; constexpr int32_t kNumAnalogInputs = 8; constexpr int32_t kNumAnalogOutputs = 2; diff --git a/hal/src/main/native/sim/mockdata/AnalogInData.cpp b/hal/src/main/native/sim/mockdata/AnalogInData.cpp index 4c062a363f..c74601c0fe 100644 --- a/hal/src/main/native/sim/mockdata/AnalogInData.cpp +++ b/hal/src/main/native/sim/mockdata/AnalogInData.cpp @@ -18,8 +18,6 @@ AnalogInData* wpi::hal::SimAnalogInData; void AnalogInData::ResetData() { initialized.Reset(false); simDevice = 0; - averageBits.Reset(7); - oversampleBits.Reset(0); voltage.Reset(0.0); } @@ -37,8 +35,6 @@ HAL_SimDeviceHandle HALSIM_GetAnalogInSimDevice(int32_t index) { SimAnalogInData, LOWERNAME) DEFINE_CAPI(HAL_Bool, Initialized, initialized) -DEFINE_CAPI(int32_t, AverageBits, averageBits) -DEFINE_CAPI(int32_t, OversampleBits, oversampleBits) DEFINE_CAPI(double, Voltage, voltage) #define REGISTER(NAME) \ @@ -48,8 +44,6 @@ void HALSIM_RegisterAnalogInAllCallbacks(int32_t index, HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) { REGISTER(initialized); - REGISTER(averageBits); - REGISTER(oversampleBits); REGISTER(voltage); } } // extern "C" diff --git a/hal/src/main/native/sim/mockdata/AnalogInDataInternal.hpp b/hal/src/main/native/sim/mockdata/AnalogInDataInternal.hpp index 9e4ce6a324..85e19598f8 100644 --- a/hal/src/main/native/sim/mockdata/AnalogInDataInternal.hpp +++ b/hal/src/main/native/sim/mockdata/AnalogInDataInternal.hpp @@ -11,16 +11,12 @@ namespace wpi::hal { class AnalogInData { HAL_SIMDATAVALUE_DEFINE_NAME(Initialized) - HAL_SIMDATAVALUE_DEFINE_NAME(AverageBits) - HAL_SIMDATAVALUE_DEFINE_NAME(OversampleBits) HAL_SIMDATAVALUE_DEFINE_NAME(Voltage) public: SimDataValue initialized{ false}; std::atomic simDevice; - SimDataValue averageBits{7}; - SimDataValue oversampleBits{0}; SimDataValue voltage{0.0}; virtual void ResetData(); diff --git a/hal/src/main/native/systemcore/AnalogInput.cpp b/hal/src/main/native/systemcore/AnalogInput.cpp index 36ac56f5e1..30f1bbea72 100644 --- a/hal/src/main/native/systemcore/AnalogInput.cpp +++ b/hal/src/main/native/systemcore/AnalogInput.cpp @@ -96,40 +96,6 @@ HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel) { void HAL_SetAnalogInputSimDevice(HAL_AnalogInputHandle handle, HAL_SimDeviceHandle device) {} -void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -double HAL_GetAnalogSampleRate(int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle, - int32_t bits, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle, - int32_t bits, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle, int32_t* status) { auto port = @@ -144,16 +110,9 @@ int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle, return ret; } -int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle, double voltage, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; + return static_cast(voltage * 4095.0 / 3.3); } double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle, @@ -173,26 +132,7 @@ double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle, double HAL_GetAnalogValueToVolts(HAL_AnalogInputHandle analogPortHandle, int32_t rawValue, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; + return rawValue / 4095.0 * 3.3; } } // extern "C" diff --git a/hal/src/main/native/systemcore/Constants.cpp b/hal/src/main/native/systemcore/Constants.cpp deleted file mode 100644 index e44fdad764..0000000000 --- a/hal/src/main/native/systemcore/Constants.cpp +++ /dev/null @@ -1,19 +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 "wpi/hal/Constants.h" - -#include "ConstantsInternal.hpp" - -using namespace wpi::hal; - -namespace wpi::hal::init { -void InitializeConstants() {} -} // namespace wpi::hal::init - -extern "C" { -int32_t HAL_GetSystemClockTicksPerMicrosecond(void) { - return kSystemClockTicksPerMicrosecond; -} -} // extern "C" diff --git a/hal/src/main/native/systemcore/ConstantsInternal.hpp b/hal/src/main/native/systemcore/ConstantsInternal.hpp deleted file mode 100644 index 1afdd66979..0000000000 --- a/hal/src/main/native/systemcore/ConstantsInternal.hpp +++ /dev/null @@ -1,11 +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 - -namespace wpi::hal { -constexpr int32_t kSystemClockTicksPerMicrosecond = 40; -} // namespace wpi::hal diff --git a/hal/src/main/native/systemcore/HAL.cpp b/hal/src/main/native/systemcore/HAL.cpp index 00cfa90f8e..a04024de70 100644 --- a/hal/src/main/native/systemcore/HAL.cpp +++ b/hal/src/main/native/systemcore/HAL.cpp @@ -42,7 +42,6 @@ void InitializeHAL() { InitializeAnalogInput(); InitializeCAN(); InitializeCANAPI(); - InitializeConstants(); InitializeCounter(); InitializeDIO(); InitializeDutyCycle(); diff --git a/hal/src/main/native/systemcore/HALInitializer.hpp b/hal/src/main/native/systemcore/HALInitializer.hpp index 90777bb6ef..31b7d21ef0 100644 --- a/hal/src/main/native/systemcore/HALInitializer.hpp +++ b/hal/src/main/native/systemcore/HALInitializer.hpp @@ -23,7 +23,6 @@ extern void InitializeAnalogInput(); extern void InitializeAnalogInternal(); extern void InitializeCAN(); extern void InitializeCANAPI(); -extern void InitializeConstants(); extern void InitializeCounter(); extern void InitializeDigitalInternal(); extern void InitializeDIO(); diff --git a/hal/src/main/native/systemcore/Ports.cpp b/hal/src/main/native/systemcore/Ports.cpp index df6cb155c8..3f2a3ad65c 100644 --- a/hal/src/main/native/systemcore/Ports.cpp +++ b/hal/src/main/native/systemcore/Ports.cpp @@ -16,6 +16,9 @@ extern "C" { int32_t HAL_GetNumCanBuses(void) { return kNumCanBuses; } +int32_t HAL_GetNumSmartIo(void) { + return kNumSmartIo; +} int32_t HAL_GetNumAnalogInputs(void) { return kNumAnalogInputs; } diff --git a/hal/src/main/native/systemcore/mockdata/AnalogInData.cpp b/hal/src/main/native/systemcore/mockdata/AnalogInData.cpp index 57b69f670a..e24b1308d0 100644 --- a/hal/src/main/native/systemcore/mockdata/AnalogInData.cpp +++ b/hal/src/main/native/systemcore/mockdata/AnalogInData.cpp @@ -17,8 +17,6 @@ HAL_SimDeviceHandle HALSIM_GetAnalogInSimDevice(int32_t index) { HAL_SIMDATAVALUE_STUB_CAPI(TYPE, HALSIM, AnalogIn##CAPINAME, RETURN) DEFINE_CAPI(HAL_Bool, Initialized, false) -DEFINE_CAPI(int32_t, AverageBits, 0) -DEFINE_CAPI(int32_t, OversampleBits, 0) DEFINE_CAPI(double, Voltage, 0) void HALSIM_RegisterAnalogInAllCallbacks(int32_t index, diff --git a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp index 4db9d62220..a87d3a5a38 100644 --- a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp +++ b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp @@ -173,20 +173,6 @@ inline void RemoveRefreshedDataEventHandle(WPI_EventHandle event) {} } // namespace DriverStation -// #ifdef __FIRST_SYSTEMCORE__ -// static constexpr int ROBORIO = 0; -// namespace RobotBase { -// inline int GetRuntimeType() { -// nLoadOut::tTargetClass targetClass = nLoadOut::getTargetClass(); -// if (targetClass == nLoadOut::kTargetClass_RoboRIO2) { -// return 1; -// } else { -// return 0; -// } -// } -// } // namespace RobotBase -// #endif - struct Thread final : public ::wpi::util::SafeThread { Thread(std::string_view dir, std::string_view filename, double period); ~Thread() override; diff --git a/simulation/halsim_ws_core/doc/hardware_ws_api.md b/simulation/halsim_ws_core/doc/hardware_ws_api.md index 7d35157726..be3ee1e8e8 100644 --- a/simulation/halsim_ws_core/doc/hardware_ws_api.md +++ b/simulation/halsim_ws_core/doc/hardware_ws_api.md @@ -111,8 +111,6 @@ The basic analog input just reads a voltage. An analog input can also be configu | Data Key | Type | Description | | ---------------------- | ------- | --------------------------------------------------- | | ``"voltage"`` | Float | Input voltage, in volts | #### Digital Input/Output ("DIO") diff --git a/simulation/halsim_ws_core/doc/wpilib-ws.yaml b/simulation/halsim_ws_core/doc/wpilib-ws.yaml index b39469d894..5713f1d46e 100644 --- a/simulation/halsim_ws_core/doc/wpilib-ws.yaml +++ b/simulation/halsim_ws_core/doc/wpilib-ws.yaml @@ -127,12 +127,6 @@ components: voltage": type: number description: "Input voltage, in volts" diff --git a/simulation/halsim_ws_core/src/main/native/cpp/WSProvider_Analog.cpp b/simulation/halsim_ws_core/src/main/native/cpp/WSProvider_Analog.cpp index 657d7d6f14..a5e28e20a0 100644 --- a/simulation/halsim_ws_core/src/main/native/cpp/WSProvider_Analog.cpp +++ b/simulation/halsim_ws_core/src/main/native/cpp/WSProvider_Analog.cpp @@ -30,9 +30,6 @@ HALSimWSProviderAnalogIn::~HALSimWSProviderAnalogIn() { void HALSimWSProviderAnalogIn::RegisterCallbacks() { m_initCbKey = REGISTER_AIN(Initialized, "voltage", double, double); } @@ -43,14 +40,10 @@ void HALSimWSProviderAnalogIn::CancelCallbacks() { void HALSimWSProviderAnalogIn::DoCancelCallbacks() { // Cancel callbacks HALSIM_CancelAnalogInInitializedCallback(m_channel, m_initCbKey); - HALSIM_CancelAnalogInAverageBitsCallback(m_channel, m_avgbitsCbKey); - HALSIM_CancelAnalogInOversampleBitsCallback(m_channel, m_oversampleCbKey); HALSIM_CancelAnalogInVoltageCallback(m_channel, m_voltageCbKey); // Reset callback IDs m_initCbKey = 0; - m_avgbitsCbKey = 0; - m_oversampleCbKey = 0; m_voltageCbKey = 0; } diff --git a/simulation/halsim_ws_core/src/main/native/include/wpi/halsim/ws_core/WSProvider_Analog.hpp b/simulation/halsim_ws_core/src/main/native/include/wpi/halsim/ws_core/WSProvider_Analog.hpp index 97f63a3b7c..f8e8ebb6d4 100644 --- a/simulation/halsim_ws_core/src/main/native/include/wpi/halsim/ws_core/WSProvider_Analog.hpp +++ b/simulation/halsim_ws_core/src/main/native/include/wpi/halsim/ws_core/WSProvider_Analog.hpp @@ -26,8 +26,6 @@ class HALSimWSProviderAnalogIn : public HALSimWSHalChanProvider { private: int32_t m_initCbKey = 0; - int32_t m_avgbitsCbKey = 0; - int32_t m_oversampleCbKey = 0; int32_t m_voltageCbKey = 0; }; diff --git a/wpilibc/src/main/native/cpp/hardware/discrete/AnalogInput.cpp b/wpilibc/src/main/native/cpp/hardware/discrete/AnalogInput.cpp index 61b8705903..f799c538cb 100644 --- a/wpilibc/src/main/native/cpp/hardware/discrete/AnalogInput.cpp +++ b/wpilibc/src/main/native/cpp/hardware/discrete/AnalogInput.cpp @@ -17,10 +17,6 @@ using namespace wpi; AnalogInput::AnalogInput(int channel) { - if (!SensorUtil::CheckAnalogInputChannel(channel)) { - throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel); - } - m_channel = channel; int32_t status = 0; std::string stackTrace = wpi::util::GetStackTrace(1); @@ -39,13 +35,6 @@ int AnalogInput::GetValue() const { return value; } -int AnalogInput::GetAverageValue() const { - int32_t status = 0; - int value = HAL_GetAnalogAverageValue(m_port, &status); - WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); - return value; -} - double AnalogInput::GetVoltage() const { int32_t status = 0; double voltage = HAL_GetAnalogVoltage(m_port, &status); @@ -53,70 +42,10 @@ double AnalogInput::GetVoltage() const { return voltage; } -double AnalogInput::GetAverageVoltage() const { - int32_t status = 0; - double voltage = HAL_GetAnalogAverageVoltage(m_port, &status); - WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); - return voltage; -} - int AnalogInput::GetChannel() const { return m_channel; } -void AnalogInput::SetAverageBits(int bits) { - int32_t status = 0; - HAL_SetAnalogAverageBits(m_port, bits, &status); - WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); -} - -int AnalogInput::GetAverageBits() const { - int32_t status = 0; - int averageBits = HAL_GetAnalogAverageBits(m_port, &status); - WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); - return averageBits; -} - -void AnalogInput::SetOversampleBits(int bits) { - int32_t status = 0; - HAL_SetAnalogOversampleBits(m_port, bits, &status); - WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); -} - -int AnalogInput::GetOversampleBits() const { - int32_t status = 0; - int oversampleBits = HAL_GetAnalogOversampleBits(m_port, &status); - WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); - return oversampleBits; -} - -int AnalogInput::GetLSBWeight() const { - int32_t status = 0; - int lsbWeight = HAL_GetAnalogLSBWeight(m_port, &status); - WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); - return lsbWeight; -} - -int AnalogInput::GetOffset() const { - int32_t status = 0; - int offset = HAL_GetAnalogOffset(m_port, &status); - WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); - return offset; -} - -void AnalogInput::SetSampleRate(double samplesPerSecond) { - int32_t status = 0; - HAL_SetAnalogSampleRate(samplesPerSecond, &status); - WPILIB_CheckErrorStatus(status, "SetSampleRate"); -} - -double AnalogInput::GetSampleRate() { - int32_t status = 0; - double sampleRate = HAL_GetAnalogSampleRate(&status); - WPILIB_CheckErrorStatus(status, "GetSampleRate"); - return sampleRate; -} - void AnalogInput::SetSimDevice(HAL_SimDeviceHandle device) { HAL_SetAnalogInputSimDevice(m_port, device); } @@ -124,5 +53,5 @@ void AnalogInput::SetSimDevice(HAL_SimDeviceHandle device) { void AnalogInput::InitSendable(wpi::util::SendableBuilder& builder) { builder.SetSmartDashboardType("Analog Input"); builder.AddDoubleProperty( - "Value", [=, this] { return GetAverageVoltage(); }, nullptr); + "Value", [=, this] { return GetVoltage(); }, nullptr); } diff --git a/wpilibc/src/main/native/cpp/hardware/discrete/DigitalInput.cpp b/wpilibc/src/main/native/cpp/hardware/discrete/DigitalInput.cpp index 4b4210a745..cf12dd0d95 100644 --- a/wpilibc/src/main/native/cpp/hardware/discrete/DigitalInput.cpp +++ b/wpilibc/src/main/native/cpp/hardware/discrete/DigitalInput.cpp @@ -17,9 +17,6 @@ using namespace wpi; DigitalInput::DigitalInput(int channel) { - if (!SensorUtil::CheckDigitalChannel(channel)) { - throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel); - } m_channel = channel; int32_t status = 0; diff --git a/wpilibc/src/main/native/cpp/hardware/discrete/DigitalOutput.cpp b/wpilibc/src/main/native/cpp/hardware/discrete/DigitalOutput.cpp index 294cfc176b..24b8d26cc1 100644 --- a/wpilibc/src/main/native/cpp/hardware/discrete/DigitalOutput.cpp +++ b/wpilibc/src/main/native/cpp/hardware/discrete/DigitalOutput.cpp @@ -18,9 +18,6 @@ using namespace wpi; DigitalOutput::DigitalOutput(int channel) { m_pwmGenerator = HAL_INVALID_HANDLE; - if (!SensorUtil::CheckDigitalChannel(channel)) { - throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel); - } m_channel = channel; int32_t status = 0; @@ -120,9 +117,6 @@ void DigitalOutput::DisablePWM() { int32_t status = 0; - // Disable the output by routing to a dead bit. - HAL_SetDigitalPWMOutputChannel(m_pwmGenerator, - SensorUtil::GetNumDigitalChannels(), &status); WPILIB_CheckErrorStatus(status, "Channel {}", m_channel); HAL_FreeDigitalPWM(m_pwmGenerator); diff --git a/wpilibc/src/main/native/cpp/hardware/discrete/PWM.cpp b/wpilibc/src/main/native/cpp/hardware/discrete/PWM.cpp index 80d04b29db..7e4bcd9759 100644 --- a/wpilibc/src/main/native/cpp/hardware/discrete/PWM.cpp +++ b/wpilibc/src/main/native/cpp/hardware/discrete/PWM.cpp @@ -15,10 +15,6 @@ using namespace wpi; PWM::PWM(int channel, bool registerSendable) { - if (!SensorUtil::CheckPWMChannel(channel)) { - throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel); - } - auto stack = wpi::util::GetStackTrace(1); int32_t status = 0; m_handle = HAL_InitializePWMPort(channel, stack.c_str(), &status); diff --git a/wpilibc/src/main/native/cpp/hardware/led/AddressableLED.cpp b/wpilibc/src/main/native/cpp/hardware/led/AddressableLED.cpp index 278a55e48f..3c8ac9c15b 100644 --- a/wpilibc/src/main/native/cpp/hardware/led/AddressableLED.cpp +++ b/wpilibc/src/main/native/cpp/hardware/led/AddressableLED.cpp @@ -9,16 +9,11 @@ #include "wpi/hal/AddressableLED.h" #include "wpi/hal/UsageReporting.hpp" #include "wpi/system/Errors.hpp" -#include "wpi/util/SensorUtil.hpp" #include "wpi/util/StackTrace.hpp" using namespace wpi; AddressableLED::AddressableLED(int channel) : m_channel{channel} { - if (!SensorUtil::CheckDigitalChannel(channel)) { - throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel); - } - int32_t status = 0; auto stack = wpi::util::GetStackTrace(1); m_handle = HAL_InitializeAddressableLED(channel, stack.c_str(), &status); diff --git a/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycle.cpp b/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycle.cpp index bdb1b49d9c..ef49c97518 100644 --- a/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycle.cpp +++ b/wpilibc/src/main/native/cpp/hardware/rotation/DutyCycle.cpp @@ -16,9 +16,6 @@ using namespace wpi; DutyCycle::DutyCycle(int channel) : m_channel{channel} { - if (!SensorUtil::CheckDigitalChannel(channel)) { - throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel); - } InitDutyCycle(); } diff --git a/wpilibc/src/main/native/cpp/simulation/AnalogInputSim.cpp b/wpilibc/src/main/native/cpp/simulation/AnalogInputSim.cpp index 58e742baa2..1b2ee0607e 100644 --- a/wpilibc/src/main/native/cpp/simulation/AnalogInputSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/AnalogInputSim.cpp @@ -34,40 +34,6 @@ void AnalogInputSim::SetInitialized(bool initialized) { HALSIM_SetAnalogInInitialized(m_index, initialized); } -std::unique_ptr AnalogInputSim::RegisterAverageBitsCallback( - NotifyCallback callback, bool initialNotify) { - auto store = std::make_unique( - m_index, -1, callback, &HALSIM_CancelAnalogInAverageBitsCallback); - store->SetUid(HALSIM_RegisterAnalogInAverageBitsCallback( - m_index, &CallbackStoreThunk, store.get(), initialNotify)); - return store; -} - -int AnalogInputSim::GetAverageBits() const { - return HALSIM_GetAnalogInAverageBits(m_index); -} - -void AnalogInputSim::SetAverageBits(int averageBits) { - HALSIM_SetAnalogInAverageBits(m_index, averageBits); -} - -std::unique_ptr AnalogInputSim::RegisterOversampleBitsCallback( - NotifyCallback callback, bool initialNotify) { - auto store = std::make_unique( - m_index, -1, callback, &HALSIM_CancelAnalogInOversampleBitsCallback); - store->SetUid(HALSIM_RegisterAnalogInOversampleBitsCallback( - m_index, &CallbackStoreThunk, store.get(), initialNotify)); - return store; -} - -int AnalogInputSim::GetOversampleBits() const { - return HALSIM_GetAnalogInOversampleBits(m_index); -} - -void AnalogInputSim::SetOversampleBits(int oversampleBits) { - HALSIM_SetAnalogInOversampleBits(m_index, oversampleBits); -} - std::unique_ptr AnalogInputSim::RegisterVoltageCallback( NotifyCallback callback, bool initialNotify) { auto store = std::make_unique( diff --git a/wpilibc/src/main/native/cpp/util/SensorUtil.cpp b/wpilibc/src/main/native/cpp/util/SensorUtil.cpp index bfc317aa38..e3086a2388 100644 --- a/wpilibc/src/main/native/cpp/util/SensorUtil.cpp +++ b/wpilibc/src/main/native/cpp/util/SensorUtil.cpp @@ -4,9 +4,6 @@ #include "wpi/util/SensorUtil.hpp" -#include "wpi/hal/AnalogInput.h" -#include "wpi/hal/DIO.h" -#include "wpi/hal/PWM.h" #include "wpi/hal/Ports.h" using namespace wpi; @@ -19,26 +16,6 @@ int SensorUtil::GetDefaultREVPHModule() { return 1; } -bool SensorUtil::CheckDigitalChannel(int channel) { - return HAL_CheckDIOChannel(channel); -} - -bool SensorUtil::CheckPWMChannel(int channel) { - return HAL_CheckPWMChannel(channel); -} - -bool SensorUtil::CheckAnalogInputChannel(int channel) { - return HAL_CheckAnalogInputChannel(channel); -} - -int SensorUtil::GetNumDigitalChannels() { - return HAL_GetNumDigitalChannels(); -} - -int SensorUtil::GetNumAnalogInputs() { - return HAL_GetNumAnalogInputs(); -} - -int SensorUtil::GetNumPwmChannels() { - return HAL_GetNumPWMChannels(); +int SensorUtil::GetNumSmartIoPorts() { + return HAL_GetNumSmartIo(); } diff --git a/wpilibc/src/main/native/cppcs/RobotBase.cpp b/wpilibc/src/main/native/cppcs/RobotBase.cpp index 58ae389394..a6dae70227 100644 --- a/wpilibc/src/main/native/cppcs/RobotBase.cpp +++ b/wpilibc/src/main/native/cppcs/RobotBase.cpp @@ -28,14 +28,10 @@ #include "wpi/util/print.hpp" #include "wpi/util/timestamp.hpp" -static_assert(wpi::RuntimeType::ROBORIO == - static_cast(HAL_RUNTIME_ROBORIO)); -static_assert(wpi::RuntimeType::ROBORIO_2 == - static_cast(HAL_RUNTIME_ROBORIO_2)); -static_assert(wpi::RuntimeType::SIMULATION == - static_cast(HAL_RUNTIME_SIMULATION)); static_assert(wpi::RuntimeType::SYSTEMCORE == static_cast(HAL_RUNTIME_SYSTEMCORE)); +static_assert(wpi::RuntimeType::SIMULATION == + static_cast(HAL_RUNTIME_SIMULATION)); using SetCameraServerSharedFP = void (*)(wpi::CameraServerShared*); diff --git a/wpilibc/src/main/native/include/wpi/hardware/discrete/AnalogInput.hpp b/wpilibc/src/main/native/include/wpi/hardware/discrete/AnalogInput.hpp index 8e7e47acaf..2c0942b8fb 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/discrete/AnalogInput.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/discrete/AnalogInput.hpp @@ -51,52 +51,15 @@ class AnalogInput : public wpi::util::Sendable, */ int GetValue() const; - /** - * Get a sample from the output of the oversample and average engine for this - * channel. - * - * The sample is 12-bit + the bits configured in SetOversampleBits(). - * The value configured in SetAverageBits() will cause this value to be - * averaged 2**bits number of samples. - * - * This is not a sliding window. The sample will not change until - * 2**(OversampleBits + AverageBits) samples have been acquired from the - * module on this channel. - * - * Use GetAverageVoltage() to get the analog value in calibrated units. - * - * @return A sample from the oversample and average engine for this channel. - */ - int GetAverageValue() const; - /** * Get a scaled sample straight from this channel. * - * The value is scaled to units of Volts using the calibrated scaling data - * from GetLSBWeight() and GetOffset(). + * The value is scaled to units of Volts. * * @return A scaled sample straight from this channel. */ double GetVoltage() const; - /** - * Get a scaled sample from the output of the oversample and average engine - * for this channel. - * - * The value is scaled to units of Volts using the calibrated scaling data - * from GetLSBWeight() and GetOffset(). - * - * Using oversampling will cause this value to be higher resolution, but it - * will update more slowly. - * - * Using averaging will cause this value to be more stable, but it will update - * more slowly. - * - * @return A scaled sample from the output of the oversample and average - * engine for this channel. - */ - double GetAverageVoltage() const; - /** * Get the channel number. * @@ -104,88 +67,6 @@ class AnalogInput : public wpi::util::Sendable, */ int GetChannel() const; - /** - * Set the number of averaging bits. - * - * This sets the number of averaging bits. The actual number of averaged - * samples is 2^bits. - * - * Use averaging to improve the stability of your measurement at the expense - * of sampling rate. The averaging is done automatically in the FPGA. - * - * @param bits Number of bits of averaging. - */ - void SetAverageBits(int bits); - - /** - * Get the number of averaging bits previously configured. - * - * This gets the number of averaging bits from the FPGA. The actual number of - * averaged samples is 2^bits. The averaging is done automatically in the - * FPGA. - * - * @return Number of bits of averaging previously configured. - */ - int GetAverageBits() const; - - /** - * Set the number of oversample bits. - * - * This sets the number of oversample bits. The actual number of oversampled - * values is 2^bits. Use oversampling to improve the resolution of your - * measurements at the expense of sampling rate. The oversampling is done - * automatically in the FPGA. - * - * @param bits Number of bits of oversampling. - */ - void SetOversampleBits(int bits); - - /** - * Get the number of oversample bits previously configured. - * - * This gets the number of oversample bits from the FPGA. The actual number of - * oversampled values is 2^bits. The oversampling is done automatically in the - * FPGA. - * - * @return Number of bits of oversampling previously configured. - */ - int GetOversampleBits() const; - - /** - * Get the factory scaling least significant bit weight constant. - * - * Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9) - * - * @return Least significant bit weight. - */ - int GetLSBWeight() const; - - /** - * Get the factory scaling offset constant. - * - * Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9) - * - * @return Offset constant. - */ - int GetOffset() const; - - /** - * Set the sample rate per channel for all analog channels. - * - * The maximum rate is 500kS/s divided by the number of channels in use. - * This is 62500 samples/s per channel. - * - * @param samplesPerSecond The number of samples per second. - */ - static void SetSampleRate(double samplesPerSecond); - - /** - * Get the current sample rate for all channels - * - * @return Sample rate. - */ - static double GetSampleRate(); - /** * Indicates this input is used by a simulated device. * diff --git a/wpilibc/src/main/native/include/wpi/hardware/discrete/PWM.hpp b/wpilibc/src/main/native/include/wpi/hardware/discrete/PWM.hpp index 7b3073991c..cf216a6120 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/discrete/PWM.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/discrete/PWM.hpp @@ -16,12 +16,7 @@ namespace wpi { class AddressableLED; /** - * Class implements the PWM generation in the FPGA. - * - * The values supplied as arguments for PWM outputs range from -1.0 to 1.0. They - * are mapped to the microseconds to keep the pulse high, with a range of 0 - * (off) to 4096. Changes are immediately sent to the FPGA, and the update - * occurs at the next FPGA cycle (5.05ms). There is no delay. + * Class for sending pulse-width modulation (PWM) signals. */ class PWM : public wpi::util::Sendable, public wpi::util::SendableHelper { public: diff --git a/wpilibc/src/main/native/include/wpi/simulation/AnalogInputSim.hpp b/wpilibc/src/main/native/include/wpi/simulation/AnalogInputSim.hpp index b35d13bf55..c08a3a0c37 100644 --- a/wpilibc/src/main/native/include/wpi/simulation/AnalogInputSim.hpp +++ b/wpilibc/src/main/native/include/wpi/simulation/AnalogInputSim.hpp @@ -59,58 +59,6 @@ class AnalogInputSim { */ void SetInitialized(bool initialized); - /** - * Register a callback on the number of average bits. - * - * @param callback the callback that will be called whenever the number of - * average bits 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 RegisterAverageBitsCallback( - NotifyCallback callback, bool initialNotify); - - /** - * Get the number of average bits. - * - * @return the number of average bits - */ - int GetAverageBits() const; - - /** - * Change the number of average bits. - * - * @param averageBits the new value - */ - void SetAverageBits(int averageBits); - - /** - * Register a callback on the amount of oversampling bits. - * - * @param callback the callback that will be called whenever the oversampling - * bits are 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 RegisterOversampleBitsCallback( - NotifyCallback callback, bool initialNotify); - - /** - * Get the amount of oversampling bits. - * - * @return the amount of oversampling bits - */ - int GetOversampleBits() const; - - /** - * Change the amount of oversampling bits. - * - * @param oversampleBits the new value - */ - void SetOversampleBits(int oversampleBits); - /** * Register a callback on the voltage. * diff --git a/wpilibc/src/main/native/include/wpi/system/RuntimeType.hpp b/wpilibc/src/main/native/include/wpi/system/RuntimeType.hpp index e10b00594b..3a8d89a11e 100644 --- a/wpilibc/src/main/native/include/wpi/system/RuntimeType.hpp +++ b/wpilibc/src/main/native/include/wpi/system/RuntimeType.hpp @@ -9,12 +9,9 @@ namespace wpi { * Runtime type. */ enum class RuntimeType { - /// roboRIO 1.0. - ROBORIO, - /// roboRIO 2.0. - ROBORIO_2, + /// Systemcore runtime. + SYSTEMCORE, /// Simulation runtime. - SIMULATION, - SYSTEMCORE + SIMULATION }; } // namespace wpi diff --git a/wpilibc/src/main/native/include/wpi/util/SensorUtil.hpp b/wpilibc/src/main/native/include/wpi/util/SensorUtil.hpp index 478e23603d..25a15fadf5 100644 --- a/wpilibc/src/main/native/include/wpi/util/SensorUtil.hpp +++ b/wpilibc/src/main/native/include/wpi/util/SensorUtil.hpp @@ -28,39 +28,7 @@ class SensorUtil final { */ static int GetDefaultREVPHModule(); - /** - * Check that the digital channel number is valid. - * - * Verify that the channel number is one of the legal channel numbers. Channel - * numbers are 0-based. - * - * @return Digital channel is valid - */ - static bool CheckDigitalChannel(int channel); - - /** - * Check that the PWM channel number is valid. - * - * Verify that the channel number is one of the legal channel numbers. Channel - * numbers are 0-based. - * - * @return PWM channel is valid - */ - static bool CheckPWMChannel(int channel); - - /** - * Check that the analog input number is value. - * - * Verify that the analog input number is one of the legal channel numbers. - * Channel numbers are 0-based. - * - * @return Analog channel is valid - */ - static bool CheckAnalogInputChannel(int channel); - - static int GetNumDigitalChannels(); - static int GetNumAnalogInputs(); - static int GetNumPwmChannels(); + static int GetNumSmartIoPorts(); }; } // namespace wpi diff --git a/wpilibc/src/main/python/semiwrap/AnalogInput.yml b/wpilibc/src/main/python/semiwrap/AnalogInput.yml index 043bede9af..e3e32b1f6e 100644 --- a/wpilibc/src/main/python/semiwrap/AnalogInput.yml +++ b/wpilibc/src/main/python/semiwrap/AnalogInput.yml @@ -8,18 +8,8 @@ classes: methods: AnalogInput: GetValue: - GetAverageValue: GetVoltage: - GetAverageVoltage: GetChannel: - SetAverageBits: - GetAverageBits: - SetOversampleBits: - GetOversampleBits: - GetLSBWeight: - GetOffset: - SetSampleRate: - GetSampleRate: SetSimDevice: InitSendable: diff --git a/wpilibc/src/main/python/semiwrap/SensorUtil.yml b/wpilibc/src/main/python/semiwrap/SensorUtil.yml index 4c2f284a71..766e70787d 100644 --- a/wpilibc/src/main/python/semiwrap/SensorUtil.yml +++ b/wpilibc/src/main/python/semiwrap/SensorUtil.yml @@ -2,11 +2,6 @@ classes: wpi::SensorUtil: nodelete: true methods: - CheckDigitalChannel: - CheckPWMChannel: - CheckAnalogInputChannel: GetDefaultCTREPCMModule: GetDefaultREVPHModule: - GetNumDigitalChannels: - GetNumAnalogInputs: - GetNumPwmChannels: + GetNumSmartIoPorts: diff --git a/wpilibc/src/main/python/semiwrap/simulation/AnalogInputSim.yml b/wpilibc/src/main/python/semiwrap/simulation/AnalogInputSim.yml index f13e7c0ae5..a7b312271c 100644 --- a/wpilibc/src/main/python/semiwrap/simulation/AnalogInputSim.yml +++ b/wpilibc/src/main/python/semiwrap/simulation/AnalogInputSim.yml @@ -13,12 +13,6 @@ classes: RegisterInitializedCallback: GetInitialized: SetInitialized: - RegisterAverageBitsCallback: - GetAverageBits: - SetAverageBits: - RegisterOversampleBitsCallback: - GetOversampleBits: - SetOversampleBits: RegisterVoltageCallback: GetVoltage: SetVoltage: diff --git a/wpilibc/src/test/native/cpp/simulation/AnalogInputSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/AnalogInputSimTest.cpp index 3395cbcda7..9899e2768d 100644 --- a/wpilibc/src/test/native/cpp/simulation/AnalogInputSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/AnalogInputSimTest.cpp @@ -62,34 +62,4 @@ TEST(AnalogInputSimTest, SetVoltage) { } } -TEST(AnalogInputSimTest, SetOverSampleBits) { - HAL_Initialize(500, 0); - AnalogInput input{5}; - AnalogInputSim sim(input); - - IntCallback callback; - auto cb = sim.RegisterOversampleBitsCallback(callback.GetCallback(), false); - - input.SetOversampleBits(3504); - EXPECT_EQ(3504, sim.GetOversampleBits()); - EXPECT_EQ(3504, input.GetOversampleBits()); - EXPECT_TRUE(callback.WasTriggered()); - EXPECT_EQ(3504, callback.GetLastValue()); -} - -TEST(AnalogInputSimTest, SetAverageBits) { - HAL_Initialize(500, 0); - AnalogInput input{5}; - AnalogInputSim sim(input); - - IntCallback callback; - auto cb = sim.RegisterAverageBitsCallback(callback.GetCallback(), false); - - input.SetAverageBits(3504); - EXPECT_EQ(3504, sim.GetAverageBits()); - EXPECT_EQ(3504, input.GetAverageBits()); - EXPECT_TRUE(callback.WasTriggered()); - EXPECT_EQ(3504, callback.GetLastValue()); -} - } // namespace wpi::sim diff --git a/wpilibcExamples/src/main/cpp/snippets/AnalogInput/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/AnalogInput/cpp/Robot.cpp index bef99a28e1..79a8e25488 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AnalogInput/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/AnalogInput/cpp/Robot.cpp @@ -12,16 +12,6 @@ class Robot : public wpi::TimedRobot { public: Robot() { - // Sets the AnalogInput to 4-bit oversampling. 16 samples will be added - // together. - // Thus, the reported values will increase by about a factor of 16, and the - // update rate will decrease by a similar amount. - m_analog.SetOversampleBits(4); - - // Sets the AnalogInput to 4-bit averaging. 16 samples will be averaged - // together. The update rate will decrease by a factor of 16. - m_analog.SetAverageBits(4); - // Gets the raw instantaneous measured value from the analog input, without // applying any calibration and ignoring oversampling and averaging // settings. @@ -30,14 +20,6 @@ class Robot : public wpi::TimedRobot { // Gets the instantaneous measured voltage from the analog input. // Oversampling and averaging settings are ignored m_analog.GetVoltage(); - - // Gets the averaged value from the analog input. The value is not - // rescaled, but oversampling and averaging are both applied. - m_analog.GetAverageValue(); - - // Gets the averaged voltage from the analog input. Rescaling, - // oversampling, and averaging are all applied. - m_analog.GetAverageVoltage(); } void TeleopPeriodic() override {} diff --git a/wpilibcExamples/src/main/cpp/snippets/AnalogPotentiometer/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/AnalogPotentiometer/cpp/Robot.cpp index 6c967d8c4d..f4b4e87b37 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AnalogPotentiometer/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/AnalogPotentiometer/cpp/Robot.cpp @@ -12,10 +12,7 @@ */ class Robot : public wpi::TimedRobot { public: - Robot() { - // Set averaging bits to 2 - m_input.SetAverageBits(2); - } + Robot() {} void TeleopPeriodic() override { // Get the value of the potentiometer diff --git a/wpilibj/src/main/java/org/wpilib/hardware/discrete/AnalogInput.java b/wpilibj/src/main/java/org/wpilib/hardware/discrete/AnalogInput.java index 7c08e5bc6b..3a4b05df89 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/discrete/AnalogInput.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/discrete/AnalogInput.java @@ -56,22 +56,7 @@ public class AnalogInput implements Sendable, AutoCloseable { } /** - * Get a sample from the output of the oversample and average engine for this channel. The sample - * is 12-bit + the bits configured in SetOversampleBits(). The value configured in - * setAverageBits() will cause this value to be averaged 2^bits number of samples. This is not a - * sliding window. The sample will not change until 2^(OversampleBits + AverageBits) samples have - * been acquired from this channel. Use getAverageVoltage() to get the analog value in calibrated - * units. - * - * @return A sample from the oversample and average engine for this channel. - */ - public int getAverageValue() { - return AnalogInputJNI.getAnalogAverageValue(m_port); - } - - /** - * Get a scaled sample straight from this channel. The value is scaled to units of Volts using the - * calibrated scaling data from getLSBWeight() and getOffset(). + * Get a scaled sample straight from this channel. The value is scaled to units of Volts. * * @return A scaled sample straight from this channel. */ @@ -79,43 +64,6 @@ public class AnalogInput implements Sendable, AutoCloseable { return AnalogInputJNI.getAnalogVoltage(m_port); } - /** - * Get a scaled sample from the output of the oversample and average engine for this channel. The - * value is scaled to units of Volts using the calibrated scaling data from getLSBWeight() and - * getOffset(). Using oversampling will cause this value to be higher resolution, but it will - * update more slowly. Using averaging will cause this value to be more stable, but it will update - * more slowly. - * - * @return A scaled sample from the output of the oversample and average engine for this channel. - */ - public double getAverageVoltage() { - return AnalogInputJNI.getAnalogAverageVoltage(m_port); - } - - /** - * Get the factory scaling the least significant bit weight constant. The least significant bit - * weight constant for the channel that was calibrated in manufacturing and stored in an eeprom. - * - *

Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9) - * - * @return Least significant bit weight. - */ - public long getLSBWeight() { - return AnalogInputJNI.getAnalogLSBWeight(m_port); - } - - /** - * Get the factory scaling offset constant. The offset constant for the channel that was - * calibrated in manufacturing and stored in an eeprom. - * - *

Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9) - * - * @return Offset constant. - */ - public int getOffset() { - return AnalogInputJNI.getAnalogOffset(m_port); - } - /** * Get the channel number. * @@ -125,70 +73,6 @@ public class AnalogInput implements Sendable, AutoCloseable { return m_channel; } - /** - * Set the number of averaging bits. This sets the number of averaging bits. The actual number of - * averaged samples is 2^bits. The averaging is done automatically in the FPGA. - * - * @param bits The number of averaging bits. - */ - public void setAverageBits(final int bits) { - AnalogInputJNI.setAnalogAverageBits(m_port, bits); - } - - /** - * Get the number of averaging bits. This gets the number of averaging bits from the FPGA. The - * actual number of averaged samples is 2^bits. The averaging is done automatically in the FPGA. - * - * @return The number of averaging bits. - */ - public int getAverageBits() { - return AnalogInputJNI.getAnalogAverageBits(m_port); - } - - /** - * Set the number of oversample bits. This sets the number of oversample bits. The actual number - * of oversampled values is 2^bits. The oversampling is done automatically in the FPGA. - * - * @param bits The number of oversample bits. - */ - public void setOversampleBits(final int bits) { - AnalogInputJNI.setAnalogOversampleBits(m_port, bits); - } - - /** - * Get the number of oversample bits. This gets the number of oversample bits from the FPGA. The - * actual number of oversampled values is 2^bits. The oversampling is done automatically in the - * FPGA. - * - * @return The number of oversample bits. - */ - public int getOversampleBits() { - return AnalogInputJNI.getAnalogOversampleBits(m_port); - } - - /** - * Set the sample rate per channel. - * - *

This is a global setting for all channels. The maximum rate is 500kS/s divided by the number - * of channels in use. This is 62500 samples/s per channel if all 8 channels are used. - * - * @param samplesPerSecond The number of samples per second. - */ - public static void setGlobalSampleRate(final double samplesPerSecond) { - AnalogInputJNI.setAnalogSampleRate(samplesPerSecond); - } - - /** - * Get the current sample rate. - * - *

This assumes one entry in the scan list. This is a global setting for all channels. - * - * @return Sample rate. - */ - public static double getGlobalSampleRate() { - return AnalogInputJNI.getAnalogSampleRate(); - } - /** * Indicates this input is used by a simulated device. * @@ -201,6 +85,6 @@ public class AnalogInput implements Sendable, AutoCloseable { @Override public void initSendable(SendableBuilder builder) { builder.setSmartDashboardType("Analog Input"); - builder.addDoubleProperty("Value", this::getAverageVoltage, null); + builder.addDoubleProperty("Value", this::getVoltage, null); } } diff --git a/wpilibj/src/main/java/org/wpilib/hardware/discrete/DigitalInput.java b/wpilibj/src/main/java/org/wpilib/hardware/discrete/DigitalInput.java index 9c3b772d32..3beff7fb66 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/discrete/DigitalInput.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/discrete/DigitalInput.java @@ -7,7 +7,6 @@ package org.wpilib.hardware.discrete; import org.wpilib.hardware.hal.DIOJNI; import org.wpilib.hardware.hal.HAL; import org.wpilib.hardware.hal.SimDevice; -import org.wpilib.system.SensorUtil; import org.wpilib.util.sendable.Sendable; import org.wpilib.util.sendable.SendableBuilder; import org.wpilib.util.sendable.SendableRegistry; @@ -29,7 +28,6 @@ public class DigitalInput implements AutoCloseable, Sendable { */ @SuppressWarnings("this-escape") public DigitalInput(int channel) { - SensorUtil.checkDigitalChannel(channel); m_channel = channel; m_handle = DIOJNI.initializeDIOPort(channel, true); diff --git a/wpilibj/src/main/java/org/wpilib/hardware/discrete/DigitalOutput.java b/wpilibj/src/main/java/org/wpilib/hardware/discrete/DigitalOutput.java index 1512887c79..f6c480721f 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/discrete/DigitalOutput.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/discrete/DigitalOutput.java @@ -7,7 +7,6 @@ package org.wpilib.hardware.discrete; import org.wpilib.hardware.hal.DIOJNI; import org.wpilib.hardware.hal.HAL; import org.wpilib.hardware.hal.SimDevice; -import org.wpilib.system.SensorUtil; import org.wpilib.util.sendable.Sendable; import org.wpilib.util.sendable.SendableBuilder; import org.wpilib.util.sendable.SendableRegistry; @@ -30,7 +29,6 @@ public class DigitalOutput implements AutoCloseable, Sendable { */ @SuppressWarnings("this-escape") public DigitalOutput(int channel) { - SensorUtil.checkDigitalChannel(channel); m_channel = channel; m_handle = DIOJNI.initializeDIOPort(channel, false); @@ -161,8 +159,6 @@ public class DigitalOutput implements AutoCloseable, Sendable { if (m_pwmGenerator == invalidPwmGenerator) { return; } - // Disable the output by routing to a dead bit. - DIOJNI.setDigitalPWMOutputChannel(m_pwmGenerator, SensorUtil.NUM_DIGITAL_CHANNELS); DIOJNI.freeDigitalPWM(m_pwmGenerator); m_pwmGenerator = invalidPwmGenerator; } diff --git a/wpilibj/src/main/java/org/wpilib/hardware/discrete/PWM.java b/wpilibj/src/main/java/org/wpilib/hardware/discrete/PWM.java index b47ec83ce9..9e8856e617 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/discrete/PWM.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/discrete/PWM.java @@ -7,7 +7,6 @@ package org.wpilib.hardware.discrete; import org.wpilib.hardware.hal.HAL; import org.wpilib.hardware.hal.PWMJNI; import org.wpilib.hardware.hal.SimDevice; -import org.wpilib.system.SensorUtil; import org.wpilib.util.sendable.Sendable; import org.wpilib.util.sendable.SendableBuilder; import org.wpilib.util.sendable.SendableRegistry; @@ -46,7 +45,6 @@ public class PWM implements Sendable, AutoCloseable { */ @SuppressWarnings("this-escape") public PWM(final int channel, final boolean registerSendable) { - SensorUtil.checkPWMChannel(channel); m_channel = channel; m_handle = PWMJNI.initializePWMPort(channel); diff --git a/wpilibj/src/main/java/org/wpilib/simulation/AnalogInputSim.java b/wpilibj/src/main/java/org/wpilib/simulation/AnalogInputSim.java index 6049b660ba..15f154aeb1 100644 --- a/wpilibj/src/main/java/org/wpilib/simulation/AnalogInputSim.java +++ b/wpilibj/src/main/java/org/wpilib/simulation/AnalogInputSim.java @@ -60,67 +60,6 @@ public class AnalogInputSim { AnalogInDataJNI.setInitialized(m_index, initialized); } - /** - * Register a callback on the number of average bits. - * - * @param callback the callback that will be called whenever the number of average bits 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 registerAverageBitsCallback(NotifyCallback callback, boolean initialNotify) { - int uid = AnalogInDataJNI.registerAverageBitsCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelAverageBitsCallback); - } - - /** - * Get the number of average bits. - * - * @return the number of average bits - */ - public int getAverageBits() { - return AnalogInDataJNI.getAverageBits(m_index); - } - - /** - * Change the number of average bits. - * - * @param averageBits the new value - */ - public void setAverageBits(int averageBits) { - AnalogInDataJNI.setAverageBits(m_index, averageBits); - } - - /** - * Register a callback on the amount of oversampling bits. - * - * @param callback the callback that will be called whenever the oversampling bits are 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 registerOversampleBitsCallback( - NotifyCallback callback, boolean initialNotify) { - int uid = AnalogInDataJNI.registerOversampleBitsCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelOversampleBitsCallback); - } - - /** - * Get the amount of oversampling bits. - * - * @return the amount of oversampling bits - */ - public int getOversampleBits() { - return AnalogInDataJNI.getOversampleBits(m_index); - } - - /** - * Change the amount of oversampling bits. - * - * @param oversampleBits the new value - */ - public void setOversampleBits(int oversampleBits) { - AnalogInDataJNI.setOversampleBits(m_index, oversampleBits); - } - /** * Register a callback on the voltage. * diff --git a/wpilibj/src/main/java/org/wpilib/system/RuntimeType.java b/wpilibj/src/main/java/org/wpilib/system/RuntimeType.java index 7879005fef..6058545272 100644 --- a/wpilibj/src/main/java/org/wpilib/system/RuntimeType.java +++ b/wpilibj/src/main/java/org/wpilib/system/RuntimeType.java @@ -8,14 +8,10 @@ import org.wpilib.hardware.hal.HALUtil; /** Runtime type. */ public enum RuntimeType { - /** roboRIO 1.0. */ - ROBORIO(HALUtil.RUNTIME_ROBORIO), - /** roboRIO 2.0. */ - ROBORIO_2(HALUtil.RUNTIME_ROBORIO_2), + /** Systemcore runtime. */ + SYSTEMCORE(HALUtil.RUNTIME_SYSTEMCORE), /** Simulation runtime. */ - SIMULATION(HALUtil.RUNTIME_SIMULATION), - /** Systemcore. */ - SYSTEMCORE(HALUtil.RUNTIME_SYSTEMCORE); + SIMULATION(HALUtil.RUNTIME_SIMULATION); /** RuntimeType value. */ public final int value; @@ -31,11 +27,10 @@ public enum RuntimeType { * @return Matching runtime type */ public static RuntimeType getValue(int type) { - return switch (type) { - case HALUtil.RUNTIME_ROBORIO -> RuntimeType.ROBORIO; - case HALUtil.RUNTIME_ROBORIO_2 -> RuntimeType.ROBORIO_2; - case HALUtil.RUNTIME_SYSTEMCORE -> RuntimeType.SYSTEMCORE; - default -> RuntimeType.SIMULATION; - }; + if (type == HALUtil.RUNTIME_SYSTEMCORE) { + return RuntimeType.SYSTEMCORE; + } else { + return RuntimeType.SIMULATION; + } } } diff --git a/wpilibj/src/main/java/org/wpilib/system/SensorUtil.java b/wpilibj/src/main/java/org/wpilib/system/SensorUtil.java index b4f5400e60..452fda6dab 100644 --- a/wpilibj/src/main/java/org/wpilib/system/SensorUtil.java +++ b/wpilibj/src/main/java/org/wpilib/system/SensorUtil.java @@ -4,10 +4,6 @@ package org.wpilib.system; -import org.wpilib.hardware.hal.AnalogInputJNI; -import org.wpilib.hardware.hal.ConstantsJNI; -import org.wpilib.hardware.hal.DIOJNI; -import org.wpilib.hardware.hal.PWMJNI; import org.wpilib.hardware.hal.PortsJNI; /** @@ -15,22 +11,12 @@ import org.wpilib.hardware.hal.PortsJNI; * channels and error processing. */ public final class SensorUtil { - /** Ticks per microsecond. */ - public static final int SYSTEM_CLOCK_TICKS_PER_MICROSECOND = - ConstantsJNI.getSystemClockTicksPerMicrosecond(); - - /** Number of digital channels per Systemcore. */ - public static final int NUM_DIGITAL_CHANNELS = PortsJNI.getNumDigitalChannels(); - - /** Number of analog input channels per Systemcore. */ - public static final int NUM_ANALOG_INPUTS = PortsJNI.getNumAnalogInputs(); + /** Number of SmartIo Ports. */ + public static final int kSmartIoPorts = PortsJNI.getNumSmartIo(); /** Number of solenoid channels per module. */ public static final int NUM_CTRE_SOLENOID_CHANNELS = PortsJNI.getNumCTRESolenoidChannels(); - /** Number of PWM channels per Systemcore. */ - public static final int NUM_PWM_CHANNELS = PortsJNI.getNumPWMChannels(); - /** Number of power distribution channels per PDP. */ public static final int NUM_CTRE_PDP_CHANNELS = PortsJNI.getNumCTREPDPChannels(); @@ -46,57 +32,6 @@ public final class SensorUtil { /** Number of PH modules. */ public static final int NUM_REV_PH_MODULES = PortsJNI.getNumREVPHModules(); - /** - * Check that the digital channel number is valid. Verify that the channel number is one of the - * legal channel numbers. Channel numbers are 0-based. - * - * @param channel The channel number to check. - */ - public static void checkDigitalChannel(final int channel) { - if (!DIOJNI.checkDIOChannel(channel)) { - String buf = - "Requested DIO channel is out of range. Minimum: 0, Maximum: " - + NUM_DIGITAL_CHANNELS - + ", Requested: " - + channel; - throw new IllegalArgumentException(buf); - } - } - - /** - * Check that the PWM channel number is valid. Verify that the channel number is one of the legal - * channel numbers. Channel numbers are 0-based. - * - * @param channel The channel number to check. - */ - public static void checkPWMChannel(final int channel) { - if (!PWMJNI.checkPWMChannel(channel)) { - String buf = - "Requested PWM channel is out of range. Minimum: 0, Maximum: " - + NUM_PWM_CHANNELS - + ", Requested: " - + channel; - throw new IllegalArgumentException(buf); - } - } - - /** - * Check that the analog input number is value. Verify that the analog input number is one of the - * legal channel numbers. Channel numbers are 0-based. - * - * @param channel The channel number to check. - */ - public static void checkAnalogInputChannel(final int channel) { - if (!AnalogInputJNI.checkAnalogInputChannel(channel)) { - String buf = - "Requested analog input channel is out of range. Minimum: 0, Maximum: " - + NUM_ANALOG_INPUTS - + ", Requested: " - + channel; - throw new IllegalArgumentException(buf); - } - } - /** * Get the number of the default solenoid module. * diff --git a/wpilibj/src/test/java/org/wpilib/simulation/AnalogInputSimTest.java b/wpilibj/src/test/java/org/wpilib/simulation/AnalogInputSimTest.java index 75a9e15670..d9f1122ff2 100644 --- a/wpilibj/src/test/java/org/wpilib/simulation/AnalogInputSimTest.java +++ b/wpilibj/src/test/java/org/wpilib/simulation/AnalogInputSimTest.java @@ -52,13 +52,4 @@ class AnalogInputSimTest { } } } - - @Test - void testSetOverSampleBits() { - HAL.initialize(500, 0); - try (AnalogInput input = new AnalogInput(5)) { - input.setOversampleBits(3504); - assertEquals(3504, input.getOversampleBits()); - } - } } diff --git a/wpilibj/src/test/java/org/wpilib/system/SensorUtilTest.java b/wpilibj/src/test/java/org/wpilib/system/SensorUtilTest.java index b02a871643..ced6158659 100644 --- a/wpilibj/src/test/java/org/wpilib/system/SensorUtilTest.java +++ b/wpilibj/src/test/java/org/wpilib/system/SensorUtilTest.java @@ -5,26 +5,10 @@ package org.wpilib.system; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; class SensorUtilTest { - @Test - void checkAnalogInputChannel() { - assertThrows(IllegalArgumentException.class, () -> SensorUtil.checkAnalogInputChannel(100)); - } - - @Test - void testInvalidDigitalChannel() { - assertThrows(IllegalArgumentException.class, () -> SensorUtil.checkDigitalChannel(100)); - } - - @Test - void testInvalidPwmChannel() { - assertThrows(IllegalArgumentException.class, () -> SensorUtil.checkPWMChannel(100)); - } - @Test void testgetDefaultCtrePcmModule() { assertEquals(0, SensorUtil.getDefaultCTREPCMModule()); diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/analoginput/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/analoginput/Robot.java index 4538c96222..dfd12a225c 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/analoginput/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/analoginput/Robot.java @@ -16,16 +16,7 @@ public class Robot extends TimedRobot { AnalogInput m_analog = new AnalogInput(0); /** Called once at the beginning of the robot program. */ - public Robot() { - // Sets the AnalogInput to 4-bit oversampling. 16 samples will be added together. - // Thus, the reported values will increase by about a factor of 16, and the update - // rate will decrease by a similar amount. - m_analog.setOversampleBits(4); - - // Sets the AnalogInput to 4-bit averaging. 16 samples will be averaged together. - // The update rate will decrease by a factor of 16. - m_analog.setAverageBits(4); - } + public Robot() {} @Override public void teleopPeriodic() { @@ -37,13 +28,5 @@ public class Robot extends TimedRobot { // Gets the instantaneous measured voltage from the analog input. // Oversampling and averaging settings are ignored m_analog.getVoltage(); - - // Gets the averaged value from the analog input. The value is not - // rescaled, but oversampling and averaging are both applied. - m_analog.getAverageValue(); - - // Gets the averaged voltage from the analog input. Rescaling, - // oversampling, and averaging are all applied. - m_analog.getAverageVoltage(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/analogpotentiometer/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/analogpotentiometer/Robot.java index ad187a7df7..f4f979dc52 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/analogpotentiometer/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/analogpotentiometer/Robot.java @@ -30,10 +30,7 @@ public class Robot extends TimedRobot { AnalogPotentiometer m_pot1 = new AnalogPotentiometer(m_input, 180, 30); /** Called once at the beginning of the robot program. */ - public Robot() { - // Set averaging bits to 2 - m_input.setAverageBits(2); - } + public Robot() {} @Override public void teleopPeriodic() { diff --git a/wpimath/src/main/java/org/wpilib/math/filter/LinearFilter.java b/wpimath/src/main/java/org/wpilib/math/filter/LinearFilter.java index b78f53e5f6..8f558950fd 100644 --- a/wpimath/src/main/java/org/wpilib/math/filter/LinearFilter.java +++ b/wpimath/src/main/java/org/wpilib/math/filter/LinearFilter.java @@ -27,11 +27,10 @@ import org.wpilib.util.container.DoubleCircularBuffer; * impact of these high frequency components. Likewise, a "high pass" filter gets rid of slow-moving * signal components, letting you detect large changes more easily. * - *

Example FRC applications of filters: - Getting rid of noise from an analog sensor input (note: - * the roboRIO's FPGA can do this faster in hardware) - Smoothing out joystick input to prevent the - * wheels from slipping or the robot from tipping - Smoothing motor commands so that unnecessary - * strain isn't put on electrical or mechanical components - If you use clever gains, you can make a - * PID controller out of this class! + *

Example FRC applications of filters: - Getting rid of noise from an analog sensor input - + * Smoothing out joystick input to prevent the wheels from slipping or the robot from tipping - + * Smoothing motor commands so that unnecessary strain isn't put on electrical or mechanical + * components - If you use clever gains, you can make a PID controller out of this class! * *

For more on filters, we highly recommend the following articles:
*