Renamed "pin" to "channel" and variables with underscores now use mixed case (#194)

This commit is contained in:
Tyler Veness
2016-08-12 13:45:28 -07:00
committed by Peter Johnson
parent 227fdc1a60
commit 45b8e9ab4f
67 changed files with 941 additions and 917 deletions

View File

@@ -14,21 +14,21 @@
#ifdef __cplusplus
extern "C" {
#endif
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analog_port_handle,
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
void HAL_InitAccumulator(HAL_AnalogInputHandle analog_port_handle,
void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
void HAL_ResetAccumulator(HAL_AnalogInputHandle analog_port_handle,
void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analog_port_handle,
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
int32_t center, int32_t* status);
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analog_port_handle,
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
int32_t deadband, int32_t* status);
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analog_port_handle,
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analog_port_handle,
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analog_port_handle,
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
int64_t* value, int64_t* count, int32_t* status);
#ifdef __cplusplus
}

View File

@@ -14,35 +14,35 @@
#ifdef __cplusplus
extern "C" {
#endif
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle port_handle,
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle,
int32_t* status);
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analog_port_handle);
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle);
HAL_Bool HAL_CheckAnalogModule(int32_t module);
HAL_Bool HAL_CheckAnalogInputChannel(int32_t pin);
HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel);
void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status);
double HAL_GetAnalogSampleRate(int32_t* status);
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
int32_t bits, int32_t* status);
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
int32_t bits, int32_t* status);
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle,
double voltage, int32_t* status);
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analog_port_handle,
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analog_port_handle,
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle,
int32_t* status);
#ifdef __cplusplus
}

View File

@@ -14,14 +14,14 @@
#ifdef __cplusplus
extern "C" {
#endif
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(
HAL_PortHandle port_handle, int32_t* status);
void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analog_output_handle);
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle,
int32_t* status);
void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analogOutputHandle);
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
double voltage, int32_t* status);
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
int32_t* status);
HAL_Bool HAL_CheckAnalogOutputChannel(int32_t pin);
HAL_Bool HAL_CheckAnalogOutputChannel(int32_t channel);
#ifdef __cplusplus
}
#endif

View File

@@ -22,26 +22,26 @@ enum HAL_AnalogTriggerType {
extern "C" {
#endif
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
HAL_AnalogInputHandle port_handle, int32_t* index, int32_t* status);
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analog_trigger_handle,
HAL_AnalogInputHandle portHandle, int32_t* index, int32_t* status);
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle,
int32_t* status);
void HAL_SetAnalogTriggerLimitsRaw(
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t lower, int32_t upper,
int32_t* status);
void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle,
int32_t lower, int32_t upper,
int32_t* status);
void HAL_SetAnalogTriggerLimitsVoltage(
HAL_AnalogTriggerHandle analog_trigger_handle, double lower, double upper,
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
int32_t* status);
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analog_trigger_handle,
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_Bool useAveragedValue, int32_t* status);
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analog_trigger_handle,
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_Bool useFilteredValue, int32_t* status);
HAL_Bool HAL_GetAnalogTriggerInWindow(
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t* status);
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status);
HAL_Bool HAL_GetAnalogTriggerTriggerState(
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t* status);
HAL_Bool HAL_GetAnalogTriggerOutput(
HAL_AnalogTriggerHandle analog_trigger_handle, HAL_AnalogTriggerType type,
int32_t* status);
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status);
HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_AnalogTriggerType type,
int32_t* status);
#ifdef __cplusplus
}
#endif

View File

@@ -17,31 +17,31 @@ extern "C" {
HAL_CompressorHandle HAL_InitializeCompressor(int32_t module, int32_t* status);
HAL_Bool HAL_CheckCompressorModule(int32_t module);
HAL_Bool HAL_GetCompressor(HAL_CompressorHandle compressor_handle,
HAL_Bool HAL_GetCompressor(HAL_CompressorHandle compressorHandle,
int32_t* status);
void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressor_handle,
void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressorHandle,
HAL_Bool value, int32_t* status);
HAL_Bool HAL_GetCompressorClosedLoopControl(
HAL_CompressorHandle compressor_handle, int32_t* status);
HAL_CompressorHandle compressorHandle, int32_t* status);
HAL_Bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressor_handle,
HAL_Bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressorHandle,
int32_t* status);
double HAL_GetCompressorCurrent(HAL_CompressorHandle compressor_handle,
double HAL_GetCompressorCurrent(HAL_CompressorHandle compressorHandle,
int32_t* status);
HAL_Bool HAL_GetCompressorCurrentTooHighFault(
HAL_CompressorHandle compressor_handle, int32_t* status);
HAL_CompressorHandle compressorHandle, int32_t* status);
HAL_Bool HAL_GetCompressorCurrentTooHighStickyFault(
HAL_CompressorHandle compressor_handle, int32_t* status);
HAL_CompressorHandle compressorHandle, int32_t* status);
HAL_Bool HAL_GetCompressorShortedStickyFault(
HAL_CompressorHandle compressor_handle, int32_t* status);
HAL_Bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressor_handle,
HAL_CompressorHandle compressorHandle, int32_t* status);
HAL_Bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressorHandle,
int32_t* status);
HAL_Bool HAL_GetCompressorNotConnectedStickyFault(
HAL_CompressorHandle compressor_handle, int32_t* status);
HAL_CompressorHandle compressorHandle, int32_t* status);
HAL_Bool HAL_GetCompressorNotConnectedFault(
HAL_CompressorHandle compressor_handle, int32_t* status);
HAL_CompressorHandle compressorHandle, int32_t* status);
#ifdef __cplusplus
}
#endif

View File

@@ -24,51 +24,49 @@ extern "C" {
#endif
HAL_CounterHandle HAL_InitializeCounter(HAL_Counter_Mode mode, int32_t* index,
int32_t* status);
void HAL_FreeCounter(HAL_CounterHandle counter_handle, int32_t* status);
void HAL_SetCounterAverageSize(HAL_CounterHandle counter_handle, int32_t size,
void HAL_FreeCounter(HAL_CounterHandle counterHandle, int32_t* status);
void HAL_SetCounterAverageSize(HAL_CounterHandle counterHandle, int32_t size,
int32_t* status);
void HAL_SetCounterUpSource(HAL_CounterHandle counter_handle,
void HAL_SetCounterUpSource(HAL_CounterHandle counterHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status);
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counter_handle,
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counterHandle,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status);
void HAL_ClearCounterUpSource(HAL_CounterHandle counter_handle,
int32_t* status);
void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
void HAL_ClearCounterUpSource(HAL_CounterHandle counterHandle, int32_t* status);
void HAL_SetCounterDownSource(HAL_CounterHandle counterHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status);
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counter_handle,
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counterHandle,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status);
void HAL_ClearCounterDownSource(HAL_CounterHandle counter_handle,
void HAL_ClearCounterDownSource(HAL_CounterHandle counterHandle,
int32_t* status);
void HAL_SetCounterUpDownMode(HAL_CounterHandle counter_handle,
int32_t* status);
void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counter_handle,
void HAL_SetCounterUpDownMode(HAL_CounterHandle counterHandle, int32_t* status);
void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counterHandle,
int32_t* status);
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counter_handle,
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counterHandle,
HAL_Bool highSemiPeriod, int32_t* status);
void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counter_handle,
void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counterHandle,
double threshold, int32_t* status);
int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
int32_t* status);
void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
int samplesToAverage, int32_t* status);
void HAL_ResetCounter(HAL_CounterHandle counter_handle, int32_t* status);
int32_t HAL_GetCounter(HAL_CounterHandle counter_handle, int32_t* status);
double HAL_GetCounterPeriod(HAL_CounterHandle counter_handle, int32_t* status);
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counter_handle, double maxPeriod,
void HAL_ResetCounter(HAL_CounterHandle counterHandle, int32_t* status);
int32_t HAL_GetCounter(HAL_CounterHandle counterHandle, int32_t* status);
double HAL_GetCounterPeriod(HAL_CounterHandle counterHandle, int32_t* status);
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counterHandle, double maxPeriod,
int32_t* status);
void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counter_handle,
void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counterHandle,
HAL_Bool enabled, int32_t* status);
HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle,
HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counterHandle,
int32_t* status);
HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle,
HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counterHandle,
int32_t* status);
void HAL_SetCounterReverseDirection(HAL_CounterHandle counter_handle,
void HAL_SetCounterReverseDirection(HAL_CounterHandle counterHandle,
HAL_Bool reverseDirection, int32_t* status);
#ifdef __cplusplus
}

View File

@@ -14,32 +14,31 @@
#ifdef __cplusplus
extern "C" {
#endif
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle port_handle,
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
HAL_Bool input, int32_t* status);
HAL_Bool HAL_CheckDIOChannel(int32_t channel);
void HAL_FreeDIOPort(HAL_DigitalHandle dio_port_handle);
void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle);
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status);
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status);
void HAL_SetDigitalPWMRate(double rate, int32_t* status);
void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
double dutyCycle, int32_t* status);
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
int32_t pin, int32_t* status);
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, HAL_Bool value,
int32_t channel, int32_t* status);
void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
int32_t* status);
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status);
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dio_port_handle,
int32_t* status);
void HAL_Pulse(HAL_DigitalHandle dio_port_handle, double pulseLength,
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status);
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status);
void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
int32_t* status);
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dio_port_handle, int32_t* status);
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status);
HAL_Bool HAL_IsAnyPulsing(int32_t* status);
void HAL_SetFilterSelect(HAL_DigitalHandle dio_port_handle,
int32_t filter_index, int32_t* status);
int32_t HAL_GetFilterSelect(HAL_DigitalHandle dio_port_handle, int32_t* status);
void HAL_SetFilterPeriod(int32_t filter_index, int64_t value, int32_t* status);
int64_t HAL_GetFilterPeriod(int32_t filter_index, int32_t* status);
void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
int32_t* status);
int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status);
void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status);
int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t* status);
#ifdef __cplusplus
}
#endif

View File

@@ -82,7 +82,7 @@ struct HAL_JoystickDescriptor {
extern "C" {
#endif
int32_t HAL_SetErrorData(const char* errors, int32_t errorsLength,
int32_t wait_ms);
int32_t waitMs);
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
const char* details, const char* location,
const char* callStack, HAL_Bool printMsg);

View File

@@ -32,49 +32,48 @@ HAL_EncoderHandle HAL_InitializeEncoder(
HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
HAL_Bool reverseDirection, HAL_EncoderEncodingType encodingType,
int32_t* status);
void HAL_FreeEncoder(HAL_EncoderHandle encoder_handle, int32_t* status);
int32_t HAL_GetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status);
int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoder_handle, int32_t* status);
int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoder_handle,
void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t* status);
int32_t HAL_GetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status);
int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoderHandle, int32_t* status);
int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoderHandle,
int32_t* status);
void HAL_ResetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status);
double HAL_GetEncoderPeriod(HAL_EncoderHandle encoder_handle, int32_t* status);
void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoder_handle, double maxPeriod,
void HAL_ResetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status);
double HAL_GetEncoderPeriod(HAL_EncoderHandle encoderHandle, int32_t* status);
void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoderHandle, double maxPeriod,
int32_t* status);
HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoder_handle,
HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoderHandle,
int32_t* status);
HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoder_handle,
HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoderHandle,
int32_t* status);
double HAL_GetEncoderDistance(HAL_EncoderHandle encoder_handle,
int32_t* status);
double HAL_GetEncoderRate(HAL_EncoderHandle encoder_handle, int32_t* status);
void HAL_SetEncoderMinRate(HAL_EncoderHandle encoder_handle, double minRate,
double HAL_GetEncoderDistance(HAL_EncoderHandle encoderHandle, int32_t* status);
double HAL_GetEncoderRate(HAL_EncoderHandle encoderHandle, int32_t* status);
void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate,
int32_t* status);
void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
double distancePerPulse, int32_t* status);
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoder_handle,
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoderHandle,
HAL_Bool reverseDirection, int32_t* status);
void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
int32_t samplesToAverage, int32_t* status);
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
int32_t* status);
void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoder_handle,
void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_EncoderIndexingType type, int32_t* status);
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoder_handle,
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle,
int32_t* status);
double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoder_handle,
double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoderHandle,
int32_t* status);
double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
int32_t* status);
HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
HAL_EncoderHandle encoder_handle, int32_t* status);
HAL_EncoderHandle encoderHandle, int32_t* status);
#ifdef __cplusplus
}
#endif

View File

@@ -41,8 +41,8 @@ namespace HALUsageReporting = nUsageReporting;
#ifdef __cplusplus
extern "C" {
#endif
HAL_PortHandle HAL_GetPort(int32_t pin);
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t pin);
HAL_PortHandle HAL_GetPort(int32_t channel);
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel);
const char* HAL_GetErrorMessage(int32_t code);
int32_t HAL_GetFPGAVersion(int32_t* status);

View File

@@ -19,27 +19,26 @@ typedef void (*InterruptHandlerFunction)(uint32_t interruptAssertedMask,
void* param);
HAL_InterruptHandle HAL_InitializeInterrupts(HAL_Bool watcher, int32_t* status);
void HAL_CleanInterrupts(HAL_InterruptHandle interrupt_handle, int32_t* status);
void HAL_CleanInterrupts(HAL_InterruptHandle interruptHandle, int32_t* status);
int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interrupt_handle,
int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interruptHandle,
double timeout, HAL_Bool ignorePrevious,
int32_t* status);
void HAL_EnableInterrupts(HAL_InterruptHandle interrupt_handle,
int32_t* status);
void HAL_DisableInterrupts(HAL_InterruptHandle interrupt_handle,
void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle, int32_t* status);
void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
int32_t* status);
double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interrupt_handle,
double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
int32_t* status);
double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interrupt_handle,
double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle,
int32_t* status);
void HAL_RequestInterrupts(HAL_InterruptHandle interrupt_handle,
void HAL_RequestInterrupts(HAL_InterruptHandle interruptHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status);
void HAL_AttachInterruptHandler(HAL_InterruptHandle interrupt_handle,
void HAL_AttachInterruptHandler(HAL_InterruptHandle interruptHandle,
InterruptHandlerFunction handler, void* param,
int32_t* status);
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interrupt_handle,
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status);
#ifdef __cplusplus

View File

@@ -16,11 +16,11 @@ extern "C" {
#endif
HAL_NotifierHandle HAL_InitializeNotifier(void (*process)(uint64_t, void*),
void* param, int32_t* status);
void HAL_CleanNotifier(HAL_NotifierHandle notifier_handle, int32_t* status);
void* HAL_GetNotifierParam(HAL_NotifierHandle notifier_handle, int32_t* status);
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifier_handle,
void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status);
void* HAL_GetNotifierParam(HAL_NotifierHandle notifierHandle, int32_t* status);
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
uint64_t triggerTime, int32_t* status);
void HAL_StopNotifierAlarm(HAL_NotifierHandle notifier_handle, int32_t* status);
void HAL_StopNotifierAlarm(HAL_NotifierHandle notifierHandle, int32_t* status);
#ifdef __cplusplus
}
#endif

View File

@@ -14,40 +14,40 @@
#ifdef __cplusplus
extern "C" {
#endif
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle port_handle,
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
int32_t* status);
void HAL_FreePWMPort(HAL_DigitalHandle pwm_port_handle, int32_t* status);
void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle, int32_t* status);
HAL_Bool HAL_CheckPWMChannel(int32_t pin);
HAL_Bool HAL_CheckPWMChannel(int32_t channel);
void HAL_SetPWMConfig(HAL_DigitalHandle pwm_port_handle, double maxPwm,
void HAL_SetPWMConfig(HAL_DigitalHandle pwmPortHandle, double maxPwm,
double deadbandMaxPwm, double centerPwm,
double deadbandMinPwm, double minPwm, int32_t* status);
void HAL_SetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t maxPwm,
void HAL_SetPWMConfigRaw(HAL_DigitalHandle pwmPortHandle, int32_t maxPwm,
int32_t deadbandMaxPwm, int32_t centerPwm,
int32_t deadbandMinPwm, int32_t minPwm,
int32_t* status);
void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t* maxPwm,
void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwmPortHandle, int32_t* maxPwm,
int32_t* deadbandMaxPwm, int32_t* centerPwm,
int32_t* deadbandMinPwm, int32_t* minPwm,
int32_t* status);
void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
HAL_Bool eliminateDeadband, int32_t* status);
HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
int32_t* status);
void HAL_SetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t value,
void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value,
int32_t* status);
void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, double speed,
void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
int32_t* status);
void HAL_SetPWMPosition(HAL_DigitalHandle pwm_port_handle, double position,
void HAL_SetPWMPosition(HAL_DigitalHandle pwmPortHandle, double position,
int32_t* status);
void HAL_SetPWMDisabled(HAL_DigitalHandle pwm_port_handle, int32_t* status);
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t* status);
double HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status);
double HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status);
void HAL_LatchPWMZero(HAL_DigitalHandle pwm_port_handle, int32_t* status);
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwm_port_handle,
int32_t squelchMask, int32_t* status);
void HAL_SetPWMDisabled(HAL_DigitalHandle pwmPortHandle, int32_t* status);
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status);
double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status);
double HAL_GetPWMPosition(HAL_DigitalHandle pwmPortHandle, int32_t* status);
void HAL_LatchPWMZero(HAL_DigitalHandle pwmPortHandle, int32_t* status);
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask,
int32_t* status);
int32_t HAL_GetLoopTiming(int32_t* status);
#ifdef __cplusplus
}

View File

@@ -19,15 +19,15 @@ int32_t HAL_GetNumAnalogOutputs(void);
int32_t HAL_GetNumCounters(void);
int32_t HAL_GetNumDigitalHeaders(void);
int32_t HAL_GetNumPWMHeaders(void);
int32_t HAL_GetNumDigitalPins(void);
int32_t HAL_GetNumPWMPins(void);
int32_t HAL_GetNumDigitalChannels(void);
int32_t HAL_GetNumPWMChannels(void);
int32_t HAL_GetNumDigitalPWMOutputs(void);
int32_t HAL_GetNumEncoders(void);
int32_t HAL_GetNumInterrupts(void);
int32_t HAL_GetNumRelayPins(void);
int32_t HAL_GetNumRelayChannels(void);
int32_t HAL_GetNumRelayHeaders(void);
int32_t HAL_GetNumPCMModules(void);
int32_t HAL_GetNumSolenoidPins(void);
int32_t HAL_GetNumSolenoidChannels(void);
int32_t HAL_GetNumPDPModules(void);
int32_t HAL_GetNumPDPChannels(void);
int32_t HAL_GetNumCanTalons(void);

View File

@@ -14,15 +14,15 @@
#ifdef __cplusplus
extern "C" {
#endif
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle port_handle,
HAL_Bool fwd, int32_t* status);
void HAL_FreeRelayPort(HAL_RelayHandle relay_port_handle);
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
int32_t* status);
void HAL_FreeRelayPort(HAL_RelayHandle relayPortHandle);
HAL_Bool HAL_CheckRelayChannel(int32_t pin);
HAL_Bool HAL_CheckRelayChannel(int32_t channel);
void HAL_SetRelay(HAL_RelayHandle relay_port_handle, HAL_Bool on,
void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
int32_t* status);
HAL_Bool HAL_GetRelay(HAL_RelayHandle relay_port_handle, int32_t* status);
HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status);
#ifdef __cplusplus
}
#endif

View File

@@ -14,15 +14,15 @@
#ifdef __cplusplus
extern "C" {
#endif
HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle port_handle,
HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle,
int32_t* status);
void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoid_port_handle);
void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoidPortHandle);
HAL_Bool HAL_CheckSolenoidModule(int32_t module);
HAL_Bool HAL_CheckSolenoidChannel(int32_t pin);
HAL_Bool HAL_GetSolenoid(HAL_SolenoidHandle solenoid_port_handle,
HAL_Bool HAL_CheckSolenoidChannel(int32_t channel);
HAL_Bool HAL_GetSolenoid(HAL_SolenoidHandle solenoidPortHandle,
int32_t* status);
int32_t HAL_GetAllSolenoids(int32_t module, int32_t* status);
void HAL_SetSolenoid(HAL_SolenoidHandle solenoid_port_handle, HAL_Bool value,
void HAL_SetSolenoid(HAL_SolenoidHandle solenoidPortHandle, HAL_Bool value,
int32_t* status);
int32_t HAL_GetPCMSolenoidBlackList(int32_t module, int32_t* status);
HAL_Bool HAL_GetPCMSolenoidVoltageStickyFault(int32_t module, int32_t* status);

View File

@@ -64,7 +64,7 @@ static inline int16_t getHandleTypedIndex(HAL_Handle handle,
/* specialized functions for Port handle
* Port Handle Data Layout
* Bits 0-7: Pin Number
* Bits 0-7: Channel Number
* Bits 8-15: Module Number
* Bits 16-23: Unused
* Bits 24-30: Handle Type
@@ -72,7 +72,7 @@ static inline int16_t getHandleTypedIndex(HAL_Handle handle,
*/
// using a 16 bit value so we can store 0-255 and still report error
static inline int16_t getPortHandlePin(HAL_PortHandle handle) {
static inline int16_t getPortHandleChannel(HAL_PortHandle handle) {
if (!isHandleType(handle, HAL_HandleEnum::Port)) return InvalidHandleIndex;
return static_cast<uint8_t>(handle & 0xff);
}
@@ -83,7 +83,7 @@ static inline int16_t getPortHandleModule(HAL_PortHandle handle) {
return static_cast<uint8_t>((handle >> 8) & 0xff);
}
HAL_PortHandle createPortHandle(uint8_t pin, uint8_t module);
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module);
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType);
} // namespace hal

View File

@@ -14,42 +14,47 @@ using namespace hal;
extern "C" {
/**
*Is the channel attached to an accumulator.
*
*@return The analog channel is attached to an accumulator.
*/
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analog_port_handle,
* Is the channel attached to an accumulator.
*
* @param analogPortHandle Handle to the analog port.
* @return The analog channel is attached to an accumulator.
*/
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
}
for (uint32_t i = 0; i < kNumAccumulators; i++) {
if (port->pin == kAccumulatorChannels[i]) return true;
if (port->channel == kAccumulatorChannels[i]) return true;
}
return false;
}
/**
* Initialize the accumulator.
*
* @param analogPortHandle Handle to the analog port.
*/
void HAL_InitAccumulator(HAL_AnalogInputHandle analog_port_handle,
void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
if (!HAL_IsAccumulatorChannel(analog_port_handle, status)) {
if (!HAL_IsAccumulatorChannel(analogPortHandle, status)) {
*status = HAL_INVALID_ACCUMULATOR_CHANNEL;
return;
}
HAL_SetAccumulatorCenter(analog_port_handle, 0, status);
HAL_ResetAccumulator(analog_port_handle, status);
HAL_SetAccumulatorCenter(analogPortHandle, 0, status);
HAL_ResetAccumulator(analogPortHandle, status);
}
/**
* Resets the accumulator to the initial value.
*
* @param analogPortHandle Handle to the analog port.
*/
void HAL_ResetAccumulator(HAL_AnalogInputHandle analog_port_handle,
void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -72,10 +77,13 @@ void HAL_ResetAccumulator(HAL_AnalogInputHandle analog_port_handle,
* This center value is based on the output of the oversampled and averaged
* source from channel 1. Because of this, any non-zero oversample bits will
* affect the size of the value for this field.
*
* @param analogPortHandle Handle to the analog port.
* @param center The center value of the accumulator.
*/
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analog_port_handle,
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
int32_t center, int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -89,10 +97,13 @@ void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analog_port_handle,
/**
* Set the accumulator's deadband.
*
* @param analogPortHandle Handle to the analog port.
* @param deadband The deadband of the accumulator.
*/
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analog_port_handle,
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
int32_t deadband, int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -110,11 +121,12 @@ void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analog_port_handle,
* Read the value that has been accumulating on channel 1.
* The accumulator is attached after the oversample and average engine.
*
* @param analogPortHandle Handle to the analog port.
* @return The 64-bit value accumulated since the last Reset().
*/
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analog_port_handle,
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -133,11 +145,12 @@ int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analog_port_handle,
* Read the count of the accumulated values since the accumulator was last
* Reset().
*
* @param analogPortHandle Handle to the analog port.
* @return The number of times samples from the channel were accumulated.
*/
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analog_port_handle,
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -155,12 +168,13 @@ int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analog_port_handle,
* This function reads the value and count from the FPGA atomically.
* This can be used for averaging.
*
* @param analogPortHandle Handle to the analog port.
* @param value Pointer to the 64-bit accumulated output.
* @param count Pointer to the number of accumulation cycles.
*/
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analog_port_handle,
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
int64_t* value, int64_t* count, int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;

View File

@@ -42,9 +42,9 @@ static void Wait(double seconds) {
}
extern "C" {
HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analog_handle,
HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analogHandle,
int32_t* status) {
if (!HAL_IsAccumulatorChannel(analog_handle, status)) {
if (!HAL_IsAccumulatorChannel(analogHandle, status)) {
if (*status == 0) {
*status = HAL_INVALID_ACCUMULATOR_CHANNEL;
}
@@ -52,7 +52,7 @@ HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analog_handle,
}
// handle known to be correct, so no need to type check
int16_t channel = getHandleIndex(analog_handle);
int16_t channel = getHandleIndex(analogHandle);
auto handle = analogGyroHandles.Allocate(channel, status);
@@ -66,7 +66,7 @@ HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analog_handle,
return HAL_kInvalidHandle;
}
gyro->handle = analog_handle;
gyro->handle = analogHandle;
gyro->voltsPerDegreePerSecond = 0;
gyro->offset = 0;
gyro->center = 0;

View File

@@ -24,20 +24,22 @@ static bool analogSampleRateSet = false;
extern "C" {
/**
* Initialize the analog input port using the given port object.
*
* @param portHandle Handle to the port to initialize.
*/
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle port_handle,
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle portHandle,
int32_t* status) {
initializeAnalog(status);
if (*status != 0) return HAL_kInvalidHandle;
int16_t pin = getPortHandlePin(port_handle);
if (pin == InvalidHandleIndex) {
int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
HAL_AnalogInputHandle handle = analogInputHandles.Allocate(pin, status);
HAL_AnalogInputHandle handle = analogInputHandles.Allocate(channel, status);
if (*status != 0)
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
@@ -48,28 +50,32 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle port_handle,
*status = HAL_HANDLE_ERROR;
return HAL_kInvalidHandle;
}
analog_port->pin = static_cast<uint8_t>(pin);
analog_port->channel = static_cast<uint8_t>(channel);
if (HAL_IsAccumulatorChannel(handle, status)) {
analog_port->accumulator.reset(tAccumulator::create(pin, status));
analog_port->accumulator.reset(tAccumulator::create(channel, status));
} else {
analog_port->accumulator = nullptr;
}
// Set default configuration
analogInputSystem->writeScanList(pin, pin, status);
analogInputSystem->writeScanList(channel, channel, status);
HAL_SetAnalogAverageBits(handle, kDefaultAverageBits, status);
HAL_SetAnalogOversampleBits(handle, kDefaultOversampleBits, status);
return handle;
}
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analog_port_handle) {
/**
* @param analogPortHandle Handle to the analog port.
*/
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle) {
// no status, so no need to check for a proper free.
analogInputHandles.Free(analog_port_handle);
analogInputHandles.Free(analogPortHandle);
}
/**
* Check that the analog module number is valid.
*
* @param module The analog module number.
* @return Analog module is valid and present
*/
HAL_Bool HAL_CheckAnalogModule(int32_t module) { return module == 1; }
@@ -79,10 +85,11 @@ HAL_Bool HAL_CheckAnalogModule(int32_t module) { return module == 1; }
* Verify that the analog channel number is one of the legal channel numbers.
* Channel numbers are 0-based.
*
* @param channel The analog output channel number.
* @return Analog channel is valid
*/
HAL_Bool HAL_CheckAnalogInputChannel(int32_t pin) {
return pin < kNumAnalogInputs && pin >= 0;
HAL_Bool HAL_CheckAnalogInputChannel(int32_t channel) {
return channel < kNumAnalogInputs && channel >= 0;
}
/**
@@ -142,17 +149,17 @@ double HAL_GetAnalogSampleRate(int32_t* status) {
* is 2**bits. Use averaging to improve the stability of your measurement at the
* expense of sampling rate. The averaging is done automatically in the FPGA.
*
* @param analog_port_pointer Pointer to the analog port to configure.
* @param analogPortHandle Handle to the analog port to configure.
* @param bits Number of bits to average.
*/
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
int32_t bits, int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
analogInputSystem->writeAverageBits(port->pin, static_cast<uint8_t>(bits),
analogInputSystem->writeAverageBits(port->channel, static_cast<uint8_t>(bits),
status);
}
@@ -162,17 +169,17 @@ void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
* This gets the number of averaging bits from the FPGA. The actual number of
* averaged samples is 2**bits. The averaging is done automatically in the FPGA.
*
* @param analog_port_pointer Pointer to the analog port to use.
* @param analogPortHandle Handle to the analog port to use.
* @return Bits to average.
*/
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return kDefaultAverageBits;
}
uint8_t result = analogInputSystem->readAverageBits(port->pin, status);
uint8_t result = analogInputSystem->readAverageBits(port->channel, status);
return result;
}
@@ -184,18 +191,18 @@ int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
* measurements at the expense of sampling rate. The oversampling is done
* automatically in the FPGA.
*
* @param analog_port_pointer Pointer to the analog port to use.
* @param analogPortHandle Handle to the analog port to use.
* @param bits Number of bits to oversample.
*/
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
int32_t bits, int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
analogInputSystem->writeOversampleBits(port->pin, static_cast<uint8_t>(bits),
status);
analogInputSystem->writeOversampleBits(port->channel,
static_cast<uint8_t>(bits), status);
}
/**
@@ -205,17 +212,17 @@ void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
* oversampled values is 2**bits. The oversampling is done automatically in the
* FPGA.
*
* @param analog_port_pointer Pointer to the analog port to use.
* @param analogPortHandle Handle to the analog port to use.
* @return Bits to oversample.
*/
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return kDefaultOversampleBits;
}
uint8_t result = analogInputSystem->readOversampleBits(port->pin, status);
uint8_t result = analogInputSystem->readOversampleBits(port->channel, status);
return result;
}
@@ -226,19 +233,19 @@ int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
* converter in the module. The units are in A/D converter codes. Use
* GetVoltage() to get the analog value in calibrated units.
*
* @param analog_port_pointer Pointer to the analog port to use.
* @param analogPortHandle Handle to the analog port to use.
* @return A sample straight from the channel on this module.
*/
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
tAI::tReadSelect readSelect;
readSelect.Channel = port->pin;
readSelect.Channel = port->channel;
readSelect.Averaged = false;
std::lock_guard<priority_recursive_mutex> sync(analogRegisterWindowMutex);
@@ -258,18 +265,18 @@ int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analog_port_handle,
* the module on this channel. Use GetAverageVoltage() to get the analog value
* in calibrated units.
*
* @param analog_port_pointer Pointer to the analog port to use.
* @param analogPortHandle Handle to the analog port to use.
* @return A sample from the oversample and average engine for the channel.
*/
int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
tAI::tReadSelect readSelect;
readSelect.Channel = port->pin;
readSelect.Channel = port->channel;
readSelect.Averaged = true;
std::lock_guard<priority_recursive_mutex> sync(analogRegisterWindowMutex);
@@ -284,14 +291,14 @@ int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analog_port_handle,
* The value is scaled to units of Volts using the calibrated scaling data from
* GetLSBWeight() and GetOffset().
*
* @param analog_port_pointer Pointer to the analog port to use.
* @param analogPortHandle Handle to the analog port to use.
* @return A scaled sample straight from the channel on this module.
*/
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analog_port_handle,
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
int32_t value = HAL_GetAnalogValue(analog_port_handle, status);
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
int32_t offset = HAL_GetAnalogOffset(analog_port_handle, status);
int32_t value = HAL_GetAnalogValue(analogPortHandle, status);
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
double voltage = LSBWeight * 1.0e-9 * value - offset * 1.0e-9;
return voltage;
}
@@ -305,17 +312,17 @@ double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analog_port_handle,
* be higher resolution, but it will update more slowly. Using averaging will
* cause this value to be more stable, but it will update more slowly.
*
* @param analog_port_pointer Pointer to the analog port to use.
* @param analogPortHandle Handle to the analog port to use.
* @return A scaled sample from the output of the oversample and average engine
* for the channel.
*/
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analog_port_handle,
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
int32_t value = HAL_GetAnalogAverageValue(analog_port_handle, status);
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
int32_t offset = HAL_GetAnalogOffset(analog_port_handle, status);
int32_t value = HAL_GetAnalogAverageValue(analogPortHandle, status);
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
int32_t oversampleBits =
HAL_GetAnalogOversampleBits(analog_port_handle, status);
HAL_GetAnalogOversampleBits(analogPortHandle, status);
double voltage =
LSBWeight * 1.0e-9 * value / static_cast<double>(1 << oversampleBits) -
offset * 1.0e-9;
@@ -325,16 +332,16 @@ double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analog_port_handle,
/**
* Convert a voltage to a raw value for a specified channel.
*
* This process depends on the calibration of each channel, so the channel
* must be specified.
* This process depends on the calibration of each channel, so the channel must
* be specified.
*
* @todo This assumes raw values. Oversampling not supported as is.
*
* @param analog_port_pointer Pointer to the analog port to use.
* @param analogPortHandle Handle to the analog port to use.
* @param voltage The voltage to convert.
* @return The raw value for the channel.
*/
int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle,
double voltage, int32_t* status) {
if (voltage > 5.0) {
voltage = 5.0;
@@ -344,8 +351,8 @@ int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analog_port_handle,
voltage = 0.0;
*status = VOLTAGE_OUT_OF_RANGE;
}
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
int32_t offset = HAL_GetAnalogOffset(analog_port_handle, status);
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analogPortHandle, status);
int32_t offset = HAL_GetAnalogOffset(analogPortHandle, status);
int32_t value =
static_cast<int32_t>((voltage + offset * 1.0e-9) / (LSBWeight * 1.0e-9));
return value;
@@ -358,18 +365,18 @@ int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analog_port_handle,
*
* Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
*
* @param analog_port_pointer Pointer to the analog port to use.
* @param analogPortHandle Handle to the analog port to use.
* @return Least significant bit weight.
*/
int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
uint32_t lsbWeight = FRC_NetworkCommunication_nAICalibration_getLSBWeight(
0, port->pin, status); // XXX: aiSystemIndex == 0?
0, port->channel, status); // XXX: aiSystemIndex == 0?
return lsbWeight;
}
@@ -380,18 +387,18 @@ int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analog_port_handle,
*
* Volts = ((LSB_Weight * 1e-9) * raw) - (Offset * 1e-9)
*
* @param analog_port_pointer Pointer to the analog port to use.
* @param analogPortHandle Handle to the analog port to use.
* @return Offset constant.
*/
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analog_port_handle,
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles.Get(analog_port_handle);
auto port = analogInputHandles.Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
int32_t offset = FRC_NetworkCommunication_nAICalibration_getOffset(
0, port->pin, status); // XXX: aiSystemIndex == 0?
0, port->channel, status); // XXX: aiSystemIndex == 0?
return offset;
}
}

View File

@@ -27,7 +27,7 @@ extern std::unique_ptr<tAO> analogOutputSystem;
extern priority_recursive_mutex analogRegisterWindowMutex;
struct AnalogPort {
uint8_t pin;
uint8_t channel;
std::unique_ptr<tAccumulator> accumulator;
};

View File

@@ -17,7 +17,7 @@ using namespace hal;
namespace {
struct AnalogOutput {
uint8_t pin;
uint8_t channel;
};
}
@@ -30,19 +30,19 @@ extern "C" {
/**
* Initialize the analog output port using the given port object.
*/
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(
HAL_PortHandle port_handle, int32_t* status) {
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(HAL_PortHandle portHandle,
int32_t* status) {
initializeAnalog(status);
if (*status != 0) return HAL_kInvalidHandle;
int16_t pin = getPortHandlePin(port_handle);
if (pin == InvalidHandleIndex) {
int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
HAL_AnalogOutputHandle handle = analogOutputHandles.Allocate(pin, status);
HAL_AnalogOutputHandle handle = analogOutputHandles.Allocate(channel, status);
if (*status != 0)
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
@@ -53,13 +53,13 @@ HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(
return HAL_kInvalidHandle;
}
port->pin = static_cast<uint8_t>(pin);
port->channel = static_cast<uint8_t>(channel);
return handle;
}
void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analog_output_handle) {
void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analogOutputHandle) {
// no status, so no need to check for a proper free.
analogOutputHandles.Free(analog_output_handle);
analogOutputHandles.Free(analogOutputHandle);
}
/**
@@ -69,13 +69,13 @@ void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analog_output_handle) {
*
* @return Analog channel is valid
*/
HAL_Bool HAL_CheckAnalogOutputChannel(int32_t pin) {
return pin < kNumAnalogOutputs && pin >= 0;
HAL_Bool HAL_CheckAnalogOutputChannel(int32_t channel) {
return channel < kNumAnalogOutputs && channel >= 0;
}
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
double voltage, int32_t* status) {
auto port = analogOutputHandles.Get(analog_output_handle);
auto port = analogOutputHandles.Get(analogOutputHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -88,18 +88,18 @@ void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
else if (voltage > 5.0)
rawValue = 0x1000;
analogOutputSystem->writeMXP(port->pin, rawValue, status);
analogOutputSystem->writeMXP(port->channel, rawValue, status);
}
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
int32_t* status) {
auto port = analogOutputHandles.Get(analog_output_handle);
auto port = analogOutputHandles.Get(analogOutputHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0.0;
}
uint16_t rawValue = analogOutputSystem->readMXP(port->pin, status);
uint16_t rawValue = analogOutputSystem->readMXP(port->channel, status);
return rawValue * 5.0 / 0x1000;
}

View File

@@ -31,9 +31,9 @@ static LimitedHandleResource<HAL_AnalogTriggerHandle, AnalogTrigger,
extern "C" {
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
HAL_AnalogInputHandle port_handle, int32_t* index, int32_t* status) {
HAL_AnalogInputHandle portHandle, int32_t* index, int32_t* status) {
// ensure we are given a valid and active AnalogInput handle
auto analog_port = analogInputHandles.Get(port_handle);
auto analog_port = analogInputHandles.Get(portHandle);
if (analog_port == nullptr) {
*status = HAL_HANDLE_ERROR;
return HAL_kInvalidHandle;
@@ -48,25 +48,25 @@ HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
*status = HAL_HANDLE_ERROR;
return HAL_kInvalidHandle;
}
trigger->analogHandle = port_handle;
trigger->analogHandle = portHandle;
trigger->index = static_cast<uint8_t>(getHandleIndex(handle));
*index = trigger->index;
trigger->trigger.reset(tAnalogTrigger::create(trigger->index, status));
trigger->trigger->writeSourceSelect_Channel(analog_port->pin, status);
trigger->trigger->writeSourceSelect_Channel(analog_port->channel, status);
return handle;
}
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analog_trigger_handle,
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle,
int32_t* status) {
analogTriggerHandles.Free(analog_trigger_handle);
analogTriggerHandles.Free(analogTriggerHandle);
// caller owns the analog input handle.
}
void HAL_SetAnalogTriggerLimitsRaw(
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t lower, int32_t upper,
int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
void HAL_SetAnalogTriggerLimitsRaw(HAL_AnalogTriggerHandle analogTriggerHandle,
int32_t lower, int32_t upper,
int32_t* status) {
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -83,9 +83,9 @@ void HAL_SetAnalogTriggerLimitsRaw(
* The limits are given as floating point voltage values.
*/
void HAL_SetAnalogTriggerLimitsVoltage(
HAL_AnalogTriggerHandle analog_trigger_handle, double lower, double upper,
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -107,9 +107,9 @@ void HAL_SetAnalogTriggerLimitsVoltage(
* If the value is true, then the averaged value is selected for the analog
* trigger, otherwise the immediate value is used.
*/
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analog_trigger_handle,
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_Bool useAveragedValue, int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -128,9 +128,9 @@ void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analog_trigger_handle,
* is designed to help with 360 degree pot applications for the period where the
* pot crosses through zero.
*/
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analog_trigger_handle,
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_Bool useFilteredValue, int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -149,8 +149,8 @@ void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analog_trigger_handle,
* @return The InWindow output of the analog trigger.
*/
HAL_Bool HAL_GetAnalogTriggerInWindow(
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) {
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -166,8 +166,8 @@ HAL_Bool HAL_GetAnalogTriggerInWindow(
* @return The TriggerState output of the analog trigger.
*/
HAL_Bool HAL_GetAnalogTriggerTriggerState(
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status) {
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -179,10 +179,10 @@ HAL_Bool HAL_GetAnalogTriggerTriggerState(
* Get the state of the analog trigger output.
* @return The state of the analog trigger output.
*/
HAL_Bool HAL_GetAnalogTriggerOutput(
HAL_AnalogTriggerHandle analog_trigger_handle, HAL_AnalogTriggerType type,
int32_t* status) {
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle,
HAL_AnalogTriggerType type,
int32_t* status) {
auto trigger = analogTriggerHandles.Get(analogTriggerHandle);
if (trigger == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;

View File

@@ -35,10 +35,10 @@ HAL_Bool HAL_CheckCompressorModule(int32_t module) {
return module < kNumPCMModules && module >= 0;
}
HAL_Bool HAL_GetCompressor(HAL_CompressorHandle compressor_handle,
HAL_Bool HAL_GetCompressor(HAL_CompressorHandle compressorHandle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -50,10 +50,10 @@ HAL_Bool HAL_GetCompressor(HAL_CompressorHandle compressor_handle,
return value;
}
void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressor_handle,
void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressorHandle,
HAL_Bool value, int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return;
@@ -63,9 +63,9 @@ void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressor_handle,
}
HAL_Bool HAL_GetCompressorClosedLoopControl(
HAL_CompressorHandle compressor_handle, int32_t* status) {
HAL_CompressorHandle compressorHandle, int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -77,10 +77,10 @@ HAL_Bool HAL_GetCompressorClosedLoopControl(
return value;
}
HAL_Bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressor_handle,
HAL_Bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressorHandle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -92,10 +92,10 @@ HAL_Bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressor_handle,
return value;
}
double HAL_GetCompressorCurrent(HAL_CompressorHandle compressor_handle,
double HAL_GetCompressorCurrent(HAL_CompressorHandle compressorHandle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -107,9 +107,9 @@ double HAL_GetCompressorCurrent(HAL_CompressorHandle compressor_handle,
return value;
}
HAL_Bool HAL_GetCompressorCurrentTooHighFault(
HAL_CompressorHandle compressor_handle, int32_t* status) {
HAL_CompressorHandle compressorHandle, int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -121,9 +121,9 @@ HAL_Bool HAL_GetCompressorCurrentTooHighFault(
return value;
}
HAL_Bool HAL_GetCompressorCurrentTooHighStickyFault(
HAL_CompressorHandle compressor_handle, int32_t* status) {
HAL_CompressorHandle compressorHandle, int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -135,9 +135,9 @@ HAL_Bool HAL_GetCompressorCurrentTooHighStickyFault(
return value;
}
HAL_Bool HAL_GetCompressorShortedStickyFault(
HAL_CompressorHandle compressor_handle, int32_t* status) {
HAL_CompressorHandle compressorHandle, int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -148,10 +148,10 @@ HAL_Bool HAL_GetCompressorShortedStickyFault(
return value;
}
HAL_Bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressor_handle,
HAL_Bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressorHandle,
int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -163,9 +163,9 @@ HAL_Bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressor_handle,
return value;
}
HAL_Bool HAL_GetCompressorNotConnectedStickyFault(
HAL_CompressorHandle compressor_handle, int32_t* status) {
HAL_CompressorHandle compressorHandle, int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -177,9 +177,9 @@ HAL_Bool HAL_GetCompressorNotConnectedStickyFault(
return value;
}
HAL_Bool HAL_GetCompressorNotConnectedFault(
HAL_CompressorHandle compressor_handle, int32_t* status) {
HAL_CompressorHandle compressorHandle, int32_t* status) {
int16_t index =
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor);
if (index == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return false;

View File

@@ -48,13 +48,13 @@ HAL_CounterHandle HAL_InitializeCounter(HAL_Counter_Mode mode, int32_t* index,
return handle;
}
void HAL_FreeCounter(HAL_CounterHandle counter_handle, int32_t* status) {
counterHandles.Free(counter_handle);
void HAL_FreeCounter(HAL_CounterHandle counterHandle, int32_t* status) {
counterHandles.Free(counterHandle);
}
void HAL_SetCounterAverageSize(HAL_CounterHandle counter_handle, int32_t size,
void HAL_SetCounterAverageSize(HAL_CounterHandle counterHandle, int32_t size,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -66,21 +66,21 @@ void HAL_SetCounterAverageSize(HAL_CounterHandle counter_handle, int32_t size,
* Set the source object that causes the counter to count up.
* Set the up counting DigitalSource.
*/
void HAL_SetCounterUpSource(HAL_CounterHandle counter_handle,
void HAL_SetCounterUpSource(HAL_CounterHandle counterHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
bool routingAnalogTrigger = false;
uint8_t routingPin = 0;
uint8_t routingChannel = 0;
uint8_t routingModule = 0;
bool success =
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingChannel,
routingModule, routingAnalogTrigger);
if (!success) {
*status = HAL_HANDLE_ERROR;
@@ -88,14 +88,14 @@ void HAL_SetCounterUpSource(HAL_CounterHandle counter_handle,
}
counter->counter->writeConfig_UpSource_Module(routingModule, status);
counter->counter->writeConfig_UpSource_Channel(routingPin, status);
counter->counter->writeConfig_UpSource_Channel(routingChannel, status);
counter->counter->writeConfig_UpSource_AnalogTrigger(routingAnalogTrigger,
status);
if (counter->counter->readConfig_Mode(status) == HAL_Counter_kTwoPulse ||
counter->counter->readConfig_Mode(status) ==
HAL_Counter_kExternalDirection) {
HAL_SetCounterUpSourceEdge(counter_handle, true, false, status);
HAL_SetCounterUpSourceEdge(counterHandle, true, false, status);
}
counter->counter->strobeReset(status);
}
@@ -104,10 +104,10 @@ void HAL_SetCounterUpSource(HAL_CounterHandle counter_handle,
* Set the edge sensitivity on an up counting source.
* Set the up source to either detect rising edges or falling edges.
*/
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counter_handle,
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counterHandle,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -119,9 +119,9 @@ void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counter_handle,
/**
* Disable the up counting source to the counter.
*/
void HAL_ClearCounterUpSource(HAL_CounterHandle counter_handle,
void HAL_ClearCounterUpSource(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -137,11 +137,11 @@ void HAL_ClearCounterUpSource(HAL_CounterHandle counter_handle,
* Set the source object that causes the counter to count down.
* Set the down counting DigitalSource.
*/
void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
void HAL_SetCounterDownSource(HAL_CounterHandle counterHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -155,10 +155,10 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
}
bool routingAnalogTrigger = false;
uint8_t routingPin = 0;
uint8_t routingChannel = 0;
uint8_t routingModule = 0;
bool success =
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingChannel,
routingModule, routingAnalogTrigger);
if (!success) {
*status = HAL_HANDLE_ERROR;
@@ -166,11 +166,11 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
}
counter->counter->writeConfig_DownSource_Module(routingModule, status);
counter->counter->writeConfig_DownSource_Channel(routingPin, status);
counter->counter->writeConfig_DownSource_Channel(routingChannel, status);
counter->counter->writeConfig_DownSource_AnalogTrigger(routingAnalogTrigger,
status);
HAL_SetCounterDownSourceEdge(counter_handle, true, false, status);
HAL_SetCounterDownSourceEdge(counterHandle, true, false, status);
counter->counter->strobeReset(status);
}
@@ -178,10 +178,10 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
* Set the edge sensitivity on a down counting source.
* Set the down source to either detect rising edges or falling edges.
*/
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counter_handle,
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counterHandle,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -193,9 +193,9 @@ void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counter_handle,
/**
* Disable the down counting source to the counter.
*/
void HAL_ClearCounterDownSource(HAL_CounterHandle counter_handle,
void HAL_ClearCounterDownSource(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -211,9 +211,9 @@ void HAL_ClearCounterDownSource(HAL_CounterHandle counter_handle,
* Set standard up / down counting mode on this counter.
* Up and down counts are sourced independently from two inputs.
*/
void HAL_SetCounterUpDownMode(HAL_CounterHandle counter_handle,
void HAL_SetCounterUpDownMode(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -226,9 +226,9 @@ void HAL_SetCounterUpDownMode(HAL_CounterHandle counter_handle,
* Counts are sourced on the Up counter input.
* The Down counter input represents the direction to count.
*/
void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counter_handle,
void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -240,16 +240,16 @@ void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counter_handle,
* Set Semi-period mode on this counter.
* Counts up on both rising and falling edges.
*/
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counter_handle,
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counterHandle,
HAL_Bool highSemiPeriod, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
counter->counter->writeConfig_Mode(HAL_Counter_kSemiperiod, status);
counter->counter->writeConfig_UpRisingEdge(highSemiPeriod, status);
HAL_SetCounterUpdateWhenEmpty(counter_handle, false, status);
HAL_SetCounterUpdateWhenEmpty(counterHandle, false, status);
}
/**
@@ -259,9 +259,9 @@ void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counter_handle,
* @param threshold The pulse length beyond which the counter counts the
* opposite direction. Units are seconds.
*/
void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counter_handle,
void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counterHandle,
double threshold, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -280,9 +280,9 @@ void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counter_handle,
* mechanical imperfections or as oversampling to increase resolution.
* @return SamplesToAverage The number of samples being averaged (from 1 to 127)
*/
int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -296,9 +296,9 @@ int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
* mechanical imperfections or as oversampling to increase resolution.
* @param samplesToAverage The number of samples to average from 1 to 127.
*/
void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counterHandle,
int32_t samplesToAverage, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -314,8 +314,8 @@ void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
* Set the counter value to zero. This doesn't effect the running state of the
* counter, just sets the current value to zero.
*/
void HAL_ResetCounter(HAL_CounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
void HAL_ResetCounter(HAL_CounterHandle counterHandle, int32_t* status) {
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -328,8 +328,8 @@ void HAL_ResetCounter(HAL_CounterHandle counter_handle, 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 HAL_GetCounter(HAL_CounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
int32_t HAL_GetCounter(HAL_CounterHandle counterHandle, int32_t* status) {
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -344,8 +344,8 @@ int32_t HAL_GetCounter(HAL_CounterHandle counter_handle, int32_t* status) {
* velocity calculations to determine shaft speed.
* @returns The period of the last two pulses in units of seconds.
*/
double HAL_GetCounterPeriod(HAL_CounterHandle counter_handle, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
double HAL_GetCounterPeriod(HAL_CounterHandle counterHandle, int32_t* status) {
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0.0;
@@ -374,9 +374,9 @@ double HAL_GetCounterPeriod(HAL_CounterHandle counter_handle, int32_t* status) {
* @param maxPeriod The maximum period where the counted device is considered
* moving in seconds.
*/
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counter_handle, double maxPeriod,
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counterHandle, double maxPeriod,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -398,9 +398,9 @@ void HAL_SetCounterMaxPeriod(HAL_CounterHandle counter_handle, 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 HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counter_handle,
void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counterHandle,
HAL_Bool enabled, int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -416,9 +416,9 @@ void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counter_handle,
* @return Returns true if the most recent counter period exceeds the MaxPeriod
* value set by SetMaxPeriod.
*/
HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle,
HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -430,9 +430,9 @@ HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle,
* The last direction the counter value changed.
* @return The last direction the counter value changed.
*/
HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle,
HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counterHandle,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -447,10 +447,10 @@ HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle,
* 1X and 2X quadrature encoding only. Any other counter mode isn't supported.
* @param reverseDirection true if the value counted should be negated.
*/
void HAL_SetCounterReverseDirection(HAL_CounterHandle counter_handle,
void HAL_SetCounterReverseDirection(HAL_CounterHandle counterHandle,
HAL_Bool reverseDirection,
int32_t* status) {
auto counter = counterHandles.Get(counter_handle);
auto counter = counterHandles.Get(counterHandle);
if (counter == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -458,9 +458,9 @@ void HAL_SetCounterReverseDirection(HAL_CounterHandle counter_handle,
if (counter->counter->readConfig_Mode(status) ==
HAL_Counter_kExternalDirection) {
if (reverseDirection)
HAL_SetCounterDownSourceEdge(counter_handle, true, true, status);
HAL_SetCounterDownSourceEdge(counterHandle, true, true, status);
else
HAL_SetCounterDownSourceEdge(counter_handle, false, true, status);
HAL_SetCounterDownSourceEdge(counterHandle, false, true, status);
}
}
}

View File

@@ -28,37 +28,38 @@ extern "C" {
/**
* Create a new instance of a digital port.
*/
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle port_handle,
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
HAL_Bool input, int32_t* status) {
initializeDigital(status);
if (*status != 0) return HAL_kInvalidHandle;
int16_t pin = getPortHandlePin(port_handle);
if (pin == InvalidHandleIndex) {
int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
auto handle = digitalPinHandles.Allocate(pin, HAL_HandleEnum::DIO, status);
auto handle =
digitalChannelHandles.Allocate(channel, HAL_HandleEnum::DIO, status);
if (*status != 0)
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
auto port = digitalPinHandles.Get(handle, HAL_HandleEnum::DIO);
auto port = digitalChannelHandles.Get(handle, HAL_HandleEnum::DIO);
if (port == nullptr) { // would only occur on thread issue.
*status = HAL_HANDLE_ERROR;
return HAL_kInvalidHandle;
}
port->pin = static_cast<uint8_t>(pin);
port->channel = static_cast<uint8_t>(channel);
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
tDIO::tOutputEnable outputEnable = digitalSystem->readOutputEnable(status);
if (port->pin < kNumDigitalHeaders) {
uint32_t bitToSet = 1u << port->pin;
if (port->channel < kNumDigitalHeaders) {
uint32_t bitToSet = 1u << port->channel;
if (input) {
outputEnable.Headers =
outputEnable.Headers & (~bitToSet); // clear the bit for read
@@ -67,7 +68,7 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle port_handle,
outputEnable.Headers | bitToSet; // set the bit for write
}
} else {
uint32_t bitToSet = 1u << remapMXPChannel(port->pin);
uint32_t bitToSet = 1u << remapMXPChannel(port->channel);
uint16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
@@ -88,12 +89,12 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle port_handle,
}
HAL_Bool HAL_CheckDIOChannel(int32_t channel) {
return channel < kNumDigitalPins && channel >= 0;
return channel < kNumDigitalChannels && channel >= 0;
}
void HAL_FreeDIOPort(HAL_DigitalHandle dio_port_handle) {
void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
// no status, so no need to check for a proper free.
digitalPinHandles.Free(dio_port_handle, HAL_HandleEnum::DIO);
digitalChannelHandles.Free(dioPortHandle, HAL_HandleEnum::DIO);
}
/**
@@ -190,18 +191,20 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
* @param channel The Digital Output channel to output on
*/
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
int32_t pin, int32_t* status) {
int32_t channel, int32_t* status) {
auto port = digitalPWMHandles.Get(pwmGenerator);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
int32_t id = *port;
if (pin >= kNumDigitalHeaders) { // if it is on the MXP
pin += kMXPDigitalPWMOffset; // then to write as a digital PWM pin requires
// an offset to write on the correct pin
if (channel >= kNumDigitalHeaders) { // If it is on the MXP
/* Then to write as a digital PWM channel an offset is needed to write on
* the correct channel
*/
channel += kMXPDigitalPWMOffset;
}
digitalSystem->writePWMOutputSelect(id, pin, status);
digitalSystem->writePWMOutputSelect(id, channel, status);
}
/**
@@ -212,9 +215,9 @@ void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
* @param value The state to set the digital channel (if it is configured as an
* output)
*/
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, HAL_Bool value,
void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -226,20 +229,22 @@ void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, HAL_Bool value,
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
tDIO::tDO currentDIO = digitalSystem->readDO(status);
if (port->pin < kNumDigitalHeaders) {
if (port->channel < kNumDigitalHeaders) {
if (value == 0) {
currentDIO.Headers = currentDIO.Headers & ~(1u << port->pin);
currentDIO.Headers = currentDIO.Headers & ~(1u << port->channel);
} else if (value == 1) {
currentDIO.Headers = currentDIO.Headers | (1u << port->pin);
currentDIO.Headers = currentDIO.Headers | (1u << port->channel);
}
} else {
if (value == 0) {
currentDIO.MXP = currentDIO.MXP & ~(1u << remapMXPChannel(port->pin));
currentDIO.MXP =
currentDIO.MXP & ~(1u << remapMXPChannel(port->channel));
} else if (value == 1) {
currentDIO.MXP = currentDIO.MXP | (1u << remapMXPChannel(port->pin));
currentDIO.MXP =
currentDIO.MXP | (1u << remapMXPChannel(port->channel));
}
int32_t bitToSet = 1 << remapMXPChannel(port->pin);
int32_t bitToSet = 1 << remapMXPChannel(port->channel);
uint16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
@@ -256,8 +261,8 @@ void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, HAL_Bool value,
* @param channel The digital I/O channel
* @return The state of the specified channel
*/
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -268,17 +273,17 @@ HAL_Bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status) {
// if it == 0, then return false
// else return true
if (port->pin < kNumDigitalHeaders) {
return ((currentDIO.Headers >> port->pin) & 1) != 0;
if (port->channel < kNumDigitalHeaders) {
return ((currentDIO.Headers >> port->channel) & 1) != 0;
} else {
// Disable special functions
int32_t bitToSet = 1 << remapMXPChannel(port->pin);
int32_t bitToSet = 1 << remapMXPChannel(port->channel);
uint16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
status);
return ((currentDIO.MXP >> remapMXPChannel(port->pin)) & 1) != 0;
return ((currentDIO.MXP >> remapMXPChannel(port->channel)) & 1) != 0;
}
}
@@ -289,24 +294,24 @@ HAL_Bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status) {
* @param channel The digital I/O channel
* @return The direction of the specified channel
*/
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dio_port_handle,
int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
}
tDIO::tOutputEnable currentOutputEnable =
digitalSystem->readOutputEnable(status);
// Shift 00000001 over port->pin-1 places.
// Shift 00000001 over port->channel-1 places.
// AND it against the currentOutputEnable
// if it == 0, then return false
// else return true
if (port->pin < kNumDigitalHeaders) {
return ((currentOutputEnable.Headers >> port->pin) & 1) != 0;
if (port->channel < kNumDigitalHeaders) {
return ((currentOutputEnable.Headers >> port->channel) & 1) != 0;
} else {
return ((currentOutputEnable.MXP >> remapMXPChannel(port->pin)) & 1) != 0;
return ((currentOutputEnable.MXP >> remapMXPChannel(port->channel)) & 1) !=
0;
}
}
@@ -318,19 +323,19 @@ HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dio_port_handle,
* @param channel The Digital Output channel that the pulse should be output on
* @param pulseLength The active length of the pulse (in seconds)
*/
void HAL_Pulse(HAL_DigitalHandle dio_port_handle, double pulseLength,
void HAL_Pulse(HAL_DigitalHandle dioPortHandle, double pulseLength,
int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
tDIO::tPulse pulse;
if (port->pin < kNumDigitalHeaders) {
pulse.Headers = 1u << port->pin;
if (port->channel < kNumDigitalHeaders) {
pulse.Headers = 1u << port->channel;
} else {
pulse.MXP = 1u << remapMXPChannel(port->pin);
pulse.MXP = 1u << remapMXPChannel(port->channel);
}
digitalSystem->writePulseLength(
@@ -345,18 +350,18 @@ void HAL_Pulse(HAL_DigitalHandle dio_port_handle, double pulseLength,
*
* @return A pulse is in progress
*/
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dio_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
}
tDIO::tPulse pulseRegister = digitalSystem->readPulse(status);
if (port->pin < kNumDigitalHeaders) {
return (pulseRegister.Headers & (1 << port->pin)) != 0;
if (port->channel < kNumDigitalHeaders) {
return (pulseRegister.Headers & (1 << port->channel)) != 0;
} else {
return (pulseRegister.MXP & (1 << remapMXPChannel(port->pin))) != 0;
return (pulseRegister.MXP & (1 << remapMXPChannel(port->channel))) != 0;
}
}
@@ -374,24 +379,24 @@ HAL_Bool HAL_IsAnyPulsing(int32_t* status) {
* Write the filter index from the FPGA.
* Set the filter index used to filter out short pulses.
*
* @param digital_port_pointer The digital I/O channel
* @param filter_index The filter index. Must be in the range 0 - 3,
* where 0 means "none" and 1 - 3 means filter # filter_index - 1.
* @param dioPortHandle Handle to the digital I/O channel
* @param filterIndex The filter index. Must be in the range 0 - 3, where 0
* means "none" and 1 - 3 means filter # filterIndex - 1.
*/
void HAL_SetFilterSelect(HAL_DigitalHandle dio_port_handle, int filter_index,
void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int filterIndex,
int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
if (port->pin < kNumDigitalHeaders) {
digitalSystem->writeFilterSelectHdr(port->pin, filter_index, status);
if (port->channel < kNumDigitalHeaders) {
digitalSystem->writeFilterSelectHdr(port->channel, filterIndex, status);
} else {
digitalSystem->writeFilterSelectMXP(remapMXPChannel(port->pin),
filter_index, status);
digitalSystem->writeFilterSelectMXP(remapMXPChannel(port->channel),
filterIndex, status);
}
}
@@ -399,22 +404,22 @@ void HAL_SetFilterSelect(HAL_DigitalHandle dio_port_handle, int filter_index,
* Read the filter index from the FPGA.
* Get the filter index used to filter out short pulses.
*
* @param digital_port_pointer The digital I/O channel
* @return filter_index The filter index. Must be in the range 0 - 3,
* where 0 means "none" and 1 - 3 means filter # filter_index - 1.
* @param dioPortHandle Handle to the digital I/O channel
* @return filterIndex The filter index. Must be in the range 0 - 3,
* where 0 means "none" and 1 - 3 means filter # filterIndex - 1.
*/
int HAL_GetFilterSelect(HAL_DigitalHandle dio_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
int HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
auto port = digitalChannelHandles.Get(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
if (port->pin < kNumDigitalHeaders) {
return digitalSystem->readFilterSelectHdr(port->pin, status);
if (port->channel < kNumDigitalHeaders) {
return digitalSystem->readFilterSelectHdr(port->channel, status);
} else {
return digitalSystem->readFilterSelectMXP(remapMXPChannel(port->pin),
return digitalSystem->readFilterSelectMXP(remapMXPChannel(port->channel),
status);
}
}
@@ -426,15 +431,15 @@ int HAL_GetFilterSelect(HAL_DigitalHandle dio_port_handle, int32_t* status) {
* filter index domains (MXP vs HDR), ignore that distinction for now since it
* compilicates the interface. That can be changed later.
*
* @param filter_index The filter index, 0 - 2.
* @param filterIndex The filter index, 0 - 2.
* @param value The number of cycles that the signal must not transition to be
* counted as a transition.
*/
void HAL_SetFilterPeriod(int32_t filter_index, int64_t value, int32_t* status) {
void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
digitalSystem->writeFilterPeriodHdr(filter_index, value, status);
digitalSystem->writeFilterPeriodHdr(filterIndex, value, status);
if (*status == 0) {
digitalSystem->writeFilterPeriodMXP(filter_index, value, status);
digitalSystem->writeFilterPeriodMXP(filterIndex, value, status);
}
}
@@ -446,24 +451,24 @@ void HAL_SetFilterPeriod(int32_t filter_index, int64_t value, int32_t* status) {
* compilicates the interface. Set status to NiFpga_Status_SoftwareFault if the
* filter values miss-match.
*
* @param filter_index The filter index, 0 - 2.
* @param filterIndex The filter index, 0 - 2.
* @param value The number of cycles that the signal must not transition to be
* counted as a transition.
*/
int64_t HAL_GetFilterPeriod(int32_t filter_index, int32_t* status) {
uint32_t hdr_period = 0;
uint32_t mxp_period = 0;
int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t* status) {
uint32_t hdrPeriod = 0;
uint32_t mxpPeriod = 0;
{
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
hdr_period = digitalSystem->readFilterPeriodHdr(filter_index, status);
hdrPeriod = digitalSystem->readFilterPeriodHdr(filterIndex, status);
if (*status == 0) {
mxp_period = digitalSystem->readFilterPeriodMXP(filter_index, status);
mxpPeriod = digitalSystem->readFilterPeriodMXP(filterIndex, status);
}
}
if (hdr_period != mxp_period) {
if (hdrPeriod != mxpPeriod) {
*status = NiFpga_Status_SoftwareFault;
return -1;
}
return hdr_period;
return hdrPeriod;
}
}

View File

@@ -30,8 +30,8 @@ std::unique_ptr<tPWM> pwmSystem;
bool digitalSystemsInitialized = false;
DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
kNumDigitalPins + kNumPWMHeaders>
digitalPinHandles;
kNumDigitalChannels + kNumPWMHeaders>
digitalChannelHandles;
/**
* Initialize the digital system.
@@ -69,21 +69,21 @@ void initializeDigital(int32_t* status) {
(kDefaultPwmCenter - kDefaultPwmStepsDown * loopTime) / loopTime + .5);
pwmSystem->writeConfig_MinHigh(minHigh, status);
// Ensure that PWM output values are set to OFF
for (uint8_t pwm_index = 0; pwm_index < kNumPWMPins; pwm_index++) {
for (uint8_t pwmIndex = 0; pwmIndex < kNumPWMChannels; pwmIndex++) {
// Copy of SetPWM
if (pwm_index < tPWM::kNumHdrRegisters) {
pwmSystem->writeHdr(pwm_index, kPwmDisabled, status);
if (pwmIndex < tPWM::kNumHdrRegisters) {
pwmSystem->writeHdr(pwmIndex, kPwmDisabled, status);
} else {
pwmSystem->writeMXP(pwm_index - tPWM::kNumHdrRegisters, kPwmDisabled,
pwmSystem->writeMXP(pwmIndex - tPWM::kNumHdrRegisters, kPwmDisabled,
status);
}
// Copy of SetPWMPeriodScale, set to 4x by default.
if (pwm_index < tPWM::kNumPeriodScaleHdrElements) {
pwmSystem->writePeriodScaleHdr(pwm_index, 3, status);
if (pwmIndex < tPWM::kNumPeriodScaleHdrElements) {
pwmSystem->writePeriodScaleHdr(pwmIndex, 3, status);
} else {
pwmSystem->writePeriodScaleMXP(
pwm_index - tPWM::kNumPeriodScaleHdrElements, 3, status);
pwmIndex - tPWM::kNumPeriodScaleHdrElements, 3, status);
}
}
@@ -91,41 +91,43 @@ void initializeDigital(int32_t* status) {
}
/**
* Map DIO pin numbers from their physical number (10 to 26) to their position
* in the bit field.
* Map DIO channel numbers from their physical number (10 to 26) to their
* position in the bit field.
*/
int32_t remapMXPChannel(int32_t pin) { return pin - 10; }
int32_t remapMXPChannel(int32_t channel) { return channel - 10; }
int32_t remapMXPPWMChannel(int32_t pin) {
if (pin < 14) {
return pin - 10; // first block of 4 pwms (MXP 0-3)
int32_t remapMXPPWMChannel(int32_t channel) {
if (channel < 14) {
return channel - 10; // first block of 4 pwms (MXP 0-3)
} else {
return pin - 6; // block of PWMs after SPI
return channel - 6; // block of PWMs after SPI
}
}
/**
* remap the digital source pin and set the module.
* remap the digital source channel and set the module.
* If it's an analog trigger, determine the module from the high order routing
* channel else do normal digital input remapping based on pin number (MXP)
* channel else do normal digital input remapping based on channel number
* (MXP)
*/
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType, uint8_t& pin,
uint8_t& module, bool& analogTrigger) {
HAL_AnalogTriggerType analogTriggerType,
uint8_t& channel, uint8_t& module,
bool& analogTrigger) {
if (isHandleType(digitalSourceHandle, HAL_HandleEnum::AnalogTrigger)) {
// If handle passed, index is not negative
int32_t index = getHandleIndex(digitalSourceHandle);
pin = (index << 2) + analogTriggerType;
module = pin >> 4;
channel = (index << 2) + analogTriggerType;
module = channel >> 4;
analogTrigger = true;
return true;
} else if (isHandleType(digitalSourceHandle, HAL_HandleEnum::DIO)) {
int32_t index = getHandleIndex(digitalSourceHandle);
if (index >= kNumDigitalHeaders) {
pin = remapMXPChannel(index);
channel = remapMXPChannel(index);
module = 1;
} else {
pin = index;
channel = index;
module = 0;
}
analogTrigger = false;

View File

@@ -18,9 +18,11 @@
#include "PortsInternal.h"
namespace hal {
constexpr uint32_t kMXPDigitalPWMOffset = 6; // MXP pins when used as digital
// output pwm are offset by 6 from
// actual value
/**
* MXP channels when used as digital output PWM are offset from actual value
*/
constexpr uint32_t kMXPDigitalPWMOffset = 6;
constexpr uint32_t kExpectedLoopTiming = 40;
/**
@@ -62,7 +64,7 @@ extern std::unique_ptr<tPWM> pwmSystem;
extern bool digitalSystemsInitialized;
struct DigitalPort {
uint8_t pin;
uint8_t channel;
bool configSet = false;
bool eliminateDeadband = false;
int32_t maxPwm = 0;
@@ -73,13 +75,13 @@ struct DigitalPort {
};
extern DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
kNumDigitalPins + kNumPWMHeaders>
digitalPinHandles;
kNumDigitalChannels + kNumPWMHeaders>
digitalChannelHandles;
void initializeDigital(int32_t* status);
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType, uint8_t& pin,
uint8_t& module, bool& analogTrigger);
int32_t remapMXPPWMChannel(int32_t pin);
int32_t remapMXPChannel(int32_t pin);
HAL_AnalogTriggerType analogTriggerType,
uint8_t& channel, uint8_t& module, bool& analogTrigger);
int32_t remapMXPPWMChannel(int32_t channel);
int32_t remapMXPChannel(int32_t channel);
} // namespace hal

View File

@@ -244,12 +244,12 @@ HAL_EncoderHandle HAL_InitializeEncoder(
return handle;
}
void HAL_FreeEncoder(HAL_EncoderHandle encoder_handle, int32_t* status) {
encoderHandles.Free(encoder_handle);
void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
encoderHandles.Free(encoderHandle);
}
int32_t HAL_GetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
int32_t HAL_GetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -257,8 +257,8 @@ int32_t HAL_GetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status) {
return encoder->Get(status);
}
int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoder_handle, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoderHandle, int32_t* status) {
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -266,9 +266,9 @@ int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoder_handle, int32_t* status) {
return encoder->GetRaw(status);
}
int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoder_handle,
int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoderHandle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -276,8 +276,8 @@ int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoder_handle,
return encoder->GetEncodingScale(status);
}
void HAL_ResetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
void HAL_ResetEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -285,8 +285,8 @@ void HAL_ResetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status) {
encoder->Reset(status);
}
double HAL_GetEncoderPeriod(HAL_EncoderHandle encoder_handle, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
double HAL_GetEncoderPeriod(HAL_EncoderHandle encoderHandle, int32_t* status) {
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -294,9 +294,9 @@ double HAL_GetEncoderPeriod(HAL_EncoderHandle encoder_handle, int32_t* status) {
return encoder->GetPeriod(status);
}
void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoder_handle, double maxPeriod,
void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoderHandle, double maxPeriod,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -304,9 +304,9 @@ void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoder_handle, double maxPeriod,
encoder->SetMaxPeriod(maxPeriod, status);
}
HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoder_handle,
HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoderHandle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -314,9 +314,9 @@ HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoder_handle,
return encoder->GetStopped(status);
}
HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoder_handle,
HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoderHandle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -324,9 +324,9 @@ HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoder_handle,
return encoder->GetDirection(status);
}
double HAL_GetEncoderDistance(HAL_EncoderHandle encoder_handle,
double HAL_GetEncoderDistance(HAL_EncoderHandle encoderHandle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -334,8 +334,8 @@ double HAL_GetEncoderDistance(HAL_EncoderHandle encoder_handle,
return encoder->GetDistance(status);
}
double HAL_GetEncoderRate(HAL_EncoderHandle encoder_handle, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
double HAL_GetEncoderRate(HAL_EncoderHandle encoderHandle, int32_t* status) {
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -343,9 +343,9 @@ double HAL_GetEncoderRate(HAL_EncoderHandle encoder_handle, int32_t* status) {
return encoder->GetRate(status);
}
void HAL_SetEncoderMinRate(HAL_EncoderHandle encoder_handle, double minRate,
void HAL_SetEncoderMinRate(HAL_EncoderHandle encoderHandle, double minRate,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -353,9 +353,9 @@ void HAL_SetEncoderMinRate(HAL_EncoderHandle encoder_handle, double minRate,
encoder->SetMinRate(minRate, status);
}
void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
double distancePerPulse, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -363,10 +363,10 @@ void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
encoder->SetDistancePerPulse(distancePerPulse, status);
}
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoder_handle,
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoderHandle,
HAL_Bool reverseDirection,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -374,9 +374,9 @@ void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoder_handle,
encoder->SetReverseDirection(reverseDirection, status);
}
void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
int32_t samplesToAverage, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -384,9 +384,9 @@ void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
encoder->SetSamplesToAverage(samplesToAverage, status);
}
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoderHandle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -394,9 +394,9 @@ int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
return encoder->GetSamplesToAverage(status);
}
double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoder_handle,
double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoderHandle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -404,9 +404,9 @@ double HAL_GetEncoderDecodingScaleFactor(HAL_EncoderHandle encoder_handle,
return encoder->DecodingScaleFactor();
}
double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoderHandle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -415,8 +415,8 @@ double HAL_GetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
}
HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
HAL_EncoderHandle encoder_handle, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
HAL_EncoderHandle encoderHandle, int32_t* status) {
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return HAL_Encoder_k4X; // default to k4X
@@ -424,11 +424,11 @@ HAL_EncoderEncodingType HAL_GetEncoderEncodingType(
return encoder->GetEncodingType();
}
void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoder_handle,
void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoderHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_EncoderIndexingType type, int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -436,9 +436,9 @@ void HAL_SetEncoderIndexSource(HAL_EncoderHandle encoder_handle,
encoder->SetIndexSource(digitalSourceHandle, analogTriggerType, type, status);
}
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoder_handle,
int32_t HAL_GetEncoderFPGAIndex(HAL_EncoderHandle encoderHandle,
int32_t* status) {
auto encoder = encoderHandles.Get(encoder_handle);
auto encoder = encoderHandles.Get(encoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;

View File

@@ -34,17 +34,17 @@ HAL_FPGAEncoderHandle HAL_InitializeFPGAEncoder(
HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
HAL_Bool reverseDirection, int32_t* index, int32_t* status) {
bool routingAnalogTriggerA = false;
uint8_t routingPinA = 0;
uint8_t routingChannelA = 0;
uint8_t routingModuleA = 0;
bool successA =
remapDigitalSource(digitalSourceHandleA, analogTriggerTypeA, routingPinA,
routingModuleA, routingAnalogTriggerA);
bool successA = remapDigitalSource(digitalSourceHandleA, analogTriggerTypeA,
routingChannelA, routingModuleA,
routingAnalogTriggerA);
bool routingAnalogTriggerB = false;
uint8_t routingPinB = 0;
uint8_t routingChannelB = 0;
uint8_t routingModuleB = 0;
bool successB =
remapDigitalSource(digitalSourceHandleB, analogTriggerTypeB, routingPinB,
routingModuleB, routingAnalogTriggerB);
bool successB = remapDigitalSource(digitalSourceHandleB, analogTriggerTypeB,
routingChannelB, routingModuleB,
routingAnalogTriggerB);
if (!successA || !successB) {
*status = HAL_HANDLE_ERROR;
@@ -68,11 +68,11 @@ HAL_FPGAEncoderHandle HAL_InitializeFPGAEncoder(
// TODO: if (index == ~0ul) { CloneError(quadEncoders); return; }
encoder->encoder.reset(tEncoder::create(encoder->index, status));
encoder->encoder->writeConfig_ASource_Module(routingModuleA, status);
encoder->encoder->writeConfig_ASource_Channel(routingPinA, status);
encoder->encoder->writeConfig_ASource_Channel(routingChannelA, status);
encoder->encoder->writeConfig_ASource_AnalogTrigger(routingAnalogTriggerA,
status);
encoder->encoder->writeConfig_BSource_Module(routingModuleB, status);
encoder->encoder->writeConfig_BSource_Channel(routingPinB, status);
encoder->encoder->writeConfig_BSource_Channel(routingChannelB, status);
encoder->encoder->writeConfig_BSource_AnalogTrigger(routingAnalogTriggerB,
status);
encoder->encoder->strobeReset(status);
@@ -82,18 +82,18 @@ HAL_FPGAEncoderHandle HAL_InitializeFPGAEncoder(
return handle;
}
void HAL_FreeFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
void HAL_FreeFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status) {
fpgaEncoderHandles.Free(fpga_encoder_handle);
fpgaEncoderHandles.Free(fpgaEncoderHandle);
}
/**
* Reset the Encoder distance to zero.
* Resets the current count to zero on the encoder.
*/
void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
auto encoder = fpgaEncoderHandles.Get(fpgaEncoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -107,9 +107,9 @@ void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
* factor.
* @return Current fpga count from the encoder
*/
int32_t HAL_GetFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t HAL_GetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
auto encoder = fpgaEncoderHandles.Get(fpgaEncoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -127,9 +127,9 @@ int32_t HAL_GetFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
*
* @return Period in seconds of the most recent pulse.
*/
double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
auto encoder = fpgaEncoderHandles.Get(fpgaEncoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0.0;
@@ -164,9 +164,9 @@ double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
* FPGA will
* report the device stopped. This is expressed in seconds.
*/
void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
double maxPeriod, int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
auto encoder = fpgaEncoderHandles.Get(fpgaEncoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -183,9 +183,9 @@ void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
* one where the most recent pulse width exceeds the MaxPeriod.
* @return True if the encoder is considered stopped.
*/
HAL_Bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpga_encoder_handle,
HAL_Bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
auto encoder = fpgaEncoderHandles.Get(fpgaEncoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -197,9 +197,9 @@ HAL_Bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpga_encoder_handle,
* The last direction the encoder value changed.
* @return The last direction the encoder value changed.
*/
HAL_Bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpga_encoder_handle,
HAL_Bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
auto encoder = fpgaEncoderHandles.Get(fpgaEncoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -213,10 +213,10 @@ HAL_Bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpga_encoder_handle,
* correct software direction regardless of the mounting.
* @param reverseDirection true if the encoder direction should be reversed
*/
void HAL_SetFPGAEncoderReverseDirection(
HAL_FPGAEncoderHandle fpga_encoder_handle, HAL_Bool reverseDirection,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
void HAL_SetFPGAEncoderReverseDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
HAL_Bool reverseDirection,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpgaEncoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -230,10 +230,10 @@ void HAL_SetFPGAEncoderReverseDirection(
* mechanical imperfections or as oversampling to increase resolution.
* @param samplesToAverage The number of samples to average from 1 to 127.
*/
void HAL_SetFPGAEncoderSamplesToAverage(
HAL_FPGAEncoderHandle fpga_encoder_handle, int32_t samplesToAverage,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
void HAL_SetFPGAEncoderSamplesToAverage(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t samplesToAverage,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpgaEncoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -251,8 +251,8 @@ void HAL_SetFPGAEncoderSamplesToAverage(
* @return SamplesToAverage The number of samples being averaged (from 1 to 127)
*/
int32_t HAL_GetFPGAEncoderSamplesToAverage(
HAL_FPGAEncoderHandle fpga_encoder_handle, int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
HAL_FPGAEncoderHandle fpgaEncoderHandle, int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpgaEncoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -264,29 +264,29 @@ int32_t HAL_GetFPGAEncoderSamplesToAverage(
* Set an index source for an encoder, which is an input that resets the
* encoder's count.
*/
void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpga_encoder_handle,
void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpgaEncoderHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_Bool activeHigh, HAL_Bool edgeSensitive,
int32_t* status) {
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
auto encoder = fpgaEncoderHandles.Get(fpgaEncoderHandle);
if (encoder == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
bool routingAnalogTrigger = false;
uint8_t routingPin = 0;
uint8_t routingChannel = 0;
uint8_t routingModule = 0;
bool success =
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingChannel,
routingModule, routingAnalogTrigger);
if (!success) {
*status = HAL_HANDLE_ERROR;
return;
}
encoder->encoder->writeConfig_IndexSource_Channel(routingPin, status);
encoder->encoder->writeConfig_IndexSource_Channel(routingChannel, status);
encoder->encoder->writeConfig_IndexSource_Module(routingModule, status);
encoder->encoder->writeConfig_IndexSource_AnalogTrigger(routingAnalogTrigger,
status);

View File

@@ -17,29 +17,29 @@ HAL_FPGAEncoderHandle HAL_InitializeFPGAEncoder(
HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
HAL_Bool reverseDirection, int32_t* index, int32_t* status);
void HAL_FreeFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
void HAL_FreeFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status);
void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status);
int32_t HAL_GetFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
int32_t HAL_GetFPGAEncoder(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status); // Raw value
double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status);
void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
double maxPeriod, int32_t* status);
HAL_Bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpga_encoder_handle,
HAL_Bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status);
HAL_Bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpga_encoder_handle,
HAL_Bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t* status);
void HAL_SetFPGAEncoderReverseDirection(
HAL_FPGAEncoderHandle fpga_encoder_handle, HAL_Bool reverseDirection,
int32_t* status);
void HAL_SetFPGAEncoderSamplesToAverage(
HAL_FPGAEncoderHandle fpga_encoder_handle, int32_t samplesToAverage,
int32_t* status);
void HAL_SetFPGAEncoderReverseDirection(HAL_FPGAEncoderHandle fpgaEncoderHandle,
HAL_Bool reverseDirection,
int32_t* status);
void HAL_SetFPGAEncoderSamplesToAverage(HAL_FPGAEncoderHandle fpgaEncoderHandle,
int32_t samplesToAverage,
int32_t* status);
int32_t HAL_GetFPGAEncoderSamplesToAverage(
HAL_FPGAEncoderHandle fpga_encoder_handle, int32_t* status);
void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpga_encoder_handle,
HAL_FPGAEncoderHandle fpgaEncoderHandle, int32_t* status);
void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpgaEncoderHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
HAL_Bool activeHigh, HAL_Bool edgeSensitive,

View File

@@ -26,8 +26,8 @@ static priority_mutex newDSDataAvailableMutex;
extern "C" {
int32_t HAL_SetErrorData(const char* errors, int32_t errorsLength,
int32_t wait_ms) {
return setErrorData(errors, errorsLength, wait_ms);
int32_t waitMs) {
return setErrorData(errors, errorsLength, waitMs);
}
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
@@ -37,17 +37,17 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
// messages and only printing again if they're longer than 1 second old.
static constexpr int KEEP_MSGS = 5;
std::lock_guard<priority_mutex> lock(msgMutex);
static std::string prev_msg[KEEP_MSGS];
static uint64_t prev_msg_time[KEEP_MSGS] = {0, 0, 0};
static std::string prevMsg[KEEP_MSGS];
static uint64_t prevMsgTime[KEEP_MSGS] = {0, 0, 0};
int32_t status = 0;
uint64_t curTime = HAL_GetFPGATime(&status);
int i;
for (i = 0; i < KEEP_MSGS; ++i) {
if (prev_msg[i] == details) break;
if (prevMsg[i] == details) break;
}
int retval = 0;
if (i == KEEP_MSGS || (curTime - prev_msg_time[i]) >= 1000000) {
if (i == KEEP_MSGS || (curTime - prevMsgTime[i]) >= 1000000) {
retval = FRC_NetworkCommunication_sendError(isError, errorCode, isLVCode,
details, location, callStack);
if (printMsg) {
@@ -62,16 +62,16 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
if (i == KEEP_MSGS) {
// replace the oldest one
i = 0;
uint64_t first = prev_msg_time[0];
uint64_t first = prevMsgTime[0];
for (int j = 1; j < KEEP_MSGS; ++j) {
if (prev_msg_time[j] < first) {
first = prev_msg_time[j];
if (prevMsgTime[j] < first) {
first = prevMsgTime[j];
i = j;
}
}
prev_msg[i] = details;
prevMsg[i] = details;
}
prev_msg_time[i] = curTime;
prevMsgTime[i] = curTime;
}
return retval;
}

View File

@@ -39,20 +39,20 @@ using namespace hal;
extern "C" {
HAL_PortHandle HAL_GetPort(int32_t pin) {
HAL_PortHandle HAL_GetPort(int32_t channel) {
// Dont allow a number that wouldn't fit in a uint8_t
if (pin < 0 || pin >= 255) return HAL_kInvalidHandle;
return createPortHandle(pin, 1);
if (channel < 0 || channel >= 255) return HAL_kInvalidHandle;
return createPortHandle(channel, 1);
}
/**
* @deprecated Uses module numbers
*/
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t pin) {
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel) {
// Dont allow a number that wouldn't fit in a uint8_t
if (pin < 0 || pin >= 255) return HAL_kInvalidHandle;
if (channel < 0 || channel >= 255) return HAL_kInvalidHandle;
if (module < 0 || module >= 255) return HAL_kInvalidHandle;
return createPortHandle(pin, module);
return createPortHandle(channel, module);
}
const char* HAL_GetErrorMessage(int32_t code) {

View File

@@ -28,7 +28,7 @@ static HAL_DigitalHandle i2CMXPDigitalHandle2 = HAL_kInvalidHandle;
extern "C" {
/*
* Initialize the I2C port. Opens the port if necessary and saves the handle.
* If opening the MXP port, also sets up the pin functions appropriately
* If opening the MXP port, also sets up the channel functions appropriately
* @param port The port to open, 0 for the on-board, 1 for the MXP.
*/
void HAL_InitializeI2C(int32_t port, int32_t* status) {

View File

@@ -50,9 +50,8 @@ HAL_InterruptHandle HAL_InitializeInterrupts(HAL_Bool watcher,
return handle;
}
void HAL_CleanInterrupts(HAL_InterruptHandle interrupt_handle,
int32_t* status) {
interruptHandles.Free(interrupt_handle);
void HAL_CleanInterrupts(HAL_InterruptHandle interruptHandle, int32_t* status) {
interruptHandles.Free(interruptHandle);
}
/**
@@ -62,11 +61,11 @@ void HAL_CleanInterrupts(HAL_InterruptHandle interrupt_handle,
* waitForInterrupt was called.
* @return The mask of interrupts that fired.
*/
int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interrupt_handle,
int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interruptHandle,
double timeout, HAL_Bool ignorePrevious,
int32_t* status) {
uint32_t result;
auto anInterrupt = interruptHandles.Get(interrupt_handle);
auto anInterrupt = interruptHandles.Get(interruptHandle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -90,9 +89,9 @@ int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interrupt_handle,
* time to do the setup of the other options before starting to field
* interrupts.
*/
void HAL_EnableInterrupts(HAL_InterruptHandle interrupt_handle,
void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
auto anInterrupt = interruptHandles.Get(interruptHandle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -103,9 +102,9 @@ void HAL_EnableInterrupts(HAL_InterruptHandle interrupt_handle,
/**
* Disable Interrupts without without deallocating structures.
*/
void HAL_DisableInterrupts(HAL_InterruptHandle interrupt_handle,
void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
auto anInterrupt = interruptHandles.Get(interruptHandle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -118,9 +117,9 @@ void HAL_DisableInterrupts(HAL_InterruptHandle interrupt_handle,
* This is in the same time domain as GetClock().
* @return Timestamp in seconds since boot.
*/
double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interrupt_handle,
double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
auto anInterrupt = interruptHandles.Get(interruptHandle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -134,9 +133,9 @@ double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interrupt_handle,
* This is in the same time domain as GetClock().
* @return Timestamp in seconds since boot.
*/
double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interrupt_handle,
double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
auto anInterrupt = interruptHandles.Get(interruptHandle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -145,21 +144,21 @@ double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interrupt_handle,
return timestamp * 1e-6;
}
void HAL_RequestInterrupts(HAL_InterruptHandle interrupt_handle,
void HAL_RequestInterrupts(HAL_InterruptHandle interruptHandle,
HAL_Handle digitalSourceHandle,
HAL_AnalogTriggerType analogTriggerType,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
auto anInterrupt = interruptHandles.Get(interruptHandle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
anInterrupt->anInterrupt->writeConfig_WaitForAck(false, status);
bool routingAnalogTrigger = false;
uint8_t routingPin = 0;
uint8_t routingChannel = 0;
uint8_t routingModule = 0;
bool success =
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingChannel,
routingModule, routingAnalogTrigger);
if (!success) {
*status = HAL_HANDLE_ERROR;
@@ -167,14 +166,14 @@ void HAL_RequestInterrupts(HAL_InterruptHandle interrupt_handle,
}
anInterrupt->anInterrupt->writeConfig_Source_AnalogTrigger(
routingAnalogTrigger, status);
anInterrupt->anInterrupt->writeConfig_Source_Channel(routingPin, status);
anInterrupt->anInterrupt->writeConfig_Source_Channel(routingChannel, status);
anInterrupt->anInterrupt->writeConfig_Source_Module(routingModule, status);
}
void HAL_AttachInterruptHandler(HAL_InterruptHandle interrupt_handle,
void HAL_AttachInterruptHandler(HAL_InterruptHandle interruptHandle,
InterruptHandlerFunction handler, void* param,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
auto anInterrupt = interruptHandles.Get(interruptHandle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -182,10 +181,10 @@ void HAL_AttachInterruptHandler(HAL_InterruptHandle interrupt_handle,
anInterrupt->manager->registerHandler(handler, param, status);
}
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interrupt_handle,
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle,
HAL_Bool risingEdge, HAL_Bool fallingEdge,
int32_t* status) {
auto anInterrupt = interruptHandles.Get(interrupt_handle);
auto anInterrupt = interruptHandles.Get(interruptHandle);
if (anInterrupt == nullptr) {
*status = HAL_HANDLE_ERROR;
return;

View File

@@ -48,11 +48,11 @@ static UnlimitedHandleResource<HAL_NotifierHandle, Notifier,
// internal version of updateAlarm used during the alarmCallback when we know
// that the pointer is a valid pointer.
void updateNotifierAlarmInternal(std::shared_ptr<Notifier> notifier_pointer,
void updateNotifierAlarmInternal(std::shared_ptr<Notifier> notifierPointer,
uint64_t triggerTime, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(notifierMutex);
auto notifier = notifier_pointer;
auto notifier = notifierPointer;
// no need for a null check, as this must always be a valid pointer.
notifier->triggerTime = triggerTime;
bool wasActive = (closestTrigger != UINT64_MAX);
@@ -140,17 +140,17 @@ HAL_NotifierHandle HAL_InitializeNotifier(void (*process)(uint64_t, void*),
return notifierHandles.Allocate(notifier);
}
void HAL_CleanNotifier(HAL_NotifierHandle notifier_handle, int32_t* status) {
void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
{
std::lock_guard<priority_recursive_mutex> sync(notifierMutex);
auto notifier = notifierHandles.Get(notifier_handle);
auto notifier = notifierHandles.Get(notifierHandle);
if (!notifier) return;
// remove from list
if (notifier->prev) notifier->prev->next = notifier->next;
if (notifier->next) notifier->next->prev = notifier->prev;
if (notifiers == notifier) notifiers = notifier->next;
notifierHandles.Free(notifier_handle);
notifierHandles.Free(notifierHandle);
}
if (notifierRefCount.fetch_sub(1) == 1) {
@@ -168,26 +168,24 @@ void HAL_CleanNotifier(HAL_NotifierHandle notifier_handle, int32_t* status) {
}
}
void* HAL_GetNotifierParam(HAL_NotifierHandle notifier_handle,
int32_t* status) {
auto notifier = notifierHandles.Get(notifier_handle);
void* HAL_GetNotifierParam(HAL_NotifierHandle notifierHandle, int32_t* status) {
auto notifier = notifierHandles.Get(notifierHandle);
if (!notifier) return nullptr;
return notifier->param;
}
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifier_handle,
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
uint64_t triggerTime, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(notifierMutex);
auto notifier = notifierHandles.Get(notifier_handle);
auto notifier = notifierHandles.Get(notifierHandle);
if (!notifier) return;
updateNotifierAlarmInternal(notifier, triggerTime, status);
}
void HAL_StopNotifierAlarm(HAL_NotifierHandle notifier_handle,
int32_t* status) {
void HAL_StopNotifierAlarm(HAL_NotifierHandle notifierHandle, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(notifierMutex);
auto notifier = notifierHandles.Get(notifier_handle);
auto notifier = notifierHandles.Get(notifierHandle);
if (!notifier) return;
notifier->triggerTime = UINT64_MAX;
}

View File

@@ -41,40 +41,41 @@ static inline int32_t GetFullRangeScaleFactor(DigitalPort* port) {
extern "C" {
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle port_handle,
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
int32_t* status) {
initializeDigital(status);
if (*status != 0) return HAL_kInvalidHandle;
int16_t pin = getPortHandlePin(port_handle);
if (pin == InvalidHandleIndex) {
int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
uint8_t origPin = static_cast<uint8_t>(pin);
uint8_t origChannel = static_cast<uint8_t>(channel);
if (origPin < kNumPWMHeaders) {
pin += kNumDigitalPins; // remap Headers to end of allocations
if (origChannel < kNumPWMHeaders) {
channel += kNumDigitalChannels; // remap Headers to end of allocations
} else {
pin = remapMXPPWMChannel(pin) + 10; // remap MXP to proper channel
channel = remapMXPPWMChannel(channel) + 10; // remap MXP to proper channel
}
auto handle = digitalPinHandles.Allocate(pin, HAL_HandleEnum::PWM, status);
auto handle =
digitalChannelHandles.Allocate(channel, HAL_HandleEnum::PWM, status);
if (*status != 0)
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
auto port = digitalPinHandles.Get(handle, HAL_HandleEnum::PWM);
auto port = digitalChannelHandles.Get(handle, HAL_HandleEnum::PWM);
if (port == nullptr) { // would only occur on thread issue.
*status = HAL_HANDLE_ERROR;
return HAL_kInvalidHandle;
}
port->pin = origPin;
port->channel = origChannel;
int32_t bitToSet = 1 << remapMXPPWMChannel(port->pin);
int32_t bitToSet = 1 << remapMXPPWMChannel(port->channel);
uint16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions | bitToSet,
@@ -82,32 +83,32 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle port_handle,
return handle;
}
void HAL_FreePWMPort(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
if (port->pin > tPWM::kNumHdrRegisters - 1) {
int32_t bitToUnset = 1 << remapMXPPWMChannel(port->pin);
if (port->channel > tPWM::kNumHdrRegisters - 1) {
int32_t bitToUnset = 1 << remapMXPPWMChannel(port->channel);
uint16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToUnset,
status);
}
digitalPinHandles.Free(pwm_port_handle, HAL_HandleEnum::PWM);
digitalChannelHandles.Free(pwmPortHandle, HAL_HandleEnum::PWM);
}
HAL_Bool HAL_CheckPWMChannel(int32_t pin) {
return pin < kNumPWMPins && pin >= 0;
HAL_Bool HAL_CheckPWMChannel(int32_t channel) {
return channel < kNumPWMChannels && channel >= 0;
}
void HAL_SetPWMConfig(HAL_DigitalHandle pwm_port_handle, double max,
void HAL_SetPWMConfig(HAL_DigitalHandle pwmPortHandle, double max,
double deadbandMax, double center, double deadbandMin,
double min, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -137,11 +138,11 @@ void HAL_SetPWMConfig(HAL_DigitalHandle pwm_port_handle, double max,
port->configSet = true;
}
void HAL_SetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t maxPwm,
void HAL_SetPWMConfigRaw(HAL_DigitalHandle pwmPortHandle, int32_t maxPwm,
int32_t deadbandMaxPwm, int32_t centerPwm,
int32_t deadbandMinPwm, int32_t minPwm,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -154,11 +155,11 @@ void HAL_SetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t maxPwm,
port->minPwm = minPwm;
}
void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t* maxPwm,
void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwmPortHandle, int32_t* maxPwm,
int32_t* deadbandMaxPwm, int32_t* centerPwm,
int32_t* deadbandMinPwm, int32_t* minPwm,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -170,9 +171,9 @@ void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t* maxPwm,
*minPwm = port->minPwm;
}
void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
HAL_Bool eliminateDeadband, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -180,9 +181,9 @@ void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
port->eliminateDeadband = eliminateDeadband;
}
HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwmPortHandle,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -198,18 +199,18 @@ HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
* @param channel The PWM channel to set.
* @param value The PWM value to set.
*/
void HAL_SetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t value,
void HAL_SetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t value,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
if (port->pin < tPWM::kNumHdrRegisters) {
pwmSystem->writeHdr(port->pin, value, status);
if (port->channel < tPWM::kNumHdrRegisters) {
pwmSystem->writeHdr(port->channel, value, status);
} else {
pwmSystem->writeMXP(port->pin - tPWM::kNumHdrRegisters, value, status);
pwmSystem->writeMXP(port->channel - tPWM::kNumHdrRegisters, value, status);
}
}
@@ -222,9 +223,9 @@ void HAL_SetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t value,
* @param channel The PWM channel to set.
* @param value The scaled PWM value to set.
*/
void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, double speed,
void HAL_SetPWMSpeed(HAL_DigitalHandle pwmPortHandle, double speed,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -263,7 +264,7 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, double speed,
return;
}
HAL_SetPWMRaw(pwm_port_handle, rawValue, status);
HAL_SetPWMRaw(pwmPortHandle, rawValue, status);
}
/**
@@ -275,9 +276,9 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, double speed,
* @param channel The PWM channel to set.
* @param value The scaled PWM value to set.
*/
void HAL_SetPWMPosition(HAL_DigitalHandle pwm_port_handle, double pos,
void HAL_SetPWMPosition(HAL_DigitalHandle pwmPortHandle, double pos,
int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -305,11 +306,11 @@ void HAL_SetPWMPosition(HAL_DigitalHandle pwm_port_handle, double pos,
return;
}
HAL_SetPWMRaw(pwm_port_handle, rawValue, status);
HAL_SetPWMRaw(pwmPortHandle, rawValue, status);
}
void HAL_SetPWMDisabled(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
HAL_SetPWMRaw(pwm_port_handle, kPwmDisabled, status);
void HAL_SetPWMDisabled(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
HAL_SetPWMRaw(pwmPortHandle, kPwmDisabled, status);
}
/**
@@ -318,17 +319,17 @@ void HAL_SetPWMDisabled(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
* @param channel The PWM channel to read from.
* @return The raw PWM value.
*/
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
if (port->pin < tPWM::kNumHdrRegisters) {
return pwmSystem->readHdr(port->pin, status);
if (port->channel < tPWM::kNumHdrRegisters) {
return pwmSystem->readHdr(port->channel, status);
} else {
return pwmSystem->readMXP(port->pin - tPWM::kNumHdrRegisters, status);
return pwmSystem->readMXP(port->channel - tPWM::kNumHdrRegisters, status);
}
}
@@ -338,8 +339,8 @@ int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
* @param channel The PWM channel to read from.
* @return The scaled PWM value.
*/
double HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
double HAL_GetPWMSpeed(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -349,7 +350,7 @@ double HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
return 0;
}
int32_t value = HAL_GetPWMRaw(pwm_port_handle, status);
int32_t value = HAL_GetPWMRaw(pwmPortHandle, status);
if (*status != 0) return 0;
DigitalPort* dPort = port.get();
@@ -376,8 +377,8 @@ double HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
* @param channel The PWM channel to read from.
* @return The scaled PWM value.
*/
double HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
double HAL_GetPWMPosition(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -387,7 +388,7 @@ double HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
return 0;
}
int32_t value = HAL_GetPWMRaw(pwm_port_handle, status);
int32_t value = HAL_GetPWMRaw(pwmPortHandle, status);
if (*status != 0) return 0;
DigitalPort* dPort = port.get();
@@ -401,15 +402,15 @@ double HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
}
}
void HAL_LatchPWMZero(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
void HAL_LatchPWMZero(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
pwmSystem->writeZeroLatch(port->pin, true, status);
pwmSystem->writeZeroLatch(port->pin, false, status);
pwmSystem->writeZeroLatch(port->channel, true, status);
pwmSystem->writeZeroLatch(port->channel, false, status);
}
/**
@@ -418,19 +419,19 @@ void HAL_LatchPWMZero(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
* @param channel The PWM channel to configure.
* @param squelchMask The 2-bit mask of outputs to squelch.
*/
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwm_port_handle,
int32_t squelchMask, int32_t* status) {
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwmPortHandle, int32_t squelchMask,
int32_t* status) {
auto port = digitalChannelHandles.Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
if (port->pin < tPWM::kNumPeriodScaleHdrElements) {
pwmSystem->writePeriodScaleHdr(port->pin, squelchMask, status);
if (port->channel < tPWM::kNumPeriodScaleHdrElements) {
pwmSystem->writePeriodScaleHdr(port->channel, squelchMask, status);
} else {
pwmSystem->writePeriodScaleMXP(port->pin - tPWM::kNumPeriodScaleHdrElements,
squelchMask, status);
pwmSystem->writePeriodScaleMXP(
port->channel - tPWM::kNumPeriodScaleHdrElements, squelchMask, status);
}
}

View File

@@ -19,15 +19,15 @@ int32_t HAL_GetNumAnalogOutputs(void) { return kNumAnalogOutputs; }
int32_t HAL_GetNumCounters(void) { return kNumCounters; }
int32_t HAL_GetNumDigitalHeaders(void) { return kNumDigitalHeaders; }
int32_t HAL_GetNumPWMHeaders(void) { return kNumPWMHeaders; }
int32_t HAL_GetNumDigitalPins(void) { return kNumDigitalPins; }
int32_t HAL_GetNumPWMPins(void) { return kNumPWMPins; }
int32_t HAL_GetNumDigitalChannels(void) { return kNumDigitalChannels; }
int32_t HAL_GetNumPWMChannels(void) { return kNumPWMChannels; }
int32_t HAL_GetNumDigitalPWMOutputs(void) { return kNumDigitalPWMOutputs; }
int32_t HAL_GetNumEncoders(void) { return kNumEncoders; }
int32_t HAL_GetNumInterrupts(void) { return kNumInterrupts; }
int32_t HAL_GetNumRelayPins(void) { return kNumRelayPins; }
int32_t HAL_GetNumRelayChannels(void) { return kNumRelayChannels; }
int32_t HAL_GetNumRelayHeaders(void) { return kNumRelayHeaders; }
int32_t HAL_GetNumPCMModules(void) { return kNumPCMModules; }
int32_t HAL_GetNumSolenoidPins(void) { return kNumSolenoidPins; }
int32_t HAL_GetNumSolenoidChannels(void) { return kNumSolenoidChannels; }
int32_t HAL_GetNumPDPModules(void) { return kNumPDPModules; }
int32_t HAL_GetNumPDPChannels(void) { return kNumPDPChannels; }
int32_t HAL_GetNumCanTalons(void) { return kNumCanTalons; }

View File

@@ -19,16 +19,16 @@ constexpr int32_t kNumAnalogOutputs = tAO::kNumMXPRegisters;
constexpr int32_t kNumCounters = tCounter::kNumSystems;
constexpr int32_t kNumDigitalHeaders = 10;
constexpr int32_t kNumPWMHeaders = tPWM::kNumHdrRegisters;
constexpr int32_t kNumDigitalPins = 26;
constexpr int32_t kNumPWMPins = tPWM::kNumMXPRegisters + kNumPWMHeaders;
constexpr int32_t kNumDigitalChannels = 26;
constexpr int32_t kNumPWMChannels = tPWM::kNumMXPRegisters + kNumPWMHeaders;
constexpr int32_t kNumDigitalPWMOutputs =
tDIO::kNumPWMDutyCycleAElements + tDIO::kNumPWMDutyCycleBElements;
constexpr int32_t kNumEncoders = tEncoder::kNumSystems;
constexpr int32_t kNumInterrupts = tInterrupt::kNumSystems;
constexpr int32_t kNumRelayPins = 8;
constexpr int32_t kNumRelayHeaders = kNumRelayPins / 2;
constexpr int32_t kNumRelayChannels = 8;
constexpr int32_t kNumRelayHeaders = kNumRelayChannels / 2;
constexpr int32_t kNumPCMModules = 63;
constexpr int32_t kNumSolenoidPins = 8;
constexpr int32_t kNumSolenoidChannels = 8;
constexpr int32_t kNumPDPModules = 63;
constexpr int32_t kNumPDPChannels = 16;
constexpr int32_t kNumCanTalons = 63;

View File

@@ -15,12 +15,12 @@ using namespace hal;
namespace {
struct Relay {
uint8_t pin;
uint8_t channel;
bool fwd;
};
}
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayPins,
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayChannels,
HAL_HandleEnum::Relay>
relayHandles;
@@ -28,21 +28,21 @@ static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayPins,
static priority_recursive_mutex digitalRelayMutex;
extern "C" {
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle port_handle,
HAL_Bool fwd, int32_t* status) {
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
int32_t* status) {
initializeDigital(status);
if (*status != 0) return HAL_kInvalidHandle;
int16_t pin = getPortHandlePin(port_handle);
if (pin == InvalidHandleIndex) {
int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
if (!fwd) pin += kNumRelayHeaders; // add 4 to reverse pins
if (!fwd) channel += kNumRelayHeaders; // add 4 to reverse channels
auto handle = relayHandles.Allocate(pin, status);
auto handle = relayHandles.Allocate(channel, status);
if (*status != 0)
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
@@ -54,35 +54,37 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle port_handle,
}
if (!fwd) {
pin -= kNumRelayHeaders; // subtract number of headers to put pin in range.
port->fwd = false; // set to reverse
// Subtract number of headers to put channel in range
channel -= kNumRelayHeaders;
port->fwd = false; // set to reverse
} else {
port->fwd = true; // set to forward
}
port->pin = static_cast<uint8_t>(pin);
port->channel = static_cast<uint8_t>(channel);
return handle;
}
void HAL_FreeRelayPort(HAL_RelayHandle relay_port_handle) {
void HAL_FreeRelayPort(HAL_RelayHandle relayPortHandle) {
// no status, so no need to check for a proper free.
relayHandles.Free(relay_port_handle);
relayHandles.Free(relayPortHandle);
}
HAL_Bool HAL_CheckRelayChannel(int32_t pin) {
HAL_Bool HAL_CheckRelayChannel(int32_t channel) {
// roboRIO only has 4 headers, and the FPGA has
// seperate functions for forward and reverse,
// instead of seperate pin IDs
return pin < kNumRelayHeaders && pin >= 0;
// instead of seperate channel IDs
return channel < kNumRelayHeaders && channel >= 0;
}
/**
* Set the state of a relay.
* Set the state of a relay output.
*/
void HAL_SetRelay(HAL_RelayHandle relay_port_handle, HAL_Bool on,
void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
int32_t* status) {
auto port = relayHandles.Get(relay_port_handle);
auto port = relayHandles.Get(relayPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -98,9 +100,9 @@ void HAL_SetRelay(HAL_RelayHandle relay_port_handle, HAL_Bool on,
if (*status != 0) return; // bad status read
if (on) {
relays |= 1 << port->pin;
relays |= 1 << port->channel;
} else {
relays &= ~(1 << port->pin);
relays &= ~(1 << port->channel);
}
if (port->fwd) {
@@ -113,8 +115,8 @@ void HAL_SetRelay(HAL_RelayHandle relay_port_handle, HAL_Bool on,
/**
* Get the current state of the relay channel
*/
HAL_Bool HAL_GetRelay(HAL_RelayHandle relay_port_handle, int32_t* status) {
auto port = relayHandles.Get(relay_port_handle);
HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
auto port = relayHandles.Get(relayPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -127,6 +129,6 @@ HAL_Bool HAL_GetRelay(HAL_RelayHandle relay_port_handle, int32_t* status) {
relays = relaySystem->readValue_Reverse(status);
}
return (relays & (1 << port->pin)) != 0;
return (relays & (1 << port->channel)) != 0;
}
}

View File

@@ -57,27 +57,27 @@ struct SPIAccumulator {
int64_t value = 0;
uint32_t count = 0;
int32_t last_value = 0;
int32_t lastValue = 0;
int32_t center = 0;
int32_t deadband = 0;
uint8_t cmd[4]; // command to send (up to 4 bytes)
int32_t valid_mask;
int32_t valid_value;
int32_t data_max; // one more than max data value
int32_t data_msb_mask; // data field MSB mask (for signed)
uint8_t data_shift; // data field shift right amount, in bits
uint8_t xfer_size; // SPI transfer size, in bytes (up to 4)
int32_t validMask;
int32_t validValue;
int32_t dataMax; // one more than max data value
int32_t dataMsbMask; // data field MSB mask (for signed)
uint8_t dataShift; // data field shift right amount, in bits
uint8_t xferSize; // SPI transfer size, in bytes (up to 4)
uint8_t port;
bool is_signed; // is data field signed?
bool big_endian; // is response big endian?
bool isSigned; // is data field signed?
bool bigEndian; // is response big endian?
};
std::unique_ptr<SPIAccumulator> spiAccumulators[5];
/*
* Initialize the spi port. Opens the port if necessary and saves the handle.
* If opening the MXP port, also sets up the pin functions appropriately
* If opening the MXP port, also sets up the channel functions appropriately
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
*/
void HAL_InitializeSPI(int32_t port, int32_t* status) {
@@ -336,39 +336,39 @@ static void spiAccumulatorProcess(uint64_t currentTime, void* param) {
std::lock_guard<priority_recursive_mutex> sync(spiGetMutex(accum->port));
spilib_writeread(
HAL_GetSPIHandle(accum->port), reinterpret_cast<const char*>(accum->cmd),
reinterpret_cast<char*>(resp_b), static_cast<int32_t>(accum->xfer_size));
reinterpret_cast<char*>(resp_b), static_cast<int32_t>(accum->xferSize));
// convert from bytes
uint32_t resp = 0;
if (accum->big_endian) {
for (int i = 0; i < accum->xfer_size; ++i) {
if (accum->bigEndian) {
for (int i = 0; i < accum->xferSize; ++i) {
resp <<= 8;
resp |= resp_b[i] & 0xff;
}
} else {
for (int i = accum->xfer_size - 1; i >= 0; --i) {
for (int i = accum->xferSize - 1; i >= 0; --i) {
resp <<= 8;
resp |= resp_b[i] & 0xff;
}
}
// process response
if ((resp & accum->valid_mask) == static_cast<uint32_t>(accum->valid_value)) {
if ((resp & accum->validMask) == static_cast<uint32_t>(accum->validValue)) {
// valid sensor data; extract data field
int32_t data = static_cast<int32_t>(resp >> accum->data_shift);
data &= accum->data_max - 1;
int32_t data = static_cast<int32_t>(resp >> accum->dataShift);
data &= accum->dataMax - 1;
// 2s complement conversion if signed MSB is set
if (accum->is_signed && (data & accum->data_msb_mask) != 0)
data -= accum->data_max;
if (accum->isSigned && (data & accum->dataMsbMask) != 0)
data -= accum->dataMax;
// center offset
data -= accum->center;
// only accumulate if outside deadband
if (data < -accum->deadband || data > accum->deadband) accum->value += data;
++accum->count;
accum->last_value = data;
accum->lastValue = data;
} else {
// no data from the sensor; just clear the last value
accum->last_value = 0;
accum->lastValue = 0;
}
// reschedule timer
@@ -386,28 +386,28 @@ static void spiAccumulatorProcess(uint64_t currentTime, void* param) {
* @param port SPI port
* @param period Time between reads, in us
* @param cmd SPI command to send to request data
* @param xfer_size SPI transfer size, in bytes
* @param valid_mask Mask to apply to received data for validity checking
* @param valid_data After valid_mask is applied, required matching value for
* @param xferSize SPI transfer size, in bytes
* @param validMask Mask to apply to received data for validity checking
* @param valid_data After validMask is applied, required matching value for
* validity checking
* @param data_shift Bit shift to apply to received data to get actual data
* @param dataShift Bit shift to apply to received data to get actual data
* value
* @param data_size Size (in bits) of data field
* @param is_signed Is data field signed?
* @param big_endian Is device big endian?
* @param dataSize Size (in bits) of data field
* @param isSigned Is data field signed?
* @param bigEndian Is device big endian?
*/
void HAL_InitSPIAccumulator(int32_t port, int32_t period, int32_t cmd,
int32_t xfer_size, int32_t valid_mask,
int32_t valid_value, int32_t data_shift,
int32_t data_size, HAL_Bool is_signed,
HAL_Bool big_endian, int32_t* status) {
int32_t xferSize, int32_t validMask,
int32_t validValue, int32_t dataShift,
int32_t dataSize, HAL_Bool isSigned,
HAL_Bool bigEndian, int32_t* status) {
std::lock_guard<priority_recursive_mutex> sync(spiGetMutex(port));
if (port > 4) return;
if (!spiAccumulators[port])
spiAccumulators[port] = std::make_unique<SPIAccumulator>();
SPIAccumulator* accum = spiAccumulators[port].get();
if (big_endian) {
for (int i = xfer_size - 1; i >= 0; --i) {
if (bigEndian) {
for (int i = xferSize - 1; i >= 0; --i) {
accum->cmd[i] = cmd & 0xff;
cmd >>= 8;
}
@@ -421,14 +421,14 @@ void HAL_InitSPIAccumulator(int32_t port, int32_t period, int32_t cmd,
accum->cmd[3] = cmd & 0xff;
}
accum->period = period;
accum->xfer_size = xfer_size;
accum->valid_mask = valid_mask;
accum->valid_value = valid_value;
accum->data_shift = data_shift;
accum->data_max = (1 << data_size);
accum->data_msb_mask = (1 << (data_size - 1));
accum->is_signed = is_signed;
accum->big_endian = big_endian;
accum->xferSize = xferSize;
accum->validMask = validMask;
accum->validValue = validValue;
accum->dataShift = dataShift;
accum->dataMax = (1 << dataSize);
accum->dataMsbMask = (1 << (dataSize - 1));
accum->isSigned = isSigned;
accum->bigEndian = bigEndian;
if (!accum->notifier) {
accum->notifier =
HAL_InitializeNotifier(spiAccumulatorProcess, accum, status);
@@ -465,7 +465,7 @@ void HAL_ResetSPIAccumulator(int32_t port, int32_t* status) {
}
accum->value = 0;
accum->count = 0;
accum->last_value = 0;
accum->lastValue = 0;
}
/**
@@ -512,7 +512,7 @@ int32_t HAL_GetSPIAccumulatorLastValue(int32_t port, int32_t* status) {
*status = NULL_PARAMETER;
return 0;
}
return accum->last_value;
return accum->lastValue;
}
/**

View File

@@ -20,30 +20,30 @@
namespace {
struct Solenoid {
uint8_t module;
uint8_t pin;
uint8_t channel;
};
}
using namespace hal;
static IndexedHandleResource<HAL_SolenoidHandle, Solenoid,
kNumPCMModules * kNumSolenoidPins,
kNumPCMModules * kNumSolenoidChannels,
HAL_HandleEnum::Solenoid>
solenoidHandles;
extern "C" {
HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle port_handle,
HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle,
int32_t* status) {
int16_t pin = getPortHandlePin(port_handle);
int16_t module = getPortHandleModule(port_handle);
if (pin == InvalidHandleIndex) {
int16_t channel = getPortHandleChannel(portHandle);
int16_t module = getPortHandleModule(portHandle);
if (channel == InvalidHandleIndex) {
*status = HAL_HANDLE_ERROR;
return HAL_kInvalidHandle;
}
// initializePCM will check the module
if (!HAL_CheckSolenoidChannel(pin)) {
if (!HAL_CheckSolenoidChannel(channel)) {
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
@@ -54,44 +54,44 @@ HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle port_handle,
}
auto handle =
solenoidHandles.Allocate(module * kNumSolenoidPins + pin, status);
solenoidHandles.Allocate(module * kNumSolenoidChannels + channel, status);
if (handle == HAL_kInvalidHandle) { // out of resources
*status = NO_AVAILABLE_RESOURCES;
return HAL_kInvalidHandle;
}
auto solenoid_port = solenoidHandles.Get(handle);
if (solenoid_port == nullptr) { // would only occur on thread issues
auto solenoidPort = solenoidHandles.Get(handle);
if (solenoidPort == nullptr) { // would only occur on thread issues
*status = HAL_HANDLE_ERROR;
return HAL_kInvalidHandle;
}
solenoid_port->module = static_cast<uint8_t>(module);
solenoid_port->pin = static_cast<uint8_t>(pin);
solenoidPort->module = static_cast<uint8_t>(module);
solenoidPort->channel = static_cast<uint8_t>(channel);
return handle;
}
void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoid_port_handle) {
solenoidHandles.Free(solenoid_port_handle);
void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoidPortHandle) {
solenoidHandles.Free(solenoidPortHandle);
}
HAL_Bool HAL_CheckSolenoidModule(int32_t module) {
return module < kNumPCMModules && module >= 0;
}
HAL_Bool HAL_CheckSolenoidChannel(int32_t pin) {
return pin < kNumSolenoidPins && pin >= 0;
HAL_Bool HAL_CheckSolenoidChannel(int32_t channel) {
return channel < kNumSolenoidChannels && channel >= 0;
}
HAL_Bool HAL_GetSolenoid(HAL_SolenoidHandle solenoid_port_handle,
HAL_Bool HAL_GetSolenoid(HAL_SolenoidHandle solenoidPortHandle,
int32_t* status) {
auto port = solenoidHandles.Get(solenoid_port_handle);
auto port = solenoidHandles.Get(solenoidPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
}
bool value;
*status = PCM_modules[port->module]->GetSolenoid(port->pin, value);
*status = PCM_modules[port->module]->GetSolenoid(port->channel, value);
return value;
}
@@ -105,15 +105,15 @@ int32_t HAL_GetAllSolenoids(int32_t module, int32_t* status) {
return value;
}
void HAL_SetSolenoid(HAL_SolenoidHandle solenoid_port_handle, HAL_Bool value,
void HAL_SetSolenoid(HAL_SolenoidHandle solenoidPortHandle, HAL_Bool value,
int32_t* status) {
auto port = solenoidHandles.Get(solenoid_port_handle);
auto port = solenoidHandles.Get(solenoidPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
*status = PCM_modules[port->module]->SetSolenoid(port->pin, value);
*status = PCM_modules[port->module]->SetSolenoid(port->channel, value);
}
int32_t HAL_GetPCMSolenoidBlackList(int32_t module, int32_t* status) {

View File

@@ -8,7 +8,7 @@
#include "HAL/handles/HandlesInternal.h"
namespace hal {
HAL_PortHandle createPortHandle(uint8_t pin, uint8_t module) {
HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module) {
// set last 8 bits, then shift to first 8 bits
HAL_PortHandle handle = static_cast<HAL_PortHandle>(HAL_HandleEnum::Port);
handle = handle << 24;
@@ -16,8 +16,8 @@ HAL_PortHandle createPortHandle(uint8_t pin, uint8_t module) {
int32_t temp = module;
temp = (temp << 8) & 0xff00;
handle += temp;
// add pin to last 8 bits
handle += pin;
// add channel to last 8 bits
handle += channel;
return handle;
}

View File

@@ -35,8 +35,8 @@ DigitalInput::DigitalInput(uint32_t channel) {
int32_t status = 0;
m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), true, &status);
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumDigitalPins(), channel,
HAL_GetErrorMessage(status));
wpi_setErrorWithContextRange(status, 0, HAL_GetNumDigitalChannels(),
channel, HAL_GetErrorMessage(status));
m_handle = HAL_kInvalidHandle;
m_channel = std::numeric_limits<uint32_t>::max();
return;

View File

@@ -36,8 +36,8 @@ DigitalOutput::DigitalOutput(uint32_t channel) {
int32_t status = 0;
m_handle = HAL_InitializeDIOPort(HAL_GetPort(channel), false, &status);
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumDigitalPins(), channel,
HAL_GetErrorMessage(status));
wpi_setErrorWithContextRange(status, 0, HAL_GetNumDigitalChannels(),
channel, HAL_GetErrorMessage(status));
m_channel = std::numeric_limits<uint32_t>::max();
m_handle = HAL_kInvalidHandle;
return;

View File

@@ -56,7 +56,7 @@ DoubleSolenoid::DoubleSolenoid(uint8_t moduleNumber, uint32_t forwardChannel,
m_forwardHandle = HAL_InitializeSolenoidPort(
HAL_GetPortWithModule(moduleNumber, m_forwardChannel), &status);
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumSolenoidPins(),
wpi_setErrorWithContextRange(status, 0, HAL_GetNumSolenoidChannels(),
forwardChannel, HAL_GetErrorMessage(status));
m_forwardHandle = HAL_kInvalidHandle;
m_reverseHandle = HAL_kInvalidHandle;
@@ -66,7 +66,7 @@ DoubleSolenoid::DoubleSolenoid(uint8_t moduleNumber, uint32_t forwardChannel,
m_reverseHandle = HAL_InitializeSolenoidPort(
HAL_GetPortWithModule(moduleNumber, m_reverseChannel), &status);
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumSolenoidPins(),
wpi_setErrorWithContextRange(status, 0, HAL_GetNumSolenoidChannels(),
reverseChannel, HAL_GetErrorMessage(status));
// free forward solenoid
HAL_FreeSolenoidPort(m_forwardHandle);

View File

@@ -35,7 +35,7 @@ PWM::PWM(uint32_t channel) {
int32_t status = 0;
m_handle = HAL_InitializePWMPort(HAL_GetPort(channel), &status);
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumPWMPins(), channel,
wpi_setErrorWithContextRange(status, 0, HAL_GetNumPWMChannels(), channel,
HAL_GetErrorMessage(status));
m_channel = std::numeric_limits<uint32_t>::max();
m_handle = HAL_kInvalidHandle;

View File

@@ -38,8 +38,8 @@ Relay::Relay(uint32_t channel, Relay::Direction direction)
int32_t status = 0;
m_forwardHandle = HAL_InitializeRelayPort(portHandle, true, &status);
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumRelayPins(), channel,
HAL_GetErrorMessage(status));
wpi_setErrorWithContextRange(status, 0, HAL_GetNumRelayChannels(),
channel, HAL_GetErrorMessage(status));
m_forwardHandle = HAL_kInvalidHandle;
m_reverseHandle = HAL_kInvalidHandle;
return;
@@ -50,8 +50,8 @@ Relay::Relay(uint32_t channel, Relay::Direction direction)
int32_t status = 0;
m_reverseHandle = HAL_InitializeRelayPort(portHandle, false, &status);
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumRelayPins(), channel,
HAL_GetErrorMessage(status));
wpi_setErrorWithContextRange(status, 0, HAL_GetNumRelayChannels(),
channel, HAL_GetErrorMessage(status));
m_forwardHandle = HAL_kInvalidHandle;
m_reverseHandle = HAL_kInvalidHandle;
return;

View File

@@ -11,11 +11,11 @@
#include "HAL/HAL.h"
#include "WPIErrors.h"
const int SensorBase::kDigitalChannels = HAL_GetNumDigitalPins();
const int SensorBase::kDigitalChannels = HAL_GetNumDigitalChannels();
const int SensorBase::kAnalogInputs = HAL_GetNumAnalogInputs();
const int SensorBase::kSolenoidChannels = HAL_GetNumSolenoidPins();
const int SensorBase::kSolenoidChannels = HAL_GetNumSolenoidChannels();
const int SensorBase::kSolenoidModules = HAL_GetNumPCMModules();
const int SensorBase::kPwmChannels = HAL_GetNumPWMPins();
const int SensorBase::kPwmChannels = HAL_GetNumPWMChannels();
const int SensorBase::kRelayChannels = HAL_GetNumRelayHeaders();
const int SensorBase::kPDPChannels = HAL_GetNumPDPChannels();

View File

@@ -44,8 +44,8 @@ Solenoid::Solenoid(uint8_t moduleNumber, uint32_t channel)
m_solenoidHandle = HAL_InitializeSolenoidPort(
HAL_GetPortWithModule(moduleNumber, channel), &status);
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumSolenoidPins(), channel,
HAL_GetErrorMessage(status));
wpi_setErrorWithContextRange(status, 0, HAL_GetNumSolenoidChannels(),
channel, HAL_GetErrorMessage(status));
m_solenoidHandle = HAL_kInvalidHandle;
return;
}

View File

@@ -44,7 +44,7 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogInputPort(
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "Analog Handle = " << analog;
CheckStatusRange(env, 0, HAL_GetNumAnalogInputs(),
hal::getPortHandlePin((HAL_PortHandle)id), status);
hal::getPortHandleChannel((HAL_PortHandle)id), status);
return (jint)analog;
}
@@ -74,7 +74,7 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogOutputPort(
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "Analog Handle = " << analog;
CheckStatusRange(env, 0, HAL_GetNumAnalogOutputs(),
hal::getPortHandlePin((HAL_PortHandle)id), status);
hal::getPortHandleChannel((HAL_PortHandle)id), status);
return (jlong)analog;
}

View File

@@ -45,9 +45,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_checkCompressorModule(
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressor(
JNIEnv *env, jclass, jint compressor_handle) {
JNIEnv *env, jclass, jint compressorHandle) {
int32_t status = 0;
bool val = HAL_GetCompressor((HAL_CompressorHandle)compressor_handle, &status);
bool val = HAL_GetCompressor((HAL_CompressorHandle)compressorHandle, &status);
CheckStatus(env, status);
return val;
}
@@ -59,9 +59,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressor(
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setCompressorClosedLoopControl(
JNIEnv *env, jclass, jint compressor_handle, jboolean value) {
JNIEnv *env, jclass, jint compressorHandle, jboolean value) {
int32_t status = 0;
HAL_SetCompressorClosedLoopControl((HAL_CompressorHandle)compressor_handle, value, &status);
HAL_SetCompressorClosedLoopControl((HAL_CompressorHandle)compressorHandle, value, &status);
CheckStatus(env, status);
}
@@ -72,9 +72,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setCompressorClosedLoopControl(
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorClosedLoopControl(
JNIEnv *env, jclass, jint compressor_handle) {
JNIEnv *env, jclass, jint compressorHandle) {
int32_t status = 0;
bool val = HAL_GetCompressorClosedLoopControl((HAL_CompressorHandle)compressor_handle, &status);
bool val = HAL_GetCompressorClosedLoopControl((HAL_CompressorHandle)compressorHandle, &status);
CheckStatus(env, status);
return val;
}
@@ -86,9 +86,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorClosedLoopControl(
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorPressureSwitch(
JNIEnv *env, jclass, jint compressor_handle) {
JNIEnv *env, jclass, jint compressorHandle) {
int32_t status = 0;
bool val = HAL_GetCompressorPressureSwitch((HAL_CompressorHandle)compressor_handle, &status);
bool val = HAL_GetCompressorPressureSwitch((HAL_CompressorHandle)compressorHandle, &status);
CheckStatus(env, status);
return val;
}
@@ -100,9 +100,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorPressureSwitch(
*/
JNIEXPORT jfloat JNICALL
Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrent(
JNIEnv *env, jclass, jint compressor_handle) {
JNIEnv *env, jclass, jint compressorHandle) {
int32_t status = 0;
float val = HAL_GetCompressorCurrent((HAL_CompressorHandle)compressor_handle, &status);
float val = HAL_GetCompressorCurrent((HAL_CompressorHandle)compressorHandle, &status);
CheckStatus(env, status);
return val;
}
@@ -114,9 +114,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrent(
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighFault(
JNIEnv *env, jclass, jint compressor_handle) {
JNIEnv *env, jclass, jint compressorHandle) {
int32_t status = 0;
bool val = HAL_GetCompressorCurrentTooHighFault((HAL_CompressorHandle)compressor_handle, &status);
bool val = HAL_GetCompressorCurrentTooHighFault((HAL_CompressorHandle)compressorHandle, &status);
CheckStatus(env, status);
return val;
}
@@ -128,10 +128,10 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighFault(
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighStickyFault(
JNIEnv *env, jclass, jint compressor_handle) {
JNIEnv *env, jclass, jint compressorHandle) {
int32_t status = 0;
bool val =
HAL_GetCompressorCurrentTooHighStickyFault((HAL_CompressorHandle)compressor_handle, &status);
HAL_GetCompressorCurrentTooHighStickyFault((HAL_CompressorHandle)compressorHandle, &status);
CheckStatus(env, status);
return val;
}
@@ -143,9 +143,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighStickyFa
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedStickyFault(
JNIEnv *env, jclass, jint compressor_handle) {
JNIEnv *env, jclass, jint compressorHandle) {
int32_t status = 0;
bool val = HAL_GetCompressorShortedStickyFault((HAL_CompressorHandle)compressor_handle, &status);
bool val = HAL_GetCompressorShortedStickyFault((HAL_CompressorHandle)compressorHandle, &status);
CheckStatus(env, status);
return val;
}
@@ -157,9 +157,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedStickyFault(
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedFault(
JNIEnv *env, jclass, jint compressor_handle) {
JNIEnv *env, jclass, jint compressorHandle) {
int32_t status = 0;
bool val = HAL_GetCompressorShortedFault((HAL_CompressorHandle)compressor_handle, &status);
bool val = HAL_GetCompressorShortedFault((HAL_CompressorHandle)compressorHandle, &status);
CheckStatus(env, status);
return val;
}
@@ -171,9 +171,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedFault(
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedStickyFault(
JNIEnv *env, jclass, jint compressor_handle) {
JNIEnv *env, jclass, jint compressorHandle) {
int32_t status = 0;
bool val = HAL_GetCompressorNotConnectedStickyFault((HAL_CompressorHandle)compressor_handle, &status);
bool val = HAL_GetCompressorNotConnectedStickyFault((HAL_CompressorHandle)compressorHandle, &status);
CheckStatus(env, status);
return val;
}
@@ -185,9 +185,9 @@ Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedStickyFaul
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedFault(
JNIEnv *env, jclass, jint compressor_handle) {
JNIEnv *env, jclass, jint compressorHandle) {
int32_t status = 0;
bool val = HAL_GetCompressorNotConnectedFault((HAL_CompressorHandle)compressor_handle, &status);
bool val = HAL_GetCompressorNotConnectedFault((HAL_CompressorHandle)compressorHandle, &status);
CheckStatus(env, status);
return val;
}

View File

@@ -43,8 +43,8 @@ Java_edu_wpi_first_wpilibj_hal_DIOJNI_initializeDIOPort(
auto dio = HAL_InitializeDIOPort((HAL_PortHandle)id, (uint8_t)input, &status);
DIOJNI_LOG(logDEBUG) << "Status = " << status;
DIOJNI_LOG(logDEBUG) << "DIO Handle = " << dio;
CheckStatusRange(env, 0, HAL_GetNumDigitalPins(),
hal::getPortHandlePin((HAL_PortHandle)id), status);
CheckStatusRange(env, 0, HAL_GetNumDigitalChannels(),
hal::getPortHandleChannel((HAL_PortHandle)id), status);
return (jint)dio;
}
@@ -261,7 +261,7 @@ Java_edu_wpi_first_wpilibj_hal_DIOJNI_setDigitalPWMOutputChannel(
JNIEnv* env, jclass, jint id, jint value) {
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI setDigitalPWMOutputChannel";
DIOJNI_LOG(logDEBUG) << "PWM Handle = " << (HAL_DigitalPWMHandle)id;
DIOJNI_LOG(logDEBUG) << "Pin= " << value;
DIOJNI_LOG(logDEBUG) << "Channel= " << value;
int32_t status = 0;
HAL_SetDigitalPWMOutputChannel((HAL_DigitalPWMHandle)id, (uint32_t)value, &status);
DIOJNI_LOG(logDEBUG) << "Status = " << status;

View File

@@ -144,12 +144,12 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_initializeInterrupts(
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_cleanInterrupts(
JNIEnv* env, jclass, jint interrupt_handle) {
JNIEnv* env, jclass, jint interruptHandle) {
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI cleanInterrupts";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interrupt_handle;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interruptHandle;
int32_t status = 0;
HAL_CleanInterrupts((HAL_InterruptHandle)interrupt_handle, &status);
HAL_CleanInterrupts((HAL_InterruptHandle)interruptHandle, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
@@ -163,13 +163,13 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_cleanInterrupts(
*/
JNIEXPORT int JNICALL
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_waitForInterrupt(
JNIEnv* env, jclass, jint interrupt_handle, jdouble timeout,
JNIEnv* env, jclass, jint interruptHandle, jdouble timeout,
jboolean ignorePrevious) {
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI waitForInterrupt";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interrupt_handle;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interruptHandle;
int32_t status = 0;
int result = HAL_WaitForInterrupt((HAL_InterruptHandle)interrupt_handle, timeout,
int result = HAL_WaitForInterrupt((HAL_InterruptHandle)interruptHandle, timeout,
ignorePrevious, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
@@ -185,12 +185,12 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_waitForInterrupt(
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_enableInterrupts(
JNIEnv* env, jclass, jint interrupt_handle) {
JNIEnv* env, jclass, jint interruptHandle) {
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI enableInterrupts";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interrupt_handle;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interruptHandle;
int32_t status = 0;
HAL_EnableInterrupts((HAL_InterruptHandle)interrupt_handle, &status);
HAL_EnableInterrupts((HAL_InterruptHandle)interruptHandle, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
@@ -204,12 +204,12 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_enableInterrupts(
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_disableInterrupts(
JNIEnv* env, jclass, jint interrupt_handle) {
JNIEnv* env, jclass, jint interruptHandle) {
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI disableInterrupts";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interrupt_handle;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interruptHandle;
int32_t status = 0;
HAL_DisableInterrupts((HAL_InterruptHandle)interrupt_handle, &status);
HAL_DisableInterrupts((HAL_InterruptHandle)interruptHandle, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
@@ -223,12 +223,12 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_disableInterrupts(
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readInterruptRisingTimestamp(
JNIEnv* env, jclass, jint interrupt_handle) {
JNIEnv* env, jclass, jint interruptHandle) {
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI readInterruptRisingTimestamp";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interrupt_handle;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interruptHandle;
int32_t status = 0;
jdouble timeStamp = HAL_ReadInterruptRisingTimestamp((HAL_InterruptHandle)interrupt_handle, &status);
jdouble timeStamp = HAL_ReadInterruptRisingTimestamp((HAL_InterruptHandle)interruptHandle, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
@@ -242,12 +242,12 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readInterruptRisingTimestamp(
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readInterruptFallingTimestamp(
JNIEnv* env, jclass, jint interrupt_handle) {
JNIEnv* env, jclass, jint interruptHandle) {
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI readInterruptFallingTimestamp";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interrupt_handle;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interruptHandle;
int32_t status = 0;
jdouble timeStamp = HAL_ReadInterruptFallingTimestamp((HAL_InterruptHandle)interrupt_handle, &status);
jdouble timeStamp = HAL_ReadInterruptFallingTimestamp((HAL_InterruptHandle)interruptHandle, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
@@ -261,15 +261,15 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readInterruptFallingTimestamp(
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_requestInterrupts(
JNIEnv* env, jclass, jint interrupt_handle, jint digitalSourceHandle,
JNIEnv* env, jclass, jint interruptHandle, jint digitalSourceHandle,
jint analogTriggerType) {
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI requestInterrupts";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interrupt_handle;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interruptHandle;
INTERRUPTJNI_LOG(logDEBUG) << "digitalSourceHandle = " << digitalSourceHandle;
INTERRUPTJNI_LOG(logDEBUG) << "analogTriggerType = " << analogTriggerType;
int32_t status = 0;
HAL_RequestInterrupts((HAL_InterruptHandle)interrupt_handle, (HAL_Handle)digitalSourceHandle,
HAL_RequestInterrupts((HAL_InterruptHandle)interruptHandle, (HAL_Handle)digitalSourceHandle,
(HAL_AnalogTriggerType)analogTriggerType, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
@@ -284,10 +284,10 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_requestInterrupts(
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_attachInterruptHandler(
JNIEnv* env, jclass, jint interrupt_handle, jobject handler,
JNIEnv* env, jclass, jint interruptHandle, jobject handler,
jobject param) {
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI attachInterruptHandler";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interrupt_handle;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interruptHandle;
jclass cls = env->GetObjectClass(handler);
INTERRUPTJNI_LOG(logDEBUG) << "class = " << cls;
@@ -311,7 +311,7 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_attachInterruptHandler(
INTERRUPTJNI_LOG(logDEBUG) << "InterruptThreadJNI Ptr = " << intr;
int32_t status = 0;
HAL_AttachInterruptHandler((HAL_InterruptHandle)interrupt_handle, interruptHandler, intr,
HAL_AttachInterruptHandler((HAL_InterruptHandle)interruptHandle, interruptHandler, intr,
&status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
@@ -325,15 +325,15 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_attachInterruptHandler(
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_setInterruptUpSourceEdge(
JNIEnv* env, jclass, jint interrupt_handle, jboolean risingEdge,
JNIEnv* env, jclass, jint interruptHandle, jboolean risingEdge,
jboolean fallingEdge) {
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI setInterruptUpSourceEdge";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interrupt_handle;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HAL_InterruptHandle)interruptHandle;
INTERRUPTJNI_LOG(logDEBUG) << "Rising Edge = " << (bool)risingEdge;
INTERRUPTJNI_LOG(logDEBUG) << "Falling Edge = " << (bool)fallingEdge;
int32_t status = 0;
HAL_SetInterruptUpSourceEdge((HAL_InterruptHandle)interrupt_handle, risingEdge, fallingEdge,
HAL_SetInterruptUpSourceEdge((HAL_InterruptHandle)interruptHandle, risingEdge, fallingEdge,
&status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;

View File

@@ -22,11 +22,11 @@ extern "C" {
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPortWithModule(
JNIEnv* env, jclass, jbyte module, jbyte pin) {
JNIEnv* env, jclass, jbyte module, jbyte channel) {
// FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue";
// FILE_LOG(logDEBUG) << "Module = " << (jint)module;
// FILE_LOG(logDEBUG) << "Pin = " << (jint)pin;
HAL_PortHandle port = HAL_GetPortWithModule(module, pin);
// FILE_LOG(logDEBUG) << "Channel = " << (jint)channel;
HAL_PortHandle port = HAL_GetPortWithModule(module, channel);
// FILE_LOG(logDEBUG) << "Port Handle = " << port;
return (jint)port;
}
@@ -37,11 +37,11 @@ Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPortWithModule(
* Signature: (B)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPort(
JNIEnv* env, jclass, jbyte pin) {
JNIEnv* env, jclass, jbyte channel) {
// FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue";
// FILE_LOG(logDEBUG) << "Module = " << (jint)module;
// FILE_LOG(logDEBUG) << "Pin = " << (jint)pin;
HAL_PortHandle port = HAL_GetPort(pin);
// FILE_LOG(logDEBUG) << "Channel = " << (jint)channel;
HAL_PortHandle port = HAL_GetPort(channel);
// FILE_LOG(logDEBUG) << "Port Handle = " << port;
return (jint)port;
}

View File

@@ -42,8 +42,8 @@ Java_edu_wpi_first_wpilibj_hal_PWMJNI_initializePWMPort(
auto pwm = HAL_InitializePWMPort((HAL_PortHandle)id, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
PWMJNI_LOG(logDEBUG) << "PWM Handle = " << pwm;
CheckStatusRange(env, 0, HAL_GetNumPWMPins(),
hal::getPortHandlePin((HAL_PortHandle)id), status);
CheckStatusRange(env, 0, HAL_GetNumPWMChannels(),
hal::getPortHandleChannel((HAL_PortHandle)id), status);
return (jint)pwm;
}

View File

@@ -131,14 +131,14 @@ Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPWMHeaders(
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumDigitalPins
* Method: getNumDigitalChannels
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumDigitalPins(
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumDigitalChannels(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumDigitalPins";
jint value = HAL_GetNumDigitalPins();
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumDigitalChannels";
jint value = HAL_GetNumDigitalChannels();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
@@ -146,14 +146,14 @@ Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumDigitalPins(
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumPWMPins
* Method: getNumPWMChannels
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPWMPins(
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPWMChannels(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPWMPins";
jint value = HAL_GetNumPWMPins();
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumPWMChannels";
jint value = HAL_GetNumPWMChannels();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
@@ -206,14 +206,14 @@ Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumInterrupts(
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumRelayPins
* Method: getNumRelayChannels
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumRelayPins(
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumRelayChannels(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumRelayPins";
jint value = HAL_GetNumRelayPins();
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumRelayChannels";
jint value = HAL_GetNumRelayChannels();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}
@@ -251,14 +251,14 @@ Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumPCMModules(
/*
* Class: edu_wpi_first_wpilibj_hal_PortsJNI
* Method: getNumSolenoidPins
* Method: getNumSolenoidChannels
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumSolenoidPins(
Java_edu_wpi_first_wpilibj_hal_PortsJNI_getNumSolenoidChannels(
JNIEnv *env, jclass) {
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumSolenoidPins";
jint value = HAL_GetNumSolenoidPins();
PORTSJNI_LOG(logDEBUG) << "Calling PortsJNI getNumSolenoidChannels";
jint value = HAL_GetNumSolenoidChannels();
PORTSJNI_LOG(logDEBUG) << "Value = " << value;
return value;
}

View File

@@ -41,8 +41,8 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_initializeRelayPo
HAL_RelayHandle handle = HAL_InitializeRelayPort((HAL_PortHandle)id, (uint8_t) fwd, &status);
RELAYJNI_LOG(logDEBUG) << "Status = " << status;
RELAYJNI_LOG(logDEBUG) << "Relay Handle = " << handle;
CheckStatusRange(env, 0, HAL_GetNumRelayPins(),
hal::getPortHandlePin((HAL_PortHandle)id), status);
CheckStatusRange(env, 0, HAL_GetNumRelayChannels(),
hal::getPortHandleChannel((HAL_PortHandle)id), status);
return (jint) handle;
}

View File

@@ -43,9 +43,9 @@ Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_initializeSolenoidPort(
SOLENOIDJNI_LOG(logDEBUG) << "Status = " << status;
SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Handle = " << handle;
// Use solenoid pins, as we have to pick one.
CheckStatusRange(env, 0, HAL_GetNumSolenoidPins(),
hal::getPortHandlePin((HAL_PortHandle)id), status);;
// Use solenoid channels, as we have to pick one.
CheckStatusRange(env, 0, HAL_GetNumSolenoidChannels(),
hal::getPortHandleChannel((HAL_PortHandle)id), status);;
return (jint)handle;
}

View File

@@ -21,12 +21,12 @@ import static java.util.Objects.requireNonNull;
/**
* Class for VEX Robotics Spike style relay outputs. Relays are intended to be connected to Spikes
* or similar relays. The relay channels controls a pair of pins that are either both off, one on,
* the other on, or both on. This translates into two Spike outputs at 0v, one at 12v and one at 0v,
* one at 0v and the other at 12v, or two Spike outputs at 12V. This allows off, full forward, or
* full reverse control of motors without variable speed. It also allows the two channels (forward
* and reverse) to be used independently for something that does not care about voltage polarity
* (like a solenoid).
* or similar relays. The relay channels controls a pair of channels that are either both off, one
* on, the other on, or both on. This translates into two Spike outputs at 0v, one at 12v and one
* at 0v, one at 0v and the other at 12v, or two Spike outputs at 12V. This allows off, full
* forward, or full reverse control of motors without variable speed. It also allows the two
* channels (forward and reverse) to be used independently for something that does not care about
* voltage polarity (like a solenoid).
*/
public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable {
private MotorSafetyHelper m_safetyHelper;

View File

@@ -29,7 +29,7 @@ public abstract class SensorBase { // TODO: Refactor
/**
* Number of digital channels per roboRIO.
*/
public static final int kDigitalChannels = PortsJNI.getNumDigitalPins();
public static final int kDigitalChannels = PortsJNI.getNumDigitalChannels();
/**
* Number of analog input channels.
*/
@@ -41,11 +41,11 @@ public abstract class SensorBase { // TODO: Refactor
/**
* Number of solenoid channels per module.
*/
public static final int kSolenoidChannels = PortsJNI.getNumSolenoidPins();
public static final int kSolenoidChannels = PortsJNI.getNumSolenoidChannels();
/**
* Number of PWM channels per roboRIO.
*/
public static final int kPwmChannels = PortsJNI.getNumPWMPins();
public static final int kPwmChannels = PortsJNI.getNumPWMChannels();
/**
* Number of relay channels per roboRIO.
*/

View File

@@ -83,9 +83,8 @@ public class Ultrasonic extends SensorBase implements PIDSource, LiveWindowSenda
return;
}
if (ultrasonic.isEnabled()) {
ultrasonic.m_pingChannel.pulse(m_pingChannel.getChannel(), (float) kPingTime); // do
// the
// ping
// Do the ping
ultrasonic.m_pingChannel.pulse(m_pingChannel.getChannel(), (float) kPingTime);
}
ultrasonic = ultrasonic.m_nextSensor;
Timer.delay(.1); // wait for ping to return

View File

@@ -43,9 +43,9 @@ public class AnalogJNI extends JNIWrapper {
public static native boolean checkAnalogModule(byte module);
public static native boolean checkAnalogInputChannel(int pin);
public static native boolean checkAnalogInputChannel(int channel);
public static native boolean checkAnalogOutputChannel(int pin);
public static native boolean checkAnalogOutputChannel(int channel);
public static native void setAnalogOutput(int portHandle, double voltage);

View File

@@ -37,5 +37,5 @@ public class DIOJNI extends JNIWrapper {
public static native void setDigitalPWMDutyCycle(int pwmGenerator, double dutyCycle);
public static native void setDigitalPWMOutputChannel(int pwmGenerator, int pin);
public static native void setDigitalPWMOutputChannel(int pwmGenerator, int channel);
}

View File

@@ -59,7 +59,7 @@ public class JNIWrapper {
}
}
public static native int getPortWithModule(byte module, byte pin);
public static native int getPortWithModule(byte module, byte channel);
public static native int getPort(byte pin);
public static native int getPort(byte channel);
}

View File

@@ -22,9 +22,9 @@ public class PortsJNI extends JNIWrapper {
public static native int getNumPWMHeaders();
public static native int getNumDigitalPins();
public static native int getNumDigitalChannels();
public static native int getNumPWMPins();
public static native int getNumPWMChannels();
public static native int getNumDigitalPWMOutputs();
@@ -32,13 +32,13 @@ public class PortsJNI extends JNIWrapper {
public static native int getNumInterrupts();
public static native int getNumRelayPins();
public static native int getNumRelayChannels();
public static native int getNumRelayHeaders();
public static native int getNumPCMModules();
public static native int getNumSolenoidPins();
public static native int getNumSolenoidChannels();
public static native int getNumPDPModules();

View File

@@ -12,7 +12,7 @@ public class RelayJNI extends DIOJNI {
public static native void freeRelayPort(int relayPortHandle);
public static native boolean checkRelayChannel(int pin);
public static native boolean checkRelayChannel(int channel);
public static native void setRelay(int relayPortHandle, boolean on);