Index: firmware/App/Controllers/LoadCell.c =================================================================== diff -u -r22176ce95e49213c48454f34ddf5d29b8109f2cb -r965eb10d9407c25e8cf334623ad45e126cecee97 --- firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision 22176ce95e49213c48454f34ddf5d29b8109f2cb) +++ firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision 965eb10d9407c25e8cf334623ad45e126cecee97) @@ -48,9 +48,9 @@ #define LOAD_CELL_MIN_ALLOWED_WEIGHT_BEFORE_TARE_GRAMS 1600.0F ///< Load cell minimum allowed weight before tare in grams. #define LOAD_CELL_WEIGHT_OUT_RANGE_PERSISTENT_PERIOD_MS (5 * MS_PER_SECOND) ///< Load cell weight out of range persistent period in milliseconds. #define LOAD_CELL_PRIMARY_BACKUP_MAX_DRIFT_PERSISTENT_PERIOD_MS (5 * MS_PER_SECOND) ///< Load cell primary and backup maximum allowed weight drift persistent period in milliseconds. -#define EMPTY_RESERVOIR_WEIGHT_GRAMS 1600 ///< Reservoirs empty weight in grams. -#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_FIRST_TARE_GRAMS 300 ///< Max allowed extra weight before first tare in grams. -#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_TARE_GRAMS 60 ///< Max allowed extra weight before tare in grams. +#define EMPTY_RESERVOIR_WEIGHT_GRAMS 1600.0F ///< Reservoirs empty weight in grams. +#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_FIRST_TARE_GRAMS 300.0F ///< Max allowed extra weight before first tare in grams. +#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_TARE_GRAMS 60.0F ///< Max allowed extra weight before tare in grams. #define LOAD_CELL_PRIMARY_BACKUP_MAX_ALLOWED_DRIFT_GRAMS 60.0F ///< Load cell primary and backup maximum allowed weight drift in grams. #define DATA_PUBLISH_COUNTER_START_COUNT 0 ///< Data publish counter start count. @@ -82,6 +82,7 @@ static U32 smallReadingsIdx; ///< Index for next sample in load cell small rolling average sample array. static U32 largeReadingsIdx; ///< Index for next sample in load cell large rolling average sample array. static DG_LOAD_CELLS_CAL_RECORD_T loadCellsCalRecord; ///< Load cells calibration record. +static BOOL hasLoadCellBeenTared[ NUM_OF_DG_RESERVOIRS ]; ///< Flags indicating whether loadcells have been tared yet. // ********** private function prototypes ********** @@ -105,10 +106,12 @@ loadCellDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; loadCellFilterTimerCount = 0; + // Initialize load cell filter data and set calibration data as benign until loaded from non-volatile memory for ( i = 0; i < NUM_OF_LOAD_CELLS; i++ ) { benignPolynomialCalRecord( &loadCellsCalRecord.loadCells[ i ] ); + hasLoadCellBeenTared[ i ] = FALSE; loadcells[ i ].rawReading = 0; loadcells[ i ].weight.data = 0.0; loadcells[ i ].weight.ovData = 0.0; @@ -303,7 +306,7 @@ F32 weight = getLoadCellSmallFilteredWeight( loadCellID ); // Check if the load cell is being tared for the first time - if ( fabs( loadcells[ loadCellID ].autoCalOffset ) < NEARLY_ZERO ) + if ( hasLoadCellBeenTared[ loadCellID ] != TRUE ) { // For the first tare, the weight of the reservoir should be considered // The current weight of the load cell should not be greater than the weight of the reservoir + the extra weight @@ -319,6 +322,7 @@ { // Add old auto calibration offset to get back to actual weight value loadcells[ loadCellID ].autoCalOffset = ( loadcells[ loadCellID ].smallFilteredWeight + loadcells[ loadCellID ].autoCalOffset ); + hasLoadCellBeenTared[ loadCellID ] = TRUE; } else { Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r22176ce95e49213c48454f34ddf5d29b8109f2cb -r965eb10d9407c25e8cf334623ad45e126cecee97 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 22176ce95e49213c48454f34ddf5d29b8109f2cb) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 965eb10d9407c25e8cf334623ad45e126cecee97) @@ -924,4 +924,32 @@ return result; } +/*********************************************************************//** + * @brief + * The testTareReservoir function tares a given reservoir. It is assumed + * that the given reservoir has already been drained. + * @details Inputs: drainVolumeTargetMl + * @details Outputs: drainVolumeTargetMl + * @param value ID of reservoir to tare + * @return TRUE if tare successful, FALSE if not + *************************************************************************/ +BOOL testTareReservoir( U32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + if ( value < NUM_OF_DG_RESERVOIRS ) + { + result = TRUE; + tareLoadCellRequest = TRUE; + testSetReservoirDrainVolumeMlOverride( 0 ); + tareLoadCellsAtEmpty( (DG_RESERVOIR_ID_T)value ); + testResetReservoirDrainVolumeMlOverride(); + } + } + + return result; +} + /**@}*/ Index: firmware/App/Services/Reservoirs.h =================================================================== diff -u -r22176ce95e49213c48454f34ddf5d29b8109f2cb -r965eb10d9407c25e8cf334623ad45e126cecee97 --- firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 22176ce95e49213c48454f34ddf5d29b8109f2cb) +++ firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 965eb10d9407c25e8cf334623ad45e126cecee97) @@ -124,7 +124,8 @@ BOOL testSetReservoirFillVolumeMlOverride( U32 value ); BOOL testResetReservoirFillVolumeMlOverride( void ); BOOL testSetReservoirDrainVolumeMlOverride( U32 value ); -BOOL testResetReservoirDrainVolumeMlOverride( void ); +BOOL testResetReservoirDrainVolumeMlOverride( void ); +BOOL testTareReservoir( U32 value ); /**@}*/ Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r439e62fe1d95d3e5398bd396e0955c1ac1ba1417 -r965eb10d9407c25e8cf334623ad45e126cecee97 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 439e62fe1d95d3e5398bd396e0955c1ac1ba1417) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 965eb10d9407c25e8cf334623ad45e126cecee97) @@ -1193,6 +1193,10 @@ handleTestSetOpModeRequest( message ); break; + case MSG_ID_DG_RESERVOIR_TARE_REQUEST: + handleTestTareReservoirRequest( message ); + break; + default: // TODO - unrecognized message ID received - ignore break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r439e62fe1d95d3e5398bd396e0955c1ac1ba1417 -r965eb10d9407c25e8cf334623ad45e126cecee97 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 439e62fe1d95d3e5398bd396e0955c1ac1ba1417) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 965eb10d9407c25e8cf334623ad45e126cecee97) @@ -1361,6 +1361,31 @@ /*********************************************************************//** * @brief + * The handleTestTareReservoirRequest function handles a request to tare a + * given reservoir's weight. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleTestTareReservoirRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + U32 res; + + memcpy( &res, message->payload, sizeof(U32) ); + result = testTareReservoir( res ); + } + + // Respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** + * @brief * The handleSetHDOperationMode function receives the HD operation modes data * publish message. * @details Inputs: none Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r439e62fe1d95d3e5398bd396e0955c1ac1ba1417 -r965eb10d9407c25e8cf334623ad45e126cecee97 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 439e62fe1d95d3e5398bd396e0955c1ac1ba1417) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 965eb10d9407c25e8cf334623ad45e126cecee97) @@ -389,6 +389,9 @@ // MSG_ID_DG_SET_OP_MODE_REQUEST void handleTestSetOpModeRequest( MESSAGE_T *message ); +// MSG_ID_DG_RESERVOIR_TARE_REQUEST +void handleTestTareReservoirRequest( MESSAGE_T *message ); + // MSG_ID_HD_OP_MODE BOOL handleSetHDOperationMode( MESSAGE_T *message );