mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Switches AnalogInputs and AnalogTriggers to Handles (#117)
Results in a breaking change to AnalogTrigger int constructor. If a user wants multiple AnalogTriggers, they must use the AnalogInput constructor.
This commit is contained in:
committed by
Peter Johnson
parent
77a1af44c4
commit
e8e052712e
@@ -14,8 +14,6 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
static std::unique_ptr<Resource> inputs;
|
||||
|
||||
const uint8_t AnalogInput::kAccumulatorModuleNumber;
|
||||
const uint32_t AnalogInput::kAccumulatorNumChannels;
|
||||
const uint32_t AnalogInput::kAccumulatorChannels[] = {0, 1};
|
||||
@@ -29,25 +27,23 @@ const uint32_t AnalogInput::kAccumulatorChannels[] = {0, 1};
|
||||
AnalogInput::AnalogInput(uint32_t channel) {
|
||||
std::stringstream buf;
|
||||
buf << "Analog Input " << channel;
|
||||
Resource::CreateResourceObject(inputs, kAnalogInputs);
|
||||
|
||||
if (!checkAnalogInputChannel(channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputs->Allocate(channel, buf.str()) ==
|
||||
std::numeric_limits<uint32_t>::max()) {
|
||||
CloneError(*inputs);
|
||||
return;
|
||||
}
|
||||
|
||||
m_channel = channel;
|
||||
|
||||
HalPortHandle port = getPort(channel);
|
||||
int32_t status = 0;
|
||||
m_port = initializeAnalogInputPort(port, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
if (status != 0) {
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
m_channel = std::numeric_limits<uint32_t>::max();
|
||||
m_port = HAL_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
|
||||
LiveWindow::GetInstance()->AddSensor("AnalogInput", channel, this);
|
||||
HALReport(HALUsageReporting::kResourceType_AnalogChannel, channel);
|
||||
@@ -58,7 +54,7 @@ AnalogInput::AnalogInput(uint32_t channel) {
|
||||
*/
|
||||
AnalogInput::~AnalogInput() {
|
||||
freeAnalogInputPort(m_port);
|
||||
inputs->Free(m_channel);
|
||||
m_port = HAL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user