2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-08-23 22:06:13 -07:00
|
|
|
/* Copyright (c) 2011-2017 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2016-05-25 22:40:15 -07:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
#include <atomic>
|
2016-09-05 13:55:31 -07:00
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
#include "SmartDashboard/SendableBase.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
class Command;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class provides an easy way to link commands to inputs.
|
|
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* It is very easy to link a polled input to a command. For instance, you could
|
2015-06-25 15:07:55 -04:00
|
|
|
* link the trigger button of a joystick to a "score" command or an encoder
|
2017-11-16 00:33:51 -08:00
|
|
|
* reaching a particular value.
|
2013-12-15 18:30:16 -05:00
|
|
|
*
|
|
|
|
|
* It is encouraged that teams write a subclass of Trigger if they want to have
|
|
|
|
|
* something unusual (for instance, if they want to react to the user holding
|
2017-11-16 00:33:51 -08:00
|
|
|
* a button while the robot is reading a certain sensor input). For this, they
|
2015-06-25 15:07:55 -04:00
|
|
|
* only have to write the {@link Trigger#Get()} method to get the full
|
2017-11-16 00:33:51 -08:00
|
|
|
* functionality of the Trigger class.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2017-12-04 23:28:33 -08:00
|
|
|
class Trigger : public SendableBase {
|
2015-06-25 15:07:55 -04:00
|
|
|
public:
|
2015-06-24 01:06:29 -07:00
|
|
|
Trigger() = default;
|
2017-12-04 23:28:33 -08:00
|
|
|
~Trigger() override = default;
|
2015-06-25 15:07:55 -04:00
|
|
|
bool Grab();
|
|
|
|
|
virtual bool Get() = 0;
|
2016-05-20 17:30:37 -07:00
|
|
|
void WhenActive(Command* command);
|
|
|
|
|
void WhileActive(Command* command);
|
|
|
|
|
void WhenInactive(Command* command);
|
|
|
|
|
void CancelWhenActive(Command* command);
|
|
|
|
|
void ToggleWhenActive(Command* command);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
void InitSendable(SendableBuilder& builder) override;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
private:
|
|
|
|
|
std::atomic_bool m_sendablePressed{false};
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|