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 | #pragma once |
| 9 | |
| 10 | #include <memory> |
| 11 | #include <string> |
| 12 | |
| 13 | #include "SmartDashboard/Sendable.h" |
| 14 | |
| 15 | namespace frc { |
| 16 | |
| 17 | class Command; |
| 18 | |
| 19 | /** |
| 20 | * This class provides an easy way to link commands to inputs. |
| 21 | * |
| 22 | * It is very easy to link a polled input to a command. For instance, you could |
| 23 | * link the trigger button of a joystick to a "score" command or an encoder |
| 24 | * reaching |
| 25 | * a particular value. |
| 26 | * |
| 27 | * It is encouraged that teams write a subclass of Trigger if they want to have |
| 28 | * something unusual (for instance, if they want to react to the user holding |
| 29 | * a button while the robot is reading a certain sensor input). For this, they |
| 30 | * only have to write the {@link Trigger#Get()} method to get the full |
| 31 | * functionality |
| 32 | * of the Trigger class. |
| 33 | */ |
| 34 | class Trigger : public Sendable { |
| 35 | public: |
| 36 | Trigger() = default; |
| 37 | virtual ~Trigger() = default; |
| 38 | bool Grab(); |
| 39 | virtual bool Get() = 0; |
| 40 | void WhenActive(Command* command); |
| 41 | void WhileActive(Command* command); |
| 42 | void WhenInactive(Command* command); |
| 43 | void CancelWhenActive(Command* command); |
| 44 | void ToggleWhenActive(Command* command); |
| 45 | |
| 46 | void InitTable(std::shared_ptr<ITable> subtable) override; |
| 47 | std::shared_ptr<ITable> GetTable() const override; |
| 48 | std::string GetSmartDashboardType() const override; |
| 49 | |
| 50 | protected: |
| 51 | std::shared_ptr<ITable> m_table; |
| 52 | }; |
| 53 | |
| 54 | } // namespace frc |