2020-12-26 14:12:05 -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.
|
2019-11-10 20:55:42 -08:00
|
|
|
|
|
|
|
|
#include "TimingGui.h"
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <glass/Model.h>
|
|
|
|
|
#include <glass/View.h>
|
|
|
|
|
|
2019-11-10 20:55:42 -08:00
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include <hal/HALBase.h>
|
2020-06-27 22:11:24 -07:00
|
|
|
#include <hal/simulation/MockHooks.h>
|
|
|
|
|
#include <hal/simulation/NotifierData.h>
|
2019-11-10 20:55:42 -08:00
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
|
|
#include "HALSimGui.h"
|
|
|
|
|
|
|
|
|
|
using namespace halsimgui;
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
namespace {
|
|
|
|
|
class TimingModel : public glass::Model {
|
|
|
|
|
public:
|
|
|
|
|
void Update() override {}
|
|
|
|
|
bool Exists() override { return true; }
|
|
|
|
|
};
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2019-11-10 20:55:42 -08:00
|
|
|
static void DisplayTiming() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
uint64_t curTime = HAL_GetFPGATime(&status);
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
if (ImGui::Button("Run")) {
|
|
|
|
|
HALSIM_ResumeTiming();
|
|
|
|
|
}
|
2019-11-10 20:55:42 -08:00
|
|
|
ImGui::SameLine();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (ImGui::Button("Pause")) {
|
|
|
|
|
HALSIM_PauseTiming();
|
|
|
|
|
}
|
2019-11-10 20:55:42 -08:00
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::PushButtonRepeat(true);
|
|
|
|
|
if (ImGui::Button("Step")) {
|
|
|
|
|
HALSIM_PauseTiming();
|
|
|
|
|
uint64_t nextTimeout = HALSIM_GetNextNotifierTimeout();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (nextTimeout != UINT64_MAX) {
|
2020-09-27 13:27:53 -07:00
|
|
|
HALSIM_StepTimingAsync(nextTimeout - curTime);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2019-11-10 20:55:42 -08:00
|
|
|
}
|
|
|
|
|
ImGui::PopButtonRepeat();
|
|
|
|
|
ImGui::PushItemWidth(ImGui::GetFontSize() * 4);
|
|
|
|
|
ImGui::LabelText("FPGA Time", "%.3f", curTime / 1000000.0);
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
|
|
static std::vector<HALSIM_NotifierInfo> notifiers;
|
|
|
|
|
int32_t num = HALSIM_GetNotifierInfo(notifiers.data(), notifiers.size());
|
|
|
|
|
if (static_cast<uint32_t>(num) > notifiers.size()) {
|
|
|
|
|
notifiers.resize(num);
|
|
|
|
|
HALSIM_GetNotifierInfo(notifiers.data(), notifiers.size());
|
|
|
|
|
}
|
2020-12-28 12:58:06 -08:00
|
|
|
if (num > 0) {
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
}
|
2019-11-10 20:55:42 -08:00
|
|
|
ImGui::PushItemWidth(ImGui::GetFontSize() * 4);
|
2020-12-28 12:58:06 -08:00
|
|
|
for (int32_t i = 0; i < num; ++i) {
|
2019-11-10 20:55:42 -08:00
|
|
|
ImGui::LabelText(notifiers[i].name, "%.3f",
|
|
|
|
|
notifiers[i].timeout / 1000000.0);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2019-11-10 20:55:42 -08:00
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingGui::Initialize() {
|
[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
|
|
|
HALSimGui::halProvider->Register(
|
2020-09-12 10:55:46 -07:00
|
|
|
"Timing", [] { return true; },
|
|
|
|
|
[] { return std::make_unique<TimingModel>(); },
|
|
|
|
|
[](glass::Window* win, glass::Model* model) {
|
|
|
|
|
win->DisableRenamePopup();
|
|
|
|
|
win->SetFlags(ImGuiWindowFlags_AlwaysAutoResize);
|
|
|
|
|
win->SetDefaultPos(5, 150);
|
|
|
|
|
return glass::MakeFunctionView(DisplayTiming);
|
|
|
|
|
});
|
[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
|
|
|
HALSimGui::halProvider->ShowDefault("Timing");
|
2019-11-10 20:55:42 -08:00
|
|
|
}
|