Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -rd4a90fda6c1f463633a4e7d45424acd2d2a0bce8 -rfbdff223ca110491c6f7776669fa46ac5fc56da4 --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision d4a90fda6c1f463633a4e7d45424acd2d2a0bce8) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision fbdff223ca110491c6f7776669fa46ac5fc56da4) @@ -35,7 +35,10 @@ #define RESERVOIR_SETTLE_TIME_MS 5000 ///< Time (in ms) allotted for reservoir to settle (after fill, before drain). #define SIZE_OF_SMALL_LOAD_CELL_AVG 8 ///< Small load cell moving average has 8 samples. -#define SIZE_OF_LARGE_LOAD_CELL_AVG 32 ///< Large load cell moving average has 32 samples. +#define SIZE_OF_LARGE_LOAD_CELL_AVG 32 ///< Large load cell moving average has 32 samples. + +#define MAX_LOAD_CELL_CHANGE_G 70.0 ///< Maximum delta between new load cell sample and its small moving average (in g). +#define MAX_ACTIVE_LOAD_CELL_CHANGE_G 30.0 ///< Maximum delta between new load cell sample and its small moving average (in g) when associated reservoir is active in treatment. /// States of the treatment reservoir management state machine. typedef enum TreatmentReservoirMgmt_States @@ -654,6 +657,8 @@ void setNewLoadCellReadings( F32 res1Primary, F32 res1Backup, F32 res2Primary, F32 res2Backup ) { DG_RESERVOIR_ID_T res; + DG_RESERVOIR_ID_T activeRes = getDGActiveReservoir(); + BOOL inTreatment = ( MODE_TREA == getCurrentOperationMode() ? TRUE : FALSE ); loadCellWeightInGrams[ LOAD_CELL_RESERVOIR_1_PRIMARY ].data = res1Primary; loadCellWeightInGrams[ LOAD_CELL_RESERVOIR_1_BACKUP ].data = res1Backup; @@ -663,8 +668,31 @@ // feed new weight samples into filters and update moving averages for ( res = DG_RESERVOIR_1; res < NUM_OF_DG_RESERVOIRS; res++ ) { - F32 wt = ( res == DG_RESERVOIR_1 ? res1Primary : res2Primary ); + F32 wt = ( res == DG_RESERVOIR_1 ? res1Primary : res2Primary ); +#ifndef DISABLE_UF_ALARMS + F32 delta = fabs( smFilteredReservoirWeightInGrams[ res ] - wt ); + BOOL deltaAlarmDetected = FALSE; + ALARM_ID_T deltaAlarm = ( res == DG_RESERVOIR_1 ? ALARM_ID_HD_LOAD_CELL_ACCELERATION_RES_1_ALARM : ALARM_ID_HD_LOAD_CELL_ACCELERATION_RES_2_ALARM ); + // Check for excessive load cell acceleration + if ( ( TRUE == inTreatment ) && ( res == activeRes ) && ( delta > MAX_ACTIVE_LOAD_CELL_CHANGE_G ) ) + { + deltaAlarmDetected = TRUE; + } + else if ( delta > MAX_LOAD_CELL_CHANGE_G ) + { + deltaAlarmDetected = TRUE; + } + // Trigger or clear excessive load cell acceleration condition + if ( TRUE == deltaAlarmDetected ) + { + SET_ALARM_WITH_2_F32_DATA( deltaAlarm, wt, smFilteredReservoirWeightInGrams[ res ] ); + } + else + { + // clearAlarmCondition( deltaAlarm ); TODO - un-comment when merged with branch that has this function implemented. + } +#endif smLoadCellReadingsTotal[ res ] -= smLoadCellReadings[ res ][ smLoadCellReadingsIdx ]; lgLoadCellReadingsTotal[ res ] -= lgLoadCellReadings[ res ][ lgLoadCellReadingsIdx ]; smLoadCellReadings[ res ][ smLoadCellReadingsIdx ] = wt;