diff --git a/simulation/halsim_gui/src/main/native/cpp/CompressorGui.cpp b/simulation/halsim_gui/src/main/native/cpp/CompressorGui.cpp index 929de6ad2d..737a6f93c1 100644 --- a/simulation/halsim_gui/src/main/native/cpp/CompressorGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/CompressorGui.cpp @@ -14,6 +14,7 @@ #include #include +#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); diff --git a/simulation/halsim_gui/src/main/native/cpp/HALSimGui.cpp b/simulation/halsim_gui/src/main/native/cpp/HALSimGui.cpp index 23afe399e4..79df3dfb05 100644 --- a/simulation/halsim_gui/src/main/native/cpp/HALSimGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/HALSimGui.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -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" diff --git a/simulation/halsim_gui/src/main/native/cpp/PWMGui.cpp b/simulation/halsim_gui/src/main/native/cpp/PWMGui.cpp index 6ae7f44c99..8303f04ea5 100644 --- a/simulation/halsim_gui/src/main/native/cpp/PWMGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/PWMGui.cpp @@ -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 diff --git a/simulation/halsim_gui/src/main/native/cpp/RelayGui.cpp b/simulation/halsim_gui/src/main/native/cpp/RelayGui.cpp index ff5db47a1a..a833fffefe 100644 --- a/simulation/halsim_gui/src/main/native/cpp/RelayGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/RelayGui.cpp @@ -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(); diff --git a/simulation/halsim_gui/src/main/native/cpp/SolenoidGui.cpp b/simulation/halsim_gui/src/main/native/cpp/SolenoidGui.cpp index f5dc85c681..75712c6d36 100644 --- a/simulation/halsim_gui/src/main/native/cpp/SolenoidGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/SolenoidGui.cpp @@ -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; } diff --git a/simulation/halsim_gui/src/main/native/include/HALSimGui.h b/simulation/halsim_gui/src/main/native/include/HALSimGui.h index 00bf9b4d88..fd71cbee1e 100644 --- a/simulation/halsim_gui/src/main/native/include/HALSimGui.h +++ b/simulation/halsim_gui/src/main/native/include/HALSimGui.h @@ -23,6 +23,7 @@ void HALSIMGUI_SetWindowVisibility(const char* name, int32_t visibility); void HALSIMGUI_SetDefaultWindowPos(const char* name, float x, float y); void HALSIMGUI_SetDefaultWindowSize(const char* name, float width, float height); +int HALSIMGUI_AreOutputsDisabled(void); } // extern "C" @@ -125,6 +126,13 @@ class HALSimGui { * @param height height */ static void SetDefaultWindowSize(const char* name, float width, float height); + + /** + * Returns true if outputs are disabled. + * + * @return true if outputs are disabled, false otherwise. + */ + static bool AreOutputsDisabled(); }; } // namespace halsimgui