mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
added float calculation for time to distance conversion
returns higher resolution, especially for measuring in inches the integer resolution was low.
This commit is contained in:
@@ -275,3 +275,12 @@ unsigned int NewPingESP8266::convert_in(unsigned int echoTime) {
|
||||
return NewPingESP8266Convert(echoTime, US_ROUNDTRIP_IN); // Convert uS to inches.
|
||||
#endif
|
||||
}
|
||||
|
||||
float NewPingESP8266::convert_cm_F(unsigned int echoTime) {
|
||||
return ((float)echoTime / US_ROUNDTRIP_CM); // Convert uS to centimeters (no rounding).
|
||||
}
|
||||
|
||||
|
||||
float NewPingESP8266::convert_in_F(unsigned int echoTime) {
|
||||
return ((float)echoTime / US_ROUNDTRIP_IN); // Convert uS to inches (no rounding).
|
||||
}
|
||||
|
||||
@@ -212,6 +212,8 @@ class NewPingESP8266 {
|
||||
unsigned long ping_median(uint32_t it = 5, unsigned int max_cm_distance = 0);
|
||||
static unsigned int convert_cm(unsigned int echoTime);
|
||||
static unsigned int convert_in(unsigned int echoTime);
|
||||
static float convert_cm_F(unsigned int echoTime);
|
||||
static float convert_in_F(unsigned int echoTime);
|
||||
|
||||
unsigned int getMaxEchoTime() { return _maxEchoTime; };
|
||||
errorState getErrorState() { return _errorState; };
|
||||
|
||||
Reference in New Issue
Block a user