Index: firmware/App/Modes/ModeHeatDisinfectActiveCool.c =================================================================== diff -u -r184ee0c5527af35d34c29bd4f80cf8b1959ffd35 -rae07878482b9c736b402b229e33b05bd74cd61bb --- firmware/App/Modes/ModeHeatDisinfectActiveCool.c (.../ModeHeatDisinfectActiveCool.c) (revision 184ee0c5527af35d34c29bd4f80cf8b1959ffd35) +++ firmware/App/Modes/ModeHeatDisinfectActiveCool.c (.../ModeHeatDisinfectActiveCool.c) (revision ae07878482b9c736b402b229e33b05bd74cd61bb) @@ -79,14 +79,21 @@ BOOL hasDisStatusBeenWrittenToNV; ///< Boolean flag to indicate whether the disinfect status been written to NV or not. } DISINFECT_NV_OPS_T; +/// +typedef struct +{ + U32 tempBelowTargetStartTimeMS; ///< Mode heat disinfect active cool temperature below target time in milliseconds. + BOOL hasTempTargetTimeBeenSet; ///< Mode heat disinfect active cool temperature target time has been set. +} TEMP_BELOW_TARGET_T; + static DG_HEAT_DISINFECT_ACTIVE_COOL_STATE_T heatDisinfectActiveCoolState; ///< Mode heat disinfect active cool state. static DG_HEAT_DISINFECT_ACTIVE_COOL_STATE_T heatDisinfectActiceCoolPrevState; ///< Mode heat disinfect active cool previous state. static U32 stateStartTimeMS; ///< Mode heat disinfect active cool state timer in milliseconds. static U32 dataPublishCounter; ///< Mode heat disinfect active cool data publish counter. static U32 overallHeatDisinfectActiveCoolTimer; ///< Mode heat disinfect active cool over mode timer. static ALARM_ID_T alarmDetectedPendingTrigger; ///< Mode heat disinfect active cool pending alarm trigger. static DIS_RSRVR_STATUS_T rsrvrsStatus; ///< Mode heat disinfect active cool reservoirs status. -static U32 tempBelowTargetStartTimeMS; ///< Mode heat disinfect active cool temperature below target time in milliseconds. +static TEMP_BELOW_TARGET_T tempBelowTarget; ///< Mode heat disinfect active cool temperature below target time in milliseconds. static DISINFECT_NV_OPS_T disinfectNVOps; ///< Disinfect non-volatile memory operations. static CANCELLATION_MODE_T cancellationMode; ///< Cancellation mode. @@ -124,7 +131,7 @@ * @details Outputs: heatDisinfectActiveCoolState, stateStartTimeMS, * dataPublishCounter, overallHeatDisinfectActiveCoolTimer, * alarmDetectedPendingTrigger, heatDisinfectActiceCoolPrevState, rsrvrsStatus, - * tempBelowTargetStartTimeMS, disinfectNVOps + * tempBelowTarget, disinfectNVOps * @return none *************************************************************************/ void initHeatDisinfectActiveCoolMode( void ) @@ -135,7 +142,8 @@ dataPublishCounter = 0; overallHeatDisinfectActiveCoolTimer = getMSTimerCount(); alarmDetectedPendingTrigger = ALARM_ID_NO_ALARM; - tempBelowTargetStartTimeMS = getMSTimerCount(); + tempBelowTarget.tempBelowTargetStartTimeMS = getMSTimerCount(); + tempBelowTarget.hasTempTargetTimeBeenSet = FALSE; cancellationMode = CANCELLATION_MODE_NONE; disinfectNVOps.hasDisStatusBeenWrittenToNV = FALSE; @@ -438,15 +446,16 @@ * The handleHeatDisinfectActiveCoolMixDrainR2State function handles the heat * disinfect active cool mix drain R2 state. * @details Inputs: none - * @details Outputs: tempBelowTargetStartTimeMS + * @details Outputs: tempBelowTarget * @return next state of the heat disinfect active cool state machine *************************************************************************/ static DG_HEAT_DISINFECT_ACTIVE_COOL_STATE_T handleHeatDisinfectActiveCoolMixDrainR2State( void ) { DG_HEAT_DISINFECT_ACTIVE_COOL_STATE_T state = DG_HEAT_DISINFECT_ACTIVE_COOL_MIX_DRAIN_R2_STATE; - tempBelowTargetStartTimeMS = getMSTimerCount(); - state = checkRsrvrMixDrainStatus( DG_RESERVOIR_2, state ); + tempBelowTarget.tempBelowTargetStartTimeMS = getMSTimerCount(); + tempBelowTarget.hasTempTargetTimeBeenSet = FALSE; + state = checkRsrvrMixDrainStatus( DG_RESERVOIR_2, state ); return state; } @@ -1050,8 +1059,8 @@ * @brief * The checkRsrvrPartialFillStatus function checks and manages the status * of the partial fill of a reservoir - * @details Inputs: tempBelowTargetStartTimeMS, rsrvrsStatus, stateStartTimeMS - * @details Outputs: tempBelowTargetStartTimeMS, rsrvrsStatus, stateStartTimeMS + * @details Inputs: tempBelowTarget, rsrvrsStatus, stateStartTimeMS + * @details Outputs: tempBelowTarget, rsrvrsStatus, stateStartTimeMS * @param rsrvrID the reservoir ID to check the status of the timeout * @param state the state of the heat disinfect active cool mode * @return: state of the heat disinfect active cool mode @@ -1060,9 +1069,10 @@ { F32 THdTemperatureC = getTemperatureValue( TEMPSENSORS_HEAT_DISINFECT ); - if ( THdTemperatureC > ROF_ACTIVE_COOL_TARGET_TEMP_C ) + if ( ( THdTemperatureC < ROF_ACTIVE_COOL_TARGET_TEMP_C ) && ( FALSE == tempBelowTarget.hasTempTargetTimeBeenSet ) ) { - tempBelowTargetStartTimeMS = getMSTimerCount(); + tempBelowTarget.tempBelowTargetStartTimeMS = getMSTimerCount(); + tempBelowTarget.hasTempTargetTimeBeenSet = TRUE; } if ( DG_RESERVOIR_BELOW_TARGET == rsrvrsStatus.rsrvr[ rsrvrID ].rStatus ) @@ -1072,9 +1082,10 @@ } else if ( DG_RESERVOIR_REACHED_TARGET == rsrvrsStatus.rsrvr[ rsrvrID ].rStatus ) { - if ( TRUE == didTimeout( tempBelowTargetStartTimeMS, ROF_ACTIVE_COOL_BELOW_TEMP_TIMEOUT_MS ) ) + if ( TRUE == didTimeout( tempBelowTarget.tempBelowTargetStartTimeMS, ROF_ACTIVE_COOL_BELOW_TEMP_TIMEOUT_MS ) ) { - stateStartTimeMS = getMSTimerCount(); + stateStartTimeMS = getMSTimerCount(); + tempBelowTarget.hasTempTargetTimeBeenSet = FALSE; // If THd temperature has been below the target temperature, transition to cooling the connection paths in between the two reservoirs if ( DG_HEAT_DISINFECT_ACTIVE_COOL_FILL_R1_STATE == state ) @@ -1190,33 +1201,36 @@ * @brief * The checkRsrvrFillStatus function checks and manages the status * of the a reservoir's fill - * @details Inputs: rsrvrsStatus, stateStartTimeMS, tempBelowTargetStartTimeMS - * @details Outputs: rsrvrsStatus, stateStartTimeMS, tempBelowTargetStartTimeMS + * @details Inputs: rsrvrsStatus, stateStartTimeMS, tempBelowTarget + * @details Outputs: rsrvrsStatus, stateStartTimeMS, tempBelowTarget * @param rsrvrID the reservoir ID to check the status of the timeout * @param state the state of the heat disinfect active cool mode * @return: state of the heat disinfect active cool mode *************************************************************************/ static DG_HEAT_DISINFECT_ACTIVE_COOL_STATE_T checkRsrvrFillStatus( DG_RESERVOIR_ID_T rsrvrID, DG_HEAT_DISINFECT_ACTIVE_COOL_STATE_T state ) { - F32 TDiTemperatureC = getTemperatureValue( TEMPSENSORS_INLET_DIALYSATE ); - - if ( TDiTemperatureC > RSRVR_ACTIVE_COOL_TARGET_TEMP_C ) - { - // Keep setting the time until the temperature is below the target - tempBelowTargetStartTimeMS = getMSTimerCount(); - } - if ( DG_RESERVOIR_BELOW_TARGET == rsrvrsStatus.rsrvr[ rsrvrID ].rStatus ) { rsrvrsStatus.rsrvr[ rsrvrID ].rStatus = getDisinfectRsrvrFillStatus( rsrvrID, &rsrvrsStatus, RSRVR_ACTIVE_COOL_FILL_TARGET_FILL_ML, RSRVR_FILL_TIMEOUT_MS, stateStartTimeMS ); } else if ( DG_RESERVOIR_REACHED_TARGET == rsrvrsStatus.rsrvr[ rsrvrID ].rStatus ) { + // once the reservoir is filled check for the temperature below target + F32 TDiTemperatureC = getTemperatureValue( TEMPSENSORS_INLET_DIALYSATE ); + + if ( ( TDiTemperatureC < RSRVR_ACTIVE_COOL_TARGET_TEMP_C ) && ( FALSE == tempBelowTarget.hasTempTargetTimeBeenSet ) ) + { + // Keep setting the time until the temperature is below the target + tempBelowTarget.tempBelowTargetStartTimeMS = getMSTimerCount(); + tempBelowTarget.hasTempTargetTimeBeenSet = TRUE; + } + // Keep waiting until the TDi temperature is below the target temperature for the specified time - if ( TRUE == didTimeout( tempBelowTargetStartTimeMS, RSRVR_ACTIVE_COOL_BELOW_TARGET_TEMP_TIMEOUT_MS ) ) + if ( TRUE == didTimeout( tempBelowTarget.tempBelowTargetStartTimeMS, RSRVR_ACTIVE_COOL_BELOW_TARGET_TEMP_TIMEOUT_MS ) ) { - stateStartTimeMS = getMSTimerCount(); + stateStartTimeMS = getMSTimerCount(); + tempBelowTarget.hasTempTargetTimeBeenSet = FALSE; // Once the TDi has been below the specified temperature for the specified time, transition to the next state per the current state if ( DG_HEAT_DISINFECT_ACTIVE_COOL_DRAIN_R2_FILL_R1_TO_R2_STATE == state )