2 #include "../../../../utilities/Utilities.hpp"
5 const float kTimeToTravelOneCmAndBack = 29.15F * 2.0F;
6 const unsigned long kTimeToMeasureOneCm = 120;
9 const unsigned long kMedianMeasurementDelay = 15;
17 : kTriggerPin{ triggerPin }
20 , kTimeout{ kMaxDistance * kTimeToMeasureOneCm }
22 , kOutput{ mRuntime.getOutputState() }
23 , kInput{ mRuntime.getInputState() }
24 , kLow{ mRuntime.getLowState() }
25 , kHigh{ mRuntime.getHighState() }
46 static constexpr
auto kSetPinToKnownStateDelay = 5;
49 static constexpr
auto kTenMicrosecondPulse = 10;
55 auto calculatedDistance
56 =
static_cast<unsigned int>(
static_cast<float>(duration) / kTimeToTravelOneCmAndBack);
58 return calculatedDistance <= kMaxDistance ? calculatedDistance :
kError;
69 for (
auto i = 0; i < iterations; i++)
75 return getMedian(measurements, iterations);