mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
The warnings included recommendations of braces for if statement readability, a recommendation for default initialization of an int array, and include-what-you-use (indirectly through clang-tidy reporting undefined symbols).
137 lines
3.7 KiB
C++
137 lines
3.7 KiB
C++
// Copyright (c) FIRST and other WPILib contributors.
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
#include "hal/AnalogAccumulator.h"
|
|
|
|
#include "AnalogInternal.h"
|
|
#include "hal/HAL.h"
|
|
|
|
using namespace hal;
|
|
|
|
namespace hal::init {
|
|
void InitializeAnalogAccumulator() {}
|
|
} // namespace hal::init
|
|
|
|
extern "C" {
|
|
|
|
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
|
|
int32_t* status) {
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
|
if (port == nullptr) {
|
|
*status = HAL_HANDLE_ERROR;
|
|
return false;
|
|
}
|
|
for (int32_t i = 0; i < kNumAccumulators; i++) {
|
|
if (port->channel == kAccumulatorChannels[i]) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
|
|
int32_t* status) {
|
|
if (!HAL_IsAccumulatorChannel(analogPortHandle, status)) {
|
|
*status = HAL_INVALID_ACCUMULATOR_CHANNEL;
|
|
return;
|
|
}
|
|
HAL_SetAccumulatorCenter(analogPortHandle, 0, status);
|
|
HAL_ResetAccumulator(analogPortHandle, status);
|
|
}
|
|
|
|
void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
|
|
int32_t* status) {
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
|
if (port == nullptr) {
|
|
*status = HAL_HANDLE_ERROR;
|
|
return;
|
|
}
|
|
if (port->accumulator == nullptr) {
|
|
*status = NULL_PARAMETER;
|
|
return;
|
|
}
|
|
port->accumulator->strobeReset(status);
|
|
}
|
|
|
|
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
|
|
int32_t center, int32_t* status) {
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
|
if (port == nullptr) {
|
|
*status = HAL_HANDLE_ERROR;
|
|
return;
|
|
}
|
|
if (port->accumulator == nullptr) {
|
|
*status = NULL_PARAMETER;
|
|
return;
|
|
}
|
|
port->accumulator->writeCenter(center, status);
|
|
}
|
|
|
|
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
|
|
int32_t deadband, int32_t* status) {
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
|
if (port == nullptr) {
|
|
*status = HAL_HANDLE_ERROR;
|
|
return;
|
|
}
|
|
if (port->accumulator == nullptr) {
|
|
*status = NULL_PARAMETER;
|
|
return;
|
|
}
|
|
port->accumulator->writeDeadband(deadband, status);
|
|
}
|
|
|
|
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
|
|
int32_t* status) {
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
|
if (port == nullptr) {
|
|
*status = HAL_HANDLE_ERROR;
|
|
return 0;
|
|
}
|
|
if (port->accumulator == nullptr) {
|
|
*status = NULL_PARAMETER;
|
|
return 0;
|
|
}
|
|
int64_t value = port->accumulator->readOutput_Value(status);
|
|
return value;
|
|
}
|
|
|
|
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
|
|
int32_t* status) {
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
|
if (port == nullptr) {
|
|
*status = HAL_HANDLE_ERROR;
|
|
return 0;
|
|
}
|
|
if (port->accumulator == nullptr) {
|
|
*status = NULL_PARAMETER;
|
|
return 0;
|
|
}
|
|
return port->accumulator->readOutput_Count(status);
|
|
}
|
|
|
|
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
|
|
int64_t* value, int64_t* count, int32_t* status) {
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
|
if (port == nullptr) {
|
|
*status = HAL_HANDLE_ERROR;
|
|
return;
|
|
}
|
|
if (port->accumulator == nullptr) {
|
|
*status = NULL_PARAMETER;
|
|
return;
|
|
}
|
|
if (value == nullptr || count == nullptr) {
|
|
*status = NULL_PARAMETER;
|
|
return;
|
|
}
|
|
|
|
tAccumulator::tOutput output = port->accumulator->readOutput(status);
|
|
|
|
*value = output.Value;
|
|
*count = output.Count;
|
|
}
|
|
|
|
} // extern "C"
|