mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[glass] Add glass: an application for display of robot data
This reuses many pieces of the current simulation GUI. The common pieces have been refactored into the libglass library. The libglass library is designed to be usable for other standalone data visualization applications (e.g. viewing data logs). The name "glass" comes from "glass cockpit", as the application features several multi-function displays that can be adjusted to display robot information as needed.
This commit is contained in:
87
glass/src/lib/native/cpp/hardware/RoboRio.cpp
Normal file
87
glass/src/lib/native/cpp/hardware/RoboRio.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019-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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "glass/hardware/RoboRio.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include "glass/Context.h"
|
||||
#include "glass/DataSource.h"
|
||||
|
||||
using namespace glass;
|
||||
|
||||
static void DisplayRail(RoboRioRailModel& rail, const char* name) {
|
||||
if (CollapsingHeader(name)) {
|
||||
ImGui::PushID(name);
|
||||
if (auto data = rail.GetVoltageData()) {
|
||||
double val = data->GetValue();
|
||||
if (data->InputDouble("Voltage (V)", &val)) {
|
||||
rail.SetVoltage(val);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto data = rail.GetCurrentData()) {
|
||||
double val = data->GetValue();
|
||||
if (data->InputDouble("Current (A)", &val)) {
|
||||
rail.SetCurrent(val);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto data = rail.GetActiveData()) {
|
||||
static const char* options[] = {"inactive", "active"};
|
||||
int val = data->GetValue() ? 1 : 0;
|
||||
if (data->Combo("Active", &val, options, 2)) {
|
||||
rail.SetActive(val);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto data = rail.GetFaultsData()) {
|
||||
int val = data->GetValue();
|
||||
if (data->InputInt("Faults", &val)) {
|
||||
rail.SetFaults(val);
|
||||
}
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayRoboRio(RoboRioModel* model) {
|
||||
ImGui::Button("User Button");
|
||||
model->SetUserButton(ImGui::IsItemActive());
|
||||
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
|
||||
|
||||
if (CollapsingHeader("RoboRIO Input")) {
|
||||
ImGui::PushID("RoboRIO Input");
|
||||
if (auto data = model->GetVInVoltageData()) {
|
||||
double val = data->GetValue();
|
||||
if (data->InputDouble("Voltage (V)", &val)) {
|
||||
model->SetVInVoltage(val);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto data = model->GetVInCurrentData()) {
|
||||
double val = data->GetValue();
|
||||
if (data->InputDouble("Current (A)", &val)) {
|
||||
model->SetVInCurrent(val);
|
||||
}
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
if (auto rail = model->GetUser6VRail()) {
|
||||
DisplayRail(*rail, "6V Rail");
|
||||
}
|
||||
if (auto rail = model->GetUser5VRail()) {
|
||||
DisplayRail(*rail, "5V Rail");
|
||||
}
|
||||
if (auto rail = model->GetUser3V3Rail()) {
|
||||
DisplayRail(*rail, "3.3V Rail");
|
||||
}
|
||||
|
||||
ImGui::PopItemWidth();
|
||||
}
|
||||
Reference in New Issue
Block a user