/************************************************************************** * * Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file ModePostTreat.c * * @author (last) Praneeth Bunne * @date (last) 13-Apr-2026 * * @author (original) Praneeth Bunne * @date (original) 13-Apr-2026 * ***************************************************************************/ #include "Buttons.h" #include "ModePostTreat.h" #include "OperationModes.h" #include "StateServices/TubeSetAutoEject.h" /** * @addtogroup TDPostTreatmentMode * @{ */ // ********** private definitions ********** static TD_POST_TREATMENT_STATE_T currentPostTreatmentState; ///< Current Post-Treatment sub-state // ********** private function prototypes ********** static void setPostTreatStateTransition( TD_POST_TREATMENT_STATE_T state ); static TD_POST_TREATMENT_STATE_T handlePatientDisconnectionState( void ); static TD_POST_TREATMENT_STATE_T handleAutoEjectState( void ); static TD_POST_TREATMENT_STATE_T handleDisposableRemovalState(void ); static TD_POST_TREATMENT_STATE_T handleVerifyState( void ); /*********************************************************************//** * @brief * The initPostTreatmentMode function initializes the Post-Treatment mode. * @details Inputs: none * @details Outputs: Resets all Post-Treatment sub-state variables. * @return none **************************************************************************/ void initPostTreatmentMode( void ) { currentPostTreatmentState = TD_POST_TREATMENT_AUTO_EJECT_STATE; } /*********************************************************************//** * @brief * The transitionToPostTreatmentMode function prepares the system for * entry into Post-Treatment mode. * @details Inputs: none * @details Outputs: Initializes mode specific state and returns the starting * Post-Treatment sub-state. * @return Initial Post-Treatment sub-state **************************************************************************/ U32 transitionToPostTreatmentMode( void ) { initPostTreatmentMode(); initTubeSetAutoEject(); setPostTreatStateTransition( currentPostTreatmentState ); return (U32)currentPostTreatmentState; } /*********************************************************************//** * @brief * The setPostTreatStateTransition function sets the actuators and variables * for the state transition in Post-Treatment mode. * @details Inputs: Valve states, Pump speed * @details Outputs: Actuate valves, pumps as desired * @Param state Post-Treatment state enum * @return none **************************************************************************/ static void setPostTreatStateTransition( TD_POST_TREATMENT_STATE_T state ) { switch( state ) { case TD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE: //TODO: actuator configuration; break; case TD_POST_TREATMENT_AUTO_EJECT_STATE: signalBloodPumpHardStop(); break; case TD_POST_TREATMENT_DISPOSABLE_REMOVAL_STATE: //TODO: actuator configuration; break; case TD_POST_TREATMENT_VERIFY_STATE: //TODO: actuator configuration; break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_POST_TREATMENT_INVALID_STATE1, currentPostTreatmentState ); break; } } /*********************************************************************//** * @brief * The execPostTreatmentMode function executes the Post-Treatment * mode state machine. * @details Inputs: stop button status and system conditions via helpers. * @details Outputs: Advances the Post-Treatment sub-state * @return current Post-Treatment sub-state. *************************************************************************/ U32 execPostTreatmentMode( void ) { BOOL stop = isStopButtonPressed(); TD_POST_TREATMENT_STATE_T prevPostTreatmentState = currentPostTreatmentState; // Execute mode state machine switch ( currentPostTreatmentState ) { case TD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE: //currentPostTreatmentState = handlePatientDisconnectionState(); break; case TD_POST_TREATMENT_AUTO_EJECT_STATE: currentPostTreatmentState = handleAutoEjectState(); break; case TD_POST_TREATMENT_DISPOSABLE_REMOVAL_STATE: //currentPostTreatmentState = handleDisposableRemovalState(); break; case TD_POST_TREATMENT_VERIFY_STATE: //currentPostTreatmentState = handleVerifyState(); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_POST_TREATMENT_INVALID_STATE, currentPostTreatmentState ); break; } if ( prevPostTreatmentState != currentPostTreatmentState) { setPostTreatStateTransition( currentPostTreatmentState ); } return (U32)currentPostTreatmentState; } /*********************************************************************//** * @brief * The handlePatientDisconnectionState function executes the Post-Treatment * mode Patient Disconnection state machine. * @details Inputs: TODO fill up if any * @details Outputs: TODO fill up if any * @return next post-treatment mode state *************************************************************************/ static TD_POST_TREATMENT_STATE_T handlePatientDisconnectionState( void ) { TD_POST_TREATMENT_STATE_T state = TD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE; // TODO: Transition to Auto Eject state on completion when implemented // state = TD_POST_TREATMENT_AUTO_EJECT_STATE; return state; } /*********************************************************************//** * @brief * The handleAutoEjectState function calls Tube Set Auto-Eject Service and * advances to Disposable removal state once the service signals * completion. * @details Inputs: none * @details Outputs: Advances Post-Treatment state when eject is complete. * @return next Post-Treatment mode state *************************************************************************/ static TD_POST_TREATMENT_STATE_T handleAutoEjectState( void ) { TD_POST_TREATMENT_STATE_T state = TD_POST_TREATMENT_AUTO_EJECT_STATE; // call tube set eject service to auto-eject tube set execTubeSetAutoEject(); if( TRUE == isTubeSetAutoEjectComplete() ) { state = TD_POST_TREATMENT_DISPOSABLE_REMOVAL_STATE; } return state; } /*********************************************************************//** * @brief * The handleDisposableRemovalState function executes the Post-Treatment * mode Disposable Removal state machine. * @details Inputs: TODO fill up if any * @details Outputs: TODO fill up if any * @return next post-treatment mode state *************************************************************************/ static TD_POST_TREATMENT_STATE_T handleDisposableRemovalState( void ) { TD_POST_TREATMENT_STATE_T state = TD_POST_TREATMENT_DISPOSABLE_REMOVAL_STATE; // TODO: Transition to Verify state on completion when implemented // state = TD_POST_TREATMENT_VERIFY_STATE; return state; } /*********************************************************************//** * @brief * The handleVerifyState function executes the Post-Treatment * mode Verify state machine. * @details Inputs: TODO fill up if any * @details Outputs: TODO fill up if any * @return next post-treatment mode state *************************************************************************/ static TD_POST_TREATMENT_STATE_T handleVerifyState( void ) { TD_POST_TREATMENT_STATE_T state = TD_POST_TREATMENT_VERIFY_STATE; // TODO return state; } /**@}*/