Now you can download a copy of these docs so you can use them offline! Download now
SmartDashboard.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 "SmartDashboard/SmartDashboard.h" 00008 00009 #include "NetworkTables/NetworkTable.h" 00010 #include "SmartDashboard/SmartDashboardData.h" 00011 #include "SmartDashboard/SmartDashboardNamedData.h" 00012 #include "WPIErrors.h" 00013 00014 SmartDashboard *SmartDashboard::_instance = NULL; 00015 00023 SmartDashboard::SmartDashboard() 00024 { 00025 AddToSingletonList(); 00026 m_table = NetworkTable::GetTable("SmartDashboard"); 00027 } 00028 00029 SmartDashboard::~SmartDashboard() 00030 { 00031 } 00032 00037 SmartDashboard *SmartDashboard::GetInstance() 00038 { 00039 if (_instance == NULL) 00040 { 00041 _instance = new SmartDashboard(); 00042 } 00043 return _instance; 00044 } 00045 00046 00054 void SmartDashboard::PutData(const char *keyName, SmartDashboardData *value) 00055 { 00056 if (keyName == NULL) 00057 { 00058 wpi_setWPIErrorWithContext(NullParameter, "keyName"); 00059 return; 00060 } 00061 if (value == NULL) 00062 { 00063 wpi_setWPIErrorWithContext(NullParameter, "value"); 00064 return; 00065 } 00066 NetworkTable *type = new NetworkTable(); 00067 type->PutString("~TYPE~", value->GetType()); 00068 type->PutSubTable("Data", value->GetTable()); 00069 m_table->PutSubTable(keyName, type); 00070 m_tablesToData[type] = value; 00071 } 00072 00079 void SmartDashboard::PutData(SmartDashboardNamedData *value) 00080 { 00081 if (value == NULL) 00082 { 00083 wpi_setWPIErrorWithContext(NullParameter, "value"); 00084 return; 00085 } 00086 PutData(value->GetName().c_str(), value); 00087 } 00088 00094 SmartDashboardData *SmartDashboard::GetData(const char *keyName) 00095 { 00096 if (keyName == NULL) 00097 { 00098 wpi_setWPIErrorWithContext(NullParameter, "keyName"); 00099 return NULL; 00100 } 00101 NetworkTable *subtable = m_table->GetSubTable(keyName); 00102 SmartDashboardData *data = m_tablesToData[subtable]; 00103 if (data == NULL) 00104 { 00105 wpi_setWPIErrorWithContext(SmartDashboardMissingKey, keyName); 00106 return NULL; 00107 } 00108 return data; 00109 } 00110 00118 void SmartDashboard::PutBoolean(const char *keyName, bool value) 00119 { 00120 m_table->PutBoolean(keyName, value); 00121 } 00122 00128 bool SmartDashboard::GetBoolean(const char *keyName) 00129 { 00130 return m_table->GetBoolean(keyName); 00131 } 00132 00140 void SmartDashboard::PutInt(const char *keyName, int value) 00141 { 00142 m_table->PutInt(keyName, value); 00143 } 00144 00150 int SmartDashboard::GetInt(const char *keyName) 00151 { 00152 return m_table->GetInt(keyName); 00153 } 00154 00162 void SmartDashboard::PutDouble(const char *keyName, double value) 00163 { 00164 m_table->PutDouble(keyName, value); 00165 } 00166 00172 double SmartDashboard::GetDouble(const char *keyName) 00173 { 00174 return m_table->GetDouble(keyName); 00175 } 00176 00184 void SmartDashboard::PutString(const char *keyName, const char *value) 00185 { 00186 m_table->PutString(keyName, value); 00187 } 00188 00196 int SmartDashboard::GetString(const char *keyName, char *value, int valueLen) 00197 { 00198 return m_table->GetString(keyName, value, valueLen); 00199 } 00200 00208 void SmartDashboard::PutString(std::string keyName, std::string value) 00209 { 00210 m_table->PutString(keyName, value); 00211 } 00212 00218 std::string SmartDashboard::GetString(std::string keyName) 00219 { 00220 return m_table->GetString(keyName); 00221 } 00222 00226 void SmartDashboard::init() 00227 { 00228 } 00229 00237 int SmartDashboard::LogChar(char value, const char *name) 00238 { 00239 GetInstance()->PutInt(name, value); 00240 return 0; 00241 } 00242 00250 int SmartDashboard::LogChar(wchar_t value, const char *name) 00251 { 00252 GetInstance()->PutInt(name, value); 00253 return 0; 00254 } 00255 00263 int SmartDashboard::Log(INT32 value, const char *name) 00264 { 00265 GetInstance()->PutInt(name, value); 00266 return 0; 00267 } 00268 00276 int SmartDashboard::Log(INT64 value, const char *name) 00277 { 00278 GetInstance()->PutDouble(name, value); 00279 return 0; 00280 } 00281 00289 int SmartDashboard::Log(bool value, const char *name) 00290 { 00291 GetInstance()->PutBoolean(name, value); 00292 return 0; 00293 } 00294 00302 int SmartDashboard::Log(float value, const char *name) 00303 { 00304 GetInstance()->PutDouble(name, value); 00305 return 0; 00306 } 00307 00315 int SmartDashboard::Log(double value, const char *name) 00316 { 00317 GetInstance()->PutDouble(name, value); 00318 return 0; 00319 } 00320 00328 int SmartDashboard::Log(const char* value, const char *name) 00329 { 00330 GetInstance()->PutString(name, value); 00331 return 0; 00332 }
Generated on Thu Jan 12 2012 22:35:24 for WPILibC++ by
1.7.1