Split Sendable into NT and non-NT portions (#3432)

The non-NT portion has been moved to wpiutil.
The NT portion has been moved to ntcore (as NTSendable).

SendableBuilder similarly split and moved.

SendableRegistry moved to wpiutil.

In C++, SendableHelper also moved to wpiutil.

This enables use of Sendable from wpimath and also enables
moving several classes from wpilib to wpimath.
This commit is contained in:
Peter Johnson
2021-06-13 16:38:05 -07:00
committed by GitHub
parent ef4ea84cb5
commit b417d961ec
196 changed files with 1147 additions and 891 deletions

View File

@@ -10,16 +10,17 @@ import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.hal.SimEnum;
import edu.wpi.first.networktables.NTSendable;
import edu.wpi.first.networktables.NTSendableBuilder;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/** ADXL345 I2C Accelerometer. */
@SuppressWarnings({"TypeName", "PMD.UnusedPrivateField"})
public class ADXL345_I2C implements Accelerometer, Sendable, AutoCloseable {
public class ADXL345_I2C implements Accelerometer, NTSendable, AutoCloseable {
private static final byte kAddress = 0x1D;
private static final byte kPowerCtlRegister = 0x2D;
private static final byte kDataFormatRegister = 0x31;
@@ -215,7 +216,7 @@ public class ADXL345_I2C implements Accelerometer, Sendable, AutoCloseable {
}
@Override
public void initSendable(SendableBuilder builder) {
public void initSendable(NTSendableBuilder builder) {
builder.setSmartDashboardType("3AxisAccelerometer");
NetworkTableEntry entryX = builder.getEntry("X");
NetworkTableEntry entryY = builder.getEntry("Y");

View File

@@ -10,16 +10,17 @@ import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.hal.SimEnum;
import edu.wpi.first.networktables.NTSendable;
import edu.wpi.first.networktables.NTSendableBuilder;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/** ADXL345 SPI Accelerometer. */
@SuppressWarnings({"TypeName", "PMD.UnusedPrivateField"})
public class ADXL345_SPI implements Accelerometer, Sendable, AutoCloseable {
public class ADXL345_SPI implements Accelerometer, NTSendable, AutoCloseable {
private static final int kPowerCtlRegister = 0x2D;
private static final int kDataFormatRegister = 0x31;
private static final int kDataRegister = 0x32;
@@ -229,7 +230,7 @@ public class ADXL345_SPI implements Accelerometer, Sendable, AutoCloseable {
}
@Override
public void initSendable(SendableBuilder builder) {
public void initSendable(NTSendableBuilder builder) {
builder.setSmartDashboardType("3AxisAccelerometer");
NetworkTableEntry entryX = builder.getEntry("X");
NetworkTableEntry entryY = builder.getEntry("Y");

View File

@@ -9,10 +9,11 @@ import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.hal.SimEnum;
import edu.wpi.first.networktables.NTSendable;
import edu.wpi.first.networktables.NTSendableBuilder;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -21,7 +22,7 @@ import java.nio.ByteOrder;
*
* <p>This class allows access to an Analog Devices ADXL362 3-axis accelerometer.
*/
public class ADXL362 implements Accelerometer, Sendable, AutoCloseable {
public class ADXL362 implements Accelerometer, NTSendable, AutoCloseable {
private static final byte kRegWrite = 0x0A;
private static final byte kRegRead = 0x0B;
@@ -258,7 +259,7 @@ public class ADXL362 implements Accelerometer, Sendable, AutoCloseable {
}
@Override
public void initSendable(SendableBuilder builder) {
public void initSendable(NTSendableBuilder builder) {
builder.setSmartDashboardType("3AxisAccelerometer");
NetworkTableEntry entryX = builder.getEntry("X");
NetworkTableEntry entryY = builder.getEntry("Y");

View File

@@ -9,9 +9,10 @@ import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimBoolean;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.interfaces.Gyro;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

View File

@@ -8,8 +8,9 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* Handle operation of an analog accelerometer. The accelerometer reads acceleration directly

View File

@@ -7,9 +7,10 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDevice.Direction;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.AnalogTriggerOutput.AnalogTriggerType;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/** Class for supporting continuous analog encoders, such as the US Digital MA3. */
public class AnalogEncoder implements Sendable, AutoCloseable {

View File

@@ -9,9 +9,10 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.hal.AnalogGyroJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.interfaces.Gyro;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/**
* Use a rate gyro to return the robots heading relative to a starting position. The Gyro class

View File

@@ -10,8 +10,9 @@ import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.util.AllocationException;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* Analog channel class.

View File

@@ -7,8 +7,9 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.AnalogJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/** Analog output class. */
public class AnalogOutput implements Sendable, AutoCloseable {

View File

@@ -4,8 +4,9 @@
package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* Class for reading analog potentiometers. Analog potentiometers read in an analog voltage that

View File

@@ -8,9 +8,10 @@ import edu.wpi.first.hal.AnalogJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.util.BoundaryException;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.AnalogTriggerOutput.AnalogTriggerType;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/** Class for creating and configuring Analog Triggers. */
public class AnalogTrigger implements Sendable, AutoCloseable {

View File

@@ -9,7 +9,8 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.hal.AnalogJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
/**
* Class to represent a specific output from an analog trigger. This class is used to get the

View File

@@ -7,9 +7,10 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.AccelerometerJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/**
* Built-in accelerometer.

View File

@@ -10,9 +10,10 @@ import static java.util.Objects.requireNonNull;
import edu.wpi.first.hal.CounterJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.AnalogTriggerOutput.AnalogTriggerType;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

View File

@@ -7,8 +7,9 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.DigitalGlitchFilterJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

View File

@@ -8,8 +8,9 @@ import edu.wpi.first.hal.DIOJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* Class to read a digital input. This class will read digital inputs and return the current value

View File

@@ -8,8 +8,9 @@ import edu.wpi.first.hal.DIOJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* Class to write digital outputs. This class will write digital outputs. Other devices that are

View File

@@ -6,8 +6,9 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.Objects;
/**

View File

@@ -7,8 +7,9 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.DutyCycleJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* Class to read a duty cycle PWM input.

View File

@@ -7,9 +7,10 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.SimBoolean;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.AnalogTriggerOutput.AnalogTriggerType;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/**
* Class for supporting duty cycle/PWM encoders, such as the US Digital MA3 with PWM Output, the

View File

@@ -11,8 +11,9 @@ import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.util.AllocationException;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* Class to read quadrature encoders.

View File

@@ -8,8 +8,9 @@ import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.PWMConfigDataResult;
import edu.wpi.first.hal.PWMJNI;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* Class implements the PWM generation in the FPGA.

View File

@@ -7,8 +7,9 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.PDPJNI;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* Class for getting voltage, current, temperature, power and energy from the Power Distribution

View File

@@ -10,8 +10,9 @@ import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.RelayJNI;
import edu.wpi.first.hal.util.UncleanStatusException;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.Arrays;
import java.util.Optional;

View File

@@ -1,17 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
/** The base interface for objects that can be sent over the network through network tables. */
public interface Sendable {
/**
* Initializes this {@link Sendable} object.
*
* @param builder sendable builder
*/
void initSendable(SendableBuilder builder);
}

View File

@@ -6,8 +6,8 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* Standard hobby style servo.

View File

@@ -6,8 +6,9 @@ package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.Objects;
/**

View File

@@ -4,9 +4,10 @@
package edu.wpi.first.wpilibj;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import java.util.Arrays;
/**

View File

@@ -12,8 +12,9 @@ import edu.wpi.first.hal.SimBoolean;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDevice.Direction;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.ArrayList;
import java.util.List;

View File

@@ -7,9 +7,9 @@ package edu.wpi.first.wpilibj.controller;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/** Implements a PID control loop. */
public class PIDController implements Sendable, AutoCloseable {

View File

@@ -8,8 +8,8 @@ import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
/**
* Implements a PID control loop whose setpoint is constrained by a trapezoid profile. Users should

View File

@@ -10,10 +10,10 @@ import edu.wpi.first.hal.FRCNetComm.tInstances;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/**
* A class for driving differential drive/skid-steer drive platforms such as the Kit of Parts drive

View File

@@ -10,10 +10,10 @@ import edu.wpi.first.hal.FRCNetComm.tInstances;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/**
* A class for driving Killough drive platforms.

View File

@@ -10,10 +10,10 @@ import edu.wpi.first.hal.FRCNetComm.tInstances;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/**
* A class for driving Mecanum drive platforms.

View File

@@ -7,8 +7,9 @@ package edu.wpi.first.wpilibj.livewindow;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl;
/**
* The LiveWindow class is the public interface for putting sensors and actuators on the LiveWindow.
@@ -31,6 +32,10 @@ public class LiveWindow {
private static Runnable enabledListener;
private static Runnable disabledListener;
static {
SendableRegistry.setLiveWindowBuilderFactory(() -> new SendableBuilderImpl());
}
private static Component getOrAdd(Sendable sendable) {
Component data = (Component) SendableRegistry.getData(sendable, dataHandle);
if (data == null) {
@@ -84,7 +89,7 @@ public class LiveWindow {
SendableRegistry.foreachLiveWindow(
dataHandle,
cbdata -> {
cbdata.builder.stopLiveWindowMode();
((SendableBuilderImpl) cbdata.builder).stopLiveWindowMode();
});
if (disabledListener != null) {
disabledListener.run();
@@ -173,7 +178,7 @@ public class LiveWindow {
table = ssTable.getSubTable(cbdata.name);
}
table.getEntry(".name").setString(cbdata.name);
cbdata.builder.setTable(table);
((SendableBuilderImpl) cbdata.builder).setTable(table);
cbdata.sendable.initSendable(cbdata.builder);
ssTable.getEntry(".type").setString("LW Subsystem");
@@ -181,9 +186,9 @@ public class LiveWindow {
}
if (startLiveWindow) {
cbdata.builder.startLiveWindowMode();
((SendableBuilderImpl) cbdata.builder).startLiveWindowMode();
}
cbdata.builder.updateTable();
cbdata.builder.update();
});
startLiveWindow = false;

View File

@@ -4,9 +4,9 @@
package edu.wpi.first.wpilibj.motorcontrol;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.Arrays;
/** Allows multiple {@link MotorController} objects to be linked together. */

View File

@@ -6,12 +6,12 @@ package edu.wpi.first.wpilibj.motorcontrol;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.DigitalOutput;
import edu.wpi.first.wpilibj.MotorSafety;
import edu.wpi.first.wpilibj.PWM;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/** Nidec Brushless Motor. */
public class NidecBrushless extends MotorSafety

View File

@@ -4,11 +4,11 @@
package edu.wpi.first.wpilibj.motorcontrol;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.MotorSafety;
import edu.wpi.first.wpilibj.PWM;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/** Common base class for all PWM Motor Controllers. */
public abstract class PWMMotorController extends MotorSafety

View File

@@ -5,8 +5,7 @@
package edu.wpi.first.wpilibj.shuffleboard;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl;
/**
@@ -31,7 +30,7 @@ public final class ComplexWidget extends ShuffleboardWidget<ComplexWidget> {
m_sendable.initSendable(m_builder);
m_builder.startListeners();
}
m_builder.updateTable();
m_builder.update();
}
/**

View File

@@ -5,8 +5,8 @@
package edu.wpi.first.wpilibj.shuffleboard;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;

View File

@@ -5,9 +5,9 @@
package edu.wpi.first.wpilibj.shuffleboard;
import edu.wpi.first.cscore.VideoSource;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.Map;
import java.util.WeakHashMap;

View File

@@ -5,7 +5,7 @@
package edu.wpi.first.wpilibj.shuffleboard;
import edu.wpi.first.cscore.VideoSource;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.util.sendable.Sendable;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.function.BooleanSupplier;

View File

@@ -7,7 +7,7 @@ package edu.wpi.first.wpilibj.shuffleboard;
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.util.sendable.Sendable;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.function.BooleanSupplier;

View File

@@ -5,7 +5,7 @@
package edu.wpi.first.wpilibj.shuffleboard;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.util.sendable.Sendable;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.function.BooleanSupplier;

View File

@@ -6,8 +6,10 @@ package edu.wpi.first.wpilibj.smartdashboard;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.networktables.NTSendable;
import edu.wpi.first.networktables.NTSendableBuilder;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.ArrayList;
import java.util.List;
@@ -27,7 +29,7 @@ import java.util.List;
* using the getObject() function. Other objects can also have multiple poses (which will show the
* object at multiple locations).
*/
public class Field2d implements Sendable {
public class Field2d implements NTSendable {
/** Constructor. */
public Field2d() {
FieldObject2d obj = new FieldObject2d("Robot");
@@ -98,7 +100,7 @@ public class Field2d implements Sendable {
}
@Override
public void initSendable(SendableBuilder builder) {
public void initSendable(NTSendableBuilder builder) {
builder.setSmartDashboardType("Field2d");
m_table = builder.getTable();

View File

@@ -4,8 +4,9 @@
package edu.wpi.first.wpilibj.smartdashboard;
import edu.wpi.first.networktables.NTSendable;
import edu.wpi.first.networktables.NTSendableBuilder;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.util.Color8Bit;
import java.util.HashMap;
import java.util.Map;
@@ -21,7 +22,7 @@ import java.util.Map.Entry;
* @see MechanismLigament2d
* @see MechanismRoot2d
*/
public final class Mechanism2d implements Sendable {
public final class Mechanism2d implements NTSendable {
private static final String kBackgroundColor = "backgroundColor";
private NetworkTable m_table;
private final Map<String, MechanismRoot2d> m_roots;
@@ -89,7 +90,7 @@ public final class Mechanism2d implements Sendable {
}
@Override
public void initSendable(SendableBuilder builder) {
public void initSendable(NTSendableBuilder builder) {
builder.setSmartDashboardType("Mechanism2d");
m_table = builder.getTable();
m_table.getEntry("dims").setDoubleArray(m_dims);

View File

@@ -1,155 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj.smartdashboard;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableValue;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.DoubleConsumer;
import java.util.function.DoubleSupplier;
import java.util.function.Supplier;
public interface SendableBuilder {
/**
* Get the network table.
*
* @return The network table
*/
NetworkTable getTable();
/**
* Set the string representation of the named data type that will be used by the smart dashboard
* for this sendable.
*
* @param type data type
*/
void setSmartDashboardType(String type);
/**
* Set a flag indicating if this sendable should be treated as an actuator. By default this flag
* is false.
*
* @param value true if actuator, false if not
*/
void setActuator(boolean value);
/**
* Set the function that should be called to set the Sendable into a safe state. This is called
* when entering and exiting Live Window mode.
*
* @param func function
*/
void setSafeState(Runnable func);
/**
* Set the function that should be called to update the network table for things other than
* properties. Note this function is not passed the network table object; instead it should use
* the entry handles returned by getEntry().
*
* @param func function
*/
void setUpdateTable(Runnable func);
/**
* Add a property without getters or setters. This can be used to get entry handles for the
* function called by setUpdateTable().
*
* @param key property name
* @return Network table entry
*/
NetworkTableEntry getEntry(String key);
/**
* Represents an operation that accepts a single boolean-valued argument and returns no result.
* This is the primitive type specialization of Consumer for boolean. Unlike most other functional
* interfaces, BooleanConsumer is expected to operate via side-effects.
*
* <p>This is a functional interface whose functional method is accept(boolean).
*/
@FunctionalInterface
interface BooleanConsumer {
/**
* Performs the operation on the given value.
*
* @param value the value
*/
void accept(boolean value);
}
/**
* Add a boolean property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
void addBooleanProperty(String key, BooleanSupplier getter, BooleanConsumer setter);
/**
* Add a double property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
void addDoubleProperty(String key, DoubleSupplier getter, DoubleConsumer setter);
/**
* Add a string property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
void addStringProperty(String key, Supplier<String> getter, Consumer<String> setter);
/**
* Add a boolean array property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
void addBooleanArrayProperty(String key, Supplier<boolean[]> getter, Consumer<boolean[]> setter);
/**
* Add a double array property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
void addDoubleArrayProperty(String key, Supplier<double[]> getter, Consumer<double[]> setter);
/**
* Add a string array property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
void addStringArrayProperty(String key, Supplier<String[]> getter, Consumer<String[]> setter);
/**
* Add a raw property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
void addRawProperty(String key, Supplier<byte[]> getter, Consumer<byte[]> setter);
/**
* Add a NetworkTableValue property.
*
* @param key property name
* @param getter getter function (returns current value)
* @param setter setter function (sets new value)
*/
void addValueProperty(
String key, Supplier<NetworkTableValue> getter, Consumer<NetworkTableValue> setter);
}

View File

@@ -5,6 +5,7 @@
package edu.wpi.first.wpilibj.smartdashboard;
import edu.wpi.first.networktables.EntryListenerFlags;
import edu.wpi.first.networktables.NTSendableBuilder;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableValue;
@@ -17,7 +18,7 @@ import java.util.function.DoubleSupplier;
import java.util.function.Function;
import java.util.function.Supplier;
public class SendableBuilderImpl implements SendableBuilder {
public class SendableBuilderImpl implements NTSendableBuilder {
private static class Property {
Property(NetworkTable table, String key) {
m_entry = table.getEntry(key);
@@ -80,7 +81,8 @@ public class SendableBuilderImpl implements SendableBuilder {
*
* @return True if it has a table, false if not.
*/
public boolean hasTable() {
@Override
public boolean isPublished() {
return m_table != null;
}
@@ -94,7 +96,8 @@ public class SendableBuilderImpl implements SendableBuilder {
}
/** Update the network table values by calling the getters for all properties. */
public void updateTable() {
@Override
public void update() {
for (Property property : m_properties) {
if (property.m_update != null) {
property.m_update.accept(property.m_entry);
@@ -148,6 +151,7 @@ public class SendableBuilderImpl implements SendableBuilder {
}
/** Clear properties. */
@Override
public void clearProperties() {
stopListeners();
m_properties.clear();

View File

@@ -6,8 +6,10 @@ package edu.wpi.first.wpilibj.smartdashboard;
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.networktables.NTSendable;
import edu.wpi.first.networktables.NTSendableBuilder;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@@ -27,7 +29,7 @@ import java.util.concurrent.locks.ReentrantLock;
*
* @param <V> The type of the values to be stored
*/
public class SendableChooser<V> implements Sendable, AutoCloseable {
public class SendableChooser<V> implements NTSendable, AutoCloseable {
/** The key for the default value. */
private static final String DEFAULT = "default";
/** The key for the selected option. */
@@ -130,7 +132,7 @@ public class SendableChooser<V> implements Sendable, AutoCloseable {
private final ReentrantLock m_mutex = new ReentrantLock();
@Override
public void initSendable(SendableBuilder builder) {
public void initSendable(NTSendableBuilder builder) {
builder.setSmartDashboardType("String Chooser");
builder.getEntry(INSTANCE).setDouble(m_instance);
builder.addStringProperty(DEFAULT, () -> m_defaultChoice, null);

View File

@@ -1,496 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj.smartdashboard;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Sendable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.function.Consumer;
/**
* The SendableRegistry class is the public interface for registering sensors and actuators for use
* on dashboards and LiveWindow.
*/
public class SendableRegistry {
private static class Component {
Component() {}
Component(Sendable sendable) {
m_sendable = new WeakReference<>(sendable);
}
WeakReference<Sendable> m_sendable;
SendableBuilderImpl m_builder = new SendableBuilderImpl();
String m_name;
String m_subsystem = "Ungrouped";
WeakReference<Sendable> m_parent;
boolean m_liveWindow;
Object[] m_data;
void setName(String moduleType, int channel) {
m_name = moduleType + "[" + channel + "]";
}
void setName(String moduleType, int moduleNumber, int channel) {
m_name = moduleType + "[" + moduleNumber + "," + channel + "]";
}
}
private static final Map<Object, Component> components = new WeakHashMap<>();
private static int nextDataHandle;
private static Component getOrAdd(Sendable sendable) {
Component comp = components.get(sendable);
if (comp == null) {
comp = new Component(sendable);
components.put(sendable, comp);
} else {
if (comp.m_sendable == null) {
comp.m_sendable = new WeakReference<>(sendable);
}
}
return comp;
}
private SendableRegistry() {
throw new UnsupportedOperationException("This is a utility class!");
}
/**
* Adds an object to the registry.
*
* @param sendable object to add
* @param name component name
*/
public static synchronized void add(Sendable sendable, String name) {
Component comp = getOrAdd(sendable);
comp.m_name = name;
}
/**
* Adds an object to the registry.
*
* @param sendable object to add
* @param moduleType A string that defines the module name in the label for the value
* @param channel The channel number the device is plugged into
*/
public static synchronized void add(Sendable sendable, String moduleType, int channel) {
Component comp = getOrAdd(sendable);
comp.setName(moduleType, channel);
}
/**
* Adds an object to the registry.
*
* @param sendable object to add
* @param moduleType A string that defines the module name in the label for the value
* @param moduleNumber The number of the particular module type
* @param channel The channel number the device is plugged into
*/
public static synchronized void add(
Sendable sendable, String moduleType, int moduleNumber, int channel) {
Component comp = getOrAdd(sendable);
comp.setName(moduleType, moduleNumber, channel);
}
/**
* Adds an object to the registry.
*
* @param sendable object to add
* @param subsystem subsystem name
* @param name component name
*/
public static synchronized void add(Sendable sendable, String subsystem, String name) {
Component comp = getOrAdd(sendable);
comp.m_name = name;
comp.m_subsystem = subsystem;
}
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param name component name
*/
public static synchronized void addLW(Sendable sendable, String name) {
Component comp = getOrAdd(sendable);
comp.m_liveWindow = true;
comp.m_name = name;
}
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param moduleType A string that defines the module name in the label for the value
* @param channel The channel number the device is plugged into
*/
public static synchronized void addLW(Sendable sendable, String moduleType, int channel) {
Component comp = getOrAdd(sendable);
comp.m_liveWindow = true;
comp.setName(moduleType, channel);
}
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param moduleType A string that defines the module name in the label for the value
* @param moduleNumber The number of the particular module type
* @param channel The channel number the device is plugged into
*/
public static synchronized void addLW(
Sendable sendable, String moduleType, int moduleNumber, int channel) {
Component comp = getOrAdd(sendable);
comp.m_liveWindow = true;
comp.setName(moduleType, moduleNumber, channel);
}
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param subsystem subsystem name
* @param name component name
*/
public static synchronized void addLW(Sendable sendable, String subsystem, String name) {
Component comp = getOrAdd(sendable);
comp.m_liveWindow = true;
comp.m_name = name;
comp.m_subsystem = subsystem;
}
/**
* Adds a child object to an object. Adds the child object to the registry if it's not already
* present.
*
* @param parent parent object
* @param child child object
*/
public static synchronized void addChild(Sendable parent, Object child) {
Component comp = components.get(child);
if (comp == null) {
comp = new Component();
components.put(child, comp);
}
comp.m_parent = new WeakReference<>(parent);
}
/**
* Removes an object from the registry.
*
* @param sendable object to remove
* @return true if the object was removed; false if it was not present
*/
public static synchronized boolean remove(Sendable sendable) {
return components.remove(sendable) != null;
}
/**
* Determines if an object is in the registry.
*
* @param sendable object to check
* @return True if in registry, false if not.
*/
public static synchronized boolean contains(Sendable sendable) {
return components.containsKey(sendable);
}
/**
* Gets the name of an object.
*
* @param sendable object
* @return Name (empty if object is not in registry)
*/
public static synchronized String getName(Sendable sendable) {
Component comp = components.get(sendable);
if (comp == null) {
return "";
}
return comp.m_name;
}
/**
* Sets the name of an object.
*
* @param sendable object
* @param name name
*/
public static synchronized void setName(Sendable sendable, String name) {
Component comp = components.get(sendable);
if (comp != null) {
comp.m_name = name;
}
}
/**
* Sets the name of an object with a channel number.
*
* @param sendable object
* @param moduleType A string that defines the module name in the label for the value
* @param channel The channel number the device is plugged into
*/
public static synchronized void setName(Sendable sendable, String moduleType, int channel) {
Component comp = components.get(sendable);
if (comp != null) {
comp.setName(moduleType, channel);
}
}
/**
* Sets the name of an object with a module and channel number.
*
* @param sendable object
* @param moduleType A string that defines the module name in the label for the value
* @param moduleNumber The number of the particular module type
* @param channel The channel number the device is plugged into
*/
public static synchronized void setName(
Sendable sendable, String moduleType, int moduleNumber, int channel) {
Component comp = components.get(sendable);
if (comp != null) {
comp.setName(moduleType, moduleNumber, channel);
}
}
/**
* Sets both the subsystem name and device name of an object.
*
* @param sendable object
* @param subsystem subsystem name
* @param name device name
*/
public static synchronized void setName(Sendable sendable, String subsystem, String name) {
Component comp = components.get(sendable);
if (comp != null) {
comp.m_name = name;
comp.m_subsystem = subsystem;
}
}
/**
* Gets the subsystem name of an object.
*
* @param sendable object
* @return Subsystem name (empty if object is not in registry)
*/
public static synchronized String getSubsystem(Sendable sendable) {
Component comp = components.get(sendable);
if (comp == null) {
return "";
}
return comp.m_subsystem;
}
/**
* Sets the subsystem name of an object.
*
* @param sendable object
* @param subsystem subsystem name
*/
public static synchronized void setSubsystem(Sendable sendable, String subsystem) {
Component comp = components.get(sendable);
if (comp != null) {
comp.m_subsystem = subsystem;
}
}
/**
* Gets a unique handle for setting/getting data with setData() and getData().
*
* @return Handle
*/
public static synchronized int getDataHandle() {
return nextDataHandle++;
}
/**
* Associates arbitrary data with an object in the registry.
*
* @param sendable object
* @param handle data handle returned by getDataHandle()
* @param data data to set
* @return Previous data (may be null)
*/
public static synchronized Object setData(Sendable sendable, int handle, Object data) {
Component comp = components.get(sendable);
if (comp == null) {
return null;
}
Object rv = null;
if (comp.m_data == null) {
comp.m_data = new Object[handle + 1];
} else if (handle < comp.m_data.length) {
rv = comp.m_data[handle];
} else {
comp.m_data = Arrays.copyOf(comp.m_data, handle + 1);
}
comp.m_data[handle] = data;
return rv;
}
/**
* Gets arbitrary data associated with an object in the registry.
*
* @param sendable object
* @param handle data handle returned by getDataHandle()
* @return data (may be null if none associated)
*/
public static synchronized Object getData(Sendable sendable, int handle) {
Component comp = components.get(sendable);
if (comp == null || comp.m_data == null || handle >= comp.m_data.length) {
return null;
}
return comp.m_data[handle];
}
/**
* Enables LiveWindow for an object.
*
* @param sendable object
*/
public static synchronized void enableLiveWindow(Sendable sendable) {
Component comp = components.get(sendable);
if (comp != null) {
comp.m_liveWindow = true;
}
}
/**
* Disables LiveWindow for an object.
*
* @param sendable object
*/
public static synchronized void disableLiveWindow(Sendable sendable) {
Component comp = components.get(sendable);
if (comp != null) {
comp.m_liveWindow = false;
}
}
/**
* Publishes an object in the registry to a network table.
*
* @param sendable object
* @param table network table
*/
public static synchronized void publish(Sendable sendable, NetworkTable table) {
Component comp = getOrAdd(sendable);
comp.m_builder.clearProperties();
comp.m_builder.setTable(table);
sendable.initSendable(comp.m_builder);
comp.m_builder.updateTable();
comp.m_builder.startListeners();
}
/**
* Updates network table information from an object.
*
* @param sendable object
*/
public static synchronized void update(Sendable sendable) {
Component comp = components.get(sendable);
if (comp != null) {
comp.m_builder.updateTable();
}
}
/** Data passed to foreachLiveWindow() callback function. */
public static class CallbackData {
/** Sendable object. */
@SuppressWarnings("MemberName")
public Sendable sendable;
/** Name. */
@SuppressWarnings("MemberName")
public String name;
/** Subsystem. */
@SuppressWarnings("MemberName")
public String subsystem;
/** Parent sendable object. */
@SuppressWarnings("MemberName")
public Sendable parent;
/** Data stored in object with setData(). Update this to change the data. */
@SuppressWarnings("MemberName")
public Object data;
/** Sendable builder for the sendable. */
@SuppressWarnings("MemberName")
public SendableBuilderImpl builder;
}
// As foreachLiveWindow is single threaded, cache the components it
// iterates over to avoid risk of ConcurrentModificationException
private static List<Component> foreachComponents = new ArrayList<>();
/**
* Iterates over LiveWindow-enabled objects in the registry. It is *not* safe to call other
* SendableRegistry functions from the callback.
*
* @param dataHandle data handle to get data object passed to callback
* @param callback function to call for each object
*/
@SuppressWarnings("PMD.AvoidCatchingThrowable")
public static synchronized void foreachLiveWindow(
int dataHandle, Consumer<CallbackData> callback) {
CallbackData cbdata = new CallbackData();
foreachComponents.clear();
foreachComponents.addAll(components.values());
for (Component comp : foreachComponents) {
if (comp.m_sendable == null) {
continue;
}
cbdata.sendable = comp.m_sendable.get();
if (cbdata.sendable != null && comp.m_liveWindow) {
cbdata.name = comp.m_name;
cbdata.subsystem = comp.m_subsystem;
if (comp.m_parent != null) {
cbdata.parent = comp.m_parent.get();
} else {
cbdata.parent = null;
}
if (comp.m_data != null && dataHandle < comp.m_data.length) {
cbdata.data = comp.m_data[dataHandle];
} else {
cbdata.data = null;
}
cbdata.builder = comp.m_builder;
try {
callback.accept(cbdata);
} catch (Throwable throwable) {
Throwable cause = throwable.getCause();
if (cause != null) {
throwable = cause;
}
DriverStation.reportError(
"Unhandled exception calling LiveWindow for "
+ comp.m_name
+ ": "
+ throwable.toString(),
false);
comp.m_liveWindow = false;
}
if (cbdata.data != null) {
if (comp.m_data == null) {
comp.m_data = new Object[dataHandle + 1];
} else if (dataHandle >= comp.m_data.length) {
comp.m_data = Arrays.copyOf(comp.m_data, dataHandle + 1);
}
comp.m_data[dataHandle] = cbdata.data;
}
}
}
foreachComponents.clear();
}
}

View File

@@ -9,7 +9,8 @@ import edu.wpi.first.hal.HAL;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
@@ -58,7 +59,10 @@ public final class SmartDashboard {
if (sddata == null || sddata != data) {
tablesToData.put(key, data);
NetworkTable dataTable = table.getSubTable(key);
SendableRegistry.publish(data, dataTable);
SendableBuilderImpl builder = new SendableBuilderImpl();
builder.setTable(dataTable);
SendableRegistry.publish(data, builder);
builder.startListeners();
dataTable.getEntry(".name").setString(key);
}
}