Index: firmware/App/Modes/ModePreTreat.c =================================================================== diff -u -rad1296a077cec6ed95674cc1267a750aaf8213c4 -rc288f2956e37f1f0b964b077af7c39b6387a5df6 --- firmware/App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision ad1296a077cec6ed95674cc1267a750aaf8213c4) +++ firmware/App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision c288f2956e37f1f0b964b077af7c39b6387a5df6) @@ -7,8 +7,8 @@ * * @file ModePreTreat.c * -* @author (last) Raghu Kallala -* @date (last) 08-May-2026 +* @author (last) Praneeth Bunne +* @date (last) 19-May-2026 * * @author (original) Dara Navaei * @date (original) 25-Sep-2025 @@ -20,26 +20,35 @@ #include "ModePreTreat.h" #include "OperationModes.h" #include "Timers.h" +#include "TubeSetInstall.h" #include "TxParams.h" /** * @addtogroup TDPreTreatmentMode * @{ */ -// ********** private definitions ********** - // ********** private data ********** static TD_PRE_TREATMENT_MODE_STATE_T currentPreTreatmentState; ///< Current Pre-Treatment sub-state +static BOOL goToInstallStateRequested; ///< Flag indicating a request to transition to Install state. // ********** private function prototypes ********** +static TD_PRE_TREATMENT_MODE_STATE_T handleWaterSampleState( void ); ///< Handle Water Sample state during Pre-Treatment +static TD_PRE_TREATMENT_MODE_STATE_T handleSelfTestConsumableState( void ); ///< Handle Self Test Consumable state during Pre-Treatment +static TD_PRE_TREATMENT_MODE_STATE_T handleSelfTestNoCartState( void ); ///< Handle Self Test No Cart state during Pre-Treatment +static TD_PRE_TREATMENT_MODE_STATE_T handleInstallState( void ); ///< Handle Install state during Pre-Treatment +static TD_PRE_TREATMENT_MODE_STATE_T handleSelfTestDryState( void ); ///< Handle Self Test Dry state during Pre-Treatment +static TD_PRE_TREATMENT_MODE_STATE_T handlePrimeState( void ); ///< Handle Prime state during Pre-Treatment +static TD_PRE_TREATMENT_MODE_STATE_T handleRecirculateState( void ); ///< Handle Recirculate state during Pre-Treatment static TD_PRE_TREATMENT_MODE_STATE_T handleRxState( void ); ///< Handle Confirm Rx state during Pre-Treatment +static TD_PRE_TREATMENT_MODE_STATE_T handlePatientConnectionState( void ); ///< Handle Patient Connection state during Pre-Treatment /*********************************************************************//** * @brief * The initPreTreatmentMode function initializes the Pre-Treatment mode. +<<<<<<< HEAD * @details Inputs: none * @details Outputs: Initializes the Treatment Parameters session and sets the initial * Pre-Treatment sub-state. @@ -49,31 +58,33 @@ { // Start a fresh Treatment Parameters session for this run. initTreatmentParameters(); - currentPreTreatmentState = TD_PRE_TREATMENT_CONFIRM_RX_STATE; + currentPreTreatmentState = TD_PRE_TREATMENT_TUBING_SET_INSTALL_STATE; + goToInstallStateRequested = FALSE; } /*********************************************************************//** * @brief * The transitionToPreTreatmentMode function prepares the system for * entry into Pre-Treatment mode. -* @details Inputs: none -* @details Outputs: Initializes mode specific state and returns the starting +* @details \b Inputs: none +* @details \b Outputs: Initializes mode specific state and returns the starting * Pre-Treatment sub-state. * @return Initial Pre-Treatment sub-state **************************************************************************/ U32 transitionToPreTreatmentMode( void ) { initPreTreatmentMode(); + initTubeSetInstall(); return (U32)currentPreTreatmentState; } /*********************************************************************//** - * @brief + * @briefs * The execPreTreatmentMode function executes the Pre-Treatment * mode state machine. - * @details Inputs: stop button status and system conditions via helpers. - * @details Outputs: Advances the Pre-Treatment sub-state and + * @details \b Inputs: stop button status and system conditions via helpers. + * @details \b Outputs: Advances the Pre-Treatment sub-state and * previously received user confirmations. * @return current Pre-Treatment sub-state. *************************************************************************/ @@ -101,8 +112,8 @@ // currentPreTreatmentState = handleSelfTestNoCartState(); break; - case TD_PRE_TREATMENT_CART_INSTALL_STATE: - // currentPreTreatmentState = handleInstallState(); + case TD_PRE_TREATMENT_TUBING_SET_INSTALL_STATE: + currentPreTreatmentState = handleInstallState(); break; case TD_PRE_TREATMENT_SELF_TEST_DRY_STATE: @@ -136,11 +147,150 @@ /*********************************************************************//** * @brief + * The handleWaterSampleState function executes the Water Sample state of + * pre-treatment mode. + * @details \b Inputs: TODO fill up if any + * @details \b Outputs: TODO fill up if any + * @return next Pre-Treatment mode state. + *************************************************************************/ +static TD_PRE_TREATMENT_MODE_STATE_T handleWaterSampleState( void ) +{ + TD_PRE_TREATMENT_MODE_STATE_T state = TD_PRE_TREATMENT_WATER_SAMPLE_STATE; + + // TODO: Transition to Self test consumable state on completion when implemented + // state = TD_PRE_TREATMENT_SELF_TEST_CONSUMABLE_STATE; + + return state; +} + +/*********************************************************************//** + * @brief + * The handleSelfTestConsumableState function executes the Self Test + * Consumable state of pre-treatment mode. + * @details \b Inputs: TODO fill up if any + * @details \b Outputs: TODO fill up if any + * @return next Pre-Treatment mode state. + *************************************************************************/ +static TD_PRE_TREATMENT_MODE_STATE_T handleSelfTestConsumableState( void ) +{ + TD_PRE_TREATMENT_MODE_STATE_T state = TD_PRE_TREATMENT_SELF_TEST_CONSUMABLE_STATE; + + // TODO: Transition to Self test no cart state on completion when implemented + // state = TD_PRE_TREATMENT_SELF_TEST_NO_CART_STATE; + + return state; +} + +/*********************************************************************//** + * @brief + * The handleSelfTestNoCartState function executes the Self Test No Cart + * state of pre-treatment mode. + * @details \b Inputs: TODO fill up if any + * @details \b Outputs: TODO fill up if any + * @return next Pre-Treatment mode state. + *************************************************************************/ +static TD_PRE_TREATMENT_MODE_STATE_T handleSelfTestNoCartState( void ) +{ + TD_PRE_TREATMENT_MODE_STATE_T state = TD_PRE_TREATMENT_SELF_TEST_NO_CART_STATE; + + // TODO: Transition to Tubing set install state on completion when implemented + // state = TD_PRE_TREATMENT_TUBING_SET_INSTALL_STATE; + + return state; +} + +/*********************************************************************//** + * @brief + * The handleInstallState function calls Tube Set Install Service and + * advances to Self Test Dry state once the service signals + * completion. + * @details \b Inputs: none + * @details \b Outputs: Advances Pre-Treatment state when install is complete. + * @return next Pre-Treatment mode state + *************************************************************************/ +static TD_PRE_TREATMENT_MODE_STATE_T handleInstallState( void ) +{ + TD_PRE_TREATMENT_MODE_STATE_T state = TD_PRE_TREATMENT_TUBING_SET_INSTALL_STATE; + + // call tube set install service to auto-load tube set + execTubeSetInstall(); + + if ( TRUE == isTubeSetInstallComplete() ) + { + state = TD_PRE_TREATMENT_SELF_TEST_DRY_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleSelfTestDryState function executes the Self Test Dry state + * of pre-treatment mode. + * @details \b Inputs: TODO fill up if any + * @details \b Outputs: TODO fill up if any + * @return next Pre-Treatment mode state. + *************************************************************************/ +static TD_PRE_TREATMENT_MODE_STATE_T handleSelfTestDryState( void ) +{ + TD_PRE_TREATMENT_MODE_STATE_T state = TD_PRE_TREATMENT_SELF_TEST_DRY_STATE; + + if ( TRUE == goToInstallStateRequested ) + { + goToInstallStateRequested = FALSE; + initTubeSetInstall(); + state = TD_PRE_TREATMENT_TUBING_SET_INSTALL_STATE; + } + + // TODO: Transition to Prime state on completion when implemented + // state = TD_PRE_TREATMENT_PRIME_STATE; + + return state; +} + +/*********************************************************************//** + * @brief + * The handlePrimeState function executes the Prime state of + * pre-treatment mode. + * @details \b Inputs: TODO fill up if any + * @details \b Outputs: TODO fill up if any + * @return next Pre-Treatment mode state. + *************************************************************************/ +static TD_PRE_TREATMENT_MODE_STATE_T handlePrimeState( void ) +{ + TD_PRE_TREATMENT_MODE_STATE_T state = TD_PRE_TREATMENT_PRIME_STATE; + + // TODO: Transition to Recirculate state on completion when implemented + // state = TD_PRE_TREATMENT_RECIRCULATE_STATE; + + return state; +} + +/*********************************************************************//** + * @brief + * The handleRecirculateState function executes the Recirculate state of + * pre-treatment mode. + * @details \b Inputs: TODO fill up if any + * @details \b Outputs: TODO fill up if any + * @return next Pre-Treatment mode state. + *************************************************************************/ +static TD_PRE_TREATMENT_MODE_STATE_T handleRecirculateState( void ) +{ + TD_PRE_TREATMENT_MODE_STATE_T state = TD_PRE_TREATMENT_RECIRCULATE_STATE; + + // TODO: Transition to Confirm RX state on completion when implemented + // state = TD_PRE_TREATMENT_CONFIRM_RX_STATE; + + return state; +} + +/*********************************************************************//** + * @brief * The handleRxState function executes the Confirm Rx pre-treatment step. - * @details Inputs: none - * @details Outputs: Requests transition to Treatment mode when the prescription + * @details \b Inputs: none + * @details \b Outputs: Requests transition to Treatment mode when the prescription * is valid and confirmed otherwise remains in Confirm Rx. - * @return next Pre-Treatment mode sub-state. + * @return next Pre-Treatment mode state. *************************************************************************/ static TD_PRE_TREATMENT_MODE_STATE_T handleRxState( void ) { @@ -183,6 +333,38 @@ /*********************************************************************//** * @brief + * The handlePatientConnectionState function executes the Patient + * Connection state of pre-treatment mode. + * @details \b Inputs: TODO fill up if any + * @details \b Outputs: TODO fill up if any + * @return next Pre-Treatment mode state. + *************************************************************************/ +static TD_PRE_TREATMENT_MODE_STATE_T handlePatientConnectionState( void ) +{ + TD_PRE_TREATMENT_MODE_STATE_T state = TD_PRE_TREATMENT_PATIENT_CONNECTION_STATE; + + // TODO : after implementing this state, place the transition in the right place + + //requestNewOperationMode( MODE_TREA ); + + return state; +} + +/*********************************************************************//** + * @brief + * The PreTxRequestTubeSetInstall function signals a request to transition + * the Pre-Treatment mode state machine to Install state. + * @details \b Inputs: none + * @details \b Outputs: goToInstallStateRequested + * @return none + *************************************************************************/ +void PreTxRequestTubeSetInstall( void ) +{ + goToInstallStateRequested = TRUE; +} + +/*********************************************************************//** + * @brief * The signalAlarmActionToPreTreatmentMode function executes the given alarm action * as appropriate while in Pre-Treatment Mode. * @details \b Inputs: none