Now you can download a copy of these docs so you can use them offline! Download now
Trigger.cpp
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2011. 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 $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #include "Buttons/Button.h"
8 
9 #include "Buttons/HeldButtonScheduler.h"
10 #include "Buttons/PressedButtonScheduler.h"
11 #include "Buttons/ReleasedButtonScheduler.h"
12 #include "Buttons/ToggleButtonScheduler.h"
13 #include "Buttons/CancelButtonScheduler.h"
14 
15 Trigger::Trigger() {
16  m_table = NULL;
17 }
18 
19 bool Trigger::Grab()
20 {
21  if (Get())
22  return true;
23  else if (m_table != NULL)
24  {
25  //if (m_table->isConnected())//TODO is connected on button?
26  return m_table->GetBoolean("pressed");
27  /*else
28  return false;*/
29  }
30  else
31  return false;
32 }
33 
34 void Trigger::WhenActive(Command *command)
35 {
36  PressedButtonScheduler *pbs = new PressedButtonScheduler(Grab(), this, command);
37  pbs->Start();
38 }
39 
40 void Trigger::WhileActive(Command *command)
41 {
42  HeldButtonScheduler *hbs = new HeldButtonScheduler(Grab(), this, command);
43  hbs->Start();
44 }
45 
46 void Trigger::WhenInactive(Command *command)
47 {
48  ReleasedButtonScheduler *rbs = new ReleasedButtonScheduler(Grab(), this, command);
49  rbs->Start();
50 }
51 
52 void Trigger::CancelWhenActive(Command *command) {
53  CancelButtonScheduler *cbs = new CancelButtonScheduler(Grab(), this, command);
54  cbs->Start();
55 }
56 
57 void Trigger::ToggleWhenActive(Command *command) {
58  ToggleButtonScheduler *tbs = new ToggleButtonScheduler(Grab(), this, command);
59  tbs->Start();
60 }
61 
63  return "Button";
64 }
65 
67  m_table = table;
68  if(m_table!=NULL){
69  m_table->PutBoolean("pressed", Get());
70  }
71 }
72 
74  return m_table;
75 }
virtual ITable * GetTable()
Definition: Trigger.cpp:73
virtual void InitTable(ITable *table)
Definition: Trigger.cpp:66
Definition: ITable.h:26
virtual std::string GetSmartDashboardType()
Definition: Trigger.cpp:62
virtual void PutBoolean(std::string key, bool value)=0
virtual bool GetBoolean(std::string key)=0

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6