mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[sim] Add initialized flag for all solenoids on a PCM (#2897)
This allows much easier/faster checking for whether any solenoid has been initialized on a particular PCM.
This commit is contained in:
@@ -75,6 +75,7 @@ HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle,
|
||||
solenoidPort->channel = static_cast<uint8_t>(channel);
|
||||
|
||||
HALSIM_SetPCMSolenoidInitialized(module, channel, true);
|
||||
HALSIM_SetPCMAnySolenoidInitialized(module, true);
|
||||
|
||||
return handle;
|
||||
}
|
||||
@@ -83,6 +84,15 @@ void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoidPortHandle) {
|
||||
if (port == nullptr) return;
|
||||
solenoidHandles->Free(solenoidPortHandle);
|
||||
HALSIM_SetPCMSolenoidInitialized(port->module, port->channel, false);
|
||||
int count = 0;
|
||||
for (int i = 0; i < kNumSolenoidChannels; ++i) {
|
||||
if (HALSIM_GetPCMSolenoidInitialized(port->module, i)) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
HALSIM_SetPCMAnySolenoidInitialized(port->module, false);
|
||||
}
|
||||
}
|
||||
HAL_Bool HAL_CheckSolenoidModule(int32_t module) {
|
||||
return module < kNumPCMModules && module >= 0;
|
||||
|
||||
Reference in New Issue
Block a user