mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
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.
93 lines
3.0 KiB
C++
93 lines
3.0 KiB
C++
/*----------------------------------------------------------------------------*/
|
|
/* 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/PDP.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstdio>
|
|
|
|
#include <imgui.h>
|
|
|
|
#include "glass/Context.h"
|
|
#include "glass/DataSource.h"
|
|
#include "glass/support/IniSaverInfo.h"
|
|
|
|
using namespace glass;
|
|
|
|
static float DisplayChannel(PDPModel& pdp, int channel) {
|
|
float width = 0;
|
|
if (auto currentData = pdp.GetCurrentData(channel)) {
|
|
ImGui::PushID(channel);
|
|
auto& leftInfo = currentData->GetNameInfo();
|
|
char name[64];
|
|
leftInfo.GetLabel(name, sizeof(name), "", channel);
|
|
double val = currentData->GetValue();
|
|
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
|
if (currentData->InputDouble(name, &val, 0, 0, "%.3f"))
|
|
pdp.SetCurrent(channel, val);
|
|
width = ImGui::GetItemRectSize().x;
|
|
leftInfo.PopupEditName(channel);
|
|
ImGui::PopID();
|
|
}
|
|
return width;
|
|
}
|
|
|
|
void glass::DisplayPDP(PDPModel* model, int index) {
|
|
char name[128];
|
|
std::snprintf(name, sizeof(name), "PDP[%d]", index);
|
|
if (CollapsingHeader(name)) {
|
|
// temperature
|
|
if (auto tempData = model->GetTemperatureData()) {
|
|
double value = tempData->GetValue();
|
|
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
|
if (tempData->InputDouble("Temp", &value, 0, 0, "%.3f")) {
|
|
model->SetTemperature(value);
|
|
}
|
|
}
|
|
|
|
// voltage
|
|
if (auto voltageData = model->GetVoltageData()) {
|
|
double value = voltageData->GetValue();
|
|
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
|
if (voltageData->InputDouble("Voltage", &value, 0, 0, "%.3f")) {
|
|
model->SetVoltage(value);
|
|
}
|
|
}
|
|
|
|
// channel currents; show as two columns laid out like PDP
|
|
const int numChannels = model->GetNumChannels();
|
|
ImGui::Text("Channel Current (A)");
|
|
ImGui::Columns(2, "channels", false);
|
|
float maxWidth = ImGui::GetFontSize() * 13;
|
|
for (int left = 0, right = numChannels - 1; left < right; ++left, --right) {
|
|
float leftWidth = DisplayChannel(*model, left);
|
|
ImGui::NextColumn();
|
|
|
|
float rightWidth = DisplayChannel(*model, right);
|
|
ImGui::NextColumn();
|
|
|
|
float width =
|
|
(std::max)(leftWidth, rightWidth) * 2 + ImGui::GetFontSize() * 4;
|
|
if (width > maxWidth) maxWidth = width;
|
|
}
|
|
ImGui::Columns(1);
|
|
ImGui::Dummy(ImVec2(maxWidth, 0));
|
|
}
|
|
}
|
|
|
|
void glass::DisplayPDPs(PDPsModel* model, wpi::StringRef noneMsg) {
|
|
bool hasAny = false;
|
|
model->ForEachPDP([&](PDPModel& pdp, int i) {
|
|
hasAny = true;
|
|
PushID(i);
|
|
DisplayPDP(&pdp, i);
|
|
PopID();
|
|
});
|
|
if (!hasAny && !noneMsg.empty())
|
|
ImGui::TextUnformatted(noneMsg.begin(), noneMsg.end());
|
|
}
|