From 6844f05c3ddde0a522841d852b4f712e2173c248 Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 23 Dec 2016 12:35:45 -0800 Subject: [PATCH] Adds SetAllSolenoids function to CTRE PCM code (#419) Closes #417. --- hal/include/HAL/Solenoid.h | 1 + hal/include/ctre/PCM.h | 8 ++++++++ hal/lib/athena/Solenoid.cpp | 6 ++++++ hal/lib/athena/ctre/PCM.cpp | 16 ++++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/hal/include/HAL/Solenoid.h b/hal/include/HAL/Solenoid.h index dc83892274..fbbbc76f6c 100644 --- a/hal/include/HAL/Solenoid.h +++ b/hal/include/HAL/Solenoid.h @@ -25,6 +25,7 @@ HAL_Bool HAL_GetSolenoid(HAL_SolenoidHandle solenoidPortHandle, int32_t HAL_GetAllSolenoids(int32_t module, int32_t* status); void HAL_SetSolenoid(HAL_SolenoidHandle solenoidPortHandle, HAL_Bool value, int32_t* status); +void HAL_SetAllSolenoids(int32_t module, int32_t state, int32_t* status); int32_t HAL_GetPCMSolenoidBlackList(int32_t module, int32_t* status); HAL_Bool HAL_GetPCMSolenoidVoltageStickyFault(int32_t module, int32_t* status); HAL_Bool HAL_GetPCMSolenoidVoltageFault(int32_t module, int32_t* status); diff --git a/hal/include/ctre/PCM.h b/hal/include/ctre/PCM.h index 625108c746..03d9b2d2d4 100644 --- a/hal/include/ctre/PCM.h +++ b/hal/include/ctre/PCM.h @@ -16,6 +16,13 @@ public: */ CTR_Code SetSolenoid(unsigned char idx, bool en); + /* Set all PCM solenoid states + * + * @Return - CTR_Code - Error code (if any) for setting solenoids + * @Param - state Bitfield to set all solenoids to + */ + CTR_Code SetAllSolenoids(UINT8 state); + /* Enables PCM Closed Loop Control of Compressor via pressure switch * @Return - CTR_Code - Error code (if any) for setting solenoid * @Param - en - Enable / Disable Closed Loop Control @@ -192,6 +199,7 @@ public: extern "C" { void * c_PCM_Init(void); CTR_Code c_SetSolenoid(void * handle,unsigned char idx,INT8 param); + CTR_Code c_SetAllSolenoids(void * handle,UINT8 state); CTR_Code c_SetClosedLoopControl(void * handle,INT8 param); CTR_Code c_ClearStickyFaults(void * handle,INT8 param); CTR_Code c_GetSolenoid(void * handle,UINT8 idx,INT8 * status); diff --git a/hal/lib/athena/Solenoid.cpp b/hal/lib/athena/Solenoid.cpp index ef0e47a478..a27265215e 100644 --- a/hal/lib/athena/Solenoid.cpp +++ b/hal/lib/athena/Solenoid.cpp @@ -116,6 +116,12 @@ void HAL_SetSolenoid(HAL_SolenoidHandle solenoidPortHandle, HAL_Bool value, *status = PCM_modules[port->module]->SetSolenoid(port->channel, value); } +void HAL_SetAllSolenoids(int32_t module, int32_t state, int32_t* status) { + if (!checkPCMInit(module, status)) return; + + *status = PCM_modules[module]->SetAllSolenoids(state); +} + int32_t HAL_GetPCMSolenoidBlackList(int32_t module, int32_t* status) { if (!checkPCMInit(module, status)) return 0; uint8_t value; diff --git a/hal/lib/athena/ctre/PCM.cpp b/hal/lib/athena/ctre/PCM.cpp index d662daab37..26767432f5 100644 --- a/hal/lib/athena/ctre/PCM.cpp +++ b/hal/lib/athena/ctre/PCM.cpp @@ -140,6 +140,19 @@ CTR_Code PCM::SetSolenoid(unsigned char idx, bool en) return CTR_OKAY; } +/* Set all PCM solenoid states + * + * @Return - CTR_Code - Error code (if any) for setting solenoids + * @Param - state Bitfield to set all solenoids to + */ +CTR_Code PCM::SetAllSolenoids(UINT8 state) { + CtreCanNode::txTask toFill = GetTx(CONTROL_1 | GetDeviceNumber()); + if(toFill.IsEmpty())return CTR_UnexpectedArbId; + toFill->solenoidBits = state; + FlushTx(toFill); + return CTR_OKAY; +} + /* Clears PCM sticky faults (indicators of past faults * * @Return - CTR_Code - Error code (if any) for setting solenoid @@ -465,6 +478,9 @@ extern "C" { CTR_Code c_SetSolenoid(void * handle, unsigned char idx, INT8 param) { return ((PCM*) handle)->SetSolenoid(idx, param); } + CTR_Code c_SetAllSolenoids(void * handle, UINT8 state) { + return ((PCM*) handle)->SetAllSolenoids(state); + } CTR_Code c_SetClosedLoopControl(void * handle, INT8 param) { return ((PCM*) handle)->SetClosedLoopControl(param); }