[command] Add NetworkButton (#2373)

Closes #2371
This commit is contained in:
Austin Shalit
2020-04-05 23:07:17 -07:00
committed by GitHub
parent 0ad0ec0985
commit e504b3ecbd
5 changed files with 222 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj2.command.button;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
/**
* A {@link Button} that uses a {@link NetworkTable} boolean field.
*/
public class NetworkButton extends Button {
private final NetworkTableEntry m_entry;
/**
* Creates a NetworkButton that commands can be bound to.
*
* @param entry The entry that is the value.
*/
public NetworkButton(NetworkTableEntry entry) {
m_entry = entry;
}
/**
* Creates a NetworkButton that commands can be bound to.
*
* @param table The table where the networktable value is located.
* @param field The field that is the value.
*/
public NetworkButton(NetworkTable table, String field) {
this(table.getEntry(field));
}
/**
* Creates a NetworkButton that commands can be bound to.
*
* @param table The table where the networktable value is located.
* @param field The field that is the value.
*/
public NetworkButton(String table, String field) {
this(NetworkTableInstance.getDefault().getTable(table), field);
}
@Override
public boolean get() {
return m_entry.getInstance().isConnected() && m_entry.getBoolean(false);
}
}