001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.wpilibj.buttons;
006
007import edu.wpi.first.networktables.NetworkTable;
008import edu.wpi.first.networktables.NetworkTableEntry;
009import edu.wpi.first.networktables.NetworkTableInstance;
010
011/** A {@link Button} that uses a {@link NetworkTable} boolean field. */
012public class NetworkButton extends Button {
013  private final NetworkTableEntry m_entry;
014
015  public NetworkButton(String table, String field) {
016    this(NetworkTableInstance.getDefault().getTable(table), field);
017  }
018
019  public NetworkButton(NetworkTable table, String field) {
020    m_entry = table.getEntry(field);
021  }
022
023  @Override
024  public boolean get() {
025    return m_entry.getInstance().isConnected() && m_entry.getBoolean(false);
026  }
027}