other way to read tare values

This commit is contained in:
Joerg Lehmann 2019-10-04 13:18:21 +02:00
parent a74a835103
commit c81d96bca8
1 changed files with 17 additions and 12 deletions

View File

@ -889,14 +889,8 @@ static void warmupDoneCb(osjob_t* pJob)
static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage, size_t nMessage)
{
union {
byte buf[9];
struct {
byte dummy;
uint32_t gram_A;
uint32_t gram_B;
} value;
} bytearray;
uint32_t gram_A;
uint32_t gram_B;
if (config_data.debug_level > 0) {
gCatena.SafePrintf("receiveMessage was called!!!\n");
@ -957,13 +951,24 @@ static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage
if (port == 1 && nMessage == 9) {
if (pMessage[0] == 1) {
memcpy(bytearray.buf, pMessage, 9);
gram_A = 0;
gram_A += (long)pMessage[1] << 24;
gram_A += (long)pMessage[2] << 16;
gram_A += (long)pMessage[3] << 8;
gram_A += (long)pMessage[4];
gram_B = 0;
gram_B += (long)pMessage[5] << 24;
gram_B += (long)pMessage[6] << 16;
gram_B += (long)pMessage[7] << 8;
gram_B += (long)pMessage[8];
if (config_data.debug_level > 0) {
gCatena.SafePrintf("tare scales, A: %d, B: %d\n", bytearray.value.gram_A, bytearray.value.gram_B);
gCatena.SafePrintf("tare scales, A: %d, B: %d\n", gram_A, gram_B);
}
ReadSensors(false, true);
config_data.cal_w1_factor = (((float)last_sensor_reading.weight1 - config_data.cal_w1_0) / bytearray.value.gram_A);
config_data.cal_w2_factor = (((float)last_sensor_reading.weight2 - config_data.cal_w2_0) / bytearray.value.gram_B);
config_data.cal_w1_factor = (((float)last_sensor_reading.weight1 - config_data.cal_w1_0) / gram_A);
config_data.cal_w2_factor = (((float)last_sensor_reading.weight2 - config_data.cal_w2_0) / gram_B);
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
}
}