diff --git a/hal/src/main/java/edu/wpi/first/hal/EncoderJNI.java b/hal/src/main/java/edu/wpi/first/hal/EncoderJNI.java index 59503f8c43e..87040eec7f9 100644 --- a/hal/src/main/java/edu/wpi/first/hal/EncoderJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/EncoderJNI.java @@ -13,22 +13,15 @@ public class EncoderJNI extends JNIWrapper { /** * Initializes an encoder. * - * @param digitalSourceHandleA the A source handle (either a digital or analog trigger) - * @param analogTriggerTypeA the analog trigger type of the A source if it is an analog trigger - * @param digitalSourceHandleB the B source handle (either a digital or analog trigger) - * @param analogTriggerTypeB the analog trigger type of the B source if it is an analog trigger + * @param aChannel the A channel + * @param bChannel the B channel * @param reverseDirection true to reverse the counting direction from standard, otherwise false * @param encodingType the encoding type * @return the created encoder handle * @see "HAL_InitializeEncoder" */ public static native int initializeEncoder( - int digitalSourceHandleA, - int analogTriggerTypeA, - int digitalSourceHandleB, - int analogTriggerTypeB, - boolean reverseDirection, - int encodingType); + int aChannel, int bChannel, boolean reverseDirection, int encodingType); /** * Frees an encoder. @@ -212,21 +205,6 @@ public static native int initializeEncoder( */ public static native int getEncoderSamplesToAverage(int encoderHandle); - /** - * Sets the source for an index pulse on the encoder. - * - *
The index pulse can be used to cause an encoder to reset based on an external input.
- *
- * @param encoderHandle the encoder handle
- * @param digitalSourceHandle the index source handle (either a HAL_AnalogTriggerHandle or a
- * HAL_DigitalHandle)
- * @param analogTriggerType the analog trigger type if the source is an analog trigger
- * @param indexingType the index triggering type
- * @see "HAL_SetEncoderIndexSource"
- */
- public static native void setEncoderIndexSource(
- int encoderHandle, int digitalSourceHandle, int analogTriggerType, int indexingType);
-
/**
* Gets the FPGA index of the encoder.
*
diff --git a/hal/src/main/native/cpp/jni/EncoderJNI.cpp b/hal/src/main/native/cpp/jni/EncoderJNI.cpp
index e15c36f8484..50845e8ee31 100644
--- a/hal/src/main/native/cpp/jni/EncoderJNI.cpp
+++ b/hal/src/main/native/cpp/jni/EncoderJNI.cpp
@@ -18,21 +18,17 @@ extern "C" {
/*
* Class: edu_wpi_first_hal_EncoderJNI
* Method: initializeEncoder
- * Signature: (IIIIZI)I
+ * Signature: (IIZI)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_EncoderJNI_initializeEncoder
- (JNIEnv* env, jclass, jint digitalSourceHandleA, jint analogTriggerTypeA,
- jint digitalSourceHandleB, jint analogTriggerTypeB,
- jboolean reverseDirection, jint encodingType)
+ (JNIEnv* env, jclass, jint aChannel, jint bChannel, jboolean reverseDirection,
+ jint encodingType)
{
int32_t status = 0;
- auto encoder = HAL_InitializeEncoder(
- (HAL_Handle)digitalSourceHandleA,
- (HAL_AnalogTriggerType)analogTriggerTypeA,
- (HAL_Handle)digitalSourceHandleB,
- (HAL_AnalogTriggerType)analogTriggerTypeB, reverseDirection,
- (HAL_EncoderEncodingType)encodingType, &status);
+ auto encoder =
+ HAL_InitializeEncoder(aChannel, bChannel, reverseDirection,
+ (HAL_EncoderEncodingType)encodingType, &status);
CheckStatusForceThrow(env, status);
return (jint)encoder;
}
@@ -286,24 +282,6 @@ Java_edu_wpi_first_hal_EncoderJNI_getEncoderSamplesToAverage
return returnValue;
}
-/*
- * Class: edu_wpi_first_hal_EncoderJNI
- * Method: setEncoderIndexSource
- * Signature: (IIII)V
- */
-JNIEXPORT void JNICALL
-Java_edu_wpi_first_hal_EncoderJNI_setEncoderIndexSource
- (JNIEnv* env, jclass, jint id, jint digitalSourceHandle,
- jint analogTriggerType, jint type)
-{
- int32_t status = 0;
- HAL_SetEncoderIndexSource((HAL_EncoderHandle)id,
- (HAL_Handle)digitalSourceHandle,
- (HAL_AnalogTriggerType)analogTriggerType,
- (HAL_EncoderIndexingType)type, &status);
- CheckStatus(env, status);
-}
-
/*
* Class: edu_wpi_first_hal_EncoderJNI
* Method: getEncoderFPGAIndex
diff --git a/hal/src/main/native/include/hal/Encoder.h b/hal/src/main/native/include/hal/Encoder.h
index 749c282c1b4..968d1d905e8 100644
--- a/hal/src/main/native/include/hal/Encoder.h
+++ b/hal/src/main/native/include/hal/Encoder.h
@@ -41,25 +41,18 @@ extern "C" {
/**
* Initializes an encoder.
*
- * @param[in] digitalSourceHandleA the A source (either a HAL_DigitalHandle or a
- * HAL_AnalogTriggerHandle)
- * @param[in] analogTriggerTypeA the analog trigger type of the A source if it
- * is an analog trigger
- * @param[in] digitalSourceHandleB the B source (either a HAL_DigitalHandle or a
- * HAL_AnalogTriggerHandle)
- * @param[in] analogTriggerTypeB the analog trigger type of the B source if it
- * is an analog trigger
+ * @param[in] aChannel the A channel
+ * @param[in] bChannel the B channel
* @param[in] reverseDirection true to reverse the counting direction from
* standard, otherwise false
* @param[in] encodingType the encoding type
* @param[out] status Error status variable. 0 on success.
* @return the created encoder handle
*/
-HAL_EncoderHandle HAL_InitializeEncoder(
- HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
- HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
- HAL_Bool reverseDirection, HAL_EncoderEncodingType encodingType,
- int32_t* status);
+HAL_EncoderHandle HAL_InitializeEncoder(int32_t aChannel, int32_t bChannel,
+ HAL_Bool reverseDirection,
+ HAL_EncoderEncodingType encodingType,
+ int32_t* status);
/**
* Frees an encoder.
@@ -260,26 +253,6 @@ void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
int32_t* status);
-/**
- * Sets the source for an index pulse on the encoder.
- *
- * The index pulse can be used to cause an encoder to reset based on an external
- * input.
- *
- * @param[in] encoderHandle the encoder handle
- * @param[in] digitalSourceHandle the index source handle (either a
- * HAL_AnalogTriggerHandle or a
- * HAL_DigitalHandle)
- * @param[in] analogTriggerType the analog trigger type if the source is an
- * analog trigger
- * @param[in] type the index triggering type
- * @param[out] status Error status variable. 0 on success.
- */
-void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle,
- HAL_Handle digitalSourceHandle,
- HAL_AnalogTriggerType analogTriggerType,
- HAL_EncoderIndexingType type, int32_t* status);
-
/**
* Gets the FPGA index of the encoder.
*
diff --git a/hal/src/main/native/sim/Encoder.cpp b/hal/src/main/native/sim/Encoder.cpp
index f7be2bdd9bd..fb469dcfe53 100644
--- a/hal/src/main/native/sim/Encoder.cpp
+++ b/hal/src/main/native/sim/Encoder.cpp
@@ -66,11 +66,10 @@ bool GetEncoderBaseHandle(HAL_EncoderHandle handle,
} // namespace hal
extern "C" {
-HAL_EncoderHandle HAL_InitializeEncoder(
- HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
- HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
- HAL_Bool reverseDirection, HAL_EncoderEncodingType encodingType,
- int32_t* status) {
+HAL_EncoderHandle HAL_InitializeEncoder(int32_t aChannel, int32_t bChannel,
+ HAL_Bool reverseDirection,
+ HAL_EncoderEncodingType encodingType,
+ int32_t* status) {
hal::init::CheckInit();
HAL_Handle nativeHandle = HAL_kInvalidHandle;
if (encodingType == HAL_EncoderEncodingType::HAL_Encoder_k4X) {
@@ -95,8 +94,8 @@ HAL_EncoderHandle HAL_InitializeEncoder(
return HAL_kInvalidHandle;
}
int16_t index = getHandleIndex(handle);
- SimEncoderData[index].digitalChannelA = getHandleIndex(digitalSourceHandleA);
- SimEncoderData[index].digitalChannelB = getHandleIndex(digitalSourceHandleB);
+ SimEncoderData[index].digitalChannelA = aChannel;
+ SimEncoderData[index].digitalChannelB = bChannel;
SimEncoderData[index].initialized = true;
SimEncoderData[index].reverseDirection = reverseDirection;
SimEncoderData[index].simDevice = 0;
@@ -328,13 +327,6 @@ int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
return SimEncoderData[encoder->index].samplesToAverage;
}
-void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle,
- HAL_Handle digitalSourceHandle,
- HAL_AnalogTriggerType analogTriggerType,
- HAL_EncoderIndexingType type, int32_t* status) {
- // Not implemented yet
-}
-
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle,
int32_t* status) {
auto encoder = encoderHandles->Get(encoderHandle);
diff --git a/hal/src/main/native/systemcore/Encoder.cpp b/hal/src/main/native/systemcore/Encoder.cpp
index 1f2c4216dfb..b48de62b3ea 100644
--- a/hal/src/main/native/systemcore/Encoder.cpp
+++ b/hal/src/main/native/systemcore/Encoder.cpp
@@ -17,25 +17,15 @@
using namespace hal;
-namespace hal {
-
-namespace init {
+namespace hal::init {
void InitializeEncoder() {}
-} // namespace init
-
-bool GetEncoderBaseHandle(HAL_EncoderHandle handle,
- HAL_FPGAEncoderHandle* fpgaHandle,
- HAL_CounterHandle* counterHandle) {
- return false;
-}
-} // namespace hal
+} // namespace hal::init
extern "C" {
-HAL_EncoderHandle HAL_InitializeEncoder(
- HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
- HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
- HAL_Bool reverseDirection, HAL_EncoderEncodingType encodingType,
- int32_t* status) {
+HAL_EncoderHandle HAL_InitializeEncoder(int32_t aChannel, int32_t bChannel,
+ HAL_Bool reverseDirection,
+ HAL_EncoderEncodingType encodingType,
+ int32_t* status) {
hal::init::CheckInit();
*status = HAL_HANDLE_ERROR;
return HAL_kInvalidHandle;
@@ -150,14 +140,6 @@ HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
return HAL_Encoder_k4X;
}
-void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle,
- HAL_Handle digitalSourceHandle,
- HAL_AnalogTriggerType analogTriggerType,
- HAL_EncoderIndexingType type, int32_t* status) {
- *status = HAL_HANDLE_ERROR;
- return;
-}
-
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle,
int32_t* status) {
*status = HAL_HANDLE_ERROR;
diff --git a/wpilibc/src/main/native/cpp/Encoder.cpp b/wpilibc/src/main/native/cpp/Encoder.cpp
index 522f4801faf..a3d4432747e 100644
--- a/wpilibc/src/main/native/cpp/Encoder.cpp
+++ b/wpilibc/src/main/native/cpp/Encoder.cpp
@@ -20,44 +20,7 @@ using namespace frc;
Encoder::Encoder(int aChannel, int bChannel, bool reverseDirection,
EncodingType encodingType) {
- m_aSource = std::make_shared The encoder will start counting immediately.
*
+ * @param aChannel The a channel.
+ * @param bChannel The b channel.
* @param reverseDirection If true, counts down instead of up (this is all relative)
*/
- private void initEncoder(boolean reverseDirection, final EncodingType type) {
- m_encoder =
- EncoderJNI.initializeEncoder(
- m_aSource.getPortHandleForRouting(),
- m_aSource.getAnalogTriggerTypeForRouting(),
- m_bSource.getPortHandleForRouting(),
- m_bSource.getAnalogTriggerTypeForRouting(),
- reverseDirection,
- type.value);
+ private void initEncoder(
+ int aChannel, int bChannel, boolean reverseDirection, final EncodingType type) {
+ m_encoder = EncoderJNI.initializeEncoder(aChannel, bChannel, reverseDirection, type.value);
int fpgaIndex = getFPGAIndex();
HAL.report(tResourceType.kResourceType_Encoder, fpgaIndex + 1, type.value + 1);
@@ -136,156 +100,10 @@ public Encoder(
final EncodingType encodingType) {
requireNonNullParam(encodingType, "encodingType", "Encoder");
- m_allocatedA = true;
- m_allocatedB = true;
- m_allocatedI = false;
- m_aSource = new DigitalInput(channelA);
- m_bSource = new DigitalInput(channelB);
- m_encodingType = encodingType;
- SendableRegistry.addChild(this, m_aSource);
- SendableRegistry.addChild(this, m_bSource);
- initEncoder(reverseDirection, encodingType);
- }
-
- /**
- * Encoder constructor. Construct an Encoder given a and b channels. Using an index pulse forces
- * 4x encoding
- *
- * The encoder will start counting immediately.
- *
- * @param channelA The a channel digital input channel.
- * @param channelB The b channel digital input channel.
- * @param indexChannel The index channel digital input channel.
- * @param reverseDirection represents the orientation of the encoder and inverts the output values
- * if necessary so forward represents positive values.
- */
- @SuppressWarnings("this-escape")
- public Encoder(
- final int channelA, final int channelB, final int indexChannel, boolean reverseDirection) {
- this(channelA, channelB, reverseDirection);
- m_allocatedI = true;
- m_indexSource = new DigitalInput(indexChannel);
- SendableRegistry.addChild(this, m_indexSource);
- setIndexSource(m_indexSource);
- }
-
- /**
- * Encoder constructor. Construct an Encoder given a and b channels. Using an index pulse forces
- * 4x encoding
- *
- * The encoder will start counting immediately.
- *
- * @param channelA The a channel digital input channel.
- * @param channelB The b channel digital input channel.
- * @param indexChannel The index channel digital input channel.
- */
- public Encoder(final int channelA, final int channelB, final int indexChannel) {
- this(channelA, channelB, indexChannel, false);
- }
-
- /**
- * Encoder constructor. Construct an Encoder given a and b channels as digital inputs. This is
- * used in the case where the digital inputs are shared. The Encoder class will not allocate the
- * digital inputs and assume that they already are counted.
- *
- * The encoder will start counting immediately.
- *
- * @param sourceA The source that should be used for the 'a' channel.
- * @param sourceB the source that should be used for the 'b' channel.
- * @param reverseDirection represents the orientation of the encoder and inverts the output values
- * if necessary so forward represents positive values.
- */
- public Encoder(DigitalSource sourceA, DigitalSource sourceB, boolean reverseDirection) {
- this(sourceA, sourceB, reverseDirection, EncodingType.k4X);
- }
-
- /**
- * Encoder constructor. Construct an Encoder given a and b channels as digital inputs. This is
- * used in the case where the digital inputs are shared. The Encoder class will not allocate the
- * digital inputs and assume that they already are counted.
- *
- * The encoder will start counting immediately.
- *
- * @param sourceA The source that should be used for the 'a' channel.
- * @param sourceB the source that should be used for the 'b' channel.
- */
- public Encoder(DigitalSource sourceA, DigitalSource sourceB) {
- this(sourceA, sourceB, false);
- }
-
- /**
- * Encoder constructor. Construct an Encoder given a and b channels as digital inputs. This is
- * used in the case where the digital inputs are shared. The Encoder class will not allocate the
- * digital inputs and assume that they already are counted.
- *
- * The encoder will start counting immediately.
- *
- * @param sourceA The source that should be used for the 'a' channel.
- * @param sourceB the source that should be used for the 'b' channel.
- * @param reverseDirection represents the orientation of the encoder and inverts the output values
- * if necessary so forward represents positive values.
- * @param encodingType either k1X, k2X, or k4X to indicate 1X, 2X or 4X decoding. If 4X is
- * selected, then an encoder FPGA object is used and the returned counts will be 4x the
- * encoder spec'd value since all rising and falling edges are counted. If 1X or 2X are
- * selected then a counter object will be used and the returned value will either exactly
- * match the spec'd count or be double (2x) the spec'd count.
- */
- @SuppressWarnings("this-escape")
- public Encoder(
- DigitalSource sourceA,
- DigitalSource sourceB,
- boolean reverseDirection,
- final EncodingType encodingType) {
- requireNonNullParam(sourceA, "sourceA", "Encoder");
- requireNonNullParam(sourceB, "sourceB", "Encoder");
- requireNonNullParam(encodingType, "encodingType", "Encoder");
-
- m_allocatedA = false;
- m_allocatedB = false;
- m_allocatedI = false;
m_encodingType = encodingType;
- m_aSource = sourceA;
- m_bSource = sourceB;
- initEncoder(reverseDirection, encodingType);
- }
-
- /**
- * Encoder constructor. Construct an Encoder given a, b and index channels as digital inputs. This
- * is used in the case where the digital inputs are shared. The Encoder class will not allocate
- * the digital inputs and assume that they already are counted.
- *
- * The encoder will start counting immediately.
- *
- * @param sourceA The source that should be used for the 'a' channel.
- * @param sourceB the source that should be used for the 'b' channel.
- * @param indexSource the source that should be used for the index channel.
- * @param reverseDirection represents the orientation of the encoder and inverts the output values
- * if necessary so forward represents positive values.
- */
- public Encoder(
- DigitalSource sourceA,
- DigitalSource sourceB,
- DigitalSource indexSource,
- boolean reverseDirection) {
- this(sourceA, sourceB, reverseDirection);
- m_allocatedI = false;
- m_indexSource = indexSource;
- setIndexSource(indexSource);
- }
-
- /**
- * Encoder constructor. Construct an Encoder given a, b and index channels as digital inputs. This
- * is used in the case where the digital inputs are shared. The Encoder class will not allocate
- * the digital inputs and assume that they already are counted.
- *
- * The encoder will start counting immediately.
- *
- * @param sourceA The source that should be used for the 'a' channel.
- * @param sourceB the source that should be used for the 'b' channel.
- * @param indexSource the source that should be used for the index channel.
- */
- public Encoder(DigitalSource sourceA, DigitalSource sourceB, DigitalSource indexSource) {
- this(sourceA, sourceB, indexSource, false);
+ // SendableRegistry.addChild(this, m_aSource);
+ // SendableRegistry.addChild(this, m_bSource);
+ initEncoder(channelA, channelB, reverseDirection, encodingType);
}
/**
@@ -309,22 +127,22 @@ public int getEncodingScale() {
@Override
public void close() {
SendableRegistry.remove(this);
- if (m_aSource != null && m_allocatedA) {
- m_aSource.close();
- m_allocatedA = false;
- }
- if (m_bSource != null && m_allocatedB) {
- m_bSource.close();
- m_allocatedB = false;
- }
- if (m_indexSource != null && m_allocatedI) {
- m_indexSource.close();
- m_allocatedI = false;
- }
-
- m_aSource = null;
- m_bSource = null;
- m_indexSource = null;
+ // if (m_aSource != null && m_allocatedA) {
+ // m_aSource.close();
+ // m_allocatedA = false;
+ // }
+ // if (m_bSource != null && m_allocatedB) {
+ // m_bSource.close();
+ // m_allocatedB = false;
+ // }
+ // if (m_indexSource != null && m_allocatedI) {
+ // m_indexSource.close();
+ // m_allocatedI = false;
+ // }
+
+ // m_aSource = null;
+ // m_bSource = null;
+ // m_indexSource = null;
EncoderJNI.freeEncoder(m_encoder);
m_encoder = 0;
}
@@ -495,58 +313,6 @@ public int getSamplesToAverage() {
return EncoderJNI.getEncoderSamplesToAverage(m_encoder);
}
- /**
- * Set the index source for the encoder. When this source is activated, the encoder count
- * automatically resets.
- *
- * @param channel A DIO channel to set as the encoder index
- */
- public final void setIndexSource(int channel) {
- setIndexSource(channel, IndexingType.kResetOnRisingEdge);
- }
-
- /**
- * Set the index source for the encoder. When this source is activated, the encoder count
- * automatically resets.
- *
- * @param source A digital source to set as the encoder index
- */
- public final void setIndexSource(DigitalSource source) {
- setIndexSource(source, IndexingType.kResetOnRisingEdge);
- }
-
- /**
- * Set the index source for the encoder. When this source rises, the encoder count automatically
- * resets.
- *
- * @param channel A DIO channel to set as the encoder index
- * @param type The state that will cause the encoder to reset
- */
- public final void setIndexSource(int channel, IndexingType type) {
- if (m_allocatedI) {
- throw new AllocationException("Digital Input for Indexing already allocated");
- }
- m_indexSource = new DigitalInput(channel);
- m_allocatedI = true;
- SendableRegistry.addChild(this, m_indexSource);
- setIndexSource(m_indexSource, type);
- }
-
- /**
- * Set the index source for the encoder. When this source rises, the encoder count automatically
- * resets.
- *
- * @param source A digital source to set as the encoder index
- * @param type The state that will cause the encoder to reset
- */
- public final void setIndexSource(DigitalSource source, IndexingType type) {
- EncoderJNI.setEncoderIndexSource(
- m_encoder,
- source.getPortHandleForRouting(),
- source.getAnalogTriggerTypeForRouting(),
- type.value);
- }
-
/**
* Indicates this input is used by a simulated device.
*