File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change 4545*/
4646const 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 }
You can’t perform that action at this time.
0 commit comments