diff --git a/tasmota/tasmota_support/support_float.ino b/tasmota/tasmota_support/support_float.ino index ac7527302..c6bfa9787 100644 --- a/tasmota/tasmota_support/support_float.ino +++ b/tasmota/tasmota_support/support_float.ino @@ -481,3 +481,7 @@ float Polynomialf(const float *factors, uint32_t degree, float x) { } return r; } + +float map_float(float x, float in_min, float in_max, float out_min, float out_max) { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} diff --git a/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino b/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino index b68341668..d43b93aaf 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino @@ -2464,7 +2464,7 @@ void CmndScale(void) float fromHigh = CharToFloat(ArgV(argument, 3)); float toLow = CharToFloat(ArgV(argument, 4)); float toHigh = CharToFloat(ArgV(argument, 5)); - float value = map_double(valueIN, fromLow, fromHigh, toLow, toHigh); + float value = map_float(valueIN, fromLow, fromHigh, toLow, toHigh); dtostrfd(value, Settings->flag2.calc_resolution, rules_vars[XdrvMailbox.index -1]); bitSet(Rules.vars_event, XdrvMailbox.index -1); } else { @@ -2475,11 +2475,6 @@ void CmndScale(void) } } -float map_double(float x, float in_min, float in_max, float out_min, float out_max) -{ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - /*********************************************************************************************\ * Interface \*********************************************************************************************/ diff --git a/tasmota/tasmota_xsns_sensor/xsns_18_pms5003.ino b/tasmota/tasmota_xsns_sensor/xsns_18_pms5003.ino index 1da6a0058..88380531c 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_18_pms5003.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_18_pms5003.ino @@ -390,17 +390,17 @@ int usaEpaStandardPm2d5Adjustment(int pm25_standard, int relative_humidity) int compute_us_aqi(int pm25_standard) { if (pm25_standard <= 9) { - return map_double(pm25_standard, 0, 9, 0, 50); + return map_float(pm25_standard, 0, 9, 0, 50); } else if (pm25_standard <= 35) { - return map_double(pm25_standard, 9.1f, 35.4f, 51, 100); + return map_float(pm25_standard, 9.1f, 35.4f, 51, 100); } else if (pm25_standard <= 55) { - return map_double(pm25_standard, 35.5f, 55.4f, 101, 150); + return map_float(pm25_standard, 35.5f, 55.4f, 101, 150); } else if (pm25_standard <= 125) { - return map_double(pm25_standard, 55.5f, 125.4f, 151, 200); + return map_float(pm25_standard, 55.5f, 125.4f, 151, 200); } else if (pm25_standard <= 225) { - return map_double(pm25_standard, 125.5f, 225.4f, 201, 300); + return map_float(pm25_standard, 125.5f, 225.4f, 201, 300); } else if (pm25_standard <= 325) { - return map_double(pm25_standard, 225.5f, 325.4f, 301, 500); + return map_float(pm25_standard, 225.5f, 325.4f, 301, 500); } else { return 500; }