mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
Switches PWM and DIO to Handles (#120)
This commit is contained in:
committed by
Peter Johnson
parent
9b2af0d090
commit
3593ecb17e
@@ -34,8 +34,13 @@ DigitalInput::DigitalInput(uint32_t channel) {
|
||||
m_channel = channel;
|
||||
|
||||
int32_t status = 0;
|
||||
allocateDIO(m_digital_ports[channel], true, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
m_handle = initializeDIOPort(getPort(channel), true, &status);
|
||||
if (status != 0) {
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
m_handle = HAL_INVALID_HANDLE;
|
||||
m_channel = std::numeric_limits<uint32_t>::max();
|
||||
return;
|
||||
}
|
||||
|
||||
LiveWindow::GetInstance()->AddSensor("DigitalInput", channel, this);
|
||||
HALReport(HALUsageReporting::kResourceType_DigitalInput, channel);
|
||||
@@ -53,9 +58,7 @@ DigitalInput::~DigitalInput() {
|
||||
m_interrupt = HAL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
freeDIO(m_digital_ports[m_channel], &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
freeDIOPort(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +69,7 @@ DigitalInput::~DigitalInput() {
|
||||
bool DigitalInput::Get() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
int32_t status = 0;
|
||||
bool value = getDIO(m_digital_ports[m_channel], &status);
|
||||
bool value = getDIO(m_handle, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
return value;
|
||||
}
|
||||
@@ -91,6 +94,11 @@ uint32_t DigitalInput::GetModuleForRouting() const { return 0; }
|
||||
*/
|
||||
bool DigitalInput::GetAnalogTriggerForRouting() const { return false; }
|
||||
|
||||
/**
|
||||
* @return The HAL Handle to the specified source.
|
||||
*/
|
||||
HalHandle DigitalInput::GetPortHandle() const { return m_handle; }
|
||||
|
||||
void DigitalInput::UpdateTable() {
|
||||
if (m_table != nullptr) {
|
||||
m_table->PutBoolean("Value", Get());
|
||||
|
||||
Reference in New Issue
Block a user