Class CounterJNI
- See Also:
-
- "hal/Counter.h"
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.wpi.first.hal.JNIWrapper
JNIWrapper.Helper
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
freeCounter
(int counterHandle) Frees a counter.static int
getCounter
(int counterHandle) Reads the current counter value.static double
getCounterPeriod
(int counterHandle) Gets the Period of the most recent count.static boolean
getCounterStopped
(int counterHandle) Determines if the clock is stopped.static int
initializeCounter
(int channel, boolean risingEdge) Initializes a counter.static void
resetCounter
(int counterHandle) Resets the Counter to zero.static void
setCounterEdgeConfiguration
(int counterHandle, boolean risingEdge) Sets the up source to either detect rising edges or falling edges.static void
setCounterMaxPeriod
(int counterHandle, double maxPeriod) Sets the maximum period where the device is still considered "moving".Methods inherited from class edu.wpi.first.hal.JNIWrapper
forceLoad, suppressUnused
-
Method Details
-
initializeCounter
Initializes a counter.- Parameters:
channel
- the DIO channelrisingEdge
- true to trigger on rising- Returns:
- the created handle
- See Also:
-
- "HAL_InitializeCounter"
-
freeCounter
Frees a counter.- Parameters:
counterHandle
- the counter handle- See Also:
-
- "HAL_FreeCounter"
-
setCounterEdgeConfiguration
Sets the up source to either detect rising edges or falling edges.Note that both are allowed to be set true at the same time without issues.
- Parameters:
counterHandle
- the counter handlerisingEdge
- true to trigger on rising- See Also:
-
- "HAL_SetCounterUpSourceEdge"
-
resetCounter
Resets the Counter to zero.Sets the counter value to zero. This does not effect the running state of the counter, just sets the current value to zero.
- Parameters:
counterHandle
- the counter handle- See Also:
-
- "HAL_ResetCounter"
-
getCounter
Reads the current counter value.Reads the value at this instant. It may still be running, so it reflects the current value. Next time it is read, it might have a different value.
- Parameters:
counterHandle
- the counter handle- Returns:
- the current counter value
- See Also:
-
- "HAL_GetCounter"
-
getCounterPeriod
Gets the Period of the most recent count.Returns the time interval of the most recent count. This can be used for velocity calculations to determine shaft speed.
- Parameters:
counterHandle
- the counter handle- Returns:
- the period of the last two pulses in units of seconds
- See Also:
-
- "HAL_GetCounterPeriod"
-
setCounterMaxPeriod
Sets the maximum period where the device is still considered "moving".Sets the maximum period where the device is considered moving. This value is used to determine the "stopped" state of the counter using the HAL_GetCounterStopped method.
- Parameters:
counterHandle
- the counter handlemaxPeriod
- the maximum period where the counted device is considered moving in seconds- See Also:
-
- "HAL_SetCounterMaxPeriod"
-
getCounterStopped
Determines if the clock is stopped.Determine if the clocked input is stopped based on the MaxPeriod value set using the SetMaxPeriod method. If the clock exceeds the MaxPeriod, then the device (and counter) are assumed to be stopped and it returns true.
- Parameters:
counterHandle
- the counter handle- Returns:
- true if the most recent counter period exceeds the MaxPeriod value set by SetMaxPeriod
- See Also:
-
- "HAL_GetCounterStopped"
-