mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
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.
102 lines
2.9 KiB
C++
102 lines
2.9 KiB
C++
// 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.
|
|
|
|
#include "glass/hardware/LEDDisplay.h"
|
|
|
|
#include <wpi/SmallVector.h>
|
|
|
|
#include "glass/Context.h"
|
|
#include "glass/Storage.h"
|
|
#include "glass/support/ExtraGuiWidgets.h"
|
|
|
|
using namespace glass;
|
|
|
|
namespace {
|
|
struct IndicatorData {
|
|
std::vector<int> values;
|
|
std::vector<ImU32> colors;
|
|
};
|
|
} // namespace
|
|
|
|
void glass::DisplayLEDDisplay(LEDDisplayModel* model, int index) {
|
|
wpi::SmallVector<LEDDisplayModel::Data, 64> dataBuf;
|
|
auto data = model->GetData(dataBuf);
|
|
int length = data.size();
|
|
bool running = model->IsRunning();
|
|
auto& storage = GetStorage();
|
|
|
|
int& numColumns = storage.GetInt("columns", 10);
|
|
bool& serpentine = storage.GetBool("serpentine", false);
|
|
int& order = storage.GetInt("order", LEDConfig::RowMajor);
|
|
int& start = storage.GetInt("start", LEDConfig::UpperLeft);
|
|
|
|
ImGui::PushItemWidth(ImGui::GetFontSize() * 6);
|
|
ImGui::LabelText("Length", "%d", length);
|
|
ImGui::LabelText("Running", "%s", running ? "Yes" : "No");
|
|
ImGui::InputInt("Columns", &numColumns);
|
|
{
|
|
static const char* options[] = {"Row Major", "Column Major"};
|
|
ImGui::Combo("Order", &order, options, 2);
|
|
}
|
|
{
|
|
static const char* options[] = {"Upper Left", "Lower Left", "Upper Right",
|
|
"Lower Right"};
|
|
ImGui::Combo("Start", &start, options, 4);
|
|
}
|
|
ImGui::Checkbox("Serpentine", &serpentine);
|
|
if (numColumns < 1) {
|
|
numColumns = 1;
|
|
}
|
|
ImGui::PopItemWidth();
|
|
|
|
// show as LED indicators
|
|
auto iData = storage.GetData<IndicatorData>();
|
|
if (!iData) {
|
|
storage.SetData(std::make_shared<IndicatorData>());
|
|
iData = storage.GetData<IndicatorData>();
|
|
}
|
|
if (length > static_cast<int>(iData->values.size())) {
|
|
iData->values.resize(length);
|
|
}
|
|
if (length > static_cast<int>(iData->colors.size())) {
|
|
iData->colors.resize(length);
|
|
}
|
|
if (!running) {
|
|
iData->colors[0] = IM_COL32(128, 128, 128, 255);
|
|
for (int j = 0; j < length; ++j) {
|
|
iData->values[j] = -1;
|
|
}
|
|
} else {
|
|
for (int j = 0; j < length; ++j) {
|
|
iData->values[j] = j + 1;
|
|
iData->colors[j] = IM_COL32(data[j].r, data[j].g, data[j].b, 255);
|
|
}
|
|
}
|
|
|
|
LEDConfig config;
|
|
config.serpentine = serpentine;
|
|
config.order = static_cast<LEDConfig::Order>(order);
|
|
config.start = static_cast<LEDConfig::Start>(start);
|
|
|
|
DrawLEDs(iData->values.data(), length, numColumns, iData->colors.data(), 0, 0,
|
|
config);
|
|
}
|
|
|
|
void glass::DisplayLEDDisplays(LEDDisplaysModel* model) {
|
|
bool hasAny = false;
|
|
|
|
model->ForEachLEDDisplay([&](LEDDisplayModel& display, int i) {
|
|
hasAny = true;
|
|
if (model->GetNumLEDDisplays() > 1) {
|
|
ImGui::Text("LEDs[%d]", i);
|
|
}
|
|
PushID(i);
|
|
DisplayLEDDisplay(&display, i);
|
|
PopID();
|
|
});
|
|
if (!hasAny) {
|
|
ImGui::Text("No addressable LEDs");
|
|
}
|
|
}
|