blob: f0e6bf3a20f436000ce089fb7999d6dd591dc3d8 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
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
15using namespace frc;
16
17bool 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
27void Trigger::WhenActive(Command* command) {
28 auto pbs = new PressedButtonScheduler(Grab(), this, command);
29 pbs->Start();
30}
31
32void Trigger::WhileActive(Command* command) {
33 auto hbs = new HeldButtonScheduler(Grab(), this, command);
34 hbs->Start();
35}
36
37void Trigger::WhenInactive(Command* command) {
38 auto rbs = new ReleasedButtonScheduler(Grab(), this, command);
39 rbs->Start();
40}
41
42void Trigger::CancelWhenActive(Command* command) {
43 auto cbs = new CancelButtonScheduler(Grab(), this, command);
44 cbs->Start();
45}
46
47void Trigger::ToggleWhenActive(Command* command) {
48 auto tbs = new ToggleButtonScheduler(Grab(), this, command);
49 tbs->Start();
50}
51
52std::string Trigger::GetSmartDashboardType() const { return "Button"; }
53
54void 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
61std::shared_ptr<ITable> Trigger::GetTable() const { return m_table; }