mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Add Toggle() function to solenoid classes (#2635)
Toggling a solenoid on a button press is a common idiom, so this provides a more readable way of accomplishing that.
This commit is contained in:
@@ -56,6 +56,7 @@ Solenoid::~Solenoid() { HAL_FreeSolenoidPort(m_solenoidHandle); }
|
||||
|
||||
void Solenoid::Set(bool on) {
|
||||
if (StatusIsFatal()) return;
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetSolenoid(m_solenoidHandle, on, &status);
|
||||
wpi_setHALError(status);
|
||||
@@ -63,12 +64,16 @@ void Solenoid::Set(bool on) {
|
||||
|
||||
bool Solenoid::Get() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
|
||||
int32_t status = 0;
|
||||
bool value = HAL_GetSolenoid(m_solenoidHandle, &status);
|
||||
wpi_setHALError(status);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void Solenoid::Toggle() { Set(!Get()); }
|
||||
|
||||
bool Solenoid::IsBlackListed() const {
|
||||
int value = GetPCMSolenoidBlackList(m_moduleNumber) & (1 << m_channel);
|
||||
return (value != 0);
|
||||
|
||||
Reference in New Issue
Block a user