mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Adds a special exception and status message for a handle error (#127)
This commit is contained in:
committed by
Peter Johnson
parent
36ac37db8c
commit
fb865d3ee7
@@ -70,6 +70,9 @@
|
||||
#define HAL_COUNTER_NOT_SUPPORTED -1058
|
||||
#define HAL_COUNTER_NOT_SUPPORTED_MESSAGE \
|
||||
"HAL: Counter mode not supported for encoder method"
|
||||
#define HAL_HANDLE_ERROR -1098
|
||||
#define HAL_HANDLE_ERROR_MESSAGE \
|
||||
"HAL: A handle parameter was passed incorrectly"
|
||||
|
||||
#define VI_ERROR_SYSTEM_ERROR_MESSAGE "HAL - VISA: System Error";
|
||||
#define VI_ERROR_INV_OBJECT_MESSAGE "HAL - VISA: Invalid Object"
|
||||
|
||||
@@ -22,7 +22,7 @@ bool isAccumulatorChannel(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
for (uint32_t i = 0; i < kNumAccumulators; i++) {
|
||||
@@ -46,7 +46,7 @@ void resetAccumulator(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (port->accumulator == nullptr) {
|
||||
@@ -72,7 +72,7 @@ void setAccumulatorCenter(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t center, int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (port->accumulator == nullptr) {
|
||||
@@ -89,7 +89,7 @@ void setAccumulatorDeadband(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t deadband, int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (port->accumulator == nullptr) {
|
||||
@@ -111,7 +111,7 @@ int64_t getAccumulatorValue(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
if (port->accumulator == nullptr) {
|
||||
@@ -134,7 +134,7 @@ uint32_t getAccumulatorCount(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
if (port->accumulator == nullptr) {
|
||||
@@ -157,7 +157,7 @@ void getAccumulatorOutput(HalAnalogInputHandle analog_port_handle,
|
||||
int64_t* value, uint32_t* count, int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (port->accumulator == nullptr) {
|
||||
|
||||
@@ -45,7 +45,7 @@ HalAnalogInputHandle initializeAnalogInputPort(HalPortHandle port_handle,
|
||||
// Initialize port structure
|
||||
auto analog_port = analogInputHandles.Get(handle);
|
||||
if (analog_port == nullptr) { // would only error on thread issue
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_INVALID_HANDLE;
|
||||
}
|
||||
analog_port->pin = static_cast<uint8_t>(pin);
|
||||
@@ -151,7 +151,7 @@ void setAnalogAverageBits(HalAnalogInputHandle analog_port_handle,
|
||||
uint32_t bits, int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
analogInputSystem->writeAverageBits(port->pin, bits, status);
|
||||
@@ -170,7 +170,7 @@ uint32_t getAnalogAverageBits(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return kDefaultAverageBits;
|
||||
}
|
||||
uint32_t result = analogInputSystem->readAverageBits(port->pin, status);
|
||||
@@ -192,7 +192,7 @@ void setAnalogOversampleBits(HalAnalogInputHandle analog_port_handle,
|
||||
uint32_t bits, int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
analogInputSystem->writeOversampleBits(port->pin, bits, status);
|
||||
@@ -212,7 +212,7 @@ uint32_t getAnalogOversampleBits(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return kDefaultOversampleBits;
|
||||
}
|
||||
uint32_t result = analogInputSystem->readOversampleBits(port->pin, status);
|
||||
@@ -233,7 +233,7 @@ int16_t getAnalogValue(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
int16_t value;
|
||||
@@ -273,7 +273,7 @@ int32_t getAnalogAverageValue(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
int32_t value;
|
||||
@@ -380,7 +380,7 @@ uint32_t getAnalogLSBWeight(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
uint32_t lsbWeight = FRC_NetworkCommunication_nAICalibration_getLSBWeight(
|
||||
@@ -402,7 +402,7 @@ int32_t getAnalogOffset(HalAnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
int32_t offset = FRC_NetworkCommunication_nAICalibration_getOffset(
|
||||
|
||||
@@ -49,7 +49,7 @@ HalAnalogOutputHandle initializeAnalogOutputPort(HalPortHandle port_handle,
|
||||
|
||||
auto port = analogOutputHandles.Get(handle);
|
||||
if (port == nullptr) { // would only error on thread issue
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ void setAnalogOutput(HalAnalogOutputHandle analog_output_handle, double voltage,
|
||||
int32_t* status) {
|
||||
auto port = analogOutputHandles.Get(analog_output_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ double getAnalogOutput(HalAnalogOutputHandle analog_output_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogOutputHandles.Get(analog_output_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ HalAnalogTriggerHandle initializeAnalogTrigger(HalAnalogInputHandle port_handle,
|
||||
|
||||
auto analog_port = analogInputHandles.Get(trigger->analogHandle);
|
||||
if (analog_port == nullptr) { // would only error on thread issue
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_INVALID_HANDLE;
|
||||
}
|
||||
*index = static_cast<uint32_t>(getHandleIndex(handle));
|
||||
@@ -75,7 +75,7 @@ void setAnalogTriggerLimitsRaw(HalAnalogTriggerHandle analog_trigger_handle,
|
||||
int32_t lower, int32_t upper, int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (lower > upper) {
|
||||
@@ -94,7 +94,7 @@ void setAnalogTriggerLimitsVoltage(HalAnalogTriggerHandle analog_trigger_handle,
|
||||
int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (lower > upper) {
|
||||
@@ -118,7 +118,7 @@ void setAnalogTriggerAveraged(HalAnalogTriggerHandle analog_trigger_handle,
|
||||
bool useAveragedValue, int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (trigger->trigger->readSourceSelect_Filter(status) != 0) {
|
||||
@@ -139,7 +139,7 @@ void setAnalogTriggerFiltered(HalAnalogTriggerHandle analog_trigger_handle,
|
||||
bool useFilteredValue, int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (trigger->trigger->readSourceSelect_Averaged(status) != 0) {
|
||||
@@ -159,7 +159,7 @@ bool getAnalogTriggerInWindow(HalAnalogTriggerHandle analog_trigger_handle,
|
||||
int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
return trigger->trigger->readOutput_InHysteresis(trigger->index, status) != 0;
|
||||
@@ -176,7 +176,7 @@ bool getAnalogTriggerTriggerState(HalAnalogTriggerHandle analog_trigger_handle,
|
||||
int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
return trigger->trigger->readOutput_OverLimit(trigger->index, status) != 0;
|
||||
@@ -190,7 +190,7 @@ bool getAnalogTriggerOutput(HalAnalogTriggerHandle analog_trigger_handle,
|
||||
AnalogTriggerType type, int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
bool result = false;
|
||||
|
||||
@@ -38,7 +38,7 @@ bool getCompressor(HalCompressorHandle compressor_handle, int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
@@ -54,7 +54,7 @@ void setClosedLoopControl(HalCompressorHandle compressor_handle, bool value,
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
@@ -67,7 +67,7 @@ bool getClosedLoopControl(HalCompressorHandle compressor_handle,
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
@@ -82,7 +82,7 @@ bool getPressureSwitch(HalCompressorHandle compressor_handle, int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
@@ -98,7 +98,7 @@ float getCompressorCurrent(HalCompressorHandle compressor_handle,
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
@@ -113,7 +113,7 @@ bool getCompressorCurrentTooHighFault(HalCompressorHandle compressor_handle,
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
@@ -128,7 +128,7 @@ bool getCompressorCurrentTooHighStickyFault(
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
@@ -143,7 +143,7 @@ bool getCompressorShortedStickyFault(HalCompressorHandle compressor_handle,
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
@@ -158,7 +158,7 @@ bool getCompressorShortedFault(HalCompressorHandle compressor_handle,
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
@@ -173,7 +173,7 @@ bool getCompressorNotConnectedStickyFault(HalCompressorHandle compressor_handle,
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
@@ -188,7 +188,7 @@ bool getCompressorNotConnectedFault(HalCompressorHandle compressor_handle,
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
@@ -203,7 +203,7 @@ void clearAllPCMStickyFaults(HalCompressorHandle compressor_handle,
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HalHandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
PCM* module = PCM_modules[index];
|
||||
|
||||
@@ -34,7 +34,7 @@ HalCounterHandle initializeCounter(Mode mode, int32_t* index, int32_t* status) {
|
||||
}
|
||||
auto counter = counterHandles.Get(handle);
|
||||
if (counter == nullptr) { // would only occur on thread issues
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_INVALID_HANDLE;
|
||||
}
|
||||
*index = static_cast<uint32_t>(getHandleIndex(handle));
|
||||
@@ -59,7 +59,7 @@ void setCounterAverageSize(HalCounterHandle counter_handle, int32_t size,
|
||||
int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->writeTimerConfig_AverageSize(size, status);
|
||||
@@ -73,7 +73,7 @@ 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;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ void setCounterUpSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
|
||||
bool fallingEdge, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->writeConfig_UpRisingEdge(risingEdge, status);
|
||||
@@ -113,7 +113,7 @@ void setCounterUpSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
|
||||
void clearCounterUpSource(HalCounterHandle counter_handle, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->writeConfig_UpFallingEdge(false, status);
|
||||
@@ -131,7 +131,7 @@ void setCounterDownSource(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;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
unsigned char mode = counter->counter->readConfig_Mode(status);
|
||||
@@ -162,7 +162,7 @@ void setCounterDownSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
|
||||
bool fallingEdge, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->writeConfig_DownRisingEdge(risingEdge, status);
|
||||
@@ -175,7 +175,7 @@ void setCounterDownSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
|
||||
void clearCounterDownSource(HalCounterHandle counter_handle, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->writeConfig_DownFallingEdge(false, status);
|
||||
@@ -192,7 +192,7 @@ void clearCounterDownSource(HalCounterHandle counter_handle, int32_t* status) {
|
||||
void setCounterUpDownMode(HalCounterHandle counter_handle, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->writeConfig_Mode(kTwoPulse, status);
|
||||
@@ -207,7 +207,7 @@ void setCounterExternalDirectionMode(HalCounterHandle counter_handle,
|
||||
int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->writeConfig_Mode(kExternalDirection, status);
|
||||
@@ -221,7 +221,7 @@ void setCounterSemiPeriodMode(HalCounterHandle counter_handle,
|
||||
bool highSemiPeriod, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->writeConfig_Mode(kSemiperiod, status);
|
||||
@@ -240,7 +240,7 @@ void setCounterPulseLengthMode(HalCounterHandle counter_handle,
|
||||
double threshold, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->writeConfig_Mode(kPulseLength, status);
|
||||
@@ -259,7 +259,7 @@ int32_t getCounterSamplesToAverage(HalCounterHandle counter_handle,
|
||||
int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return counter->counter->readTimerConfig_AverageSize(status);
|
||||
@@ -275,7 +275,7 @@ void setCounterSamplesToAverage(HalCounterHandle counter_handle,
|
||||
int samplesToAverage, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (samplesToAverage < 1 || samplesToAverage > 127) {
|
||||
@@ -292,7 +292,7 @@ void setCounterSamplesToAverage(HalCounterHandle counter_handle,
|
||||
void resetCounter(HalCounterHandle counter_handle, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->strobeReset(status);
|
||||
@@ -306,7 +306,7 @@ void resetCounter(HalCounterHandle counter_handle, int32_t* status) {
|
||||
int32_t getCounter(HalCounterHandle counter_handle, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
int32_t value = counter->counter->readOutput_Value(status);
|
||||
@@ -322,7 +322,7 @@ int32_t getCounter(HalCounterHandle counter_handle, int32_t* status) {
|
||||
double getCounterPeriod(HalCounterHandle counter_handle, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0.0;
|
||||
}
|
||||
tCounter::tTimerOutput output = counter->counter->readTimerOutput(status);
|
||||
@@ -351,7 +351,7 @@ void setCounterMaxPeriod(HalCounterHandle counter_handle, double maxPeriod,
|
||||
int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->writeTimerConfig_StallPeriod((uint32_t)(maxPeriod * 4.0e8),
|
||||
@@ -375,7 +375,7 @@ void setCounterUpdateWhenEmpty(HalCounterHandle counter_handle, bool enabled,
|
||||
int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
counter->counter->writeTimerConfig_UpdateWhenEmpty(enabled, status);
|
||||
@@ -392,7 +392,7 @@ void setCounterUpdateWhenEmpty(HalCounterHandle counter_handle, bool enabled,
|
||||
bool getCounterStopped(HalCounterHandle counter_handle, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
return counter->counter->readTimerOutput_Stalled(status);
|
||||
@@ -405,7 +405,7 @@ bool getCounterStopped(HalCounterHandle counter_handle, int32_t* status) {
|
||||
bool getCounterDirection(HalCounterHandle counter_handle, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
bool value = counter->counter->readOutput_Direction(status);
|
||||
@@ -422,7 +422,7 @@ void setCounterReverseDirection(HalCounterHandle counter_handle,
|
||||
bool reverseDirection, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (counter->counter->readConfig_Mode(status) == kExternalDirection) {
|
||||
|
||||
@@ -47,7 +47,7 @@ HalDigitalHandle initializeDIOPort(HalPortHandle port_handle, uint8_t input,
|
||||
|
||||
auto port = digitalPinHandles.Get(handle, HalHandleEnum::DIO);
|
||||
if (port == nullptr) { // would only occur on thread issue.
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ HalDigitalPWMHandle allocateDigitalPWM(int32_t* status) {
|
||||
|
||||
auto id = digitalPWMHandles.Get(handle);
|
||||
if (id == nullptr) { // would only occur on thread issue.
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_INVALID_HANDLE;
|
||||
}
|
||||
*id = static_cast<uint8_t>(getHandleIndex(handle));
|
||||
@@ -155,7 +155,7 @@ void setDigitalPWMDutyCycle(HalDigitalPWMHandle pwmGenerator, double dutyCycle,
|
||||
int32_t* status) {
|
||||
auto port = digitalPWMHandles.Get(pwmGenerator);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
uint32_t id = *port;
|
||||
@@ -188,7 +188,7 @@ void setDigitalPWMOutputChannel(HalDigitalPWMHandle pwmGenerator, uint32_t pin,
|
||||
int32_t* status) {
|
||||
auto port = digitalPWMHandles.Get(pwmGenerator);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
uint32_t id = *port;
|
||||
@@ -210,7 +210,7 @@ void setDigitalPWMOutputChannel(HalDigitalPWMHandle pwmGenerator, uint32_t pin,
|
||||
void setDIO(HalDigitalHandle dio_port_handle, short value, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (value != 0 && value != 1) {
|
||||
@@ -253,7 +253,7 @@ void setDIO(HalDigitalHandle dio_port_handle, short value, int32_t* status) {
|
||||
bool getDIO(HalDigitalHandle dio_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
tDIO::tDI currentDIO = digitalSystem->readDI(status);
|
||||
@@ -286,7 +286,7 @@ bool getDIO(HalDigitalHandle dio_port_handle, int32_t* status) {
|
||||
bool getDIODirection(HalDigitalHandle dio_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
tDIO::tOutputEnable currentOutputEnable =
|
||||
@@ -315,7 +315,7 @@ void pulse(HalDigitalHandle dio_port_handle, double pulseLength,
|
||||
int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
tDIO::tPulse pulse;
|
||||
@@ -340,7 +340,7 @@ void pulse(HalDigitalHandle dio_port_handle, double pulseLength,
|
||||
bool isPulsing(HalDigitalHandle dio_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
tDIO::tPulse pulseRegister = digitalSystem->readPulse(status);
|
||||
@@ -374,7 +374,7 @@ void setFilterSelect(HalDigitalHandle dio_port_handle, int filter_index,
|
||||
int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ void setFilterSelect(HalDigitalHandle dio_port_handle, int filter_index,
|
||||
int getFilterSelect(HalDigitalHandle dio_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(dio_port_handle, HalHandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ void freeEncoder(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
int32_t getEncoder(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->Get(status);
|
||||
@@ -252,7 +252,7 @@ int32_t getEncoder(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
int32_t getEncoderRaw(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->GetRaw(status);
|
||||
@@ -262,7 +262,7 @@ int32_t getEncoderEncodingScale(HalEncoderHandle encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->GetEncodingScale(status);
|
||||
@@ -271,7 +271,7 @@ int32_t getEncoderEncodingScale(HalEncoderHandle encoder_handle,
|
||||
void resetEncoder(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->Reset(status);
|
||||
@@ -280,7 +280,7 @@ void resetEncoder(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
int32_t getEncoderPeriod(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->GetPeriod(status);
|
||||
@@ -290,7 +290,7 @@ void setEncoderMaxPeriod(HalEncoderHandle encoder_handle, double maxPeriod,
|
||||
int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->SetMaxPeriod(maxPeriod, status);
|
||||
@@ -299,7 +299,7 @@ void setEncoderMaxPeriod(HalEncoderHandle encoder_handle, double maxPeriod,
|
||||
uint8_t getEncoderStopped(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->GetStopped(status);
|
||||
@@ -308,7 +308,7 @@ uint8_t getEncoderStopped(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
uint8_t getEncoderDirection(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->GetDirection(status);
|
||||
@@ -317,7 +317,7 @@ uint8_t getEncoderDirection(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
double getEncoderDistance(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->GetDistance(status);
|
||||
@@ -326,7 +326,7 @@ double getEncoderDistance(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
double getEncoderRate(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->GetRate(status);
|
||||
@@ -336,7 +336,7 @@ void setEncoderMinRate(HalEncoderHandle encoder_handle, double minRate,
|
||||
int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->SetMinRate(minRate, status);
|
||||
@@ -346,7 +346,7 @@ void setEncoderDistancePerPulse(HalEncoderHandle encoder_handle,
|
||||
double distancePerPulse, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->SetDistancePerPulse(distancePerPulse, status);
|
||||
@@ -356,7 +356,7 @@ void setEncoderReverseDirection(HalEncoderHandle encoder_handle,
|
||||
uint8_t reverseDirection, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->SetReverseDirection(reverseDirection, status);
|
||||
@@ -366,7 +366,7 @@ void setEncoderSamplesToAverage(HalEncoderHandle encoder_handle,
|
||||
int32_t samplesToAverage, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->SetSamplesToAverage(samplesToAverage, status);
|
||||
@@ -376,7 +376,7 @@ int32_t getEncoderSamplesToAverage(HalEncoderHandle encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->GetSamplesToAverage(status);
|
||||
@@ -386,7 +386,7 @@ double getEncoderDecodingScaleFactor(HalEncoderHandle encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->DecodingScaleFactor();
|
||||
@@ -396,7 +396,7 @@ double getEncoderDistancePerPulse(HalEncoderHandle encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->GetDistancePerPulse();
|
||||
@@ -406,7 +406,7 @@ EncoderEncodingType getEncoderEncodingType(HalEncoderHandle encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_Encoder_k4X; // default to k4X
|
||||
}
|
||||
return encoder->GetEncodingType();
|
||||
@@ -417,7 +417,7 @@ void setEncoderIndexSource(HalEncoderHandle encoder_handle, uint32_t pin,
|
||||
int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->SetIndexSource(pin, analogTrigger, type, status);
|
||||
@@ -426,7 +426,7 @@ void setEncoderIndexSource(HalEncoderHandle encoder_handle, uint32_t pin,
|
||||
int32_t getEncoderFPGAIndex(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->GetFPGAIndex();
|
||||
|
||||
@@ -103,6 +103,8 @@ const char* getHALErrorMessage(int32_t code) {
|
||||
return NO_AVAILABLE_RESOURCES_MESSAGE;
|
||||
case RESOURCE_IS_ALLOCATED:
|
||||
return RESOURCE_IS_ALLOCATED_MESSAGE;
|
||||
case HAL_HANDLE_ERROR:
|
||||
return HAL_HANDLE_ERROR_MESSAGE;
|
||||
case NULL_PARAMETER:
|
||||
return NULL_PARAMETER_MESSAGE;
|
||||
case ANALOG_TRIGGER_LIMIT_ORDER_ERROR:
|
||||
|
||||
@@ -51,7 +51,7 @@ HalInterruptHandle initializeInterrupts(bool watcher, int32_t* status) {
|
||||
void cleanInterrupts(HalInterruptHandle interrupt_handle, int32_t* status) {
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
interruptHandles.Free(interrupt_handle);
|
||||
@@ -71,7 +71,7 @@ uint32_t waitForInterrupt(HalInterruptHandle interrupt_handle, double timeout,
|
||||
uint32_t result;
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ uint32_t waitForInterrupt(HalInterruptHandle interrupt_handle, double timeout,
|
||||
void enableInterrupts(HalInterruptHandle interrupt_handle, int32_t* status) {
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
anInterrupt->manager->enable(status);
|
||||
@@ -108,7 +108,7 @@ void enableInterrupts(HalInterruptHandle interrupt_handle, int32_t* status) {
|
||||
void disableInterrupts(HalInterruptHandle interrupt_handle, int32_t* status) {
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
anInterrupt->manager->disable(status);
|
||||
@@ -123,7 +123,7 @@ double readRisingTimestamp(HalInterruptHandle interrupt_handle,
|
||||
int32_t* status) {
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
uint32_t timestamp = anInterrupt->anInterrupt->readRisingTimeStamp(status);
|
||||
@@ -139,7 +139,7 @@ double readFallingTimestamp(HalInterruptHandle interrupt_handle,
|
||||
int32_t* status) {
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
uint32_t timestamp = anInterrupt->anInterrupt->readFallingTimeStamp(status);
|
||||
@@ -151,7 +151,7 @@ void requestInterrupts(HalInterruptHandle interrupt_handle,
|
||||
bool routing_analog_trigger, int32_t* status) {
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
anInterrupt->anInterrupt->writeConfig_WaitForAck(false, status);
|
||||
@@ -167,7 +167,7 @@ void attachInterruptHandler(HalInterruptHandle interrupt_handle,
|
||||
int32_t* status) {
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
anInterrupt->manager->registerHandler(handler, param, status);
|
||||
@@ -178,7 +178,7 @@ void setInterruptUpSourceEdge(HalInterruptHandle interrupt_handle,
|
||||
int32_t* status) {
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
anInterrupt->anInterrupt->writeConfig_RisingEdge(risingEdge, status);
|
||||
|
||||
@@ -41,7 +41,7 @@ HalDigitalHandle initializePWMPort(HalPortHandle port_handle, int32_t* status) {
|
||||
|
||||
auto port = digitalPinHandles.Get(handle, HalHandleEnum::PWM);
|
||||
if (port == nullptr) { // would only occur on thread issue.
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ HalDigitalHandle initializePWMPort(HalPortHandle port_handle, int32_t* status) {
|
||||
void freePWMPort(HalDigitalHandle pwm_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ void setPWM(HalDigitalHandle pwm_port_handle, unsigned short value,
|
||||
int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ void setPWM(HalDigitalHandle pwm_port_handle, unsigned short value,
|
||||
unsigned short getPWM(HalDigitalHandle pwm_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ unsigned short getPWM(HalDigitalHandle pwm_port_handle, int32_t* status) {
|
||||
void latchPWMZero(HalDigitalHandle pwm_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ void setPWMPeriodScale(HalDigitalHandle pwm_port_handle, uint32_t squelchMask,
|
||||
int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HalHandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ HalRelayHandle initializeRelayPort(HalPortHandle port_handle, uint8_t fwd,
|
||||
|
||||
auto port = relayHandles.Get(handle);
|
||||
if (port == nullptr) { // would only occur on thread issue.
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ bool checkRelayChannel(uint8_t pin) {
|
||||
void setRelay(HalRelayHandle relay_port_handle, bool on, int32_t* status) {
|
||||
auto port = relayHandles.Get(relay_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
std::lock_guard<priority_recursive_mutex> sync(digitalRelayMutex);
|
||||
@@ -115,7 +115,7 @@ void setRelay(HalRelayHandle relay_port_handle, bool on, int32_t* status) {
|
||||
bool getRelay(HalRelayHandle relay_port_handle, int32_t* status) {
|
||||
auto port = relayHandles.Get(relay_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ HalSolenoidHandle initializeSolenoidPort(HalPortHandle port_handle,
|
||||
}
|
||||
auto solenoid_port = solenoidHandles.Get(handle);
|
||||
if (solenoid_port == nullptr) { // would only occur on thread issues
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_INVALID_HANDLE;
|
||||
}
|
||||
solenoid_port->module = static_cast<uint8_t>(module);
|
||||
@@ -75,7 +75,7 @@ bool checkSolenoidModule(uint8_t module) { return module < kNumPCMModules; }
|
||||
bool getSolenoid(HalSolenoidHandle solenoid_port_handle, int32_t* status) {
|
||||
auto port = solenoidHandles.Get(solenoid_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
bool value;
|
||||
@@ -101,7 +101,7 @@ void setSolenoid(HalSolenoidHandle solenoid_port_handle, bool value,
|
||||
int32_t* status) {
|
||||
auto port = solenoidHandles.Get(solenoid_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ static jclass runtimeExCls = nullptr;
|
||||
static jclass illegalArgExCls = nullptr;
|
||||
static jclass boundaryExCls = nullptr;
|
||||
static jclass allocationExCls = nullptr;
|
||||
static jclass halHandleExCls = nullptr;
|
||||
static jclass canInvalidBufferExCls = nullptr;
|
||||
static jclass canMessageNotFoundExCls = nullptr;
|
||||
static jclass canMessageNotAllowedExCls = nullptr;
|
||||
@@ -126,12 +127,23 @@ void ThrowAllocationException(JNIEnv *env, int32_t status) {
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
void ThrowHalHandleException(JNIEnv *env, int32_t status) {
|
||||
const char *message = getHALErrorMessage(status);
|
||||
char *buf = new char[strlen(message) + 30];
|
||||
sprintf(buf, " Code: $%d. %s", status, message);
|
||||
env->ThrowNew(halHandleExCls, buf);
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
void ReportError(JNIEnv *env, int32_t status, bool do_throw) {
|
||||
if (status == 0) return;
|
||||
if (status == NO_AVAILABLE_RESOURCES ||
|
||||
status == RESOURCE_IS_ALLOCATED) {
|
||||
ThrowAllocationException(env, status);
|
||||
}
|
||||
if (status == HAL_HANDLE_ERROR) {
|
||||
ThrowHalHandleException(env, status);
|
||||
}
|
||||
const char *message = getHALErrorMessage(status);
|
||||
if (do_throw && status < 0) {
|
||||
char *buf = new char[strlen(message) + 30];
|
||||
@@ -277,6 +289,12 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
allocationExCls = static_cast<jclass>(env->NewGlobalRef(local));
|
||||
if (!allocationExCls) return JNI_ERR;
|
||||
env->DeleteLocalRef(local);
|
||||
|
||||
local = env->FindClass("edu/wpi/first/wpilibj/util/HalHandleException");
|
||||
if (!local) return JNI_ERR;
|
||||
halHandleExCls = static_cast<jclass>(env->NewGlobalRef(local));
|
||||
if (!halHandleExCls) return JNI_ERR;
|
||||
env->DeleteLocalRef(local);
|
||||
|
||||
local = env->FindClass("edu/wpi/first/wpilibj/can/CANInvalidBufferException");
|
||||
if (!local) return JNI_ERR;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.util;
|
||||
|
||||
/**
|
||||
* Exception indicating that an error has occured with a HAL Handle.
|
||||
*/
|
||||
public class HalHandleException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Create a new HalHandleException.
|
||||
*
|
||||
* @param msg the message to attach to the exception
|
||||
*/
|
||||
public HalHandleException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user