Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 2 | /* Copyright (c) FIRST 2011-2016. All Rights Reserved. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #ifndef __TRIGGER_H__ |
| 9 | #define __TRIGGER_H__ |
| 10 | |
| 11 | #include "SmartDashboard/Sendable.h" |
| 12 | #include <memory> |
| 13 | |
| 14 | class Command; |
| 15 | |
| 16 | /** |
| 17 | * This class provides an easy way to link commands to inputs. |
| 18 | * |
| 19 | * It is very easy to link a polled input to a command. For instance, you could |
| 20 | * link the trigger button of a joystick to a "score" command or an encoder |
| 21 | * reaching |
| 22 | * a particular value. |
| 23 | * |
| 24 | * It is encouraged that teams write a subclass of Trigger if they want to have |
| 25 | * something unusual (for instance, if they want to react to the user holding |
| 26 | * a button while the robot is reading a certain sensor input). For this, they |
| 27 | * only have to write the {@link Trigger#Get()} method to get the full |
| 28 | * functionality |
| 29 | * of the Trigger class. |
| 30 | * |
| 31 | * @author Brad Miller, Joe Grinstead |
| 32 | */ |
| 33 | class Trigger : public Sendable { |
| 34 | public: |
| 35 | Trigger() = default; |
| 36 | virtual ~Trigger() = default; |
| 37 | bool Grab(); |
| 38 | virtual bool Get() = 0; |
| 39 | void WhenActive(Command *command); |
| 40 | void WhileActive(Command *command); |
| 41 | void WhenInactive(Command *command); |
| 42 | void CancelWhenActive(Command *command); |
| 43 | void ToggleWhenActive(Command *command); |
| 44 | |
| 45 | virtual void InitTable(std::shared_ptr<ITable> table); |
| 46 | virtual std::shared_ptr<ITable> GetTable() const; |
| 47 | virtual std::string GetSmartDashboardType() const; |
| 48 | |
| 49 | protected: |
| 50 | std::shared_ptr<ITable> m_table; |
| 51 | }; |
| 52 | |
| 53 | #endif |