jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame] | 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 |
|
| 13 | Trigger::Trigger() {
|
| 14 | m_table = NULL;
|
| 15 | }
|
| 16 |
|
| 17 | bool Trigger::Grab()
|
| 18 | {
|
| 19 | if (Get())
|
| 20 | return true;
|
| 21 | else if (m_table != NULL)
|
| 22 | {
|
| 23 | //if (m_table->isConnected())//TODO is connected on button?
|
| 24 | return m_table->GetBoolean("pressed");
|
| 25 | /*else
|
| 26 | return false;*/
|
| 27 | }
|
| 28 | else
|
| 29 | return false;
|
| 30 | }
|
| 31 |
|
| 32 | void Trigger::WhenActive(Command *command)
|
| 33 | {
|
| 34 | PressedButtonScheduler *pbs = new PressedButtonScheduler(Grab(), this, command);
|
| 35 | pbs->Start();
|
| 36 | }
|
| 37 |
|
| 38 | void Trigger::WhileActive(Command *command)
|
| 39 | {
|
| 40 | HeldButtonScheduler *hbs = new HeldButtonScheduler(Grab(), this, command);
|
| 41 | hbs->Start();
|
| 42 | }
|
| 43 |
|
| 44 | void Trigger::WhenInactive(Command *command)
|
| 45 | {
|
| 46 | ReleasedButtonScheduler *rbs = new ReleasedButtonScheduler(Grab(), this, command);
|
| 47 | rbs->Start();
|
| 48 | }
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 | std::string Trigger::GetSmartDashboardType(){
|
| 53 | return "Button";
|
| 54 | }
|
| 55 |
|
| 56 | void Trigger::InitTable(ITable* table){
|
| 57 | m_table = table;
|
| 58 | if(m_table!=NULL){
|
| 59 | m_table->PutBoolean("pressed", Get());
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | ITable* Trigger::GetTable(){
|
| 64 | return m_table;
|
| 65 | }
|