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