Skip to content

Commit c61c84b

Browse files
committed
Ignorw all values below 19 cm
1 parent d0df4a9 commit c61c84b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

OpenBikeSensorFirmware/sensor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
*/
4646
const uint8_t MICRO_SEC_TO_CM_DIVIDER = 58; // sound speed 340M/S, 2 times back and forward
4747

48-
const uint32_t MAX_DURATION_MICRO_SEC = 255 * 58;
48+
const uint32_t MAX_DURATION_MICRO_SEC = 255 * MICRO_SEC_TO_CM_DIVIDER;
49+
const uint32_t MIN_SURATION_MICRO_SEC = 19 * MICRO_SEC_TO_CM_DIVIDER;
4950

5051
/*
5152
https://de.aliexpress.com/item/32737648330.html and other sources give 60ms here
@@ -124,7 +125,7 @@ void HCSR04SensorManager::collectSensorResults() {
124125
{
125126
const unsigned long duration = m_sensors[idx].duration;
126127
uint8_t dist;
127-
if (duration == 0 || duration > m_sensors[idx].timeout || duration >= MAX_DURATION_MICRO_SEC)
128+
if (duration < MIN_SURATION_MICRO_SEC || duration >= MAX_DURATION_MICRO_SEC)
128129
{
129130
dist = MAX_SENSOR_VALUE;
130131
}

0 commit comments

Comments
 (0)