Switches Counters to Handles (#123)

This commit is contained in:
Thad House
2016-07-01 00:29:08 -07:00
committed by Peter Johnson
parent 47694ef810
commit 0f105a26f7
9 changed files with 323 additions and 216 deletions

View File

@@ -9,6 +9,8 @@
#include <stdint.h>
#include "HAL/Handles.h"
enum Mode {
kTwoPulse = 0,
kSemiperiod = 1,
@@ -17,38 +19,40 @@ enum Mode {
};
extern "C" {
void* initializeCounter(Mode mode, uint32_t* index, int32_t* status);
void freeCounter(void* counter_pointer, int32_t* status);
void setCounterAverageSize(void* counter_pointer, int32_t size,
HalCounterHandle initializeCounter(Mode mode, uint32_t* index, int32_t* status);
void freeCounter(HalCounterHandle counter_handle, int32_t* status);
void setCounterAverageSize(HalCounterHandle counter_handle, int32_t size,
int32_t* status);
void setCounterUpSource(void* counter_pointer, uint32_t pin, bool analogTrigger,
int32_t* status);
void setCounterUpSourceEdge(void* counter_pointer, bool risingEdge,
void setCounterUpSource(HalCounterHandle counter_handle, uint32_t pin,
bool analogTrigger, int32_t* status);
void setCounterUpSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
bool fallingEdge, int32_t* status);
void clearCounterUpSource(void* counter_pointer, int32_t* status);
void setCounterDownSource(void* counter_pointer, uint32_t pin,
void clearCounterUpSource(HalCounterHandle counter_handle, int32_t* status);
void setCounterDownSource(HalCounterHandle counter_handle, uint32_t pin,
bool analogTrigger, int32_t* status);
void setCounterDownSourceEdge(void* counter_pointer, bool risingEdge,
void setCounterDownSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
bool fallingEdge, int32_t* status);
void clearCounterDownSource(void* counter_pointer, int32_t* status);
void setCounterUpDownMode(void* counter_pointer, int32_t* status);
void setCounterExternalDirectionMode(void* counter_pointer, int32_t* status);
void setCounterSemiPeriodMode(void* counter_pointer, bool highSemiPeriod,
int32_t* status);
void setCounterPulseLengthMode(void* counter_pointer, double threshold,
int32_t* status);
int32_t getCounterSamplesToAverage(void* counter_pointer, int32_t* status);
void setCounterSamplesToAverage(void* counter_pointer, int samplesToAverage,
int32_t* status);
void resetCounter(void* counter_pointer, int32_t* status);
int32_t getCounter(void* counter_pointer, int32_t* status);
double getCounterPeriod(void* counter_pointer, int32_t* status);
void setCounterMaxPeriod(void* counter_pointer, double maxPeriod,
void clearCounterDownSource(HalCounterHandle counter_handle, int32_t* status);
void setCounterUpDownMode(HalCounterHandle counter_handle, int32_t* status);
void setCounterExternalDirectionMode(HalCounterHandle counter_handle,
int32_t* status);
void setCounterSemiPeriodMode(HalCounterHandle counter_handle,
bool highSemiPeriod, int32_t* status);
void setCounterPulseLengthMode(HalCounterHandle counter_handle,
double threshold, int32_t* status);
int32_t getCounterSamplesToAverage(HalCounterHandle counter_handle,
int32_t* status);
void setCounterSamplesToAverage(HalCounterHandle counter_handle,
int samplesToAverage, int32_t* status);
void resetCounter(HalCounterHandle counter_handle, int32_t* status);
int32_t getCounter(HalCounterHandle counter_handle, int32_t* status);
double getCounterPeriod(HalCounterHandle counter_handle, int32_t* status);
void setCounterMaxPeriod(HalCounterHandle counter_handle, double maxPeriod,
int32_t* status);
void setCounterUpdateWhenEmpty(void* counter_pointer, bool enabled,
void setCounterUpdateWhenEmpty(HalCounterHandle counter_handle, bool enabled,
int32_t* status);
bool getCounterStopped(void* counter_pointer, int32_t* status);
bool getCounterDirection(void* counter_pointer, int32_t* status);
void setCounterReverseDirection(void* counter_pointer, bool reverseDirection,
int32_t* status);
bool getCounterStopped(HalCounterHandle counter_handle, int32_t* status);
bool getCounterDirection(HalCounterHandle counter_handle, int32_t* status);
void setCounterReverseDirection(HalCounterHandle counter_handle,
bool reverseDirection, int32_t* status);
}

View File

@@ -30,3 +30,5 @@ typedef HalHandle HalRelayHandle;
typedef HalHandle HalDigitalHandle;
typedef HalHandle HalDigitalPWMHandle;
typedef HalHandle HalCounterHandle;

View File

@@ -9,46 +9,62 @@
#include "DigitalInternal.h"
#include "HAL/HAL.h"
#include "handles/LimitedHandleResource.h"
static_assert(sizeof(uint32_t) <= sizeof(void*),
"This file shoves uint32_ts into pointers.");
using namespace hal;
extern "C" {
struct counter_t {
namespace {
struct Counter {
tCounter* counter;
uint32_t index;
};
typedef struct counter_t Counter;
}
static hal::Resource* counters = nullptr;
static LimitedHandleResource<HalCounterHandle, Counter, tCounter::kNumSystems,
HalHandleEnum::Counter>
counterHandles;
void* initializeCounter(Mode mode, uint32_t* index, int32_t* status) {
hal::Resource::CreateResourceObject(&counters, tCounter::kNumSystems);
*index = counters->Allocate("Counter");
if (*index == ~0ul) {
extern "C" {
HalCounterHandle initializeCounter(Mode mode, uint32_t* index,
int32_t* status) {
auto handle = counterHandles.Allocate();
if (handle == HAL_INVALID_HANDLE) { // out of resources
*status = NO_AVAILABLE_RESOURCES;
return nullptr;
return HAL_INVALID_HANDLE;
}
Counter* counter = new Counter();
auto counter = counterHandles.Get(handle);
if (counter == nullptr) { // would only occur on thread issues
*status = PARAMETER_OUT_OF_RANGE;
return HAL_INVALID_HANDLE;
}
*index = static_cast<uint32_t>(getHandleIndex(handle));
counter->counter = tCounter::create(*index, status);
counter->counter->writeConfig_Mode(mode, status);
counter->counter->writeTimerConfig_AverageSize(1, status);
counter->index = *index;
return counter;
return handle;
}
void freeCounter(void* counter_pointer, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
if (!counter) return;
void freeCounter(HalCounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) { // don't throw status as unneccesary
return;
}
delete counter->counter;
counters->Free(counter->index);
counterHandles.Free(counter_handle);
}
void setCounterAverageSize(void* counter_pointer, int32_t size,
void setCounterAverageSize(HalCounterHandle counter_handle, int32_t size,
int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->writeTimerConfig_AverageSize(size, status);
}
@@ -56,9 +72,13 @@ void setCounterAverageSize(void* counter_pointer, int32_t size,
* Set the source object that causes the counter to count up.
* Set the up counting DigitalSource.
*/
void setCounterUpSource(void* counter_pointer, uint32_t pin, bool analogTrigger,
int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
void setCounterUpSource(HalCounterHandle counter_handle, uint32_t pin,
bool analogTrigger, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
uint8_t module;
@@ -70,7 +90,7 @@ void setCounterUpSource(void* counter_pointer, uint32_t pin, bool analogTrigger,
if (counter->counter->readConfig_Mode(status) == kTwoPulse ||
counter->counter->readConfig_Mode(status) == kExternalDirection) {
setCounterUpSourceEdge(counter_pointer, true, false, status);
setCounterUpSourceEdge(counter_handle, true, false, status);
}
counter->counter->strobeReset(status);
}
@@ -79,9 +99,13 @@ void setCounterUpSource(void* counter_pointer, uint32_t pin, bool analogTrigger,
* Set the edge sensitivity on an up counting source.
* Set the up source to either detect rising edges or falling edges.
*/
void setCounterUpSourceEdge(void* counter_pointer, bool risingEdge,
void setCounterUpSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
bool fallingEdge, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->writeConfig_UpRisingEdge(risingEdge, status);
counter->counter->writeConfig_UpFallingEdge(fallingEdge, status);
}
@@ -89,8 +113,12 @@ void setCounterUpSourceEdge(void* counter_pointer, bool risingEdge,
/**
* Disable the up counting source to the counter.
*/
void clearCounterUpSource(void* counter_pointer, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
void clearCounterUpSource(HalCounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->writeConfig_UpFallingEdge(false, status);
counter->counter->writeConfig_UpRisingEdge(false, status);
// Index 0 of digital is always 0.
@@ -102,9 +130,13 @@ void clearCounterUpSource(void* counter_pointer, int32_t* status) {
* Set the source object that causes the counter to count down.
* Set the down counting DigitalSource.
*/
void setCounterDownSource(void* counter_pointer, uint32_t pin,
void setCounterDownSource(HalCounterHandle counter_handle, uint32_t pin,
bool analogTrigger, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
unsigned char mode = counter->counter->readConfig_Mode(status);
if (mode != kTwoPulse && mode != kExternalDirection) {
// TODO: wpi_setWPIErrorWithContext(ParameterOutOfRange, "Counter only
@@ -121,7 +153,7 @@ void setCounterDownSource(void* counter_pointer, uint32_t pin,
counter->counter->writeConfig_DownSource_Channel(pin, status);
counter->counter->writeConfig_DownSource_AnalogTrigger(analogTrigger, status);
setCounterDownSourceEdge(counter_pointer, true, false, status);
setCounterDownSourceEdge(counter_handle, true, false, status);
counter->counter->strobeReset(status);
}
@@ -129,9 +161,13 @@ void setCounterDownSource(void* counter_pointer, uint32_t pin,
* Set the edge sensitivity on a down counting source.
* Set the down source to either detect rising edges or falling edges.
*/
void setCounterDownSourceEdge(void* counter_pointer, bool risingEdge,
void setCounterDownSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
bool fallingEdge, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->writeConfig_DownRisingEdge(risingEdge, status);
counter->counter->writeConfig_DownFallingEdge(fallingEdge, status);
}
@@ -139,8 +175,12 @@ void setCounterDownSourceEdge(void* counter_pointer, bool risingEdge,
/**
* Disable the down counting source to the counter.
*/
void clearCounterDownSource(void* counter_pointer, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
void clearCounterDownSource(HalCounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->writeConfig_DownFallingEdge(false, status);
counter->counter->writeConfig_DownRisingEdge(false, status);
// Index 0 of digital is always 0.
@@ -152,8 +192,12 @@ void clearCounterDownSource(void* counter_pointer, int32_t* status) {
* Set standard up / down counting mode on this counter.
* Up and down counts are sourced independently from two inputs.
*/
void setCounterUpDownMode(void* counter_pointer, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
void setCounterUpDownMode(HalCounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->writeConfig_Mode(kTwoPulse, status);
}
@@ -162,8 +206,13 @@ void setCounterUpDownMode(void* counter_pointer, int32_t* status) {
* Counts are sourced on the Up counter input.
* The Down counter input represents the direction to count.
*/
void setCounterExternalDirectionMode(void* counter_pointer, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
void setCounterExternalDirectionMode(HalCounterHandle counter_handle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->writeConfig_Mode(kExternalDirection, status);
}
@@ -171,12 +220,16 @@ void setCounterExternalDirectionMode(void* counter_pointer, int32_t* status) {
* Set Semi-period mode on this counter.
* Counts up on both rising and falling edges.
*/
void setCounterSemiPeriodMode(void* counter_pointer, bool highSemiPeriod,
int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
void setCounterSemiPeriodMode(HalCounterHandle counter_handle,
bool highSemiPeriod, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->writeConfig_Mode(kSemiperiod, status);
counter->counter->writeConfig_UpRisingEdge(highSemiPeriod, status);
setCounterUpdateWhenEmpty(counter_pointer, false, status);
setCounterUpdateWhenEmpty(counter_handle, false, status);
}
/**
@@ -186,9 +239,13 @@ void setCounterSemiPeriodMode(void* counter_pointer, bool highSemiPeriod,
* @param threshold The pulse length beyond which the counter counts the
* opposite direction. Units are seconds.
*/
void setCounterPulseLengthMode(void* counter_pointer, double threshold,
int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
void setCounterPulseLengthMode(HalCounterHandle counter_handle,
double threshold, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->writeConfig_Mode(kPulseLength, status);
counter->counter->writeConfig_PulseLengthThreshold(
(uint32_t)(threshold * 1.0e6) * kSystemClockTicksPerMicrosecond, status);
@@ -201,8 +258,13 @@ void setCounterPulseLengthMode(void* counter_pointer, double threshold,
* mechanical imperfections or as oversampling to increase resolution.
* @return SamplesToAverage The number of samples being averaged (from 1 to 127)
*/
int32_t getCounterSamplesToAverage(void* counter_pointer, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
int32_t getCounterSamplesToAverage(HalCounterHandle counter_handle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return 0;
}
return counter->counter->readTimerConfig_AverageSize(status);
}
@@ -212,9 +274,13 @@ int32_t getCounterSamplesToAverage(void* counter_pointer, int32_t* status) {
* mechanical imperfections or as oversampling to increase resolution.
* @param samplesToAverage The number of samples to average from 1 to 127.
*/
void setCounterSamplesToAverage(void* counter_pointer, int samplesToAverage,
int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
void setCounterSamplesToAverage(HalCounterHandle counter_handle,
int samplesToAverage, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
if (samplesToAverage < 1 || samplesToAverage > 127) {
*status = PARAMETER_OUT_OF_RANGE;
}
@@ -226,8 +292,12 @@ void setCounterSamplesToAverage(void* counter_pointer, int samplesToAverage,
* Set the counter value to zero. This doesn't effect the running state of the
* counter, just sets the current value to zero.
*/
void resetCounter(void* counter_pointer, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
void resetCounter(HalCounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->strobeReset(status);
}
@@ -236,8 +306,12 @@ void resetCounter(void* counter_pointer, int32_t* status) {
* Read 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.
*/
int32_t getCounter(void* counter_pointer, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
int32_t getCounter(HalCounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return 0;
}
int32_t value = counter->counter->readOutput_Value(status);
return value;
}
@@ -248,8 +322,12 @@ int32_t getCounter(void* counter_pointer, int32_t* status) {
* velocity calculations to determine shaft speed.
* @returns The period of the last two pulses in units of seconds.
*/
double getCounterPeriod(void* counter_pointer, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
double getCounterPeriod(HalCounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return 0.0;
}
tCounter::tTimerOutput output = counter->counter->readTimerOutput(status);
double period;
if (output.Stalled) {
@@ -272,9 +350,13 @@ double getCounterPeriod(void* counter_pointer, int32_t* status) {
* @param maxPeriod The maximum period where the counted device is considered
* moving in seconds.
*/
void setCounterMaxPeriod(void* counter_pointer, double maxPeriod,
void setCounterMaxPeriod(HalCounterHandle counter_handle, double maxPeriod,
int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->writeTimerConfig_StallPeriod((uint32_t)(maxPeriod * 4.0e8),
status);
}
@@ -292,9 +374,13 @@ void setCounterMaxPeriod(void* counter_pointer, double maxPeriod,
* and you will likely not see the stopped bit become true (since it is updated
* at the end of an average and there are no samples to average).
*/
void setCounterUpdateWhenEmpty(void* counter_pointer, bool enabled,
void setCounterUpdateWhenEmpty(HalCounterHandle counter_handle, bool enabled,
int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
counter->counter->writeTimerConfig_UpdateWhenEmpty(enabled, status);
}
@@ -306,8 +392,12 @@ void setCounterUpdateWhenEmpty(void* counter_pointer, bool enabled,
* @return Returns true if the most recent counter period exceeds the MaxPeriod
* value set by SetMaxPeriod.
*/
bool getCounterStopped(void* counter_pointer, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
bool getCounterStopped(HalCounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return false;
}
return counter->counter->readTimerOutput_Stalled(status);
}
@@ -315,8 +405,12 @@ bool getCounterStopped(void* counter_pointer, int32_t* status) {
* The last direction the counter value changed.
* @return The last direction the counter value changed.
*/
bool getCounterDirection(void* counter_pointer, int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
bool getCounterDirection(HalCounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return false;
}
bool value = counter->counter->readOutput_Direction(status);
return value;
}
@@ -327,14 +421,18 @@ bool getCounterDirection(void* counter_pointer, int32_t* status) {
* 1X and 2X quadrature encoding only. Any other counter mode isn't supported.
* @param reverseDirection true if the value counted should be negated.
*/
void setCounterReverseDirection(void* counter_pointer, bool reverseDirection,
int32_t* status) {
Counter* counter = (Counter*)counter_pointer;
void setCounterReverseDirection(HalCounterHandle counter_handle,
bool reverseDirection, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
if (counter == nullptr) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
if (counter->counter->readConfig_Mode(status) == kExternalDirection) {
if (reverseDirection)
setCounterDownSourceEdge(counter_pointer, true, true, status);
setCounterDownSourceEdge(counter_handle, true, true, status);
else
setCounterDownSourceEdge(counter_pointer, false, true, status);
setCounterDownSourceEdge(counter_handle, false, true, status);
}
}
}

View File

@@ -36,7 +36,8 @@ enum class HalHandleEnum {
AnalogTrigger = 7,
Relay = 8,
PWM = 9,
DigitalPWM = 10
DigitalPWM = 10,
Counter = 11
};
static inline int16_t getHandleIndex(HalHandle handle) {

View File

@@ -12,6 +12,7 @@
#include "AnalogTrigger.h"
#include "CounterBase.h"
#include "HAL/Counter.h"
#include "HAL/Handles.h"
#include "LiveWindow/LiveWindowSendable.h"
#include "SensorBase.h"
@@ -97,9 +98,10 @@ class Counter : public SensorBase,
// Makes the counter count down.
std::shared_ptr<DigitalSource> m_downSource;
// The FPGA counter object
void* m_counter = nullptr; ///< The FPGA counter object.
HalCounterHandle m_counter = HAL_INVALID_HANDLE;
private:
uint32_t m_index = 0; ///< The index of this counter.
uint32_t m_index = 0; // The index of this counter.
std::shared_ptr<ITable> m_table;
friend class DigitalGlitchFilter;

View File

@@ -182,7 +182,7 @@ Counter::~Counter() {
int32_t status = 0;
freeCounter(m_counter, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
m_counter = nullptr;
m_counter = HAL_INVALID_HANDLE;
}
/**

View File

@@ -29,9 +29,9 @@ extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: initializeCounter
* Signature: (ILjava/nio/IntBuffer;)J
* Signature: (ILjava/nio/IntBuffer;)I
*/
JNIEXPORT jlong JNICALL
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_initializeCounter(
JNIEnv* env, jclass, jint mode, jobject index) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI initializeCounter";
@@ -39,25 +39,25 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_initializeCounter(
jint* indexPtr = (jint*)env->GetDirectBufferAddress(index);
COUNTERJNI_LOG(logDEBUG) << "Index Ptr = " << (uint32_t*)indexPtr;
int32_t status = 0;
void* counter = initializeCounter((Mode)mode, (uint32_t*)indexPtr, &status);
auto counter = initializeCounter((Mode)mode, (uint32_t*)indexPtr, &status);
COUNTERJNI_LOG(logDEBUG) << "Index = " << *indexPtr;
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
COUNTERJNI_LOG(logDEBUG) << "COUNTER Ptr = " << counter;
COUNTERJNI_LOG(logDEBUG) << "COUNTER Handle = " << counter;
CheckStatus(env, status);
return (jlong)counter;
return (jint)counter;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: freeCounter
* Signature: (J)V
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_freeCounter(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI freeCounter";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
int32_t status = 0;
freeCounter((void*)id, &status);
freeCounter((HalCounterHandle)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -65,16 +65,16 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_freeCounter(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterAverageSize
* Signature: (JI)V
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterAverageSize(
JNIEnv* env, jclass, jlong id, jint value) {
JNIEnv* env, jclass, jint id, jint value) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterAverageSize";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
COUNTERJNI_LOG(logDEBUG) << "AverageSize = " << value;
int32_t status = 0;
setCounterAverageSize((void*)id, value, &status);
setCounterAverageSize((HalCounterHandle)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -82,17 +82,17 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterAverageSize(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterUpSource
* Signature: (JIZ)V
* Signature: (IIZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpSource(
JNIEnv* env, jclass, jlong id, jint pin, jboolean analogTrigger) {
JNIEnv* env, jclass, jint id, jint pin, jboolean analogTrigger) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpSource";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
COUNTERJNI_LOG(logDEBUG) << "Pin = " << pin;
COUNTERJNI_LOG(logDEBUG) << "AnalogTrigger = " << (jint)analogTrigger;
int32_t status = 0;
setCounterUpSource((void*)id, pin, analogTrigger, &status);
setCounterUpSource((HalCounterHandle)id, pin, analogTrigger, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -100,17 +100,17 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpSource(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterUpSourceEdge
* Signature: (JZZ)V
* Signature: (IZZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpSourceEdge(
JNIEnv* env, jclass, jlong id, jboolean valueRise, jboolean valueFall) {
JNIEnv* env, jclass, jint id, jboolean valueRise, jboolean valueFall) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpSourceEdge";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
COUNTERJNI_LOG(logDEBUG) << "Rise = " << (jint)valueRise;
COUNTERJNI_LOG(logDEBUG) << "Fall = " << (jint)valueFall;
int32_t status = 0;
setCounterUpSourceEdge((void*)id, valueRise, valueFall, &status);
setCounterUpSourceEdge((HalCounterHandle)id, valueRise, valueFall, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -118,15 +118,15 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpSourceEdge(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: clearCounterUpSource
* Signature: (J)V
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_clearCounterUpSource(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI clearCounterUpSource";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
int32_t status = 0;
clearCounterUpSource((void*)id, &status);
clearCounterUpSource((HalCounterHandle)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -134,17 +134,17 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_clearCounterUpSource(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterDownSource
* Signature: (JIZ)V
* Signature: (IIZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterDownSource(
JNIEnv* env, jclass, jlong id, jint pin, jboolean analogTrigger) {
JNIEnv* env, jclass, jint id, jint pin, jboolean analogTrigger) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterDownSource";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
COUNTERJNI_LOG(logDEBUG) << "Pin = " << pin;
COUNTERJNI_LOG(logDEBUG) << "AnalogTrigger = " << (jint)analogTrigger;
int32_t status = 0;
setCounterDownSource((void*)id, pin, analogTrigger, &status);
setCounterDownSource((HalCounterHandle)id, pin, analogTrigger, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
if (status == PARAMETER_OUT_OF_RANGE) {
ThrowIllegalArgumentException(env,
@@ -158,17 +158,17 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterDownSource(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterDownSourceEdge
* Signature: (JZZ)V
* Signature: (IZZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterDownSourceEdge(
JNIEnv* env, jclass, jlong id, jboolean valueRise, jboolean valueFall) {
JNIEnv* env, jclass, jint id, jboolean valueRise, jboolean valueFall) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterDownSourceEdge";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
COUNTERJNI_LOG(logDEBUG) << "Rise = " << (jint)valueRise;
COUNTERJNI_LOG(logDEBUG) << "Fall = " << (jint)valueFall;
int32_t status = 0;
setCounterDownSourceEdge((void*)id, valueRise, valueFall, &status);
setCounterDownSourceEdge((HalCounterHandle)id, valueRise, valueFall, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -176,15 +176,15 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterDownSourceEdge(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: clearCounterDownSource
* Signature: (J)V
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_clearCounterDownSource(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI clearCounterDownSource";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
int32_t status = 0;
clearCounterDownSource((void*)id, &status);
clearCounterDownSource((HalCounterHandle)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -192,15 +192,15 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_clearCounterDownSource(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterUpDownMode
* Signature: (J)V
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpDownMode(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpDownMode";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
int32_t status = 0;
setCounterUpDownMode((void*)id, &status);
setCounterUpDownMode((HalCounterHandle)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -208,16 +208,16 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpDownMode(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterExternalDirectionMode
* Signature: (J)V
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterExternalDirectionMode(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
COUNTERJNI_LOG(logDEBUG)
<< "Calling COUNTERJNI setCounterExternalDirectionMode";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
int32_t status = 0;
setCounterExternalDirectionMode((void*)id, &status);
setCounterExternalDirectionMode((HalCounterHandle)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -225,16 +225,16 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterExternalDirectionMode(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterSemiPeriodMode
* Signature: (JZ)V
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterSemiPeriodMode(
JNIEnv* env, jclass, jlong id, jboolean value) {
JNIEnv* env, jclass, jint id, jboolean value) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterSemiPeriodMode";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
COUNTERJNI_LOG(logDEBUG) << "SemiPeriodMode = " << (jint)value;
int32_t status = 0;
setCounterSemiPeriodMode((void*)id, value, &status);
setCounterSemiPeriodMode((HalCounterHandle)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -242,16 +242,16 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterSemiPeriodMode(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterPulseLengthMode
* Signature: (JD)V
* Signature: (ID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterPulseLengthMode(
JNIEnv* env, jclass, jlong id, jdouble value) {
JNIEnv* env, jclass, jint id, jdouble value) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterPulseLengthMode";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
COUNTERJNI_LOG(logDEBUG) << "PulseLengthMode = " << value;
int32_t status = 0;
setCounterPulseLengthMode((void*)id, value, &status);
setCounterPulseLengthMode((HalCounterHandle)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -259,15 +259,15 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterPulseLengthMode(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: getCounterSamplesToAverage
* Signature: (J)I
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterSamplesToAverage(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterSamplesToAverage";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
int32_t status = 0;
jint returnValue = getCounterSamplesToAverage((void*)id, &status);
jint returnValue = getCounterSamplesToAverage((HalCounterHandle)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
COUNTERJNI_LOG(logDEBUG) << "getCounterSamplesToAverageResult = "
<< returnValue;
@@ -278,16 +278,16 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterSamplesToAverage(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterSamplesToAverage
* Signature: (JI)V
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterSamplesToAverage(
JNIEnv* env, jclass, jlong id, jint value) {
JNIEnv* env, jclass, jint id, jint value) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterSamplesToAverage";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
COUNTERJNI_LOG(logDEBUG) << "SamplesToAverage = " << value;
int32_t status = 0;
setCounterSamplesToAverage((void*)id, value, &status);
setCounterSamplesToAverage((HalCounterHandle)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
if (status == PARAMETER_OUT_OF_RANGE) {
ThrowBoundaryException(env, value, 1, 127);
@@ -299,14 +299,14 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterSamplesToAverage(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: resetCounter
* Signature: (J)V
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_resetCounter(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI resetCounter";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
int32_t status = 0;
resetCounter((void*)id, &status);
resetCounter((HalCounterHandle)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -314,14 +314,14 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_resetCounter(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: getCounter
* Signature: (J)I
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounter(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
// COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounter";
// COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
// COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
int32_t status = 0;
jint returnValue = getCounter((void*)id, &status);
jint returnValue = getCounter((HalCounterHandle)id, &status);
// COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
// COUNTERJNI_LOG(logDEBUG) << "getCounterResult = " << returnValue;
CheckStatus(env, status);
@@ -331,15 +331,15 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounter(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: getCounterPeriod
* Signature: (J)D
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterPeriod(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterPeriod";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
int32_t status = 0;
jdouble returnValue = getCounterPeriod((void*)id, &status);
jdouble returnValue = getCounterPeriod((HalCounterHandle)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
COUNTERJNI_LOG(logDEBUG) << "getCounterPeriodResult = " << returnValue;
CheckStatus(env, status);
@@ -349,16 +349,16 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterPeriod(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterMaxPeriod
* Signature: (JD)V
* Signature: (ID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterMaxPeriod(
JNIEnv* env, jclass, jlong id, jdouble value) {
JNIEnv* env, jclass, jint id, jdouble value) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterMaxPeriod";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
COUNTERJNI_LOG(logDEBUG) << "MaxPeriod = " << value;
int32_t status = 0;
setCounterMaxPeriod((void*)id, value, &status);
setCounterMaxPeriod((HalCounterHandle)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -366,16 +366,16 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterMaxPeriod(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterUpdateWhenEmpty
* Signature: (JZ)V
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpdateWhenEmpty(
JNIEnv* env, jclass, jlong id, jboolean value) {
JNIEnv* env, jclass, jint id, jboolean value) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterMaxPeriod";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
COUNTERJNI_LOG(logDEBUG) << "UpdateWhenEmpty = " << (jint)value;
int32_t status = 0;
setCounterUpdateWhenEmpty((void*)id, value, &status);
setCounterUpdateWhenEmpty((HalCounterHandle)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -383,15 +383,15 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpdateWhenEmpty(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: getCounterStopped
* Signature: (J)Z
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterStopped(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterStopped";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
int32_t status = 0;
jboolean returnValue = getCounterStopped((void*)id, &status);
jboolean returnValue = getCounterStopped((HalCounterHandle)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
COUNTERJNI_LOG(logDEBUG) << "getCounterStoppedResult = " << (jint)returnValue;
CheckStatus(env, status);
@@ -401,15 +401,15 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterStopped(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: getCounterDirection
* Signature: (J)Z
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterDirection(
JNIEnv* env, jclass, jlong id) {
JNIEnv* env, jclass, jint id) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterDirection";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
int32_t status = 0;
jboolean returnValue = getCounterDirection((void*)id, &status);
jboolean returnValue = getCounterDirection((HalCounterHandle)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
COUNTERJNI_LOG(logDEBUG) << "getCounterDirectionResult = "
<< (jint)returnValue;
@@ -420,16 +420,16 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterDirection(
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterReverseDirection
* Signature: (JZ)V
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterReverseDirection(
JNIEnv* env, jclass, jlong id, jboolean value) {
JNIEnv* env, jclass, jint id, jboolean value) {
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterReverseDirection";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
COUNTERJNI_LOG(logDEBUG) << "ReverseDirection = " << (jint)value;
int32_t status = 0;
setCounterReverseDirection((void*)id, value, &status);
setCounterReverseDirection((HalCounterHandle)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}

View File

@@ -65,7 +65,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
protected DigitalSource m_downSource; // /< What makes the counter count down.
private boolean m_allocatedUpSource;
private boolean m_allocatedDownSource;
private long m_counter; // /< The FPGA counter object.
private int m_counter; // /< The FPGA counter object.
private int m_index; // /< The index of this counter.
private PIDSourceType m_pidSource;
private double m_distancePerPulse; // distance of travel for each tick

View File

@@ -10,56 +10,56 @@ package edu.wpi.first.wpilibj.hal;
import java.nio.IntBuffer;
public class CounterJNI extends JNIWrapper {
public static native long initializeCounter(int mode, IntBuffer index);
public static native int initializeCounter(int mode, IntBuffer index);
public static native void freeCounter(long counterPointer);
public static native void freeCounter(int counterHandle);
public static native void setCounterAverageSize(long counterPointer, int size);
public static native void setCounterAverageSize(int counterHandle, int size);
public static native void setCounterUpSource(long counterPointer, int pin,
public static native void setCounterUpSource(int counterHandle, int pin,
boolean analogTrigger);
public static native void setCounterUpSourceEdge(long counterPointer, boolean risingEdge,
public static native void setCounterUpSourceEdge(int counterHandle, boolean risingEdge,
boolean fallingEdge);
public static native void clearCounterUpSource(long counterPointer);
public static native void clearCounterUpSource(int counterHandle);
public static native void setCounterDownSource(long counterPointer, int pin,
public static native void setCounterDownSource(int counterHandle, int pin,
boolean analogTrigger);
public static native void setCounterDownSourceEdge(long counterPointer, boolean risingEdge,
public static native void setCounterDownSourceEdge(int counterHandle, boolean risingEdge,
boolean fallingEdge);
public static native void clearCounterDownSource(long counterPointer);
public static native void clearCounterDownSource(int counterHandle);
public static native void setCounterUpDownMode(long counterPointer);
public static native void setCounterUpDownMode(int counterHandle);
public static native void setCounterExternalDirectionMode(long counterPointer);
public static native void setCounterExternalDirectionMode(int counterHandle);
public static native void setCounterSemiPeriodMode(long counterPointer,
public static native void setCounterSemiPeriodMode(int counterHandle,
boolean highSemiPeriod);
public static native void setCounterPulseLengthMode(long counterPointer, double threshold);
public static native void setCounterPulseLengthMode(int counterHandle, double threshold);
public static native int getCounterSamplesToAverage(long counterPointer);
public static native int getCounterSamplesToAverage(int counterHandle);
public static native void setCounterSamplesToAverage(long counterPointer,
public static native void setCounterSamplesToAverage(int counterHandle,
int samplesToAverage);
public static native void resetCounter(long counterPointer);
public static native void resetCounter(int counterHandle);
public static native int getCounter(long counterPointer);
public static native int getCounter(int counterHandle);
public static native double getCounterPeriod(long counterPointer);
public static native double getCounterPeriod(int counterHandle);
public static native void setCounterMaxPeriod(long counterPointer, double maxPeriod);
public static native void setCounterMaxPeriod(int counterHandle, double maxPeriod);
public static native void setCounterUpdateWhenEmpty(long counterPointer, boolean enabled);
public static native void setCounterUpdateWhenEmpty(int counterHandle, boolean enabled);
public static native boolean getCounterStopped(long counterPointer);
public static native boolean getCounterStopped(int counterHandle);
public static native boolean getCounterDirection(long counterPointer);
public static native boolean getCounterDirection(int counterHandle);
public static native void setCounterReverseDirection(long counterPointer,
public static native void setCounterReverseDirection(int counterHandle,
boolean reverseDirection);
}