mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[sim] Add GUI support for the REV PH (#6704)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "glass/hardware/PCM.h"
|
||||
#include "glass/hardware/Pneumatic.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
@@ -20,8 +20,8 @@
|
||||
|
||||
using namespace glass;
|
||||
|
||||
bool glass::DisplayPCMSolenoids(PCMModel* model, int index,
|
||||
bool outputsEnabled) {
|
||||
bool glass::DisplayPneumaticControlSolenoids(PneumaticControlModel* model,
|
||||
int index, bool outputsEnabled) {
|
||||
wpi::SmallVector<int, 16> channels;
|
||||
model->ForEachSolenoid([&](SolenoidModel& solenoid, int j) {
|
||||
if (auto data = solenoid.GetOutputData()) {
|
||||
@@ -50,7 +50,8 @@ bool glass::DisplayPCMSolenoids(PCMModel* model, int index,
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{} [{}]###header", name,
|
||||
index);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "PCM[{}]###header", index);
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{}[{}]###header",
|
||||
model->GetName(), index);
|
||||
}
|
||||
|
||||
// header
|
||||
@@ -85,32 +86,29 @@ bool glass::DisplayPCMSolenoids(PCMModel* model, int index,
|
||||
return true;
|
||||
}
|
||||
|
||||
void glass::DisplayPCMsSolenoids(PCMsModel* model, bool outputsEnabled,
|
||||
std::string_view noneMsg) {
|
||||
void glass::DisplayPneumaticControlsSolenoids(PneumaticControlsModel* model,
|
||||
bool outputsEnabled,
|
||||
std::string_view noneMsg) {
|
||||
bool hasAny = false;
|
||||
model->ForEachPCM([&](PCMModel& pcm, int i) {
|
||||
PushID(i);
|
||||
if (DisplayPCMSolenoids(&pcm, i, outputsEnabled)) {
|
||||
hasAny = true;
|
||||
}
|
||||
PopID();
|
||||
});
|
||||
model->ForEachPneumaticControl(
|
||||
[&](PneumaticControlModel& pneumaticControl, int i) {
|
||||
PushID(i);
|
||||
if (DisplayPneumaticControlSolenoids(&pneumaticControl, i,
|
||||
outputsEnabled)) {
|
||||
hasAny = true;
|
||||
}
|
||||
PopID();
|
||||
});
|
||||
if (!hasAny && !noneMsg.empty()) {
|
||||
ImGui::TextUnformatted(noneMsg.data(), noneMsg.data() + noneMsg.size());
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayCompressorDevice(PCMModel* model, int index,
|
||||
bool outputsEnabled) {
|
||||
auto compressor = model->GetCompressor();
|
||||
if (!compressor || !compressor->Exists()) {
|
||||
return;
|
||||
}
|
||||
DisplayCompressorDevice(compressor, index, outputsEnabled);
|
||||
}
|
||||
|
||||
void glass::DisplayCompressorDevice(CompressorModel* model, int index,
|
||||
bool outputsEnabled) {
|
||||
if (!model || !model->Exists()) {
|
||||
return;
|
||||
}
|
||||
char name[32];
|
||||
wpi::format_to_n_c_str(name, sizeof(name), "Compressor[{}]", index);
|
||||
|
||||
@@ -155,8 +153,11 @@ void glass::DisplayCompressorDevice(CompressorModel* model, int index,
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayCompressorsDevice(PCMsModel* model, bool outputsEnabled) {
|
||||
model->ForEachPCM([&](PCMModel& pcm, int i) {
|
||||
DisplayCompressorDevice(&pcm, i, outputsEnabled);
|
||||
});
|
||||
void glass::DisplayCompressorsDevice(PneumaticControlsModel* model,
|
||||
bool outputsEnabled) {
|
||||
model->ForEachPneumaticControl(
|
||||
[&](PneumaticControlModel& pneumaticControl, int i) {
|
||||
DisplayCompressorDevice(pneumaticControl.GetCompressor(), i,
|
||||
outputsEnabled);
|
||||
});
|
||||
}
|
||||
@@ -4,7 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include <wpi/function_ref.h>
|
||||
|
||||
@@ -34,27 +36,45 @@ class SolenoidModel : public Model {
|
||||
virtual void SetOutput(bool val) = 0;
|
||||
};
|
||||
|
||||
class PCMModel : public Model {
|
||||
class PneumaticControlModel : public Model {
|
||||
public:
|
||||
virtual CompressorModel* GetCompressor() = 0;
|
||||
|
||||
virtual void ForEachSolenoid(
|
||||
wpi::function_ref<void(SolenoidModel& model, int index)> func) = 0;
|
||||
|
||||
virtual std::string_view GetName() = 0;
|
||||
};
|
||||
|
||||
class PCMsModel : public Model {
|
||||
class PneumaticControlsModel : public Model {
|
||||
public:
|
||||
virtual void ForEachPCM(
|
||||
wpi::function_ref<void(PCMModel& model, int index)> func) = 0;
|
||||
virtual void ForEachPneumaticControl(
|
||||
wpi::function_ref<void(PneumaticControlModel& model, int index)>
|
||||
func) = 0;
|
||||
};
|
||||
|
||||
bool DisplayPCMSolenoids(PCMModel* model, int index, bool outputsEnabled);
|
||||
void DisplayPCMsSolenoids(PCMsModel* model, bool outputsEnabled,
|
||||
std::string_view noneMsg = "No solenoids");
|
||||
struct AllPneumaticControlsModel : public Model {
|
||||
AllPneumaticControlsModel(std::unique_ptr<PneumaticControlsModel> pcms,
|
||||
std::unique_ptr<PneumaticControlsModel> phs)
|
||||
: pcms{std::move(pcms)}, phs{std::move(phs)} {};
|
||||
std::unique_ptr<PneumaticControlsModel> pcms;
|
||||
std::unique_ptr<PneumaticControlsModel> phs;
|
||||
void Update() override {
|
||||
pcms->Update();
|
||||
phs->Update();
|
||||
};
|
||||
bool Exists() override { return true; }
|
||||
};
|
||||
|
||||
bool DisplayPneumaticControlSolenoids(PneumaticControlModel* model, int index,
|
||||
bool outputsEnabled);
|
||||
void DisplayPneumaticControlsSolenoids(
|
||||
PneumaticControlsModel* model, bool outputsEnabled,
|
||||
std::string_view noneMsg = "No solenoids");
|
||||
|
||||
void DisplayCompressorDevice(PCMModel* model, int index, bool outputsEnabled);
|
||||
void DisplayCompressorDevice(CompressorModel* model, int index,
|
||||
bool outputsEnabled);
|
||||
void DisplayCompressorsDevice(PCMsModel* model, bool outputsEnabled);
|
||||
void DisplayCompressorsDevice(PneumaticControlsModel* model,
|
||||
bool outputsEnabled);
|
||||
|
||||
} // namespace glass
|
||||
Reference in New Issue
Block a user