Fix SmartDashboard PutData to hook setters. (#851)

* Fix SmartDashboard PutData to hook setters.

Also update all PutData values in main periodic loop (same as LiveWindow).

* Improve SmartDashboard.putData() repeat call handling.
This commit is contained in:
Peter Johnson
2017-12-26 17:18:02 -06:00
committed by bradamiller
parent a3e5378d14
commit 40eb6dfc9b
8 changed files with 97 additions and 25 deletions

View File

@@ -9,6 +9,7 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.hal.HAL;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
* IterativeRobotBase implements a specific type of robot program framework, extending the RobotBase
@@ -222,6 +223,7 @@ public abstract class IterativeRobotBase extends RobotBase {
testPeriodic();
}
robotPeriodic();
SmartDashboard.updateValues();
LiveWindow.updateValues();
}
}

View File

@@ -88,26 +88,42 @@ public class SendableBuilderImpl implements SendableBuilder {
}
/**
* Start LiveWindow mode by hooking the setters for all properties.
* Hook setters for all properties.
*/
public void startLiveWindowMode() {
if (m_safeState != null) {
m_safeState.run();
}
public void startListeners() {
for (Property property : m_properties) {
property.startListener();
}
}
/**
* Stop LiveWindow mode by unhooking the setters for all properties.
* Unhook setters for all properties.
*/
public void stopLiveWindowMode() {
public void stopListeners() {
for (Property property : m_properties) {
property.stopListener();
}
}
/**
* Start LiveWindow mode by hooking the setters for all properties. Also
* calls the safeState function if one was provided.
*/
public void startLiveWindowMode() {
if (m_safeState != null) {
m_safeState.run();
}
for (Property property : m_properties) {
property.stopListener();
startListeners();
}
/**
* Stop LiveWindow mode by unhooking the setters for all properties. Also
* calls the safeState function if one was provided.
*/
public void stopLiveWindowMode() {
stopListeners();
if (m_safeState != null) {
m_safeState.run();
}
}

View File

@@ -33,7 +33,11 @@ public class SmartDashboard {
NetworkTableInstance.getDefault().getTable("SmartDashboard");
private static class Data {
Sendable m_sendable;
Data(Sendable sendable) {
m_sendable = sendable;
}
final Sendable m_sendable;
final SendableBuilderImpl m_builder = new SendableBuilderImpl();
}
@@ -57,16 +61,17 @@ public class SmartDashboard {
*/
public static synchronized void putData(String key, Sendable data) {
Data sddata = tablesToData.get(key);
if (sddata == null) {
sddata = new Data();
if (sddata == null || sddata.m_sendable != data) {
if (sddata != null) {
sddata.m_builder.stopListeners();
}
sddata = new Data(data);
tablesToData.put(key, sddata);
}
if (sddata.m_sendable == null || sddata.m_sendable != data) {
sddata.m_sendable = data;
sddata.m_builder.setTable(table.getSubTable(key));
data.initSendable(sddata.m_builder);
sddata.m_builder.updateTable();
sddata.m_builder.startListeners();
}
sddata.m_builder.updateTable();
}
/**
@@ -506,4 +511,13 @@ public class SmartDashboard {
public static byte[] getRaw(String key, byte[] defaultValue) {
return getEntry(key).getRaw(defaultValue);
}
/**
* Puts all sendable data to the dashboard.
*/
public static synchronized void updateValues() {
for (Data data : tablesToData.values()) {
data.m_builder.updateTable();
}
}
}