diff --git a/wpilibc/wpilibC++/include/SmartDashboard/SmartDashboard.h b/wpilibc/wpilibC++/include/SmartDashboard/SmartDashboard.h index 3fae9d4517..5906c0f76a 100644 --- a/wpilibc/wpilibC++/include/SmartDashboard/SmartDashboard.h +++ b/wpilibc/wpilibC++/include/SmartDashboard/SmartDashboard.h @@ -19,21 +19,21 @@ class SmartDashboard : public SensorBase { public: static void init(); - + static void PutData(std::string key, Sendable *data); static void PutData(NamedSendable *value); - //static Sendable* GetData(std::string keyName); - + static Sendable* GetData(std::string keyName); + static void PutBoolean(std::string keyName, bool value); static bool GetBoolean(std::string keyName); - + static void PutNumber(std::string keyName, double value); static double GetNumber(std::string keyName); - + static void PutString(std::string keyName, std::string value); static int GetString(std::string keyName, char *value, unsigned int valueLen); static std::string GetString(std::string keyName); - + static void PutValue(std::string keyName, ComplexData& value); static void RetrieveValue(std::string keyName, ComplexData& value); private: @@ -43,8 +43,8 @@ private: /** The {@link NetworkTable} used by {@link SmartDashboard} */ static ITable* m_table; - - /** + + /** * A map linking tables in the SmartDashboard to the {@link SmartDashboardData} objects * they came from. */ @@ -52,4 +52,3 @@ private: }; #endif - diff --git a/wpilibc/wpilibC++/lib/SmartDashboard/SmartDashboard.cpp b/wpilibc/wpilibC++/lib/SmartDashboard/SmartDashboard.cpp index a5b40c582e..4c77b83e95 100644 --- a/wpilibc/wpilibC++/lib/SmartDashboard/SmartDashboard.cpp +++ b/wpilibc/wpilibC++/lib/SmartDashboard/SmartDashboard.cpp @@ -16,9 +16,9 @@ std::map SmartDashboard::m_tablesToData; void SmartDashboard::init(){ m_table = NetworkTable::GetTable("SmartDashboard"); -} -//TODO usage reporting + HALReport(HALUsageReporting::kResourceType_SmartDashboard, 0); +} /** * Maps the specified key to the specified value in this table. @@ -31,13 +31,13 @@ void SmartDashboard::PutData(std::string key, Sendable *data) { if (data == NULL) { - //TODO wpi_setWPIErrorWithContext(NullParameter, "value"); + wpi_setGlobalWPIErrorWithContext(NullParameter, "value"); return; } - ITable* dataTable = m_table->GetSubTable(key); - dataTable->PutString("~TYPE~", data->GetSmartDashboardType()); - data->InitTable(dataTable); - m_tablesToData[dataTable] = data; + ITable* dataTable = m_table->GetSubTable(key); + dataTable->PutString("~TYPE~", data->GetSmartDashboardType()); + data->InitTable(dataTable); + m_tablesToData[dataTable] = data; } /** @@ -50,7 +50,7 @@ void SmartDashboard::PutData(NamedSendable *value) { if (value == NULL) { - //TODO wpi_setWPIErrorWithContext(NullParameter, "value"); + wpi_setGlobalWPIErrorWithContext(NullParameter, "value"); return; } PutData(value->GetName(), value); @@ -61,17 +61,17 @@ void SmartDashboard::PutData(NamedSendable *value) * @param keyName the key * @return the value */ -//TODO Sendable *SmartDashboard::GetData(std::string key) -/*{ - ITable* subtable = m_table->GetSubTable(keyName); +Sendable *SmartDashboard::GetData(std::string key) +{ + ITable* subtable = m_table->GetSubTable(key); Sendable *data = m_tablesToData[subtable]; if (data == NULL) { - wpi_setWPIErrorWithContext(SmartDashboardMissingKey, keyName); + wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key.c_str()); return NULL; } - return data; -}*/ + return data; +} /** * Maps the specified key to the specified complex value (such as an array) in this table. diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java index 74b1e23836..cb022b0d6c 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java +++ b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/HLUsageReporting.java @@ -2,7 +2,7 @@ package edu.wpi.first.wpilibj; /** * Support for high level usage reporting. - * + * * @author alex */ public class HLUsageReporting { @@ -11,21 +11,28 @@ public class HLUsageReporting { public static void SetImplementation(Interface i) { impl = i; } - + public static void reportScheduler() { - if (impl != null) { + if (impl != null) { impl.reportScheduler(); } } - + public static void reportPIDController(int num) { - if (impl != null) { + if (impl != null) { impl.reportPIDController(num); } } + public static void reportSmartDashboard() { + if(impl != null) { + impl.reportSmartDashboard(); + } + } + public interface Interface { void reportScheduler(); void reportPIDController(int num); + void reportSmartDashboard(); } } diff --git a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java index 23adfeaad6..a65f0cbe9a 100644 --- a/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java +++ b/wpilibj/wpilibJava/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SmartDashboard.java @@ -13,6 +13,7 @@ import edu.wpi.first.wpilibj.networktables.NetworkTable; import edu.wpi.first.wpilibj.networktables.NetworkTableKeyNotDefined; import edu.wpi.first.wpilibj.tables.ITable; import edu.wpi.first.wpilibj.tables.TableKeyNotDefinedException; +import edu.wpi.first.wpilibj.HLUsageReporting; import java.util.Hashtable; import java.util.NoSuchElementException; @@ -26,7 +27,6 @@ import java.util.NoSuchElementException; * @author Joe Grinstead */ public class SmartDashboard { - //TODO usage reporting /** The {@link NetworkTable} used by {@link SmartDashboard} */ private static final NetworkTable table = NetworkTable.getTable("SmartDashboard"); /** @@ -35,6 +35,10 @@ public class SmartDashboard { */ private static final Hashtable tablesToData = new Hashtable(); + static { + HLUsageReporting.reportSmartDashboard(); + } + /** * Maps the specified key to the specified value in this table. * The key can not be null. @@ -71,15 +75,15 @@ public class SmartDashboard { * @throws IllegalArgumentException if the value mapped to by the key is not a {@link SmartDashboardData} * @throws IllegalArgumentException if the key is null */ -//TODO public static SmartDashboardData getData(String key) { -// NetworkTable subtable = table.getSubTable(key); -// Object data = tablesToData.get(subtable); -// if (data == null) { -// throw new IllegalArgumentException("Value at \"" + key + "\" is not a boolean"); -// } else { -// return (SmartDashboardData) data; -// } -// } + public static Sendable getData(String key) { + ITable subtable = table.getSubTable(key); + Object data = tablesToData.get(subtable); + if (data == null) { + throw new IllegalArgumentException("SmartDashboard data does not exist: " + key); + } else { + return (Sendable) data; + } + } /** * Maps the specified key to the specified value in this table. diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareHLUsageReporting.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareHLUsageReporting.java index 09b70000a5..02eba2c256 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareHLUsageReporting.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/internal/HardwareHLUsageReporting.java @@ -15,4 +15,9 @@ public class HardwareHLUsageReporting implements HLUsageReporting.Interface { public void reportPIDController(int num) { UsageReporting.report(tResourceType.kResourceType_PIDController, num); } + + @Override + public void reportSmartDashboard() { + UsageReporting.report(tResourceType.kResourceType_SmartDashboard, 0); + } }