mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add simulation GUI plugin
This uses Dear Imgui to provide a cross-platform integrated GUI for robot simulation. The GUI provides fully integrated DS and joystick support so it's not necessary to run the official DS.
This commit is contained in:
58
simulation/halsim_gui/src/main/native/cpp/SolenoidGui.cpp
Normal file
58
simulation/halsim_gui/src/main/native/cpp/SolenoidGui.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* 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 "SolenoidGui.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <imgui.h>
|
||||
#include <mockdata/PCMData.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
|
||||
#include "ExtraGuiWidgets.h"
|
||||
#include "HALSimGui.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
static void DisplaySolenoids() {
|
||||
bool hasOutputs = false;
|
||||
static const int numPCM = HAL_GetNumPCMModules();
|
||||
static const int numChannels = HAL_GetNumSolenoidChannels();
|
||||
for (int i = 0; i < numPCM; ++i) {
|
||||
bool anyInit = false;
|
||||
wpi::SmallVector<int, 16> channels;
|
||||
channels.resize(numChannels);
|
||||
for (int j = 0; j < numChannels; ++j) {
|
||||
if (HALSIM_GetPCMSolenoidInitialized(i, j)) {
|
||||
anyInit = true;
|
||||
channels[j] = HALSIM_GetPCMSolenoidOutput(i, j) ? 1 : -1;
|
||||
} else {
|
||||
channels[j] = -2;
|
||||
}
|
||||
}
|
||||
|
||||
if (!anyInit) continue;
|
||||
hasOutputs = true;
|
||||
|
||||
ImGui::Text("PCM[%d]", i);
|
||||
ImGui::SameLine();
|
||||
|
||||
// show channels as LED indicators
|
||||
static const ImU32 colors[] = {IM_COL32(255, 255, 102, 255),
|
||||
IM_COL32(128, 128, 128, 255)};
|
||||
DrawLEDs(channels.data(), channels.size(), channels.size(), colors);
|
||||
}
|
||||
if (!hasOutputs) ImGui::Text("No solenoids");
|
||||
}
|
||||
|
||||
void SolenoidGui::Initialize() {
|
||||
HALSimGui::AddWindow("Solenoids", DisplaySolenoids,
|
||||
ImGuiWindowFlags_AlwaysAutoResize);
|
||||
HALSimGui::SetDefaultWindowPos("Solenoids", 290, 20);
|
||||
}
|
||||
Reference in New Issue
Block a user