Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -raeb1dea9ea10fcc70ae66023a87b565f29924c07 -rdaaf76c5b69282cb044896b7722c73ac7c89f1a1 --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision aeb1dea9ea10fcc70ae66023a87b565f29924c07) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision daaf76c5b69282cb044896b7722c73ac7c89f1a1) @@ -653,28 +653,27 @@ *************************************************************************/ void setNewLoadCellReadings( F32 res1Primary, F32 res1Backup, F32 res2Primary, F32 res2Backup ) { + DG_RESERVOIR_ID_T res; + loadCellWeightInGrams[ LOAD_CELL_RESERVOIR_1_PRIMARY ].data = res1Primary; loadCellWeightInGrams[ LOAD_CELL_RESERVOIR_1_BACKUP ].data = res1Backup; loadCellWeightInGrams[ LOAD_CELL_RESERVOIR_2_PRIMARY ].data = res2Primary; loadCellWeightInGrams[ LOAD_CELL_RESERVOIR_2_BACKUP ].data = res2Backup; // feed new weight samples into filters and update moving averages - smLoadCellReadingsTotal[ DG_RESERVOIR_1 ] -= smLoadCellReadings[ DG_RESERVOIR_1 ][ smLoadCellReadingsIdx ]; - lgLoadCellReadingsTotal[ DG_RESERVOIR_1 ] -= lgLoadCellReadings[ DG_RESERVOIR_1 ][ lgLoadCellReadingsIdx ]; - smLoadCellReadingsTotal[ DG_RESERVOIR_2 ] -= smLoadCellReadings[ DG_RESERVOIR_2 ][ smLoadCellReadingsIdx ]; - lgLoadCellReadingsTotal[ DG_RESERVOIR_2 ] -= lgLoadCellReadings[ DG_RESERVOIR_2 ][ lgLoadCellReadingsIdx ]; - smLoadCellReadings[ DG_RESERVOIR_1 ][ smLoadCellReadingsIdx ] = res1Primary; - lgLoadCellReadings[ DG_RESERVOIR_1 ][ lgLoadCellReadingsIdx ] = res1Primary; - smLoadCellReadings[ DG_RESERVOIR_2 ][ smLoadCellReadingsIdx ] = res2Primary; - lgLoadCellReadings[ DG_RESERVOIR_2 ][ lgLoadCellReadingsIdx ] = res2Primary; - smLoadCellReadingsTotal[ DG_RESERVOIR_1 ] += res1Primary; - lgLoadCellReadingsTotal[ DG_RESERVOIR_1 ] += res1Primary; - smLoadCellReadingsTotal[ DG_RESERVOIR_2 ] += res2Primary; - lgLoadCellReadingsTotal[ DG_RESERVOIR_2 ] += res2Primary; - smFilteredReservoirWeightInGrams[ DG_RESERVOIR_1 ] = smLoadCellReadingsTotal[ DG_RESERVOIR_1 ] / (F32)SIZE_OF_SMALL_LOAD_CELL_AVG; - lgFilteredReservoirWeightInGrams[ DG_RESERVOIR_1 ] = lgLoadCellReadingsTotal[ DG_RESERVOIR_1 ] / (F32)SIZE_OF_LARGE_LOAD_CELL_AVG; - smFilteredReservoirWeightInGrams[ DG_RESERVOIR_2 ] = smLoadCellReadingsTotal[ DG_RESERVOIR_2 ] / (F32)SIZE_OF_SMALL_LOAD_CELL_AVG; - lgFilteredReservoirWeightInGrams[ DG_RESERVOIR_2 ] = lgLoadCellReadingsTotal[ DG_RESERVOIR_2 ] / (F32)SIZE_OF_LARGE_LOAD_CELL_AVG; + for ( res = DG_RESERVOIR_1; res < NUM_OF_DG_RESERVOIRS; res++ ) + { + F32 wt = ( res == DG_RESERVOIR_1 ? res1Primary : res2Primary ); + + smLoadCellReadingsTotal[ res ] -= smLoadCellReadings[ res ][ smLoadCellReadingsIdx ]; + lgLoadCellReadingsTotal[ res ] -= lgLoadCellReadings[ res ][ lgLoadCellReadingsIdx ]; + smLoadCellReadings[ res ][ smLoadCellReadingsIdx ] = wt; + lgLoadCellReadings[ res ][ lgLoadCellReadingsIdx ] = wt; + smLoadCellReadingsTotal[ res ] += wt; + lgLoadCellReadingsTotal[ res ] += wt; + smFilteredReservoirWeightInGrams[ res ] = smLoadCellReadingsTotal[ res ] / (F32)SIZE_OF_SMALL_LOAD_CELL_AVG; + lgFilteredReservoirWeightInGrams[ res ] = lgLoadCellReadingsTotal[ res ] / (F32)SIZE_OF_LARGE_LOAD_CELL_AVG; + } smLoadCellReadingsIdx = INC_WRAP( smLoadCellReadingsIdx, 0, SIZE_OF_SMALL_LOAD_CELL_AVG - 1 ); lgLoadCellReadingsIdx = INC_WRAP( lgLoadCellReadingsIdx, 0, SIZE_OF_LARGE_LOAD_CELL_AVG - 1 ); }