Index: firmware/App/Modes/ModePreTreat.c =================================================================== diff -u -r1a685471524555a374854c0c9ec8e208e71fe2df -r4d2dcd2d5ee3c7684be139b7e560b16d8c3abc06 --- firmware/App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision 1a685471524555a374854c0c9ec8e208e71fe2df) +++ firmware/App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision 4d2dcd2d5ee3c7684be139b7e560b16d8c3abc06) @@ -15,16 +15,15 @@ * ***************************************************************************/ -#include "AirTrap.h" -#include "AlarmLamp.h" -#include "BloodFlow.h" -#include "DialInFlow.h" -#include "DialOutFlow.h" -#include "Buttons.h" +//#include "AirTrap.h" +//#include "BloodFlow.h" +//#include "DialInFlow.h" +//#include "DialOutFlow.h" +#include "ModePreTreat.h" #include "OperationModes.h" +#include "Prime.h" #include "SystemCommMessages.h" -#include "ModePreTreat.h" -#include "SystemCommMessages.h" + #ifdef RM46_EVAL_BOARD_TARGET #include "Timers.h" static U32 start; @@ -37,9 +36,13 @@ // ********** private data ********** -static BOOL treatStartReqReceived = FALSE; ///< Flag indicates user requests treatment begin. +static BOOL treatStartReqReceived = FALSE; ///< Flag indicates user requests treatment begin. +static PRE_TREATMENT_MODE_STATE_T currentPreTreatmentState; ///< Current state of pre-treatment mode state machine. + // ********** private function prototypes ********** +static PRE_TREATMENT_MODE_STATE_T handlePrimeState( void ); +static PRE_TREATMENT_MODE_STATE_T handlePatientConnectionState( void ); /*********************************************************************//** * @brief @@ -50,6 +53,7 @@ *************************************************************************/ void initPreTreatmentMode( void ) { + currentPreTreatmentState = PRE_TREATMENT_START_STATE; } /*********************************************************************//** @@ -78,37 +82,66 @@ *************************************************************************/ U32 execPreTreatmentMode( void ) { - BOOL stop = isStopButtonPressed(); - -#ifndef DISABLE_UI_TREATMENT_WORKFLOW - if ( TRUE == treatStartReqReceived ) -#endif + // execute mode state machine + switch ( currentPreTreatmentState ) { - requestNewOperationMode( MODE_TREA ); + case PRE_TREATMENT_START_STATE: + currentPreTreatmentState = PRE_TREATMENT_WATER_SAMPLE_STATE; + break; + + case PRE_TREATMENT_WATER_SAMPLE_STATE: + currentPreTreatmentState = PRE_TREATMENT_SELF_TEST_NO_CART_STATE; + break; + + case PRE_TREATMENT_SELF_TEST_NO_CART_STATE: + currentPreTreatmentState = PRE_TREATMENT_CART_INSTALL_STATE; + break; + + case PRE_TREATMENT_CART_INSTALL_STATE: + currentPreTreatmentState = PRE_TREATMENT_SELF_TEST_DRY_STATE; + break; + + case PRE_TREATMENT_SELF_TEST_DRY_STATE: + currentPreTreatmentState = PRE_TREATMENT_PRIME_STATE; + break; + + case PRE_TREATMENT_PRIME_STATE: + currentPreTreatmentState = handlePrimeState(); + break; + + case PRE_TREATMENT_SELF_TEST_WET_STATE: + currentPreTreatmentState = PRE_TREATMENT_RECIRC_STATE; + break; + + case PRE_TREATMENT_RECIRC_STATE: + currentPreTreatmentState = PRE_TREATMENT_PATIENT_CONNECTION_STATE; + break; + + case PRE_TREATMENT_PATIENT_CONNECTION_STATE: + currentPreTreatmentState = handlePatientConnectionState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_PRE_TREATMENT_INVALID_STATE, (U32)currentPreTreatmentState ) + break; } -#ifdef RM46_EVAL_BOARD_TARGET - if ( TRUE == didTimeout( start, 5000U ) ) - { - requestNewOperationMode( MODE_TREA ); - } -#endif - return 0; // TODO - return current state + return (U32)currentPreTreatmentState; } /*********************************************************************//** * @brief * The signalUserBeginningTreatment function handles user start of a * treatment. * @details Inputs: none - * @details Outputs: requested mode transition to treatment mode + * @details Outputs: treatStartReqReceived, send response to treatment start * @return TRUE if signal accepted, FALSE if not *************************************************************************/ BOOL signalUserBeginningTreatment( void ) { BOOL result = FALSE; - if ( MODE_PRET == getCurrentOperationMode() ) + if ( ( MODE_PRET == getCurrentOperationMode() ) && ( PRE_TREATMENT_PATIENT_CONNECTION_STATE == currentPreTreatmentState ) ) { treatStartReqReceived = TRUE; result = TRUE; @@ -118,4 +151,51 @@ return result; } +/*********************************************************************//** + * @brief + * The handlePrimeState function handles priming the blood and dialysate circuits. + * @details Inputs: none + * @details Outputs: requested mode transition to treatment mode + * @return current state (sub-mode) + *************************************************************************/ +static PRE_TREATMENT_MODE_STATE_T handlePrimeState( void ) +{ + PRE_TREATMENT_MODE_STATE_T state = PRE_TREATMENT_PRIME_STATE; + + execPrime(); + + if ( TRUE == isPrimingPassed() ) + { + state = PRE_TREATMENT_SELF_TEST_WET_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handlePatientConnectionState function handles patient connection state + * during pre-treatment mode. + * @details Inputs: none + * @details Outputs: requested mode transition to treatment mode + * @return current state (sub-mode) + *************************************************************************/ +static PRE_TREATMENT_MODE_STATE_T handlePatientConnectionState( void ) +{ +#ifndef DISABLE_UI_TREATMENT_WORKFLOW + if ( TRUE == treatStartReqReceived ) +#endif + { + requestNewOperationMode( MODE_TREA ); + } +#ifdef RM46_EVAL_BOARD_TARGET + if ( TRUE == didTimeout( start, 5000U ) ) + { + requestNewOperationMode( MODE_TREA ); + } +#endif + + return PRE_TREATMENT_PATIENT_CONNECTION_STATE; +} + /**@}*/ Index: firmware/App/Modes/Prime.c =================================================================== diff -u --- firmware/App/Modes/Prime.c (revision 0) +++ firmware/App/Modes/Prime.c (revision 4d2dcd2d5ee3c7684be139b7e560b16d8c3abc06) @@ -0,0 +1,54 @@ +/************************************************************************** +* +* Copyright (c) 2019-2020 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 Prime.h +* +* @author (last) Quang Nguyen +* @date (last) 08-Dec-2020 +* +* @author (original) Quang Nguyen +* @date (original) 08-Dec-2020 +* +***************************************************************************/ + +#include "Prime.h" + +/** + * @addtogroup Prime + * @{ + */ + +// ********** private definitions ********** + +// ********** private data ********** + +static BOOL primeStatus; + +// ********** private function prototypes ********** + + +void initPrime( void ) +{ + primeStatus = FALSE; +} + +void transitionToPrime( void ) +{ +} + +void execPrime( void ) +{ +} + +BOOL isPrimingPassed( void ) +{ + primeStatus = TRUE; + return primeStatus; +} + + +/**@}*/ Index: firmware/App/Modes/Prime.h =================================================================== diff -u --- firmware/App/Modes/Prime.h (revision 0) +++ firmware/App/Modes/Prime.h (revision 4d2dcd2d5ee3c7684be139b7e560b16d8c3abc06) @@ -0,0 +1,44 @@ +/************************************************************************** +* +* Copyright (c) 2019-2020 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 Prime.h +* +* @author (last) Quang Nguyen +* @date (last) 08-Dec-2020 +* +* @author (original) Quang Nguyen +* @date (original) 08-Dec-2020 +* +***************************************************************************/ + +#ifndef __PRIME_H__ +#define __PRIME_H__ + +#include "HDCommon.h" +#include "HDDefs.h" + +/** + * @defgroup Prime Prime + * @brief Prime sub-mode of pre-treatment mode. This sub-mode handles blood and dialysate circuits priming functionality. + * + * @addtogroup Prime + * @{ + */ + +// ********** public definitions ********** + +// ********** public function prototypes ********** + +void initPrime( void ); +void transitionToPrime( void ); +void execPrime( void ); + +BOOL isPrimingPassed( void ); + +/**@}*/ + +#endif Index: firmware/App/Services/AlarmMgmt.h =================================================================== diff -u -r933a18d740285e70be9d00696ed0f5a5381bc8e4 -r4d2dcd2d5ee3c7684be139b7e560b16d8c3abc06 --- firmware/App/Services/AlarmMgmt.h (.../AlarmMgmt.h) (revision 933a18d740285e70be9d00696ed0f5a5381bc8e4) +++ firmware/App/Services/AlarmMgmt.h (.../AlarmMgmt.h) (revision 4d2dcd2d5ee3c7684be139b7e560b16d8c3abc06) @@ -215,6 +215,7 @@ SW_FAULT_ID_AIR_TRAP_INVALID_STATE, SW_FAULT_ID_AIR_TRAP_INVALID_LEVEL_SENSOR, // 90 SW_FAULT_ID_DIALYSIS_INVALID_SALINE_BOLUS_STATE, + SW_FAULT_ID_MODE_PRE_TREATMENT_INVALID_STATE, NUM_OF_SW_FAULT_IDS } SW_FAULT_ID_T;