Skip to content

Commit

Permalink
Refactor sensorsReturningFalse to existing no events block
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Jun 12, 2024
1 parent 7170e64 commit be850e8
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions src/components/i2c/WipperSnapper_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,6 @@ void WipperSnapper_Component_I2C::update() {
} else {
WS_DEBUG_PRINTLN(
"ERROR: Failed to get ambient temperature sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorAmbientTempPeriodPrv(curTime);
}
Expand Down Expand Up @@ -1074,7 +1073,6 @@ void WipperSnapper_Component_I2C::update() {
} else {
WS_DEBUG_PRINTLN(
"ERROR: Failed to obtain ambient temp. (°F)) sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorAmbientTempFPeriodPrv(curTime);
}
Expand Down Expand Up @@ -1103,7 +1101,6 @@ void WipperSnapper_Component_I2C::update() {
} else {
WS_DEBUG_PRINTLN(
"ERROR: Failed to get object temperature sensor (°C) reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorObjectTempPeriodPrv(curTime);
}
Expand Down Expand Up @@ -1132,7 +1129,6 @@ void WipperSnapper_Component_I2C::update() {
} else {
WS_DEBUG_PRINTLN(
"ERROR: Failed to get object temperature sensor (°F) reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorObjectTempFPeriodPrv(curTime);
}
Expand Down Expand Up @@ -1184,7 +1180,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorPressurePeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to get Pressure sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorPressurePeriodPrv(curTime);
}
Expand All @@ -1209,7 +1204,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorCO2PeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to obtain CO2 sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorCO2PeriodPrv(curTime);
}
Expand All @@ -1234,7 +1228,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorECO2PeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to obtain eCO2 sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorECO2PeriodPrv(curTime);
}
Expand All @@ -1259,7 +1252,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorTVOCPeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to obtain TVOC sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorTVOCPeriodPrv(curTime);
}
Expand Down Expand Up @@ -1287,7 +1279,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorAltitudePeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to get altitude sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorAltitudePeriodPrv(curTime);
}
Expand All @@ -1314,7 +1305,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorLightPeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to get light sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorLightPeriodPrv(curTime);
}
Expand Down Expand Up @@ -1342,7 +1332,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorPM10_STDPeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to get PM1.0 sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorPM10_STDPeriodPrv(curTime);
}
Expand Down Expand Up @@ -1370,7 +1359,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorPM25_STDPeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to get PM2.5 sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorPM25_STDPeriodPrv(curTime);
}
Expand Down Expand Up @@ -1398,7 +1386,6 @@ void WipperSnapper_Component_I2C::update() {
curTime); // try again in curTime seconds
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to get PM10.0 sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorPM100_STDPeriodPrv(curTime);
}
Expand All @@ -1425,7 +1412,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorVoltagePeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to get voltage sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorVoltagePeriodPrv(curTime);
}
Expand All @@ -1452,7 +1438,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorCurrentPeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to get Current sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorCurrentPeriodPrv(curTime);
}
Expand Down Expand Up @@ -1481,7 +1466,6 @@ void WipperSnapper_Component_I2C::update() {
} else {
WS_DEBUG_PRINTLN(
"ERROR: Failed to get unitless percent sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorUnitlessPercentPeriodPrv(curTime);
}
Expand All @@ -1505,7 +1489,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorRawPeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to obtain Raw sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorRawPeriodPrv(curTime);
}
Expand All @@ -1532,7 +1515,6 @@ void WipperSnapper_Component_I2C::update() {
} else {
WS_DEBUG_PRINTLN(
"ERROR: Failed to obtain gas resistance sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorGasResistancePeriodPrv(curTime);
}
Expand All @@ -1557,7 +1539,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorNOxIndexPeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to obtain NOx index sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorNOxIndexPeriodPrv(curTime);
}
Expand All @@ -1582,7 +1563,6 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorVOCIndexPeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to obtain VOC index sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorVOCIndexPeriodPrv(curTime);
}
Expand All @@ -1609,16 +1589,18 @@ void WipperSnapper_Component_I2C::update() {
(*iter)->setSensorProximityPeriodPrv(curTime);
} else {
WS_DEBUG_PRINTLN("ERROR: Failed to get proximity sensor reading!");
sensorsReturningFalse = true;
if (retries == 1) {
(*iter)->setSensorProximityPeriodPrv(curTime);
}
}
}

// Did this driver obtain data from sensors?
if (msgi2cResponse.payload.resp_i2c_device_event.sensor_event_count == 0)
if (msgi2cResponse.payload.resp_i2c_device_event.sensor_event_count ==
0) {
sensorsReturningFalse = true;
continue;
}

displayDeviceEventMessage(&msgi2cResponse, (*iter)->getI2CAddress());

Expand Down

0 comments on commit be850e8

Please sign in to comment.