mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[hal, wpilib] Remove analog output (#7696)
This commit is contained in:
@@ -1,111 +0,0 @@
|
||||
// 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/AnalogOutput.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "HALInitializer.h"
|
||||
#include "HALInternal.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "hal/Errors.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "hal/handles/IndexedHandleResource.h"
|
||||
#include "mockdata/AnalogOutDataInternal.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace {
|
||||
struct AnalogOutput {
|
||||
uint8_t channel;
|
||||
std::string previousAllocation;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static IndexedHandleResource<HAL_AnalogOutputHandle, AnalogOutput,
|
||||
kNumAnalogOutputs, HAL_HandleEnum::AnalogOutput>*
|
||||
analogOutputHandles;
|
||||
|
||||
namespace hal::init {
|
||||
void InitializeAnalogOutput() {
|
||||
static IndexedHandleResource<HAL_AnalogOutputHandle, AnalogOutput,
|
||||
kNumAnalogOutputs, HAL_HandleEnum::AnalogOutput>
|
||||
aoH;
|
||||
analogOutputHandles = &aoH;
|
||||
}
|
||||
} // namespace hal::init
|
||||
|
||||
extern "C" {
|
||||
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(
|
||||
HAL_PortHandle portHandle, const char* allocationLocation,
|
||||
int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
int16_t channel = getPortHandleChannel(portHandle);
|
||||
if (channel == InvalidHandleIndex || channel >= kNumAnalogOutputs) {
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Output",
|
||||
0, kNumAnalogOutputs, channel);
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
HAL_AnalogOutputHandle handle;
|
||||
auto port = analogOutputHandles->Allocate(channel, &handle, status);
|
||||
|
||||
if (*status != 0) {
|
||||
if (port) {
|
||||
hal::SetLastErrorPreviouslyAllocated(status, "Analog Output", channel,
|
||||
port->previousAllocation);
|
||||
} else {
|
||||
hal::SetLastErrorIndexOutOfRange(status,
|
||||
"Invalid Index for Analog Output", 0,
|
||||
kNumAnalogOutputs, channel);
|
||||
}
|
||||
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
||||
}
|
||||
|
||||
port->channel = static_cast<uint8_t>(channel);
|
||||
|
||||
// Initialize sim analog input
|
||||
SimAnalogOutData[channel].initialized = true;
|
||||
|
||||
port->previousAllocation = allocationLocation ? allocationLocation : "";
|
||||
return handle;
|
||||
}
|
||||
|
||||
void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analogOutputHandle) {
|
||||
// no status, so no need to check for a proper free.
|
||||
auto port = analogOutputHandles->Get(analogOutputHandle);
|
||||
if (port == nullptr) {
|
||||
return;
|
||||
}
|
||||
analogOutputHandles->Free(analogOutputHandle);
|
||||
SimAnalogOutData[port->channel].initialized = false;
|
||||
}
|
||||
|
||||
HAL_Bool HAL_CheckAnalogOutputChannel(int32_t channel) {
|
||||
return channel < kNumAnalogOutputs && channel >= 0;
|
||||
}
|
||||
|
||||
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
|
||||
double voltage, int32_t* status) {
|
||||
auto port = analogOutputHandles->Get(analogOutputHandle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
SimAnalogOutData[port->channel].voltage = voltage;
|
||||
}
|
||||
|
||||
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analogOutputHandle,
|
||||
int32_t* status) {
|
||||
auto port = analogOutputHandles->Get(analogOutputHandle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return SimAnalogOutData[port->channel].voltage;
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -70,7 +70,6 @@ void InitializeHAL() {
|
||||
InitializeAddressableLEDData();
|
||||
InitializeAnalogGyroData();
|
||||
InitializeAnalogInData();
|
||||
InitializeAnalogOutData();
|
||||
InitializeAnalogTriggerData();
|
||||
InitializeCanData();
|
||||
InitializeCANAPI();
|
||||
@@ -94,7 +93,6 @@ void InitializeHAL() {
|
||||
InitializeAnalogGyro();
|
||||
InitializeAnalogInput();
|
||||
InitializeAnalogInternal();
|
||||
InitializeAnalogOutput();
|
||||
InitializeAnalogTrigger();
|
||||
InitializeCAN();
|
||||
InitializeConstants();
|
||||
|
||||
@@ -20,7 +20,6 @@ extern void InitializeAccelerometerData();
|
||||
extern void InitializeAddressableLEDData();
|
||||
extern void InitializeAnalogGyroData();
|
||||
extern void InitializeAnalogInData();
|
||||
extern void InitializeAnalogOutData();
|
||||
extern void InitializeAnalogTriggerData();
|
||||
extern void InitializeCanData();
|
||||
extern void InitializeCANAPI();
|
||||
@@ -45,7 +44,6 @@ extern void InitializeAnalogAccumulator();
|
||||
extern void InitializeAnalogGyro();
|
||||
extern void InitializeAnalogInput();
|
||||
extern void InitializeAnalogInternal();
|
||||
extern void InitializeAnalogOutput();
|
||||
extern void InitializeAnalogTrigger();
|
||||
extern void InitializeCAN();
|
||||
extern void InitializeConstants();
|
||||
|
||||
@@ -22,9 +22,6 @@ int32_t HAL_GetNumAnalogTriggers(void) {
|
||||
int32_t HAL_GetNumAnalogInputs(void) {
|
||||
return kNumAnalogInputs;
|
||||
}
|
||||
int32_t HAL_GetNumAnalogOutputs(void) {
|
||||
return kNumAnalogOutputs;
|
||||
}
|
||||
int32_t HAL_GetNumCounters(void) {
|
||||
return kNumCounters;
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
// 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 "../PortsInternal.h"
|
||||
#include "AnalogOutDataInternal.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
namespace hal::init {
|
||||
void InitializeAnalogOutData() {
|
||||
static AnalogOutData siod[kNumAnalogOutputs];
|
||||
::hal::SimAnalogOutData = siod;
|
||||
}
|
||||
} // namespace hal::init
|
||||
|
||||
AnalogOutData* hal::SimAnalogOutData;
|
||||
void AnalogOutData::ResetData() {
|
||||
voltage.Reset(0.0);
|
||||
initialized.Reset(0);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void HALSIM_ResetAnalogOutData(int32_t index) {
|
||||
SimAnalogOutData[index].ResetData();
|
||||
}
|
||||
|
||||
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
|
||||
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, AnalogOut##CAPINAME, \
|
||||
SimAnalogOutData, LOWERNAME)
|
||||
|
||||
DEFINE_CAPI(double, Voltage, voltage)
|
||||
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
|
||||
|
||||
#define REGISTER(NAME) \
|
||||
SimAnalogOutData[index].NAME.RegisterCallback(callback, param, initialNotify)
|
||||
|
||||
void HALSIM_RegisterAnalogOutAllCallbacks(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify) {
|
||||
REGISTER(voltage);
|
||||
REGISTER(initialized);
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -1,22 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/simulation/AnalogOutData.h"
|
||||
#include "hal/simulation/SimDataValue.h"
|
||||
|
||||
namespace hal {
|
||||
class AnalogOutData {
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(Voltage)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
|
||||
|
||||
public:
|
||||
SimDataValue<double, HAL_MakeDouble, GetVoltageName> voltage{0.0};
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{0};
|
||||
|
||||
virtual void ResetData();
|
||||
};
|
||||
extern AnalogOutData* SimAnalogOutData;
|
||||
} // namespace hal
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <hal/simulation/AddressableLEDData.h>
|
||||
#include <hal/simulation/AnalogGyroData.h>
|
||||
#include <hal/simulation/AnalogInData.h>
|
||||
#include <hal/simulation/AnalogOutData.h>
|
||||
#include <hal/simulation/AnalogTriggerData.h>
|
||||
#include <hal/simulation/CTREPCMData.h>
|
||||
#include <hal/simulation/CanData.h>
|
||||
@@ -43,10 +42,6 @@ extern "C" void HALSIM_ResetAllSimData(void) {
|
||||
HALSIM_ResetAnalogInData(i);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < hal::kNumAnalogOutputs; i++) {
|
||||
HALSIM_ResetAnalogOutData(i);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < hal::kNumAnalogTriggers; i++) {
|
||||
HALSIM_ResetAnalogTriggerData(i);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user