[hal] Add a unified PCM object (#3331)

This commit is contained in:
Thad House
2021-06-05 22:36:39 -07:00
committed by GitHub
parent dea841103d
commit 0e702eb799
103 changed files with 2643 additions and 5676 deletions

View File

@@ -5,10 +5,10 @@
#include "WSProvider_PCM.h"
#include <hal/Ports.h>
#include <hal/simulation/PCMData.h>
#include <hal/simulation/CTREPCMData.h>
#define REGISTER_PCM(halsim, jsonid, ctype, haltype) \
HALSIM_RegisterPCM##halsim##Callback( \
#define REGISTER_CTREPCM(halsim, jsonid, ctype, haltype) \
HALSIM_RegisterCTREPCM##halsim##Callback( \
m_channel, \
[](const char* name, void* param, const struct HAL_Value* value) { \
static_cast<HALSimWSProviderPCM*>(param)->ProcessHalCallback( \
@@ -17,7 +17,7 @@
this, true)
namespace wpilibws {
void HALSimWSProviderPCM::Initialize(WSRegisterFunc webRegisterFunc) {
CreateProviders<HALSimWSProviderPCM>("PCM", HAL_GetNumPCMModules(),
CreateProviders<HALSimWSProviderPCM>("CTREPCM", HAL_GetNumCTREPCMModules(),
webRegisterFunc);
}
@@ -26,13 +26,14 @@ HALSimWSProviderPCM::~HALSimWSProviderPCM() {
}
void HALSimWSProviderPCM::RegisterCallbacks() {
m_initCbKey = REGISTER_PCM(CompressorInitialized, "<init", bool, boolean);
m_onCbKey = REGISTER_PCM(CompressorInitialized, ">on", bool, boolean);
m_initCbKey = REGISTER_CTREPCM(Initialized, "<init", bool, boolean);
m_onCbKey = REGISTER_CTREPCM(CompressorOn, ">on", bool, boolean);
m_closedLoopCbKey =
REGISTER_PCM(ClosedLoopEnabled, "<closed_loop", bool, boolean);
REGISTER_CTREPCM(ClosedLoopEnabled, "<closed_loop", bool, boolean);
m_pressureSwitchCbKey =
REGISTER_PCM(PressureSwitch, ">pressure_switch", bool, boolean);
m_currentCbKey = REGISTER_PCM(CompressorCurrent, ">current", double, double);
REGISTER_CTREPCM(PressureSwitch, ">pressure_switch", bool, boolean);
m_currentCbKey =
REGISTER_CTREPCM(CompressorCurrent, ">current", double, double);
}
void HALSimWSProviderPCM::CancelCallbacks() {
@@ -40,11 +41,11 @@ void HALSimWSProviderPCM::CancelCallbacks() {
}
void HALSimWSProviderPCM::DoCancelCallbacks() {
HALSIM_CancelPCMCompressorInitializedCallback(m_channel, m_initCbKey);
HALSIM_CancelPCMCompressorOnCallback(m_channel, m_onCbKey);
HALSIM_CancelPCMClosedLoopEnabledCallback(m_channel, m_closedLoopCbKey);
HALSIM_CancelPCMPressureSwitchCallback(m_channel, m_pressureSwitchCbKey);
HALSIM_CancelPCMCompressorCurrentCallback(m_channel, m_currentCbKey);
HALSIM_CancelCTREPCMInitializedCallback(m_channel, m_initCbKey);
HALSIM_CancelCTREPCMCompressorOnCallback(m_channel, m_onCbKey);
HALSIM_CancelCTREPCMClosedLoopEnabledCallback(m_channel, m_closedLoopCbKey);
HALSIM_CancelCTREPCMPressureSwitchCallback(m_channel, m_pressureSwitchCbKey);
HALSIM_CancelCTREPCMCompressorCurrentCallback(m_channel, m_currentCbKey);
m_initCbKey = 0;
m_onCbKey = 0;

View File

@@ -5,10 +5,10 @@
#include "WSProvider_Solenoid.h"
#include <hal/Ports.h>
#include <hal/simulation/PCMData.h>
#include <hal/simulation/CTREPCMData.h>
#define REGISTER_SOLENOID(halsim, jsonid, ctype, haltype) \
HALSIM_RegisterPCMSolenoid##halsim##Callback( \
HALSIM_RegisterCTREPCMSolenoid##halsim##Callback( \
m_pcmIndex, m_solenoidIndex, \
[](const char* name, void* param, const struct HAL_Value* value) { \
static_cast<HALSimWSProviderSolenoid*>(param)->ProcessHalCallback( \
@@ -18,25 +18,26 @@
namespace wpilibws {
void HALSimWSProviderSolenoid::Initialize(WSRegisterFunc webRegisterFunc) {
for (int32_t pcmIndex = 0; pcmIndex < HAL_GetNumPCMModules(); ++pcmIndex) {
for (int32_t CTREPCMIndex = 0; CTREPCMIndex < HAL_GetNumCTREPCMModules();
++CTREPCMIndex) {
for (int32_t solenoidIndex = 0;
solenoidIndex < HAL_GetNumSolenoidChannels(); ++solenoidIndex) {
auto key =
("Solenoid/" + wpi::Twine(pcmIndex) + "," + wpi::Twine(solenoidIndex))
.str();
auto key = ("Solenoid/" + wpi::Twine(CTREPCMIndex) + "," +
wpi::Twine(solenoidIndex))
.str();
auto ptr = std::make_unique<HALSimWSProviderSolenoid>(
pcmIndex, solenoidIndex, key, "Solenoid");
CTREPCMIndex, solenoidIndex, key, "Solenoid");
webRegisterFunc(key, std::move(ptr));
}
}
}
HALSimWSProviderSolenoid::HALSimWSProviderSolenoid(int32_t pcmChannel,
HALSimWSProviderSolenoid::HALSimWSProviderSolenoid(int32_t CTREPCMChannel,
int32_t solenoidChannel,
const std::string& key,
const std::string& type)
: HALSimWSHalProvider(key, type),
m_pcmIndex(pcmChannel),
m_pcmIndex(CTREPCMChannel),
m_solenoidIndex(solenoidChannel) {
m_deviceId =
std::to_string(m_pcmIndex) + "," + std::to_string(solenoidChannel);
@@ -47,7 +48,7 @@ HALSimWSProviderSolenoid::~HALSimWSProviderSolenoid() {
}
void HALSimWSProviderSolenoid::RegisterCallbacks() {
m_initCbKey = REGISTER_SOLENOID(Initialized, "<init", bool, boolean);
// m_initCbKey = REGISTER_SOLENOID(Initialized, "<init", bool, boolean);
m_outputCbKey = REGISTER_SOLENOID(Output, "<output", bool, boolean);
}
@@ -56,10 +57,11 @@ void HALSimWSProviderSolenoid::CancelCallbacks() {
}
void HALSimWSProviderSolenoid::DoCancelCallbacks() {
HALSIM_CancelPCMSolenoidInitializedCallback(m_pcmIndex, m_solenoidIndex,
m_initCbKey);
HALSIM_CancelPCMSolenoidOutputCallback(m_pcmIndex, m_solenoidIndex,
m_outputCbKey);
// HALSIM_CancelCTREPCMSolenoidInitializedCallback(m_pcmIndex,
// m_solenoidIndex,
// m_initCbKey);
HALSIM_CancelCTREPCMSolenoidOutputCallback(m_pcmIndex, m_solenoidIndex,
m_outputCbKey);
m_initCbKey = 0;
m_outputCbKey = 0;