mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Use new NetworkTables across WPILib (C++ and Java).
Also make sure table listeners stop listening in their destructors. This might be better handled by moving the table itself into ITableListener and providing cleanup functionality there. A submodule is used to pull in ntcore. Change-Id: I3031c1a768595cf0f8754c47e15cd423e2dbcce5
This commit is contained in:
committed by
Brad Miller (WPI)
parent
f65e697107
commit
f89c5e150f
@@ -13,8 +13,6 @@ import java.util.Vector;
|
||||
import edu.wpi.first.wpilibj.HLUsageReporting;
|
||||
import edu.wpi.first.wpilibj.NamedSendable;
|
||||
import edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler;
|
||||
import edu.wpi.first.wpilibj.networktables2.type.NumberArray;
|
||||
import edu.wpi.first.wpilibj.networktables2.type.StringArray;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
|
||||
/**
|
||||
@@ -318,49 +316,48 @@ public class Scheduler implements NamedSendable {
|
||||
return "Scheduler";
|
||||
}
|
||||
|
||||
private StringArray commands;
|
||||
private NumberArray ids, toCancel;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void initTable(ITable subtable) {
|
||||
m_table = subtable;
|
||||
commands = new StringArray();
|
||||
ids = new NumberArray();
|
||||
toCancel = new NumberArray();
|
||||
|
||||
m_table.putValue("Names", commands);
|
||||
m_table.putValue("Ids", ids);
|
||||
m_table.putValue("Cancel", toCancel);
|
||||
m_table.putStringArray("Names", new String[0]);
|
||||
m_table.putNumberArray("Ids", new double[0]);
|
||||
m_table.putNumberArray("Cancel", new double[0]);
|
||||
}
|
||||
|
||||
private void updateTable() {
|
||||
if (m_table != null) {
|
||||
// Get the commands to cancel
|
||||
m_table.retrieveValue("Cancel", toCancel);
|
||||
if (toCancel.size() > 0) {
|
||||
double[] toCancel = m_table.getNumberArray("Cancel", new double[0]);
|
||||
if (toCancel.length > 0) {
|
||||
for (LinkedListElement e = firstCommand; e != null; e = e.getNext()) {
|
||||
for (int i = 0; i < toCancel.size(); i++) {
|
||||
if (e.getData().hashCode() == toCancel.get(i)) {
|
||||
for (int i = 0; i < toCancel.length; i++) {
|
||||
if (e.getData().hashCode() == toCancel[i]) {
|
||||
e.getData().cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
toCancel.setSize(0);
|
||||
m_table.putValue("Cancel", toCancel);
|
||||
m_table.putNumberArray("Cancel", new double[0]);
|
||||
}
|
||||
|
||||
if (m_runningCommandsChanged) {
|
||||
commands.setSize(0);
|
||||
ids.setSize(0);
|
||||
// Set the the running commands
|
||||
int n = 0;
|
||||
for (LinkedListElement e = firstCommand; e != null; e = e.getNext()) {
|
||||
commands.add(e.getData().getName());
|
||||
ids.add(e.getData().hashCode());
|
||||
n++;
|
||||
}
|
||||
m_table.putValue("Names", commands);
|
||||
m_table.putValue("Ids", ids);
|
||||
String[] commands = new String[n];
|
||||
double[] ids = new double[n];
|
||||
n = 0;
|
||||
for (LinkedListElement e = firstCommand; e != null; e = e.getNext()) {
|
||||
commands[n] = e.getData().getName();
|
||||
ids[n] = e.getData().hashCode();
|
||||
n++;
|
||||
}
|
||||
m_table.putStringArray("Names", commands);
|
||||
m_table.putNumberArray("Ids", ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ package edu.wpi.first.wpilibj.smartdashboard;
|
||||
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
import edu.wpi.first.wpilibj.networktables2.type.StringArray;
|
||||
import edu.wpi.first.wpilibj.networktables2.util.List;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* The {@link SendableChooser} class is a useful tool for presenting a selection
|
||||
* of options to the {@link SmartDashboard}.
|
||||
@@ -44,8 +44,8 @@ public class SendableChooser implements Sendable {
|
||||
/**
|
||||
* A table linking strings to the objects the represent
|
||||
*/
|
||||
private StringArray choices = new StringArray();
|
||||
private List values = new List();
|
||||
private ArrayList<String> choices = new ArrayList<String>();
|
||||
private ArrayList<Object> values = new ArrayList<Object>();
|
||||
private String defaultChoice = null;
|
||||
private Object defaultValue = null;
|
||||
|
||||
@@ -77,8 +77,9 @@ public class SendableChooser implements Sendable {
|
||||
// not found
|
||||
choices.add(name);
|
||||
values.add(object);
|
||||
|
||||
if (table != null) {
|
||||
table.putValue(OPTIONS, choices);
|
||||
table.putStringArray(OPTIONS, choices.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ public class SendableChooser implements Sendable {
|
||||
public void initTable(ITable table) {
|
||||
this.table = table;
|
||||
if (table != null) {
|
||||
table.putValue(OPTIONS, choices);
|
||||
table.putStringArray(OPTIONS, choices.toArray(new String[0]));
|
||||
if (defaultChoice != null) {
|
||||
table.putString(DEFAULT, defaultChoice);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user