2020-12-26 14:31:24 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
#include "glass/hardware/PCM.h"
|
|
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
#include <wpi/SmallVector.h>
|
2023-09-17 20:00:16 -07:00
|
|
|
#include <wpi/StringExtras.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
#include "glass/Context.h"
|
|
|
|
|
#include "glass/DataSource.h"
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
#include "glass/Storage.h"
|
2020-09-12 10:55:46 -07:00
|
|
|
#include "glass/other/DeviceTree.h"
|
|
|
|
|
#include "glass/support/ExtraGuiWidgets.h"
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
#include "glass/support/NameSetting.h"
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
using namespace glass;
|
|
|
|
|
|
|
|
|
|
bool glass::DisplayPCMSolenoids(PCMModel* model, int index,
|
|
|
|
|
bool outputsEnabled) {
|
|
|
|
|
wpi::SmallVector<int, 16> channels;
|
|
|
|
|
model->ForEachSolenoid([&](SolenoidModel& solenoid, int j) {
|
|
|
|
|
if (auto data = solenoid.GetOutputData()) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (j >= static_cast<int>(channels.size())) {
|
|
|
|
|
channels.resize(j + 1);
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
channels[j] = (outputsEnabled && data->GetValue()) ? 1 : -1;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
if (channels.empty()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
// show nonexistent channels as empty
|
|
|
|
|
for (auto&& ch : channels) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (ch == 0) {
|
|
|
|
|
ch = -2;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// build header label
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
std::string& name = GetStorage().GetString("name");
|
2020-09-12 10:55:46 -07:00
|
|
|
char label[128];
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (!name.empty()) {
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "{} [{}]###header", name,
|
|
|
|
|
index);
|
2020-09-12 10:55:46 -07:00
|
|
|
} else {
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "PCM[{}]###header", index);
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// header
|
|
|
|
|
bool open = CollapsingHeader(label);
|
|
|
|
|
|
2021-12-19 07:35:12 -08:00
|
|
|
PopupEditName("header", &name);
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
ImGui::SetItemAllowOverlap();
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
// show channels as LED indicators
|
|
|
|
|
static const ImU32 colors[] = {IM_COL32(255, 255, 102, 255),
|
|
|
|
|
IM_COL32(128, 128, 128, 255)};
|
|
|
|
|
DrawLEDs(channels.data(), channels.size(), channels.size(), colors);
|
|
|
|
|
|
|
|
|
|
if (open) {
|
|
|
|
|
ImGui::PushItemWidth(ImGui::GetFontSize() * 4);
|
|
|
|
|
model->ForEachSolenoid([&](SolenoidModel& solenoid, int j) {
|
|
|
|
|
if (auto data = solenoid.GetOutputData()) {
|
|
|
|
|
PushID(j);
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
char label[64];
|
|
|
|
|
NameSetting name{data->GetName()};
|
|
|
|
|
name.GetLabel(label, sizeof(label), "Solenoid", j);
|
|
|
|
|
data->LabelText(label, "%s", channels[j] == 1 ? "On" : "Off");
|
|
|
|
|
name.PopupEditName(j);
|
2020-09-12 10:55:46 -07:00
|
|
|
PopID();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::DisplayPCMsSolenoids(PCMsModel* model, bool outputsEnabled,
|
2021-06-06 16:13:58 -07:00
|
|
|
std::string_view noneMsg) {
|
2020-09-12 10:55:46 -07:00
|
|
|
bool hasAny = false;
|
|
|
|
|
model->ForEachPCM([&](PCMModel& pcm, int i) {
|
|
|
|
|
PushID(i);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (DisplayPCMSolenoids(&pcm, i, outputsEnabled)) {
|
|
|
|
|
hasAny = true;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
PopID();
|
|
|
|
|
});
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!hasAny && !noneMsg.empty()) {
|
2021-06-06 16:13:58 -07:00
|
|
|
ImGui::TextUnformatted(noneMsg.data(), noneMsg.data() + noneMsg.size());
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::DisplayCompressorDevice(PCMModel* model, int index,
|
|
|
|
|
bool outputsEnabled) {
|
|
|
|
|
auto compressor = model->GetCompressor();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!compressor || !compressor->Exists()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
DisplayCompressorDevice(compressor, index, outputsEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::DisplayCompressorDevice(CompressorModel* model, int index,
|
|
|
|
|
bool outputsEnabled) {
|
|
|
|
|
char name[32];
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(name, sizeof(name), "Compressor[{}]", index);
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
if (BeginDevice(name)) {
|
|
|
|
|
// output enabled
|
|
|
|
|
if (auto runningData = model->GetRunningData()) {
|
|
|
|
|
bool value = outputsEnabled && runningData->GetValue();
|
|
|
|
|
if (DeviceBoolean("Running", false, &value, runningData)) {
|
|
|
|
|
model->SetRunning(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// closed loop enabled
|
|
|
|
|
if (auto enabledData = model->GetEnabledData()) {
|
|
|
|
|
int value = enabledData->GetValue() ? 1 : 0;
|
|
|
|
|
static const char* enabledOptions[] = {"disabled", "enabled"};
|
|
|
|
|
if (DeviceEnum("Closed Loop", true, &value, enabledOptions, 2,
|
|
|
|
|
enabledData)) {
|
|
|
|
|
model->SetEnabled(value != 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pressure switch
|
|
|
|
|
if (auto pressureSwitchData = model->GetPressureSwitchData()) {
|
|
|
|
|
int value = pressureSwitchData->GetValue() ? 1 : 0;
|
|
|
|
|
static const char* switchOptions[] = {"full", "low"};
|
|
|
|
|
if (DeviceEnum("Pressure", false, &value, switchOptions, 2,
|
|
|
|
|
pressureSwitchData)) {
|
|
|
|
|
model->SetPressureSwitch(value != 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// compressor current
|
|
|
|
|
if (auto currentData = model->GetCurrentData()) {
|
|
|
|
|
double value = currentData->GetValue();
|
|
|
|
|
if (DeviceDouble("Current (A)", false, &value, currentData)) {
|
|
|
|
|
model->SetCurrent(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndDevice();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::DisplayCompressorsDevice(PCMsModel* model, bool outputsEnabled) {
|
|
|
|
|
model->ForEachPCM([&](PCMModel& pcm, int i) {
|
|
|
|
|
DisplayCompressorDevice(&pcm, i, outputsEnabled);
|
|
|
|
|
});
|
|
|
|
|
}
|