Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes including choosers that don't appear and livewindow widgets that don't appear. #185

Merged
merged 19 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c8992e3
Fix FakeRobot test case for DigitalInput to use boolean instead of st…
chauser Aug 24, 2023
5b9afd6
Register SchedulerType so Scheduler instances in network tables don't…
chauser Aug 26, 2023
ea85b01
fix Chooser element so that NT keys seen before the .options key do n…
chauser Aug 26, 2023
dc7e122
Suppress attempts to create widgets for DataTypes that don't exist
chauser Aug 26, 2023
3dbac59
Disable NT driverstation client so SmartDashboard doesn't connect to …
chauser Sep 5, 2023
f4c9fc4
Fix formatting mistakes
chauser Sep 5, 2023
6068a32
Disable DSClient to fix 'Disappearing Chooser problem
chauser Sep 5, 2023
440d63f
Remove DSClient disable -- moved to separate branch
chauser Sep 5, 2023
33469b7
Enable DSClient after loading save.xml
chauser Sep 5, 2023
3bb28ee
Fix formatting errors
chauser Sep 5, 2023
3f372d5
Arrange that NetworkTables acquired in Robot.java are unique
chauser Sep 6, 2023
9009cd8
Merge branch 'UniqueTables' into DisableDSClient
chauser Sep 9, 2023
409bc81
Improve unique tables implementation
chauser Sep 9, 2023
0823260
add livewindow widgets to parent widgets when loaded from save file. …
chauser Sep 9, 2023
961b54f
Merge branch 'DisableDSClient' into FixSchedulerInLiveWindow; the branch
chauser Sep 9, 2023
90745f9
Merge branch 'FakeRobotDigitalInputFix' into FixSchedulerInLiveWindow
chauser Sep 9, 2023
9286be2
Merge branch 'main' into FixSchedulerInLiveWindow
chauser Sep 10, 2023
c19e72b
Fix UnsupportedOperationException when pressing scheduler Cancel buttons
chauser Sep 10, 2023
999d9ca
Fix compilation error
chauser Sep 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 36 additions & 27 deletions src/main/java/edu/wpi/first/smartdashboard/SmartDashboard.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.wpi.first.smartdashboard;

import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTablesJNI;
import edu.wpi.first.smartdashboard.extensions.FileSniffer;
import edu.wpi.first.smartdashboard.gui.DashboardFrame;
Expand Down Expand Up @@ -101,32 +102,6 @@ public void run() {
System.exit(2);
}

if (argParser.hasValue("ip")) {
monitor.setProgress(650);
monitor.setNote("Connecting to robot at: " + argParser.getValue("ip"));
Robot.setHost(argParser.getValue("ip"));
System.out.println("IP: " + argParser.getValue("ip"));
} else {
monitor.setProgress(600);
monitor.setNote("Getting Team Number");
StringProperty teamProp = frame.getPrefs().team;
String teamNumber = teamProp.getValue();

teamNumberLoop:
while (teamNumber.equals("0")) {
String input = JOptionPane.showInputDialog("Input Team Number\\Host");
if (input == null) {
break teamNumberLoop;
}
teamNumber = input;
}

monitor.setProgress(650);
monitor.setNote("Connecting to robot: " + teamNumber);
Robot.setHost(teamNumber);
teamProp.setValue(teamNumber);
}

try {
SwingUtilities.invokeAndWait(new Runnable() {

Expand All @@ -144,7 +119,7 @@ public void run() {
frame.load(file.getPath());
}

monitor.setProgress(1000);
monitor.setProgress(750);

} catch (Exception e) {
e.printStackTrace();
Expand All @@ -157,5 +132,39 @@ public void run() {
ex.printStackTrace();
System.exit(2);
}


if (argParser.hasValue("ip")) {
monitor.setProgress(1000);
monitor.setNote("Connecting to robot at: " + argParser.getValue("ip"));
Robot.setHost(argParser.getValue("ip"));
System.out.println("IP: " + argParser.getValue("ip"));
} else {
NetworkTable.setDSClientEnabled(true);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// No harm if the sleep is interrupted
}
monitor.setProgress(800);
monitor.setNote("Getting Team Number");
StringProperty teamProp = frame.getPrefs().team;
String teamNumber = teamProp.getValue();

teamNumberLoop:
while (teamNumber.equals("0")) {
String input = JOptionPane.showInputDialog("Input Team Number\\Host");
if (input == null) {
break teamNumberLoop;
}
teamNumber = input;
}

monitor.setProgress(850);
monitor.setNote("Connecting to robot: " + teamNumber);
Robot.setHost(teamNumber);
teamProp.setValue(teamNumber);
monitor.setProgress(1000);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public void load(String path) {
.getFieldName());
DataType type = DataType.getType(value2);
mostRecentParent.addWidget(w);
mostRecentParent.add(w);
w.setField(w.getFieldName(), w, type, value2, mostRecentParent, w.getSavedLocation());
mostRecentParent.setSize(mostRecentParent.getPreferredSize());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public void valueChanged(ITable source, String key, Object value, boolean isNew)
}

if (!source.containsKey(SELECTED)) {
source.putString(SELECTED, source.getString(DEFAULT, choices.get(0)));
source.putString(SELECTED,
source.getString(DEFAULT,
!choices.isEmpty() ? choices.get(0)
: "No Selection"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public void run() {
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Cancel commands
toCancel = Arrays.asList(table.getNumberArray("Cancel", new Double[0]));
toCancel = new ArrayList<Double>(Arrays.asList(table.getNumberArray("Cancel", new Double[0])));
toCancel.add(ids.get(index));
table.putValue("Cancel", toCancel);
table.putValue("Cancel", toCancel.toArray(new Double[toCancel.size()]));
}
});
buttons.add(button);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,30 @@ private void addSubsystemElement(String key, ITable value) {
"\nSubsystem \"" + getFieldName() + "\" does not contain widget \"" + key + "\"");
System.out.println("Table: " + value);
System.out.println("Type: " + value.getString(".type", null));
System.out.println(
"Trying to add a widget of type \"" + DataType.getType(value) + "\" and key " + key);
Class<? extends Widget> widgetClass = DataType.getType(value).getDefault();
Widget widget = widgetClass.newInstance();
widget.setFieldName(key);
widget.setType(DataType.getType(value));
widget.init();
widget.setValue(value);
widgets.add(widget);
add(widget);
preferredSize = layout.preferredLayoutSize(this);
setPreferredSize(preferredSize);
setMinimumSize(preferredSize);
setSavedSize(preferredSize);
setSize(preferredSize);
System.out.println("New size [" + preferredSize.width + ", " + preferredSize.height + "]");
revalidate();
repaint();
DataType dataType = DataType.getType(value);
if (dataType != null) {
System.out.println(
"Trying to add a widget of type \"" + dataType + "\" and key " + key);

Class<? extends Widget> widgetClass = DataType.getType(value).getDefault();
Widget widget = widgetClass.newInstance();
widget.setFieldName(key);
widget.setType(DataType.getType(value));
widget.init();
widget.setValue(value);
widgets.add(widget);
add(widget);
preferredSize = layout.preferredLayoutSize(this);
setPreferredSize(preferredSize);
setMinimumSize(preferredSize);
setSavedSize(preferredSize);
setSize(preferredSize);
System.out.println("New size [" + preferredSize.width + ", " + preferredSize.height + "]");
revalidate();
repaint();
} else {
System.out.println("Skipping: No registered dataType for type " + value.getString(".type", null) );
}
System.out.println();
} catch (InstantiationException | IllegalAccessException ex) {
Logger.getLogger(LWSubsystem.class.getName()).log(Level.SEVERE, null, ex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.wpi.first.smartdashboard.livewindow.elements;

import edu.wpi.first.smartdashboard.gui.elements.Scheduler;
import edu.wpi.first.smartdashboard.types.DisplayElementRegistry;

/**
Expand All @@ -24,6 +25,7 @@ public static void init() {
DisplayElementRegistry.registerWidget(PowerDistribution.class);
DisplayElementRegistry.registerWidget(ThreeAxisAccelerometer.class);
DisplayElementRegistry.registerWidget(CANSpeedController.class);
DisplayElementRegistry.registerWidget(Scheduler.class);
}

}
24 changes: 19 additions & 5 deletions src/main/java/edu/wpi/first/smartdashboard/robot/Robot.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package edu.wpi.first.smartdashboard.robot;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.tables.IRemoteConnectionListener;
import edu.wpi.first.wpilibj.tables.ITable;
Expand All @@ -21,6 +24,7 @@ public class Robot {
static {
NetworkTable.setClientMode();
NetworkTable.setNetworkIdentity(identity);
NetworkTable.setDSClientEnabled(false);
NetworkTable.initialize();
}

Expand Down Expand Up @@ -63,20 +67,30 @@ public static void setPort(int port) {
NetworkTable.initialize();
}

public static ITable getTable(String tableName) {
return NetworkTable.getTable(tableName);
// NetworkTable.getTable() returns a new table every time it's called.
// We need to make sure there is only one table for each table name.
private static final ConcurrentMap<String, ITable> tables = new ConcurrentHashMap<String, ITable>();

public static synchronized ITable getTable(String tableName) {
if (tables.containsKey(tableName)) {
return tables.get(tableName);
} else {
ITable newTable = NetworkTable.getTable(tableName);
tables.put(tableName, newTable);
return newTable;
}
}

public static ITable getTable() {
return NetworkTable.getTable(TABLE_NAME);
return getTable(TABLE_NAME);
}

public static ITable getPreferences() {
return NetworkTable.getTable(PREFERENCES_NAME);
return getTable(PREFERENCES_NAME);
}

public static ITable getLiveWindow() {
return NetworkTable.getTable(LIVE_WINDOW_NAME);
return getTable(LIVE_WINDOW_NAME);
}

public static void addConnectionListener(IRemoteConnectionListener listener, boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.wpi.first.smartdashboard.types.named;

import edu.wpi.first.smartdashboard.types.NamedDataType;
import edu.wpi.first.smartdashboard.gui.elements.Scheduler;

/**
* @author Joe Grinstead
Expand All @@ -10,7 +11,7 @@ public class SchedulerType extends NamedDataType {
public static final String LABEL = "Scheduler";

private SchedulerType() {
super(LABEL);
super(LABEL, Scheduler.class);
}

public static NamedDataType get() {
Expand Down