[commands] GenericHIDController: use composition in C++ (#6296)

This commit is contained in:
Jade
2024-05-25 07:36:05 +08:00
committed by GitHub
parent 221d568bd9
commit f1e072fc98
12 changed files with 469 additions and 129 deletions

View File

@@ -6,8 +6,14 @@
using namespace frc2;
CommandGenericHID::CommandGenericHID(int port) : m_hid{port} {}
frc::GenericHID& CommandGenericHID::GetHID() {
return m_hid;
}
Trigger CommandGenericHID::Button(int button, frc::EventLoop* loop) const {
return GenericHID::Button(button, loop).CastTo<Trigger>();
return m_hid.Button(button, loop).CastTo<Trigger>();
}
Trigger CommandGenericHID::POV(int angle, frc::EventLoop* loop) const {
@@ -16,7 +22,7 @@ Trigger CommandGenericHID::POV(int angle, frc::EventLoop* loop) const {
Trigger CommandGenericHID::POV(int pov, int angle, frc::EventLoop* loop) const {
return Trigger(loop,
[this, pov, angle] { return this->GetPOV(pov) == angle; });
[this, pov, angle] { return m_hid.GetPOV(pov) == angle; });
}
Trigger CommandGenericHID::POVUp(frc::EventLoop* loop) const {
@@ -58,13 +64,13 @@ Trigger CommandGenericHID::POVCenter(frc::EventLoop* loop) const {
Trigger CommandGenericHID::AxisLessThan(int axis, double threshold,
frc::EventLoop* loop) const {
return Trigger(loop, [this, axis, threshold]() {
return this->GetRawAxis(axis) < threshold;
return m_hid.GetRawAxis(axis) < threshold;
});
}
Trigger CommandGenericHID::AxisGreaterThan(int axis, double threshold,
frc::EventLoop* loop) const {
return Trigger(loop, [this, axis, threshold]() {
return this->GetRawAxis(axis) > threshold;
return m_hid.GetRawAxis(axis) > threshold;
});
}