2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2017-08-18 21:35:53 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "hal/AnalogAccumulator.h"
|
2017-08-18 21:35:53 -07:00
|
|
|
|
|
|
|
|
#include "AnalogInternal.h"
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "mockdata/AnalogInDataInternal.h"
|
2017-08-18 21:35:53 -07:00
|
|
|
|
|
|
|
|
using namespace hal;
|
|
|
|
|
|
2017-12-10 19:38:53 -08:00
|
|
|
namespace hal {
|
|
|
|
|
namespace init {
|
|
|
|
|
void InitializeAnalogAccumulator() {}
|
|
|
|
|
} // namespace init
|
|
|
|
|
} // namespace hal
|
|
|
|
|
|
2017-08-18 21:35:53 -07:00
|
|
|
extern "C" {
|
|
|
|
|
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
|
|
|
|
|
int32_t* status) {
|
2017-12-10 19:38:53 -08:00
|
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
2017-08-18 21:35:53 -07:00
|
|
|
if (port == nullptr) {
|
|
|
|
|
*status = HAL_HANDLE_ERROR;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
for (int32_t i = 0; i < kNumAccumulators; i++) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (port->channel == kAccumulatorChannels[i]) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-18 21:35:53 -07:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
|
|
|
|
|
int32_t* status) {
|
2017-12-10 19:38:53 -08:00
|
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
2017-08-18 21:35:53 -07:00
|
|
|
if (port == nullptr) {
|
|
|
|
|
*status = HAL_HANDLE_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!HAL_IsAccumulatorChannel(analogPortHandle, status)) {
|
|
|
|
|
*status = HAL_INVALID_ACCUMULATOR_CHANNEL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
SimAnalogInData[port->channel].accumulatorInitialized = true;
|
2017-08-18 21:35:53 -07:00
|
|
|
}
|
|
|
|
|
void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
|
|
|
|
|
int32_t* status) {
|
2017-12-10 19:38:53 -08:00
|
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
2017-08-18 21:35:53 -07:00
|
|
|
if (port == nullptr) {
|
|
|
|
|
*status = HAL_HANDLE_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
SimAnalogInData[port->channel].accumulatorCenter = 0;
|
|
|
|
|
SimAnalogInData[port->channel].accumulatorCount = 0;
|
|
|
|
|
SimAnalogInData[port->channel].accumulatorValue = 0;
|
2017-08-18 21:35:53 -07:00
|
|
|
}
|
|
|
|
|
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
|
|
|
|
|
int32_t center, int32_t* status) {
|
2017-12-10 19:38:53 -08:00
|
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
2017-08-18 21:35:53 -07:00
|
|
|
if (port == nullptr) {
|
|
|
|
|
*status = HAL_HANDLE_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
SimAnalogInData[port->channel].accumulatorCenter = center;
|
2017-08-18 21:35:53 -07:00
|
|
|
}
|
|
|
|
|
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
|
|
|
|
|
int32_t deadband, int32_t* status) {
|
2017-12-10 19:38:53 -08:00
|
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
2017-08-18 21:35:53 -07:00
|
|
|
if (port == nullptr) {
|
|
|
|
|
*status = HAL_HANDLE_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
SimAnalogInData[port->channel].accumulatorDeadband = deadband;
|
2017-08-18 21:35:53 -07:00
|
|
|
}
|
|
|
|
|
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
|
|
|
|
|
int32_t* status) {
|
2017-12-10 19:38:53 -08:00
|
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
2017-08-18 21:35:53 -07:00
|
|
|
if (port == nullptr) {
|
|
|
|
|
*status = HAL_HANDLE_ERROR;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
return SimAnalogInData[port->channel].accumulatorValue;
|
2017-08-18 21:35:53 -07:00
|
|
|
}
|
|
|
|
|
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
|
|
|
|
|
int32_t* status) {
|
2017-12-10 19:38:53 -08:00
|
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
2017-08-18 21:35:53 -07:00
|
|
|
if (port == nullptr) {
|
|
|
|
|
*status = HAL_HANDLE_ERROR;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
return SimAnalogInData[port->channel].accumulatorCount;
|
2017-08-18 21:35:53 -07:00
|
|
|
}
|
|
|
|
|
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
|
|
|
|
|
int64_t* value, int64_t* count, int32_t* status) {
|
2017-12-10 19:38:53 -08:00
|
|
|
auto port = analogInputHandles->Get(analogPortHandle);
|
2017-08-18 21:35:53 -07:00
|
|
|
if (port == nullptr) {
|
|
|
|
|
*status = HAL_HANDLE_ERROR;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
*count = SimAnalogInData[port->channel].accumulatorCount;
|
|
|
|
|
*value = SimAnalogInData[port->channel].accumulatorValue;
|
2017-08-18 21:35:53 -07:00
|
|
|
}
|
2017-10-16 19:56:08 -07:00
|
|
|
} // extern "C"
|