diff --git a/hal/src/main/native/include/hal/simulation/PCMData.h b/hal/src/main/native/include/hal/simulation/PCMData.h index ad2188dc78..58f5e4cac0 100644 --- a/hal/src/main/native/include/hal/simulation/PCMData.h +++ b/hal/src/main/native/include/hal/simulation/PCMData.h @@ -34,6 +34,14 @@ HAL_Bool HALSIM_GetPCMSolenoidOutput(int32_t index, int32_t channel); void HALSIM_SetPCMSolenoidOutput(int32_t index, int32_t channel, HAL_Bool solenoidOutput); +int32_t HALSIM_RegisterPCMAnySolenoidInitializedCallback( + int32_t index, HAL_NotifyCallback callback, void* param, + HAL_Bool initialNotify); +void HALSIM_CancelPCMAnySolenoidInitializedCallback(int32_t index, int32_t uid); +HAL_Bool HALSIM_GetPCMAnySolenoidInitialized(int32_t index); +void HALSIM_SetPCMAnySolenoidInitialized(int32_t index, + HAL_Bool anySolenoidInitialized); + int32_t HALSIM_RegisterPCMCompressorInitializedCallback( int32_t index, HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify); diff --git a/hal/src/main/native/sim/Solenoid.cpp b/hal/src/main/native/sim/Solenoid.cpp index 1881a3235a..14662a20b7 100644 --- a/hal/src/main/native/sim/Solenoid.cpp +++ b/hal/src/main/native/sim/Solenoid.cpp @@ -75,6 +75,7 @@ HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle portHandle, solenoidPort->channel = static_cast(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; diff --git a/hal/src/main/native/sim/mockdata/PCMData.cpp b/hal/src/main/native/sim/mockdata/PCMData.cpp index 6193b05e0e..0495c54c29 100644 --- a/hal/src/main/native/sim/mockdata/PCMData.cpp +++ b/hal/src/main/native/sim/mockdata/PCMData.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 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. */ @@ -25,6 +25,7 @@ void PCMData::ResetData() { solenoidInitialized[i].Reset(false); solenoidOutput[i].Reset(false); } + anySolenoidInitialized.Reset(false); compressorInitialized.Reset(false); compressorOn.Reset(false); closedLoopEnabled.Reset(true); @@ -43,6 +44,7 @@ HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(HAL_Bool, HALSIM, PCMSolenoidInitialized, SimPCMData, solenoidInitialized) HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(HAL_Bool, HALSIM, PCMSolenoidOutput, SimPCMData, solenoidOutput) +DEFINE_CAPI(HAL_Bool, AnySolenoidInitialized, anySolenoidInitialized) DEFINE_CAPI(HAL_Bool, CompressorInitialized, compressorInitialized) DEFINE_CAPI(HAL_Bool, CompressorOn, compressorOn) DEFINE_CAPI(HAL_Bool, ClosedLoopEnabled, closedLoopEnabled) diff --git a/hal/src/main/native/sim/mockdata/PCMDataInternal.h b/hal/src/main/native/sim/mockdata/PCMDataInternal.h index 0d3752ee85..0e2c6236a0 100644 --- a/hal/src/main/native/sim/mockdata/PCMDataInternal.h +++ b/hal/src/main/native/sim/mockdata/PCMDataInternal.h @@ -15,6 +15,7 @@ namespace hal { class PCMData { HAL_SIMDATAVALUE_DEFINE_NAME(SolenoidInitialized) HAL_SIMDATAVALUE_DEFINE_NAME(SolenoidOutput) + HAL_SIMDATAVALUE_DEFINE_NAME(AnySolenoidInitialized) HAL_SIMDATAVALUE_DEFINE_NAME(CompressorInitialized) HAL_SIMDATAVALUE_DEFINE_NAME(CompressorOn) HAL_SIMDATAVALUE_DEFINE_NAME(ClosedLoopEnabled) @@ -37,6 +38,8 @@ class PCMData { SimDataValue solenoidOutput[kNumSolenoidChannels]; + SimDataValue + anySolenoidInitialized{false}; SimDataValue compressorInitialized{false}; SimDataValue compressorOn{