Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wpilib] Add on/off, forward/reverse/off boolean methods to Solenoid and DoubleSolenoids #7079

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions wpilibc/src/main/native/cpp/DoubleSolenoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ void DoubleSolenoid::Toggle() {
}
}

bool DoubleSolenoid::IsForward() {
return Get() == kForward;
}

bool DoubleSolenoid::IsReverse() {
return Get() == kReverse;
}

bool DoubleSolenoid::IsOff() {
return Get() == kOff;
}

void DoubleSolenoid::SetForward() {
Set(kForward);
}

void DoubleSolenoid::SetReverse() {
Set(kReverse);
}

void DoubleSolenoid::SetOff() {
Set(kOff);
}

int DoubleSolenoid::GetFwdChannel() const {
return m_forwardChannel;
}
Expand Down
18 changes: 18 additions & 0 deletions wpilibc/src/main/native/cpp/Solenoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ bool Solenoid::Get() const {
return (currentAll & m_mask) != 0;
}

bool Solenoid::IsOn() const {
int currentAll = m_module->GetSolenoids();
return (currentAll & m_mask) != 0;
}

bool Solenoid::IsOff() const {
int currentAll = m_module->GetSolenoids();
return (currentAll & m_mask) == 0;
}

void Solenoid::SetOn() {
Set(true);
}

void Solenoid::SetOff() {
Set(false);
}

void Solenoid::Toggle() {
Set(!Get());
}
Expand Down
25 changes: 25 additions & 0 deletions wpilibc/src/main/native/cpp/simulation/DoubleSolenoidSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <memory>
#include <utility>

#include "frc/DoubleSolenoid.h"
#include "frc/PneumaticsBase.h"

using namespace frc;
Expand Down Expand Up @@ -46,6 +47,30 @@ void DoubleSolenoidSim::Set(DoubleSolenoid::Value output) {
m_module->SetSolenoidOutput(m_rev, output == DoubleSolenoid::Value::kReverse);
}

bool DoubleSolenoidSim::IsForward() {
return Get() == DoubleSolenoid::Value::kForward;
}

bool DoubleSolenoidSim::IsReverse() {
return Get() == DoubleSolenoid::Value::kReverse;
}

bool DoubleSolenoidSim::IsOff() {
return Get() == DoubleSolenoid::Value::kOff;
}

void DoubleSolenoidSim::SetForward() {
Set(DoubleSolenoid::Value::kForward);
}

void DoubleSolenoidSim::SetReverse() {
Set(DoubleSolenoid::Value::kReverse);
}

void DoubleSolenoidSim::SetOff() {
Set(DoubleSolenoid::Value::kOff);
}

std::shared_ptr<PneumaticsBaseSim> DoubleSolenoidSim::GetModuleSim() const {
return m_module;
}
16 changes: 16 additions & 0 deletions wpilibc/src/main/native/cpp/simulation/SolenoidSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ void SolenoidSim::SetOutput(bool output) {
m_module->SetSolenoidOutput(m_channel, output);
}

bool SolenoidSim::IsOn() {
return m_module->GetSolenoidOutput(m_channel);
}

bool SolenoidSim::IsOff() {
return !m_module->GetSolenoidOutput(m_channel);
}

void SolenoidSim::SetOn() {
m_module->SetSolenoidOutput(m_channel, true);
}

void SolenoidSim::SetOff() {
m_module->SetSolenoidOutput(m_channel, false);
}

std::unique_ptr<CallbackStore> SolenoidSim::RegisterOutputCallback(
NotifyCallback callback, bool initialNotify) {
return m_module->RegisterSolenoidOutputCallback(m_channel, callback,
Expand Down
33 changes: 33 additions & 0 deletions wpilibc/src/main/native/include/frc/DoubleSolenoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,39 @@ class DoubleSolenoid : public wpi::Sendable,
*/
void Toggle();

/**
* Returns true if the double solenoid is in a forward state.
* @return true if the double solenoid is in a forward state.
*/
bool IsForward();

/**
* Returns true if the double solenoid is in a reverse state.
* @return true if the double solenoid is in a reverse state.
*/
bool IsReverse();

/**
* Returns true if the double solenoid is in an off state.
* @return true if the double solenoid is in an off state.
*/
bool IsOff();

/**
* Sets the double solenoid to a forward state
*/
void SetForward();

/**
* Sets the double solenoid to a reverse state
*/
void SetReverse();

/**
* Sets the double solenoid to an off state
*/
void SetOff();

/**
* Get the forward channel.
*
Expand Down
26 changes: 26 additions & 0 deletions wpilibc/src/main/native/include/frc/Solenoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ class Solenoid : public wpi::Sendable, public wpi::SendableHelper<Solenoid> {
*/
bool Get() const;

/**
* Returns true if the solenoid is on.
*
* @return true if the solenoid is on.
*
*/
bool IsOn() const;

/**
* Returns true if the solenoid is off.
*
* @return true if the solenoid is off.
*
*/
bool IsOff() const;

/**
* Turns the solenoid on.
*/
void SetOn();

/**
* Turns the solenoid off.
*/
void SetOff();

/**
* Toggle the value of the solenoid.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,39 @@ class DoubleSolenoidSim {
DoubleSolenoid::Value Get() const;
void Set(DoubleSolenoid::Value output);

/**
* Returns true if the double solenoid is in a forward state.
* @return true if the double solenoid is in a forward state.
*/
bool IsForward();

/**
* Returns true if the double solenoid is in a reverse state.
* @return true if the double solenoid is in a reverse state.
*/
bool IsReverse();

/**
* Returns true if the double solenoid is in an off state.
* @return true if the double solenoid is in an off state.
*/
bool IsOff();

/**
* Sets the double solenoid to a forward state
*/
void SetForward();

/**
* Sets the double solenoid to a reverse state
*/
void SetReverse();

/**
* Sets the double solenoid to an off state
*/
void SetOff();

std::shared_ptr<PneumaticsBaseSim> GetModuleSim() const;

private:
Expand Down
37 changes: 37 additions & 0 deletions wpilibc/src/main/native/include/frc/simulation/SolenoidSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,46 @@ class SolenoidSim {
SolenoidSim(PneumaticsModuleType type, int channel);
~SolenoidSim() = default;

/**
* Returns the solenoid output.
* @return the solenoid output.
*/
[[deprecated("Use IsOn or IsOff methods instead.")]]
bool GetOutput() const;

/**
* Sets the solenoid output.
* @param output The new solenoid output.
*/
[[deprecated("Use SetOn or SetOff methods instead.")]]
void SetOutput(bool output);

/**
* Returns true if the solenoid is on.
*
* @return true if the solenoid is on.
*
*/
bool IsOn();

/**
* Returns true if the solenoid is off.
*
* @return true if the solenoid is off.
*
*/
bool IsOff();

/**
* Turns the solenoid on.
*/
void SetOn();

/**
* Turns the solenoid off.
*/
void SetOff();

/**
* Register a callback to be run when the output of this solenoid has changed.
*
Expand Down
42 changes: 42 additions & 0 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/DoubleSolenoid.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ public void set(final Value value) {
m_module.setSolenoids(m_mask, setValue);
}

/** Sets the double solenoid to a forward state. */
public void setForward() {
set(Value.kForward);
}

/** Sets the double solenoid to a reverse state. */
public void setReverse() {
set(Value.kReverse);
}

/** Sets the double solenoid to a off state. */
public void setOff() {
set(Value.kOff);
}

/**
* Read the current value of the solenoid.
*
Expand All @@ -152,6 +167,33 @@ public Value get() {
}
}

/**
* Returns true if the double solenoid is in a forward state.
*
* @return true if the double solenoid is in a forward state.
*/
public boolean isForward() {
return get() == Value.kForward;
}

/**
* Returns true if the double solenoid is in a reverse state.
*
* @return true if the double solenoid is in a reverse state.
*/
public boolean isReverse() {
return get() == Value.kReverse;
}

/**
* Returns true if the double solenoid is in an off state.
*
* @return true if the double solenoid in in an off state.
*/
public boolean isOff() {
return get() == Value.kOff;
}

/**
* Toggle the value of the solenoid.
*
Expand Down
30 changes: 30 additions & 0 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/Solenoid.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,36 @@ public boolean get() {
return (currentAll & m_mask) != 0;
}

/**
* Returns true if the solenoid is on.
*
* @return true if the solenoid is on.
*/
public boolean isOn() {
int currentAll = m_module.getSolenoids();
return (currentAll & m_mask) != 0;
}

/**
* Returns true if the solenoid is off.
*
* @return true if the solenoid off.
*/
public boolean isOff() {
int currentAll = m_module.getSolenoids();
return (currentAll & m_mask) == 0;
}

/** Turns the solenoid on. */
public void setOn() {
set(true);
}

/** Turns the solenoid off. */
public void setOff() {
set(false);
}

/**
* Toggle the value of the solenoid.
*
Expand Down
Loading
Loading