mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Sim GUI: Add option to disable outputs on DS disable
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <imgui.h>
|
||||
#include <mockdata/PCMData.h>
|
||||
|
||||
#include "HALSimGui.h"
|
||||
#include "SimDeviceGui.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
@@ -28,7 +29,10 @@ static void DisplayCompressors() {
|
||||
HAL_Value value;
|
||||
|
||||
// enabled
|
||||
value = HAL_MakeBoolean(HALSIM_GetPCMCompressorOn(i));
|
||||
if (HALSimGui::AreOutputsDisabled())
|
||||
value = HAL_MakeBoolean(false);
|
||||
else
|
||||
value = HAL_MakeBoolean(HALSIM_GetPCMCompressorOn(i));
|
||||
if (SimDeviceGui::DisplayValue("Running", false, &value))
|
||||
HALSIM_SetPCMCompressorOn(i, value.data.v_boolean);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <imgui_impl_glfw.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <mockdata/DriverStationData.h>
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
@@ -61,6 +62,7 @@ static int gUserScale = 2;
|
||||
static int gStyle = 0;
|
||||
static constexpr int kScaledFontLevels = 9;
|
||||
static ImFont* gScaledFont[kScaledFontLevels];
|
||||
static bool gDisableOutputsOnDSDisable = true;
|
||||
|
||||
static void glfw_error_callback(int error, const char* description) {
|
||||
wpi::errs() << "GLFW Error " << error << ": " << description << '\n';
|
||||
@@ -126,6 +128,8 @@ static void SimWindowsReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
gUserScale = num;
|
||||
} else if (name == "style") {
|
||||
gStyle = num;
|
||||
} else if (name == "disableOutputsOnDS") {
|
||||
gDisableOutputsOnDSDisable = num;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -146,9 +150,9 @@ static void SimWindowsWriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
ImGuiTextBuffer* out_buf) {
|
||||
out_buf->appendf(
|
||||
"[SimWindow][GLOBAL]\nwidth=%d\nheight=%d\nmaximized=%d\n"
|
||||
"xpos=%d\nypos=%d\nuserScale=%d\nstyle=%d\n\n",
|
||||
"xpos=%d\nypos=%d\nuserScale=%d\nstyle=%d\ndisableOutputsOnDS=%d\n",
|
||||
gWindowWidth, gWindowHeight, gWindowMaximized, gWindowXPos, gWindowYPos,
|
||||
gUserScale, gStyle);
|
||||
gUserScale, gStyle, gDisableOutputsOnDSDisable ? 1 : 0);
|
||||
for (auto&& window : gWindows)
|
||||
out_buf->appendf("[SimWindow][%s]\nvisible=%d\nenabled=%d\n\n",
|
||||
window.name.c_str(), window.visible ? 1 : 0,
|
||||
@@ -244,6 +248,10 @@ void HALSimGui::SetDefaultWindowSize(const char* name, float width,
|
||||
window.size = ImVec2{width, height};
|
||||
}
|
||||
|
||||
bool HALSimGui::AreOutputsDisabled() {
|
||||
return gDisableOutputsOnDSDisable && !HALSIM_GetDriverStationEnabled();
|
||||
}
|
||||
|
||||
bool HALSimGui::Initialize() {
|
||||
// Setup window
|
||||
glfwSetErrorCallback(glfw_error_callback);
|
||||
@@ -432,6 +440,8 @@ void HALSimGui::Main(void*) {
|
||||
ImGui::BeginMainMenuBar();
|
||||
|
||||
if (ImGui::BeginMenu("Options")) {
|
||||
ImGui::MenuItem("Disable outputs on DS disable", nullptr,
|
||||
&gDisableOutputsOnDSDisable, true);
|
||||
for (auto&& menu : gOptionMenus) {
|
||||
if (menu) menu();
|
||||
}
|
||||
@@ -581,4 +591,8 @@ void HALSIMGUI_SetDefaultWindowSize(const char* name, float width,
|
||||
HALSimGui::SetDefaultWindowSize(name, width, height);
|
||||
}
|
||||
|
||||
int HALSIMGUI_AreOutputsDisabled(void) {
|
||||
return HALSimGui::AreOutputsDisabled();
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -42,7 +42,7 @@ static void DisplayPWMs() {
|
||||
|
||||
char name[32];
|
||||
std::snprintf(name, sizeof(name), "PWM[%d]", i);
|
||||
float val = HALSIM_GetPWMSpeed(i);
|
||||
float val = HALSimGui::AreOutputsDisabled() ? 0 : HALSIM_GetPWMSpeed(i);
|
||||
ImGui::Value(name, val, "%0.3f");
|
||||
|
||||
// lazily build history storage
|
||||
|
||||
@@ -35,8 +35,12 @@ static void DisplayRelays() {
|
||||
else
|
||||
first = false;
|
||||
|
||||
bool forward = HALSIM_GetRelayForward(i);
|
||||
bool reverse = HALSIM_GetRelayReverse(i);
|
||||
bool forward = false;
|
||||
bool reverse = false;
|
||||
if (!HALSimGui::AreOutputsDisabled()) {
|
||||
reverse = HALSIM_GetRelayReverse(i);
|
||||
forward = HALSIM_GetRelayForward(i);
|
||||
}
|
||||
|
||||
ImGui::Text("Relay[%d]", i);
|
||||
ImGui::SameLine();
|
||||
|
||||
@@ -31,7 +31,10 @@ static void DisplaySolenoids() {
|
||||
for (int j = 0; j < numChannels; ++j) {
|
||||
if (HALSIM_GetPCMSolenoidInitialized(i, j)) {
|
||||
anyInit = true;
|
||||
channels[j] = HALSIM_GetPCMSolenoidOutput(i, j) ? 1 : -1;
|
||||
channels[j] = (!HALSimGui::AreOutputsDisabled() &&
|
||||
HALSIM_GetPCMSolenoidOutput(i, j))
|
||||
? 1
|
||||
: -1;
|
||||
} else {
|
||||
channels[j] = -2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user