mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Add methods to retreive the FPGA index for counters and encoders and return the encoding type as an integer
Change-Id: Iaa4062ec124b968b27e7c812cc754032fcb354d2 Add methods to retrieve the FPGA index for counters and encoders and return the encoding type as an integer Change-Id: If04dc291f39a9b331495d2b97a8b87d3ded71280
This commit is contained in:
@@ -216,6 +216,13 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
m_counter = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Counter's FPGA index
|
||||
*/
|
||||
public int getFPGAIndex() {
|
||||
return m_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the upsource for the counter as a digital input channel.
|
||||
*
|
||||
|
||||
@@ -52,6 +52,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
// tick
|
||||
private Counter m_counter; // Counter object for 1x and 2x encoding
|
||||
private EncodingType m_encodingType = EncodingType.k4X;
|
||||
private int m_encodingScale; // 1x, 2x, or 4x, per the encodingType
|
||||
private boolean m_allocatedA;
|
||||
private boolean m_allocatedB;
|
||||
private boolean m_allocatedI;
|
||||
@@ -77,6 +78,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
private void initEncoder(boolean reverseDirection) {
|
||||
switch (m_encodingType.value) {
|
||||
case EncodingType.k4X_val:
|
||||
m_encodingScale = 4;
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -98,8 +100,10 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
break;
|
||||
case EncodingType.k2X_val:
|
||||
case EncodingType.k1X_val:
|
||||
m_encodingScale = m_encodingType == EncodingType.k1X ? 1 : 2;
|
||||
m_counter = new Counter(m_encodingType, m_aSource, m_bSource,
|
||||
reverseDirection);
|
||||
m_index = m_counter.getFPGAIndex();
|
||||
break;
|
||||
}
|
||||
m_distancePerPulse = 1.0;
|
||||
@@ -375,6 +379,21 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
this(aSource, bSource, indexSource, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Encoder's FPGA index
|
||||
*/
|
||||
public int getFPGAIndex() {
|
||||
return m_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the encoding scale factor 1x, 2x, or 4x, per the requested
|
||||
* encodingType. Used to divide raw edge counts down to spec'd counts.
|
||||
*/
|
||||
public int getEncodingScale() {
|
||||
return m_encodingScale;
|
||||
}
|
||||
|
||||
public void free() {
|
||||
if (m_aSource != null && m_allocatedA) {
|
||||
m_aSource.free();
|
||||
|
||||
Reference in New Issue
Block a user