Now you can download a copy of these docs so you can use them offline! Download now
Button.cpp
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2011. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #include "Buttons/Button.h" 00008 00009 #include "Buttons/HeldButtonScheduler.h" 00010 #include "Buttons/PressedButtonScheduler.h" 00011 #include "Buttons/ReleasedButtonScheduler.h" 00012 #include "NetworkTables/NetworkTable.h" 00013 00014 Button::Button() { 00015 m_table = NULL; 00016 } 00017 00018 bool Button::Grab() 00019 { 00020 if (Get()) 00021 return true; 00022 else if (m_table != NULL) 00023 { 00024 if (m_table->IsConnected()) 00025 return m_table->GetBoolean("pressed"); 00026 else 00027 return false; 00028 } 00029 else 00030 return false; 00031 } 00032 00033 void Button::WhenPressed(Command *command) 00034 { 00035 PressedButtonScheduler *pbs = new PressedButtonScheduler(Grab(), this, command); 00036 pbs->Start(); 00037 } 00038 00039 void Button::WhileHeld(Command *command) 00040 { 00041 HeldButtonScheduler *hbs = new HeldButtonScheduler(Grab(), this, command); 00042 hbs->Start(); 00043 } 00044 00045 void Button::WhenReleased(Command *command) 00046 { 00047 ReleasedButtonScheduler *rbs = new ReleasedButtonScheduler(Grab(), this, command); 00048 rbs->Start(); 00049 } 00050 00051 NetworkTable* Button::GetTable() 00052 { 00053 if (m_table == NULL) 00054 { 00055 m_table = new NetworkTable(); 00056 m_table->PutBoolean("pressed", Get()); 00057 } 00058 return m_table; 00059 }
Generated on Thu Jan 12 2012 22:35:18 for WPILibC++ by
1.7.1