Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2011-2017. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "Buttons/Button.h" |
| 9 | #include "Buttons/CancelButtonScheduler.h" |
| 10 | #include "Buttons/HeldButtonScheduler.h" |
| 11 | #include "Buttons/PressedButtonScheduler.h" |
| 12 | #include "Buttons/ReleasedButtonScheduler.h" |
| 13 | #include "Buttons/ToggleButtonScheduler.h" |
| 14 | |
| 15 | using namespace frc; |
| 16 | |
| 17 | bool Trigger::Grab() { |
| 18 | if (Get()) { |
| 19 | return true; |
| 20 | } else if (m_table != nullptr) { |
| 21 | return m_table->GetBoolean("pressed", false); |
| 22 | } else { |
| 23 | return false; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | void Trigger::WhenActive(Command* command) { |
| 28 | auto pbs = new PressedButtonScheduler(Grab(), this, command); |
| 29 | pbs->Start(); |
| 30 | } |
| 31 | |
| 32 | void Trigger::WhileActive(Command* command) { |
| 33 | auto hbs = new HeldButtonScheduler(Grab(), this, command); |
| 34 | hbs->Start(); |
| 35 | } |
| 36 | |
| 37 | void Trigger::WhenInactive(Command* command) { |
| 38 | auto rbs = new ReleasedButtonScheduler(Grab(), this, command); |
| 39 | rbs->Start(); |
| 40 | } |
| 41 | |
| 42 | void Trigger::CancelWhenActive(Command* command) { |
| 43 | auto cbs = new CancelButtonScheduler(Grab(), this, command); |
| 44 | cbs->Start(); |
| 45 | } |
| 46 | |
| 47 | void Trigger::ToggleWhenActive(Command* command) { |
| 48 | auto tbs = new ToggleButtonScheduler(Grab(), this, command); |
| 49 | tbs->Start(); |
| 50 | } |
| 51 | |
| 52 | std::string Trigger::GetSmartDashboardType() const { return "Button"; } |
| 53 | |
| 54 | void Trigger::InitTable(std::shared_ptr<ITable> subtable) { |
| 55 | m_table = subtable; |
| 56 | if (m_table != nullptr) { |
| 57 | m_table->PutBoolean("pressed", Get()); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | std::shared_ptr<ITable> Trigger::GetTable() const { return m_table; } |