Skip to content

Commit 3728e86

Browse files
committed
Avoid switch and type conversion (SQ finding)
1 parent af31e0c commit 3728e86

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

OpenBikeSensorFirmware/sensor.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,13 @@ void IRAM_ATTR HCSR04SensorManager::isr(int idx) {
247247
if (sensor->duration == 0) // ignore unexpected signals
248248
{
249249
const unsigned long time = micros();
250-
switch(digitalRead(sensor->echoPin))
250+
if (HIGH == digitalRead(sensor->echoPin))
251251
{
252-
case HIGH:
253-
sensor->start = time;
254-
break;
255-
case LOW:
256-
sensor->duration = time - sensor->start;
257-
break;
252+
sensor->start = time;
253+
}
254+
else // LOW
255+
{
256+
sensor->duration = time - sensor->start;
258257
}
259258
}
260259
}

0 commit comments

Comments
 (0)