Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r37a9fd8f15e413db5337371a7d1a1cb65567af7c -r5b448e81db260e5b041699a83c6f2a3faa260ea9 --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 37a9fd8f15e413db5337371a7d1a1cb65567af7c) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 5b448e81db260e5b041699a83c6f2a3faa260ea9) @@ -26,9 +26,12 @@ #include "ModePreTreat.h" #include "ModeTreatment.h" #include "ModePostTreat.h" +#include "NVDataMgmt.h" #include "OperationModes.h" +#include "RTC.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" +#include "Timers.h" /** * @addtogroup HDOperationModes @@ -136,6 +139,16 @@ lastMode = currentMode; transitionToNewOperationMode( newMode ); currentMode = newMode; + + if ( MODE_TREA == currentMode ) + { + // If the current mode is treatment but transitioning to another mode has been requested (including transitioning to fault mode) + // it means the treatment is done. Get the elapsed time since the beginning of the treatment and convert it to hours to be written + U32 txElapsedTimeMS = calcTimeSince( getTreatmentStartTimeStamp() ); + F32 txElapsedTimeHrs = (F32)txElapsedTimeMS / ( MIN_PER_HOUR * SEC_PER_MIN * MS_PER_SECOND ); + // Write the treatment hours and set the service to be false so the treatment hours is not reset + setTxTimeHours( txElapsedTimeHrs, FALSE ); + } } // Mode specific processing to be done continuously