[wpilib] Fix usage reporting for static classes (#6090)

This commit is contained in:
Gold856
2023-12-27 00:16:55 -05:00
committed by GitHub
parent f2c2bab7dc
commit 141241d2d6
4 changed files with 50 additions and 26 deletions

View File

@@ -18,7 +18,7 @@ import java.util.function.Consumer;
final class ShuffleboardInstance implements ShuffleboardRoot {
private final Map<String, ShuffleboardTab> m_tabs = new LinkedHashMap<>();
private boolean m_reported = false; // NOPMD redundant field initializer
private boolean m_tabsChanged = false; // NOPMD redundant field initializer
private final NetworkTable m_rootTable;
private final NetworkTable m_rootMetaTable;
@@ -35,12 +35,15 @@ final class ShuffleboardInstance implements ShuffleboardRoot {
m_rootMetaTable = m_rootTable.getSubTable(".metadata");
m_selectedTabPub =
m_rootMetaTable.getStringTopic("Selected").publish(PubSubOption.keepDuplicates(true));
HAL.report(tResourceType.kResourceType_Shuffleboard, 0);
}
@Override
public ShuffleboardTab getTab(String title) {
requireNonNullParam(title, "title", "getTab");
if (!m_reported) {
HAL.report(tResourceType.kResourceType_Shuffleboard, 0);
m_reported = true;
}
if (!m_tabs.containsKey(title)) {
m_tabs.put(title, new ShuffleboardTab(this, title));
m_tabsChanged = true;

View File

@@ -35,9 +35,10 @@ public final class SmartDashboard {
/** The executor for listener tasks; calls listener tasks synchronously from main thread. */
private static final ListenerExecutor listenerExecutor = new ListenerExecutor();
private static boolean m_reported = false; // NOPMD redundant field initializer
static {
setNetworkTableInstance(NetworkTableInstance.getDefault());
HAL.report(tResourceType.kResourceType_SmartDashboard, 0);
}
private SmartDashboard() {
@@ -64,6 +65,10 @@ public final class SmartDashboard {
*/
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public static synchronized void putData(String key, Sendable data) {
if (!m_reported) {
HAL.report(tResourceType.kResourceType_SmartDashboard, 0);
m_reported = true;
}
Sendable sddata = tablesToData.get(key);
if (sddata == null || sddata != data) {
tablesToData.put(key, data);
@@ -114,6 +119,10 @@ public final class SmartDashboard {
* @return Network table entry.
*/
public static NetworkTableEntry getEntry(String key) {
if (!m_reported) {
HAL.report(tResourceType.kResourceType_SmartDashboard, 0);
m_reported = true;
}
return table.getEntry(key);
}