Brian Silverman | 890a32a | 2018-03-11 15:41:56 -0700 | [diff] [blame^] | 1 | #include "ctre/phoenix/Tasking/ButtonMonitor.h" |
| 2 | #include <GenericHID.h> // WPILIB |
| 3 | |
| 4 | #ifndef CTR_EXCLUDE_WPILIB_CLASSES |
| 5 | |
| 6 | namespace ctre { |
| 7 | namespace phoenix { |
| 8 | namespace tasking { |
| 9 | |
| 10 | ButtonMonitor::ButtonMonitor(frc::GenericHID * controller, int buttonIndex, |
| 11 | IButtonPressEventHandler * ButtonPressEventHandler) { |
| 12 | _gameCntrlr = controller; |
| 13 | _btnIdx = buttonIndex; |
| 14 | _handler = ButtonPressEventHandler; |
| 15 | } |
| 16 | ButtonMonitor::ButtonMonitor(const ButtonMonitor & rhs) { |
| 17 | _gameCntrlr = rhs._gameCntrlr; |
| 18 | _btnIdx = rhs._btnIdx; |
| 19 | _handler = rhs._handler; |
| 20 | } |
| 21 | |
| 22 | void ButtonMonitor::Process() { |
| 23 | bool down = ((frc::GenericHID*)_gameCntrlr)->GetRawButton(_btnIdx); |
| 24 | |
| 25 | if (!_isDown && down) |
| 26 | _handler->OnButtonPress(_btnIdx, down); |
| 27 | |
| 28 | _isDown = down; |
| 29 | } |
| 30 | |
| 31 | void ButtonMonitor::OnStart() { |
| 32 | } |
| 33 | void ButtonMonitor::OnLoop() { |
| 34 | Process(); |
| 35 | } |
| 36 | bool ButtonMonitor::IsDone() { |
| 37 | return false; |
| 38 | } |
| 39 | void ButtonMonitor::OnStop() { |
| 40 | } |
| 41 | |
| 42 | } // namespace tasking |
| 43 | } // namespace phoenix |
| 44 | } // namespace ctre |
| 45 | |
| 46 | #endif // CTR_EXCLUDE_WPILIB_CLASSES |