Add constants for built-in Shuffleboard widgets and layouts (#1468)

Prevents users from having to remember (and correctly type) the names of Shuffleboard widgets.
This commit is contained in:
Sam Carlberg
2018-12-29 20:22:47 -05:00
committed by Peter Johnson
parent ceed1d74dc
commit 01d1322066
24 changed files with 1278 additions and 52 deletions

View File

@@ -0,0 +1,13 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 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. */
/*----------------------------------------------------------------------------*/
#include "frc/shuffleboard/BuiltInLayouts.h"
using namespace frc;
const LayoutType BuiltInLayouts::kList{"List Layout"};
const LayoutType BuiltInLayouts::kGrid{"Grid Layout"};

View File

@@ -0,0 +1,35 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 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. */
/*----------------------------------------------------------------------------*/
#include "frc/shuffleboard/BuiltInWidgets.h"
using namespace frc;
const WidgetType BuiltInWidgets::kTextView{"Text View"};
const WidgetType BuiltInWidgets::kNumberSlider{"Number Slider"};
const WidgetType BuiltInWidgets::kNumberBar{"Number Bar"};
const WidgetType BuiltInWidgets::kDial{"Simple Dial"};
const WidgetType BuiltInWidgets::kGraph{"Graph"};
const WidgetType BuiltInWidgets::kBooleanBox{"Boolean Box"};
const WidgetType BuiltInWidgets::kToggleButton{"Toggle Button"};
const WidgetType BuiltInWidgets::kToggleSwitch{"Toggle Switch"};
const WidgetType BuiltInWidgets::kVoltageView{"Voltage View"};
const WidgetType BuiltInWidgets::kPowerDistributionPanel{"PDP"};
const WidgetType BuiltInWidgets::kComboBoxChooser{"ComboBox Chooser"};
const WidgetType BuiltInWidgets::kSplitButtonChooser{"Split Button Chooser"};
const WidgetType BuiltInWidgets::kEncoder{"Encoder"};
const WidgetType BuiltInWidgets::kSpeedController{"Speed Controller"};
const WidgetType BuiltInWidgets::kCommand{"Command"};
const WidgetType BuiltInWidgets::kPIDCommand{"PID Command"};
const WidgetType BuiltInWidgets::kPIDController{"PID Controller"};
const WidgetType BuiltInWidgets::kAccelerometer{"Accelerometer"};
const WidgetType BuiltInWidgets::k3AxisAccelerometer{"3-Axis Accelerometer"};
const WidgetType BuiltInWidgets::kGyro{"Gyro"};
const WidgetType BuiltInWidgets::kRelay{"Relay"};
const WidgetType BuiltInWidgets::kDifferentialDrive{"Differential Drivebase"};
const WidgetType BuiltInWidgets::kMecanumDrive{"Mecanum Drivebase"};
const WidgetType BuiltInWidgets::kCameraStream{"Camera Stream"};

View File

@@ -0,0 +1,12 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 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. */
/*----------------------------------------------------------------------------*/
#include "frc/shuffleboard/LayoutType.h"
using namespace frc;
wpi::StringRef LayoutType::GetLayoutName() const { return m_layoutName; }

View File

@@ -25,8 +25,13 @@ ShuffleboardContainer::GetComponents() const {
return m_components;
}
ShuffleboardLayout& ShuffleboardContainer::GetLayout(const wpi::Twine& type,
const wpi::Twine& title) {
ShuffleboardLayout& ShuffleboardContainer::GetLayout(const wpi::Twine& title,
const LayoutType& type) {
return GetLayout(title, type.GetLayoutName());
}
ShuffleboardLayout& ShuffleboardContainer::GetLayout(const wpi::Twine& title,
const wpi::Twine& type) {
wpi::SmallVector<char, 16> storage;
auto titleRef = title.toStringRef(storage);
if (m_layouts.count(titleRef) == 0) {
@@ -38,6 +43,16 @@ ShuffleboardLayout& ShuffleboardContainer::GetLayout(const wpi::Twine& type,
return *m_layouts[titleRef];
}
ShuffleboardLayout& ShuffleboardContainer::GetLayout(const wpi::Twine& title) {
wpi::SmallVector<char, 16> storage;
auto titleRef = title.toStringRef(storage);
if (m_layouts.count(titleRef) == 0) {
wpi_setWPIErrorWithContext(
InvalidParameter, "No layout with the given title has been defined");
}
return *m_layouts[titleRef];
}
ComplexWidget& ShuffleboardContainer::Add(const wpi::Twine& title,
Sendable& sendable) {
CheckTitle(title);

View File

@@ -0,0 +1,12 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 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. */
/*----------------------------------------------------------------------------*/
#include "frc/shuffleboard/WidgetType.h"
using namespace frc;
wpi::StringRef WidgetType::GetWidgetName() const { return m_widgetName; }