mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
Switches Solenoids to Handles (#126)
This commit is contained in:
committed by
Peter Johnson
parent
62c217cd01
commit
8c4ad62422
@@ -39,12 +39,13 @@ Solenoid::Solenoid(uint8_t moduleNumber, uint32_t channel)
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
Resource::CreateResourceObject(m_allocated, m_maxModules * m_maxPorts);
|
||||
buf << "Solenoid " << m_channel << " (Module: " << m_moduleNumber << ")";
|
||||
if (m_allocated->Allocate(m_moduleNumber * kSolenoidChannels + m_channel,
|
||||
buf.str()) ==
|
||||
std::numeric_limits<uint32_t>::max()) {
|
||||
CloneError(*m_allocated);
|
||||
|
||||
int32_t status = 0;
|
||||
m_solenoidHandle =
|
||||
initializeSolenoidPort(getPortWithModule(moduleNumber, channel), &status);
|
||||
if (status != 0) {
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
m_solenoidHandle = HAL_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,9 +59,7 @@ Solenoid::Solenoid(uint8_t moduleNumber, uint32_t channel)
|
||||
* Destructor.
|
||||
*/
|
||||
Solenoid::~Solenoid() {
|
||||
if (CheckSolenoidModule(m_moduleNumber)) {
|
||||
m_allocated->Free(m_moduleNumber * kSolenoidChannels + m_channel);
|
||||
}
|
||||
freeSolenoidPort(m_solenoidHandle);
|
||||
if (m_table != nullptr) m_table->RemoveTableListener(this);
|
||||
}
|
||||
|
||||
@@ -71,10 +70,9 @@ Solenoid::~Solenoid() {
|
||||
*/
|
||||
void Solenoid::Set(bool on) {
|
||||
if (StatusIsFatal()) return;
|
||||
uint8_t value = on ? 0xFF : 0x00;
|
||||
uint8_t mask = 1 << m_channel;
|
||||
|
||||
SolenoidBase::Set(value, mask, m_moduleNumber);
|
||||
int32_t status = 0;
|
||||
setSolenoid(m_solenoidHandle, on, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,8 +82,10 @@ void Solenoid::Set(bool on) {
|
||||
*/
|
||||
bool Solenoid::Get() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
uint8_t value = GetAll(m_moduleNumber) & (1 << m_channel);
|
||||
return (value != 0);
|
||||
int32_t status = 0;
|
||||
bool value = getSolenoid(m_solenoidHandle, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user