From 467258e050ff5a40467611cbc1cebf00fcbf06b0 Mon Sep 17 00:00:00 2001 From: Dean Brettle Date: Mon, 23 Nov 2020 19:46:27 -0800 Subject: [PATCH] [sim] GUI: Add option to not zero disconnected joysticks (#2876) This allows team sim code to set the joystick values and not have them overwritten by the GUI. --- .../src/main/native/cpp/DriverStationGui.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp b/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp index 96b53cba6f..67774ca54f 100644 --- a/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp @@ -103,6 +103,7 @@ static RobotJoystick gRobotJoysticks[HAL_kMaxJoysticks]; static std::unique_ptr gJoystickSources[HAL_kMaxJoysticks]; static bool gDisableDS = false; +static bool gZeroDisconnectedJoysticks = true; static std::atomic* gDSSocketConnected = nullptr; static inline bool IsDSDisabled() { @@ -229,13 +230,19 @@ static void DriverStationReadLine(ImGuiContext* ctx, int num; if (value.getAsInteger(10, num)) return; gDisableDS = num; + } else if (name == "zeroDisconnectedJoysticks") { + int num; + if (value.getAsInteger(10, num)) return; + gZeroDisconnectedJoysticks = num; } } static void DriverStationWriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf) { - out_buf->appendf("[DriverStation][Main]\ndisable=%d\n\n", gDisableDS ? 1 : 0); + out_buf->appendf( + "[DriverStation][Main]\ndisable=%d\nzeroDisconnectedJoysticks=%d\n\n", + gDisableDS ? 1 : 0, gZeroDisconnectedJoysticks ? 1 : 0); } void SystemJoystick::Update(int i) { @@ -370,6 +377,7 @@ void RobotJoystick::Update() { } void RobotJoystick::SetHAL(int i) { + if (!gZeroDisconnectedJoysticks && (!sys || !sys->present)) return; // set at HAL level HALSIM_SetJoystickDescriptor(i, &desc); HALSIM_SetJoystickAxes(i, &axes); @@ -675,6 +683,8 @@ static void DriverStationOptionMenu() { ImGui::MenuItem("Turn off DS (real DS connected)", nullptr, true, false); } else { ImGui::MenuItem("Turn off DS", nullptr, &gDisableDS); + ImGui::MenuItem("Zero disconnected joysticks", nullptr, + &gZeroDisconnectedJoysticks, true); } }