From d8f11eb149f1147d6d28d1add391319b191ac170 Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 6 Dec 2019 20:56:40 -0800 Subject: [PATCH] Hardcode channels for LSB weight (#2153) Avoids a mutex and a lookup. --- hal/src/main/native/athena/AnalogInput.cpp | 44 ++++++++++++++-------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/hal/src/main/native/athena/AnalogInput.cpp b/hal/src/main/native/athena/AnalogInput.cpp index 9002aea994..1d502b9864 100644 --- a/hal/src/main/native/athena/AnalogInput.cpp +++ b/hal/src/main/native/athena/AnalogInput.cpp @@ -224,26 +224,38 @@ double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle, int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle, int32_t* status) { - auto port = analogInputHandles->Get(analogPortHandle); - if (port == nullptr) { - *status = HAL_HANDLE_ERROR; - return 0; - } - int32_t lsbWeight = FRC_NetworkCommunication_nAICalibration_getLSBWeight( - 0, port->channel, status); // XXX: aiSystemIndex == 0? - return lsbWeight; + // On the roboRIO, LSB is the same for all channels. So the channel lookup can + // be avoided + return FRC_NetworkCommunication_nAICalibration_getLSBWeight(0, 0, status); + + // Keep the old code for future hardware + + // auto port = analogInputHandles->Get(analogPortHandle); + // if (port == nullptr) { + // *status = HAL_HANDLE_ERROR; + // return 0; + // } + // int32_t lsbWeight = FRC_NetworkCommunication_nAICalibration_getLSBWeight( + // 0, port->channel, status); // XXX: aiSystemIndex == 0? + // return lsbWeight; } int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle, int32_t* status) { - auto port = analogInputHandles->Get(analogPortHandle); - if (port == nullptr) { - *status = HAL_HANDLE_ERROR; - return 0; - } - int32_t offset = FRC_NetworkCommunication_nAICalibration_getOffset( - 0, port->channel, status); // XXX: aiSystemIndex == 0? - return offset; + // On the roboRIO, offset is the same for all channels. So the channel lookup + // can be avoided + return FRC_NetworkCommunication_nAICalibration_getOffset(0, 0, status); + + // Keep the old code for future hardware + + // auto port = analogInputHandles->Get(analogPortHandle); + // if (port == nullptr) { + // *status = HAL_HANDLE_ERROR; + // return 0; + // } + // int32_t offset = FRC_NetworkCommunication_nAICalibration_getOffset( + // 0, port->channel, status); // XXX: aiSystemIndex == 0? + // return offset; } } // extern "C"