2019-11-10 20:55:42 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-06-27 22:11:24 -07:00
|
|
|
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
2019-11-10 20:55:42 -08:00
|
|
|
/* 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 "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);
|
|
|
|
|
|
|
|
|
|
if (ImGui::Button("Run")) HALSIM_ResumeTiming();
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("Pause")) HALSIM_PauseTiming();
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::PushButtonRepeat(true);
|
|
|
|
|
if (ImGui::Button("Step")) {
|
|
|
|
|
HALSIM_PauseTiming();
|
|
|
|
|
uint64_t nextTimeout = HALSIM_GetNextNotifierTimeout();
|
2020-09-27 13:27:53 -07:00
|
|
|
if (nextTimeout != UINT64_MAX)
|
|
|
|
|
HALSIM_StepTimingAsync(nextTimeout - curTime);
|
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());
|
|
|
|
|
}
|
|
|
|
|
if (num > 0) ImGui::Separator();
|
|
|
|
|
ImGui::PushItemWidth(ImGui::GetFontSize() * 4);
|
|
|
|
|
for (int32_t i = 0; i < num; ++i)
|
|
|
|
|
ImGui::LabelText(notifiers[i].name, "%.3f",
|
|
|
|
|
notifiers[i].timeout / 1000000.0);
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimingGui::Initialize() {
|
2020-09-12 10:55:46 -07:00
|
|
|
HALSimGui::halProvider.Register(
|
|
|
|
|
"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);
|
|
|
|
|
});
|
|
|
|
|
HALSimGui::halProvider.ShowDefault("Timing");
|
2019-11-10 20:55:42 -08:00
|
|
|
}
|