Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -r49533d4870aa10c1b20406dd5c013567fe854694 -r7cf04dc00d1242aba62f3cd4e4bcb19f1e83ebc6 --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 49533d4870aa10c1b20406dd5c013567fe854694) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 7cf04dc00d1242aba62f3cd4e4bcb19f1e83ebc6) @@ -106,6 +106,7 @@ static void updateUFVolumes( void ); static void publishSalineBolusData( void ); +static void checkLoadCellsStablePrimaryBackupDriftOutOfRange( DG_RESERVOIR_ID_T reservoirID, BOOL reservoirFull ); /*********************************************************************//** * @brief @@ -1135,6 +1136,8 @@ // Set starting baseline volume for next reservoir before we switch to it resStartVolume[ reservoirID ] = resVolume; resFinalVolume[ reservoirID ] = resVolume; + + checkLoadCellsStablePrimaryBackupDriftOutOfRange( reservoirID, false ); } /*********************************************************************//** @@ -1172,6 +1175,8 @@ measUFVolumeFromPriorReservoirs -= ( resFinalVolume[ inactiveRes ] - resStartVolume[ inactiveRes ] ); resFinalVolume[ inactiveRes ] = resVolume; measUFVolumeFromPriorReservoirs += ( resFinalVolume[ inactiveRes ] - resStartVolume[ inactiveRes ] ); + + checkLoadCellsStablePrimaryBackupDriftOutOfRange( inactiveRes, true ); } /*********************************************************************//** @@ -1206,4 +1211,109 @@ return ( resFinalVolume[ reservoirID ] - resStartVolume[ reservoirID ] ); } +/*********************************************************************//** + * @brief + * The checkLoadCellsStablePrimaryBackupDriftOutOfRange function checks the + * load cells' primary and backup drift when the reservoir level has been stable + * for greater than large filter time. + * @details Inputs: none + * @details Outputs: none + * @param reservoirID which is the reservoir ID that is range checked + * @param reservoirFull is the reservoir status full or empty + * @return none + *************************************************************************/ +#define LOAD_CELL_ILLEGAL_WEIGHT_VALUE -1000.0F +static void checkLoadCellsStablePrimaryBackupDriftOutOfRange( DG_RESERVOIR_ID_T reservoirID, BOOL reservoirFull ) +{ + static F32 lastEmptyWeight[NUM_OF_LOAD_CELLS] = { LOAD_CELL_ILLEGAL_WEIGHT_VALUE, + LOAD_CELL_ILLEGAL_WEIGHT_VALUE, + LOAD_CELL_ILLEGAL_WEIGHT_VALUE, + LOAD_CELL_ILLEGAL_WEIGHT_VALUE }; + static F32 lastFullWeight[NUM_OF_LOAD_CELLS] = { LOAD_CELL_ILLEGAL_WEIGHT_VALUE, + LOAD_CELL_ILLEGAL_WEIGHT_VALUE, + LOAD_CELL_ILLEGAL_WEIGHT_VALUE, + LOAD_CELL_ILLEGAL_WEIGHT_VALUE }; + F32 loadCellPrimaryWeight, loadCellBackupWeight; + F32 loadCellPreviousDrift, loadCellCurrentDrift; + F32 driftDiff = 0.0; + + if ( reservoirID == DG_RESERVOIR_1 ) + { + // Reservoir 1 + loadCellPrimaryWeight = getReservoirWeightLargeFilter( DG_RESERVOIR_1 ); + loadCellBackupWeight = getReservoirBackupWeightLargeFilter( DG_RESERVOIR_1 ); + loadCellCurrentDrift = fabs( loadCellPrimaryWeight - loadCellBackupWeight ); + + if ( reservoirFull ) + { + if ( lastFullWeight[LOAD_CELL_RESERVOIR_1_PRIMARY] > (LOAD_CELL_ILLEGAL_WEIGHT_VALUE + 1) ) + { + // Weight has been previously saved, ok to test + loadCellPreviousDrift = fabs( lastFullWeight[LOAD_CELL_RESERVOIR_1_PRIMARY] - + lastFullWeight[LOAD_CELL_RESERVOIR_1_BACKUP] ); + driftDiff = fabs ( loadCellCurrentDrift - loadCellPreviousDrift ); + } + // Save latest reading for next test time + lastFullWeight[LOAD_CELL_RESERVOIR_1_PRIMARY] = loadCellPrimaryWeight; + lastFullWeight[LOAD_CELL_RESERVOIR_1_BACKUP] = loadCellBackupWeight; + } + else + { + if ( lastEmptyWeight[LOAD_CELL_RESERVOIR_1_PRIMARY] > (LOAD_CELL_ILLEGAL_WEIGHT_VALUE + 1) ) + { + // Weight has been previously saved, ok to test + loadCellPreviousDrift = fabs( lastEmptyWeight[LOAD_CELL_RESERVOIR_1_PRIMARY] - + lastEmptyWeight[LOAD_CELL_RESERVOIR_1_BACKUP] ); + driftDiff = fabs ( loadCellCurrentDrift - loadCellPreviousDrift ); + } + // Save latest reading for next test time + lastEmptyWeight[LOAD_CELL_RESERVOIR_1_PRIMARY] = loadCellPrimaryWeight; + lastEmptyWeight[LOAD_CELL_RESERVOIR_1_BACKUP] = loadCellBackupWeight; + } + } + else + { + // Reservoir 2 + loadCellPrimaryWeight = getReservoirWeightLargeFilter( DG_RESERVOIR_2 ); + loadCellBackupWeight = getReservoirBackupWeightLargeFilter( DG_RESERVOIR_2 ); + loadCellCurrentDrift = fabs( loadCellPrimaryWeight - loadCellBackupWeight ); + + if ( reservoirFull ) + { + if ( lastFullWeight[LOAD_CELL_RESERVOIR_2_PRIMARY] > (LOAD_CELL_ILLEGAL_WEIGHT_VALUE + 1) ) + { + // Weight has been previously saved, ok to test + loadCellPreviousDrift = fabs( lastFullWeight[LOAD_CELL_RESERVOIR_2_PRIMARY] - + lastFullWeight[LOAD_CELL_RESERVOIR_2_BACKUP] ); + driftDiff = fabs ( loadCellCurrentDrift - loadCellPreviousDrift ); + } + // Save latest reading for next test time + lastFullWeight[LOAD_CELL_RESERVOIR_2_PRIMARY] = loadCellPrimaryWeight; + lastFullWeight[LOAD_CELL_RESERVOIR_2_BACKUP] = loadCellBackupWeight; + } + else + { + if ( lastEmptyWeight[LOAD_CELL_RESERVOIR_2_PRIMARY] > (LOAD_CELL_ILLEGAL_WEIGHT_VALUE + 1) ) + { + // Weight has been previously saved, ok to test + loadCellPreviousDrift = fabs( lastEmptyWeight[LOAD_CELL_RESERVOIR_2_PRIMARY] - + lastEmptyWeight[LOAD_CELL_RESERVOIR_2_BACKUP] ); + driftDiff = fabs ( loadCellCurrentDrift - loadCellPreviousDrift ); + } + // Save latest reading for next test time + lastEmptyWeight[LOAD_CELL_RESERVOIR_2_PRIMARY] = loadCellPrimaryWeight; + lastEmptyWeight[LOAD_CELL_RESERVOIR_2_BACKUP] = loadCellBackupWeight; + } + } + + // TODO Set proper limits and use separate Alarm Number + if ( driftDiff > LOAD_CELL_PRIMARY_BACKUP_MAX_ALLOWED_DRIFT_GRAMS ) + { + //checkPersistentAlarm( ALARM_ID_DG_LOAD_CELL_PRIMARY_BACKUP_DRIFT_OUT_OF_RANGE, isDriftOutOfRange, driftDiff, + // LOAD_CELL_PRIMARY_BACKUP_MAX_ALLOWED_DRIFT_GRAMS ); + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_LOAD_CELL_PRIMARY_BACKUP_DRIFT_OUT_OF_RANGE, loadCellCurrentDrift, loadCellPreviousDrift ) + } +} + + /**@}*/