2019-09-23 00:24:10 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-01-20 22:47:36 -08:00
|
|
|
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
2019-09-23 00:24:10 -07: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 "PDPGui.h"
|
|
|
|
|
|
2020-01-20 22:47:36 -08:00
|
|
|
#include <algorithm>
|
2019-09-23 00:24:10 -07:00
|
|
|
#include <cstdio>
|
2020-01-20 22:47:36 -08:00
|
|
|
#include <cstring>
|
2019-11-02 14:06:24 -07:00
|
|
|
#include <memory>
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
#include <hal/Ports.h>
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
#include <mockdata/PDPData.h>
|
|
|
|
|
|
|
|
|
|
#include "HALSimGui.h"
|
2020-01-20 22:47:36 -08:00
|
|
|
#include "IniSaver.h"
|
|
|
|
|
#include "IniSaverInfo.h"
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
using namespace halsimgui;
|
|
|
|
|
|
2020-01-20 22:47:36 -08:00
|
|
|
static IniSaver<NameInfo> gChannels{"PDP"};
|
|
|
|
|
|
2019-09-23 00:24:10 -07:00
|
|
|
static void DisplayPDP() {
|
|
|
|
|
bool hasAny = false;
|
|
|
|
|
static int numPDP = HAL_GetNumPDPModules();
|
|
|
|
|
static int numChannels = HAL_GetNumPDPChannels();
|
2019-11-02 14:06:24 -07:00
|
|
|
static auto channelCurrents = std::make_unique<double[]>(numChannels);
|
2019-09-23 00:24:10 -07:00
|
|
|
for (int i = 0; i < numPDP; ++i) {
|
|
|
|
|
if (HALSIM_GetPDPInitialized(i)) {
|
|
|
|
|
hasAny = true;
|
|
|
|
|
|
2020-01-20 22:47:36 -08:00
|
|
|
char name[128];
|
2019-09-23 00:24:10 -07:00
|
|
|
std::snprintf(name, sizeof(name), "PDP[%d]", i);
|
|
|
|
|
if (ImGui::CollapsingHeader(name, ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
|
ImGui::PushID(i);
|
|
|
|
|
|
|
|
|
|
// temperature
|
|
|
|
|
double temp = HALSIM_GetPDPTemperature(i);
|
2020-01-20 22:47:36 -08:00
|
|
|
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
|
|
|
|
if (ImGui::InputDouble("Temp", &temp, 0, 0, "%.3f"))
|
2019-09-23 00:24:10 -07:00
|
|
|
HALSIM_SetPDPTemperature(i, temp);
|
|
|
|
|
|
|
|
|
|
// voltage
|
|
|
|
|
double volts = HALSIM_GetPDPVoltage(i);
|
2020-01-20 22:47:36 -08:00
|
|
|
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
|
|
|
|
if (ImGui::InputDouble("Voltage", &volts, 0, 0, "%.3f"))
|
2019-09-23 00:24:10 -07:00
|
|
|
HALSIM_SetPDPVoltage(i, volts);
|
|
|
|
|
|
|
|
|
|
// channel currents; show as two columns laid out like PDP
|
2019-11-02 14:06:24 -07:00
|
|
|
HALSIM_GetPDPAllCurrents(i, channelCurrents.get());
|
2019-09-23 00:24:10 -07:00
|
|
|
ImGui::Text("Channel Current (A)");
|
|
|
|
|
ImGui::Columns(2, "channels", false);
|
2020-01-20 22:47:36 -08:00
|
|
|
float maxWidth = ImGui::GetFontSize() * 13;
|
2019-09-23 00:24:10 -07:00
|
|
|
for (int left = 0, right = numChannels - 1; left < right;
|
|
|
|
|
++left, --right) {
|
|
|
|
|
double val;
|
|
|
|
|
|
2020-01-20 22:47:36 -08:00
|
|
|
auto& leftInfo = gChannels[i * numChannels + left];
|
|
|
|
|
leftInfo.GetName(name, sizeof(name), "", left);
|
2019-11-02 14:06:24 -07:00
|
|
|
val = channelCurrents[left];
|
2020-01-20 22:47:36 -08:00
|
|
|
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
|
|
|
|
if (ImGui::InputDouble(name, &val, 0, 0, "%.3f"))
|
2019-09-23 00:24:10 -07:00
|
|
|
HALSIM_SetPDPCurrent(i, left, val);
|
2020-01-20 22:47:36 -08:00
|
|
|
float leftWidth = ImGui::GetItemRectSize().x;
|
|
|
|
|
leftInfo.PopupEditName(left);
|
2019-09-23 00:24:10 -07:00
|
|
|
ImGui::NextColumn();
|
|
|
|
|
|
2020-01-20 22:47:36 -08:00
|
|
|
auto& rightInfo = gChannels[i * numChannels + right];
|
|
|
|
|
rightInfo.GetName(name, sizeof(name), "", right);
|
2019-11-02 14:06:24 -07:00
|
|
|
val = channelCurrents[right];
|
2020-01-20 22:47:36 -08:00
|
|
|
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
|
|
|
|
if (ImGui::InputDouble(name, &val, 0, 0, "%.3f"))
|
2019-09-23 00:24:10 -07:00
|
|
|
HALSIM_SetPDPCurrent(i, right, val);
|
2020-01-20 22:47:36 -08:00
|
|
|
float rightWidth = ImGui::GetItemRectSize().x;
|
|
|
|
|
rightInfo.PopupEditName(right);
|
2019-09-23 00:24:10 -07:00
|
|
|
ImGui::NextColumn();
|
2020-01-20 22:47:36 -08:00
|
|
|
|
|
|
|
|
float width = (std::max)(leftWidth, rightWidth) * 2;
|
|
|
|
|
if (width > maxWidth) maxWidth = width;
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
ImGui::Columns(1);
|
2020-01-20 22:47:36 -08:00
|
|
|
ImGui::Dummy(ImVec2(maxWidth, 0));
|
2019-09-23 00:24:10 -07:00
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!hasAny) ImGui::Text("No PDPs");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PDPGui::Initialize() {
|
2020-01-20 22:47:36 -08:00
|
|
|
gChannels.Initialize();
|
2019-09-23 00:24:10 -07:00
|
|
|
HALSimGui::AddWindow("PDP", DisplayPDP, ImGuiWindowFlags_AlwaysAutoResize);
|
|
|
|
|
// hide it by default
|
|
|
|
|
HALSimGui::SetWindowVisibility("PDP", HALSimGui::kHide);
|
|
|
|
|
HALSimGui::SetDefaultWindowPos("PDP", 245, 155);
|
|
|
|
|
}
|