Index: firmware/App/Modes/ModeTreatment.c =================================================================== diff -u -r04334ed8d1e927939718b1d62fb01afef0a2b9a9 -ra7104162b3467a67c5f4ed2f0f2ec038a8738d33 --- firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 04334ed8d1e927939718b1d62fb01afef0a2b9a9) +++ firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision a7104162b3467a67c5f4ed2f0f2ec038a8738d33) @@ -34,6 +34,10 @@ // ********** private definitions ********** +#define MAX_TREATMENT_TIME_MINUTES ( 8 * MIN_PER_HOUR ) +#define MAX_UF_RATE_ML_MIN ( (F32)2500 / (F32)MIN_PER_HOUR ) +#define MAX_DIALYSATE_VOLUME_ML ( 180 * ML_PER_LITER ) + #define TREATMENT_TIME_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) // interval (ms/task time) at which the treatment time data is published on the CAN bus /// Sub-mode states while in treatment mode @@ -69,6 +73,10 @@ static BUTTON_STATE_T lastOffButtonState = BUTTON_STATE_RELEASED; +static U32 pendingUFVolumeChange; ///< An ultrafiltration volume change (mL) is pending user confirmation. +static F32 pendingUFRateChange; ///< An ultrafiltration rate change (mL/min) is pending user confirmation. +static U32 pendingTreatmentTimeChange; ///< A treatment time change (min) is pending user confirmation. + // ********** private function prototypes ********** static TREATMENT_STATE_T handleTreatmentStartState( void ); @@ -336,6 +344,45 @@ /************************************************************************* * @brief + * The verifyTreatmentDurationSettingChange function verifies the user treatment \n + * duration setting change. + * @details + * Inputs : none + * Outputs : none + * @param treatmentTime : Proposed new treatment duration (in min). + * @return TRUE if new treatment duration setting valid, FALSE if not. + *************************************************************************/ +BOOL verifyTreatmentDurationSettingChange( U32 treatmentTime ) +{ + BOOL result = FALSE; + U32 timeDiff = 0; + F32 rateDiff = 0.0; + OP_MODE currMode = getCurrentOperationMode(); + + // check if we are in an appropriate treatment state for settings adjustment + if ( ( MODE_TREA == currMode ) && ( currentTreatmentState > TREATMENT_START_STATE ) && ( currentTreatmentState < TREATMENT_DIALYSIS_END_STATE ) ) + { + U32 uFVolume; + U32 dialVolume = presDialysateFlowRate * treatmentTime; // in mL + + // always adjust UF volume to accommodate treatment time change (not UF rate) + uFVolume = (U32)( (F32)treatmentTime * presUFRate ); + if ( ( treatmentTime <= MAX_TREATMENT_TIME_MINUTES ) && ( dialVolume <= MAX_DIALYSATE_VOLUME_ML ) ) + { + result = TRUE; + pendingUFVolumeChange = uFVolume; // mL + pendingUFRateChange = presUFRate; // no UF rate change + pendingTreatmentTimeChange = treatmentTime; // min + timeDiff = treatmentTime - ( (U32)( (F32)presTreatmentTimeSecs / (F32)SEC_PER_MIN ) + 1 ); + } + } + sendChangeUFSettingsResponse( result, pendingUFVolumeChange, pendingTreatmentTimeChange, pendingUFRateChange, timeDiff, rateDiff ); + + return result; +} + +/************************************************************************* + * @brief * The verifyUFSettingsChange function verifies new ultrafiltration settings \n * from the user. * @details @@ -348,15 +395,55 @@ BOOL verifyUFSettingsChange( F32 uFVolume, UF_ADJ_T adjustment ) { BOOL result = FALSE; + U32 timeDiff = 0; + F32 rateDiff = 0.0; OP_MODE currMode = getCurrentOperationMode(); - // check if we are in treatment mode - if ( MODE_TREA == currMode ) + // check if we are in an appropriate treatment state for settings adjustment + if ( ( MODE_TREA == currMode ) && ( currentTreatmentState > TREATMENT_START_STATE ) && ( currentTreatmentState < TREATMENT_DIALYSIS_END_STATE ) ) { - // check - } - //sendChangeUFSettingsResponse( BOOL accepted, U32 volume_mL, U32 time_min, F32 ufRate_mL_min, U32 timeDiff, F32 rateDiff ); + // TODO - verify not too close to end of treatment for settings change + F32 uFRate; + U32 trtTime; + // reset pending UF/time settings change + pendingUFVolumeChange = 0; + pendingUFRateChange = 0.0; + pendingTreatmentTimeChange = 0; + + // which setting does user want to adjust to accommodate the UF volume change? (treatment time or UF rate) + if ( UF_ADJ_TREATMENT_TIME == adjustment ) + { + F32 uFRate = presUFRate; // no change in UF rate + U32 trtTime = ( uFVolume / uFRate ) + 1; // in minutes + U32 dialVolume = presDialysateFlowRate * trtTime; // in mL + + // verify new treatment duration is valid + if ( ( trtTime <= MAX_TREATMENT_TIME_MINUTES ) && ( dialVolume <= MAX_DIALYSATE_VOLUME_ML ) ) + { + result = TRUE; + pendingUFVolumeChange = uFVolume; + pendingUFRateChange = uFRate; + pendingTreatmentTimeChange = trtTime; + timeDiff = trtTime - ( (U32)( (F32)presTreatmentTimeSecs / (F32)SEC_PER_MIN ) + 1 ); + } + } + else + { // UF Rate is adjusted then + trtTime = presTreatmentTimeSecs / SEC_PER_MIN; // in minutes + uFRate = uFVolume / (F32)trtTime; + if ( uFRate <= (F32)MAX_UF_RATE_ML_MIN ) + { + result = TRUE; + pendingUFVolumeChange = uFVolume; + pendingUFRateChange = uFRate; + pendingTreatmentTimeChange = trtTime; + rateDiff = ( uFRate - presUFRate ); + } + } + } // current mode allows change + sendChangeUFSettingsResponse( result, pendingUFVolumeChange, pendingTreatmentTimeChange, pendingUFRateChange, timeDiff, rateDiff ); + return result; } @@ -377,5 +464,16 @@ { BOOL result = FALSE; + // user confirmed UF settings change(s)? + if ( TRUE == confirmed ) + { + // user confirmed changes are same as verified pending changes? + if ( ( (S32)uFVolume == pendingUFVolumeChange ) && ( treatmentTime == pendingTreatmentTimeChange ) && ( ( uFRate - pendingUFRateChange ) < NEARLY_ZERO ) ) + { + // TODO - implement changes, resume UF if appropriate + result = TRUE; + } + } + return result; }