mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Update wpilibj to use new NetworkTables package and interfaces.
This may be breaking to CANSpeedController implementations.
This commit is contained in:
@@ -7,11 +7,12 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.networktables.EntryListenerFlags;
|
||||
import edu.wpi.first.networktables.NetworkTable;
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import edu.wpi.first.wpilibj.tables.ITableListener;
|
||||
|
||||
/**
|
||||
* Standard hobby style servo.
|
||||
@@ -114,31 +115,37 @@ public class Servo extends PWM {
|
||||
return "Servo";
|
||||
}
|
||||
|
||||
private ITable m_table;
|
||||
private ITableListener m_tableListener;
|
||||
private NetworkTable m_table;
|
||||
private NetworkTableEntry m_valueEntry;
|
||||
private int m_valueListener;
|
||||
|
||||
@Override
|
||||
public void initTable(ITable subtable) {
|
||||
public void initTable(NetworkTable subtable) {
|
||||
m_table = subtable;
|
||||
updateTable();
|
||||
if (m_table != null) {
|
||||
m_valueEntry = m_table.getEntry("Value");
|
||||
updateTable();
|
||||
} else {
|
||||
m_valueEntry = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTable() {
|
||||
if (m_table != null) {
|
||||
m_table.putNumber("Value", get());
|
||||
if (m_valueEntry != null) {
|
||||
m_valueEntry.setDouble(get());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startLiveWindowMode() {
|
||||
m_tableListener = (source, key, value, isNew) -> set((double) value);
|
||||
m_table.addTableListener("Value", m_tableListener, true);
|
||||
m_valueListener = m_valueEntry.addListener((event) -> set(event.value.getDouble()),
|
||||
EntryListenerFlags.kImmediate | EntryListenerFlags.kNew | EntryListenerFlags.kUpdate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopLiveWindowMode() {
|
||||
// TODO: Broken, should only remove the listener from "Value" only.
|
||||
m_table.removeTableListener(m_tableListener);
|
||||
m_valueEntry.removeListener(m_valueListener);
|
||||
m_valueListener = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user