From b17d7bbdea08263910bfa940f16451e608525d7f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 19 Apr 2022 15:44:53 +0200 Subject: [PATCH] Save another 500 bytes by moving from double to float --- tasmota/support.ino | 20 +++++++++++--------- tasmota/support_command.ino | 4 ++-- tasmota/xdrv_03_energy.ino | 20 ++++++++++---------- tasmota/xnrg_03_pzem004t.ino | 6 +++--- tasmota/xnrg_05_pzem_ac.ino | 12 ++++++------ tasmota/xnrg_06_pzem_dc.ino | 8 ++++---- tasmota/xnrg_09_dds2382.ino | 12 ++++++------ tasmota/xsns_05_ds18x20.ino | 6 +++--- tasmota/xsns_05_esp32_ds18x20.ino | 6 +++--- tasmota/xsns_06_dht.ino | 12 ++++++------ tasmota/xsns_06_esp32_dht.ino | 4 ++-- tasmota/xsns_07_sht1x.ino | 14 +++++++------- tasmota/xsns_08_htu21.ino | 16 ++++++++-------- tasmota/xsns_09_bmp.ino | 18 +++++++++--------- tasmota/xsns_21_sgp30.ino | 8 ++++---- tasmota/xsns_26_lm75ad.ino | 2 +- tasmota/xsns_37_rfsensor.ino | 4 ++-- tasmota/xsns_39_max31855.ino | 6 +++--- tasmota/xsns_41_max44009.ino | 2 +- tasmota/xsns_42_scd30.ino | 4 ++-- tasmota/xsns_43_hre.ino | 2 +- tasmota/xsns_46_MLX90614.ino | 4 ++-- tasmota/xsns_55_hih_series.ino | 4 ++-- tasmota/xsns_59_ds1624.ino | 2 +- tasmota/xsns_65_hdc1080.ino | 14 +++++++------- tasmota/xsns_88_am2320.ino | 4 ++-- 26 files changed, 108 insertions(+), 106 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 97a4f9221..e124dd3cf 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -319,7 +319,7 @@ float CharToFloat(const char *str) strlcpy(strbuf, str, sizeof(strbuf)); char *pt = strbuf; - if (*pt == '\0') { return 0.0; } + if (*pt == '\0') { return 0.0f; } while ((*pt != '\0') && isspace(*pt)) { pt++; } // Trim leading spaces @@ -816,12 +816,15 @@ float ConvertPressureForSeaLevel(float pressure) { if (pressure == 0.0f) { return pressure; } - return ConvertPressure((pressure / FastPrecisePow(1.0f - ((float)Settings->altitude / 44330.0f), 5.255f)) - 21.6f); + return ConvertPressure((pressure / FastPrecisePowf(1.0f - ((float)Settings->altitude / 44330.0f), 5.255f)) - 21.6f); } -String PressureUnit(void) -{ - return (Settings->flag.pressure_conversion) ? (Settings->flag5.mm_vs_inch) ? String(F(D_UNIT_INCH_MERCURY)) : String(F(D_UNIT_MILLIMETER_MERCURY)) : String(F(D_UNIT_PRESSURE)); +const char kPressureUnit[] PROGMEM = D_UNIT_PRESSURE "|" D_UNIT_MILLIMETER_MERCURY "|" D_UNIT_INCH_MERCURY; + +String PressureUnit(void) { + uint32_t index = (Settings->flag.pressure_conversion) ? Settings->flag5.mm_vs_inch +1 : 0; + char text[8]; + return String(GetTextIndexed(text, sizeof(text), index, kPressureUnit)); } float ConvertSpeed(float s) @@ -830,10 +833,9 @@ float ConvertSpeed(float s) return s * kSpeedConversionFactor[Settings->flag2.speed_conversion]; } -String SpeedUnit(void) -{ - char speed[8]; - return String(GetTextIndexed(speed, sizeof(speed), Settings->flag2.speed_conversion, kSpeedUnit)); +String SpeedUnit(void) { + char text[8]; + return String(GetTextIndexed(text, sizeof(text), Settings->flag2.speed_conversion, kSpeedUnit)); } void ResetGlobalValues(void) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 3c72125c1..bba801784 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -798,7 +798,7 @@ void CmndGlobalTemp(void) if (XdrvMailbox.data_len > 0) { float temperature = CharToFloat(XdrvMailbox.data); if (!isnan(temperature) && Settings->flag.temperature_conversion) { // SetOption8 - Switch between Celsius or Fahrenheit - temperature = (temperature - 32) / 1.8; // Celsius + temperature = (temperature - 32) / 1.8f; // Celsius } if ((temperature >= -50.0f) && (temperature <= 100.0f)) { ConvertTemp(temperature); @@ -812,7 +812,7 @@ void CmndGlobalHum(void) { if (XdrvMailbox.data_len > 0) { float humidity = CharToFloat(XdrvMailbox.data); - if ((humidity >= 0.0) && (humidity <= 100.0)) { + if ((humidity >= 0.0f) && (humidity <= 100.0f)) { ConvertHumidity(humidity); TasmotaGlobal.global_update = 1; // Keep global values just entered valid } diff --git a/tasmota/xdrv_03_energy.ino b/tasmota/xdrv_03_energy.ino index d66b76b93..4ea476ea8 100644 --- a/tasmota/xdrv_03_energy.ino +++ b/tasmota/xdrv_03_energy.ino @@ -143,7 +143,7 @@ char* EnergyFormat(char* result, float* input, uint32_t resolution, uint32_t sin // single = 7 - single &0x03 = 3 - [xx,xx,xx] uint32_t index = (single > 3) ? single &0x03 : (0 == single) ? Energy.phase_count : 1; // 1,2,3 if (single > 2) { single = 0; } // 0,1,2 - float input_sum = 0.0; + float input_sum = 0.0f; if (single > 1) { if (!Settings->flag5.energy_phase) { // SetOption129 - (Energy) Show phase information for (uint32_t i = 0; i < Energy.phase_count; i++) { @@ -167,7 +167,7 @@ char* WebEnergyFormat(char* result, float* input, uint32_t resolution, uint32_t // single = 0 - Energy.phase_count - xx / xx / xx or multi column // single = 1 - Energy.voltage_common or Energy.frequency_common - xx or single column using colspan (if needed) // single = 2 - Sum of Energy.phase_count if SO129 0 - xx or single column using colspan (if needed) or if SO129 1 - xx / xx / xx or multi column - float input_sum = 0.0; + float input_sum = 0.0f; if (single > 1) { // Sum and/or Single column if (!Settings->flag5.energy_phase) { // SetOption129 - (Energy) Show phase information for (uint32_t i = 0; i < Energy.phase_count; i++) { @@ -235,9 +235,9 @@ bool EnergyTariff1Active() // Off-Peak hours } void EnergyUpdateToday(void) { - Energy.total_sum = 0.0; - Energy.yesterday_sum = 0.0; - Energy.daily_sum = 0.0; + Energy.total_sum = 0.0f; + Energy.yesterday_sum = 0.0f; + Energy.daily_sum = 0.0f; for (uint32_t i = 0; i < Energy.phase_count; i++) { if (abs(Energy.kWhtoday_delta[i]) > 1000) { @@ -272,7 +272,7 @@ void EnergyUpdateToday(void) { // return_diff = (uint32_t)(Energy.export_active * 100000) - RtcSettings.energy_usage.last_return_kWhtotal; // RtcSettings.energy_usage.last_return_kWhtotal = (uint32_t)(Energy.export_active * 100000); - float export_active = 0.0; + float export_active = 0.0f; for (uint32_t i = 0; i < Energy.phase_count; i++) { if (!isnan(Energy.export_active[i])) { export_active += Energy.export_active[i]; @@ -305,7 +305,7 @@ void EnergyUpdateTotal(void) { Energy.kWhtoday[i] = (int32_t)((Energy.import_active[i] - Energy.start_energy[i]) * 100000); } - if ((Energy.total[i] < (Energy.import_active[i] - 0.01)) && // We subtract a little offset to avoid continuous updates + if ((Energy.total[i] < (Energy.import_active[i] - 0.01f)) && // We subtract a little offset to avoid continuous updates Settings->flag3.hardware_energy_total) { // SetOption72 - Enable hardware energy total counter as reference (#6561) RtcSettings.energy_kWhtotal_ph[i] = (int32_t)((Energy.import_active[i] * 100000) - Energy.kWhtoday_offset[i] - Energy.kWhtoday[i]); Settings->energy_kWhtotal_ph[i] = RtcSettings.energy_kWhtotal_ph[i]; @@ -1129,13 +1129,13 @@ void EnergyShow(bool json) { if (isnan(reactive_power[i])) { reactive_power[i] = 0; uint32_t difference = ((uint32_t)(apparent_power[i] * 100) - (uint32_t)(Energy.active_power[i] * 100)) / 10; - if ((Energy.current[i] > 0.005) && ((difference > 15) || (difference > (uint32_t)(apparent_power[i] * 100 / 1000)))) { + if ((Energy.current[i] > 0.005f) && ((difference > 15) || (difference > (uint32_t)(apparent_power[i] * 100 / 1000)))) { // calculating reactive power only if current is greater than 0.005A and // difference between active and apparent power is greater than 1.5W or 1% //reactive_power[i] = (float)(RoundSqrtInt((uint64_t)(apparent_power[i] * apparent_power[i] * 100) - (uint64_t)(Energy.active_power[i] * Energy.active_power[i] * 100))) / 10; float power_diff = apparent_power[i] * apparent_power[i] - Energy.active_power[i] * Energy.active_power[i]; if (power_diff < 10737418) // 2^30 / 100 (RoundSqrtInt is limited to 2^30-1) - reactive_power[i] = (float)(RoundSqrtInt((uint32_t)(power_diff * 100.0))) / 10.0; + reactive_power[i] = (float)(RoundSqrtInt((uint32_t)(power_diff * 100.0f))) / 10.0f; else reactive_power[i] = (float)(SqrtInt((uint32_t)(power_diff))); } @@ -1145,7 +1145,7 @@ void EnergyShow(bool json) { } } - float active_power_sum = 0.0; + float active_power_sum = 0.0f; float energy_yesterday_ph[Energy.phase_count]; for (uint32_t i = 0; i < Energy.phase_count; i++) { energy_yesterday_ph[i] = (float)Settings->energy_kWhyesterday_ph[i] / 100000; diff --git a/tasmota/xnrg_03_pzem004t.ino b/tasmota/xnrg_03_pzem004t.ino index 1d07b1626..a9df4cd0b 100644 --- a/tasmota/xnrg_03_pzem004t.ino +++ b/tasmota/xnrg_03_pzem004t.ino @@ -153,10 +153,10 @@ bool PzemRecieve(uint8_t resp, float *data) switch (resp) { case RESP_VOLTAGE: - *data = (float)(buffer[1] << 8) + buffer[2] + (buffer[3] / 10.0); // 65535.x V + *data = (float)(buffer[1] << 8) + buffer[2] + (buffer[3] / 10.0f); // 65535.x V break; case RESP_CURRENT: - *data = (float)(buffer[1] << 8) + buffer[2] + (buffer[3] / 100.0); // 65535.xx A + *data = (float)(buffer[1] << 8) + buffer[2] + (buffer[3] / 100.0f); // 65535.xx A break; case RESP_POWER: *data = (float)(buffer[1] << 8) + buffer[2]; // 65535 W @@ -192,7 +192,7 @@ void PzemEvery250ms(void) Energy.active_power[Pzem.phase] = value; break; case 4: // Total energy as 99999Wh - Energy.import_active[Pzem.phase] = value / 1000.0; // 99.999kWh + Energy.import_active[Pzem.phase] = value / 1000.0f; // 99.999kWh if (Pzem.phase == Energy.phase_count -1) { if (TasmotaGlobal.uptime > PZEM_STABILIZE) { EnergyUpdateTotal(); diff --git a/tasmota/xnrg_05_pzem_ac.ino b/tasmota/xnrg_05_pzem_ac.ino index 67ef47dee..21c50a4ff 100644 --- a/tasmota/xnrg_05_pzem_ac.ino +++ b/tasmota/xnrg_05_pzem_ac.ino @@ -72,12 +72,12 @@ void PzemAcEverySecond(void) // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 = Buffer index // 01 04 14 08 D1 00 6C 00 00 00 F4 00 00 00 26 00 00 01 F4 00 64 00 00 51 34 // Id Cc Sz Volt- Current---- Power------ Energy----- Frequ PFact Alarm Crc-- - Energy.voltage[PzemAc.phase] = (float)((buffer[3] << 8) + buffer[4]) / 10.0; // 6553.0 V - Energy.current[PzemAc.phase] = (float)((buffer[7] << 24) + (buffer[8] << 16) + (buffer[5] << 8) + buffer[6]) / 1000.0; // 4294967.000 A - Energy.active_power[PzemAc.phase] = (float)((buffer[11] << 24) + (buffer[12] << 16) + (buffer[9] << 8) + buffer[10]) / 10.0; // 429496729.0 W - Energy.frequency[PzemAc.phase] = (float)((buffer[17] << 8) + buffer[18]) / 10.0; // 50.0 Hz - Energy.power_factor[PzemAc.phase] = (float)((buffer[19] << 8) + buffer[20]) / 100.0; // 1.00 - Energy.import_active[PzemAc.phase] = (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[13] << 8) + buffer[14]) / 1000.0; // 4294967.295 kWh + Energy.voltage[PzemAc.phase] = (float)((buffer[3] << 8) + buffer[4]) / 10.0f; // 6553.0 V + Energy.current[PzemAc.phase] = (float)((buffer[7] << 24) + (buffer[8] << 16) + (buffer[5] << 8) + buffer[6]) / 1000.0f; // 4294967.000 A + Energy.active_power[PzemAc.phase] = (float)((buffer[11] << 24) + (buffer[12] << 16) + (buffer[9] << 8) + buffer[10]) / 10.0f; // 429496729.0 W + Energy.frequency[PzemAc.phase] = (float)((buffer[17] << 8) + buffer[18]) / 10.0f; // 50.0 Hz + Energy.power_factor[PzemAc.phase] = (float)((buffer[19] << 8) + buffer[20]) / 100.0f; // 1.00 + Energy.import_active[PzemAc.phase] = (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[13] << 8) + buffer[14]) / 1000.0f; // 4294967.295 kWh if (PzemAc.phase == Energy.phase_count -1) { if (TasmotaGlobal.uptime > PZEM_AC_STABILIZE) { EnergyUpdateTotal(); diff --git a/tasmota/xnrg_06_pzem_dc.ino b/tasmota/xnrg_06_pzem_dc.ino index 4e325594f..1c6841154 100644 --- a/tasmota/xnrg_06_pzem_dc.ino +++ b/tasmota/xnrg_06_pzem_dc.ino @@ -71,10 +71,10 @@ void PzemDcEverySecond(void) // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 = Buffer index // 01 04 10 05 40 00 0A 00 0D 00 00 00 02 00 00 00 00 00 00 D6 29 // Id Cc Sz Volt- Curre Power------ Energy----- HiAlm LoAlm Crc-- - Energy.voltage[PzemDc.channel] = (float)((buffer[3] << 8) + buffer[4]) / 100.0; // 655.00 V - Energy.current[PzemDc.channel] = (float)((buffer[5] << 8) + buffer[6]) / 100.0; // 655.00 A - Energy.active_power[PzemDc.channel] = (float)((buffer[9] << 24) + (buffer[10] << 16) + (buffer[7] << 8) + buffer[8]) / 10.0; // 429496729.0 W - Energy.import_active[PzemDc.channel] = (float)((buffer[13] << 24) + (buffer[14] << 16) + (buffer[11] << 8) + buffer[12]) / 1000.0; // 4294967.295 kWh + Energy.voltage[PzemDc.channel] = (float)((buffer[3] << 8) + buffer[4]) / 100.0f; // 655.00 V + Energy.current[PzemDc.channel] = (float)((buffer[5] << 8) + buffer[6]) / 100.0f; // 655.00 A + Energy.active_power[PzemDc.channel] = (float)((buffer[9] << 24) + (buffer[10] << 16) + (buffer[7] << 8) + buffer[8]) / 10.0f; // 429496729.0 W + Energy.import_active[PzemDc.channel] = (float)((buffer[13] << 24) + (buffer[14] << 16) + (buffer[11] << 8) + buffer[12]) / 1000.0f; // 4294967.295 kWh if (PzemDc.channel == Energy.phase_count -1) { if (TasmotaGlobal.uptime > PZEM_DC_STABILIZE) { EnergyUpdateTotal(); diff --git a/tasmota/xnrg_09_dds2382.ino b/tasmota/xnrg_09_dds2382.ino index d960183dd..885f966d6 100644 --- a/tasmota/xnrg_09_dds2382.ino +++ b/tasmota/xnrg_09_dds2382.ino @@ -64,18 +64,18 @@ void Dds2382EverySecond(void) // {"TotalStartTime":"2020-01-08T09:43:05","Total":0.060,"Yesterday":0.001,"Today":0.001,"ExportActive":12.670,"Period":0,"Power":1016,"ApparentPower":1020,"ReactivePower":112,"Factor":0.99,"Frequency":50,"Voltage":242,"Current":4.210}} // {"TotalStartTime":"2020-01-08T00:00:00","Total":0.061,"Yesterday":0.001,"Today":0.001,"ExportActive":12.670,"Period":0.020,"Power":1199.000,"ApparentPower":1204.231,"ReactivePower":108.000,"Factor":1.00,"Frequency":49.98,"Voltage":242.3,"Current":4.970}} - Energy.voltage[0] = (float)((buffer[27] << 8) + buffer[28]) / 10.0; - Energy.current[0] = (float)((buffer[29] << 8) + buffer[30]) / 100.0; + Energy.voltage[0] = (float)((buffer[27] << 8) + buffer[28]) / 10.0f; + Energy.current[0] = (float)((buffer[29] << 8) + buffer[30]) / 100.0f; Energy.active_power[0] = (float)((buffer[31] << 8) + buffer[32]); Energy.reactive_power[0] = (float)(int16_t)((buffer[33] << 8) + buffer[34]); - Energy.power_factor[0] = (float)((buffer[35] << 8) + buffer[36]) / 1000.0; // 1.00 - Energy.frequency[0] = (float)((buffer[37] << 8) + buffer[38]) / 100.0; // 50.0 Hz + Energy.power_factor[0] = (float)((buffer[35] << 8) + buffer[36]) / 1000.0f; // 1.00 + Energy.frequency[0] = (float)((buffer[37] << 8) + buffer[38]) / 100.0f; // 50.0 Hz uint8_t offset = 11; if (Settings->flag3.dds2382_model) { // SetOption71 - Select different Modbus registers for Active Energy (#6531) offset = 19; } - Energy.export_active[0] = (float)((buffer[offset] << 24) + (buffer[offset +1] << 16) + (buffer[offset +2] << 8) + buffer[offset +3]) / 100.0; // 429496.729 kW - Energy.import_active[0] = (float)((buffer[offset +4] << 24) + (buffer[offset +5] << 16) + (buffer[offset +6] << 8) + buffer[offset +7]) / 100.0; // 429496.729 kW + Energy.export_active[0] = (float)((buffer[offset] << 24) + (buffer[offset +1] << 16) + (buffer[offset +2] << 8) + buffer[offset +3]) / 100.0f; // 429496.729 kW + Energy.import_active[0] = (float)((buffer[offset +4] << 24) + (buffer[offset +5] << 16) + (buffer[offset +6] << 8) + buffer[offset +7]) / 100.0f; // 429496.729 kW EnergyUpdateTotal(); // 484.708 kWh } } // end data ready diff --git a/tasmota/xsns_05_ds18x20.ino b/tasmota/xsns_05_ds18x20.ino index 324411987..276a0d71a 100644 --- a/tasmota/xsns_05_ds18x20.ino +++ b/tasmota/xsns_05_ds18x20.ino @@ -370,7 +370,7 @@ bool Ds18x20Read(uint8_t sensor) { switch(ds18x20_sensor[index].address[0]) { case DS18S20_CHIPID: { int16_t tempS = (((data[1] << 8) | (data[0] & 0xFE)) << 3) | ((0x10 - data[6]) & 0x0F); - temperature = ConvertTemp(tempS * 0.0625 - 0.250); + temperature = ConvertTemp(tempS * 0.0625f - 0.250f); break; } case DS1822_CHIPID: @@ -394,12 +394,12 @@ bool Ds18x20Read(uint8_t sensor) { temp12 = (~temp12) +1; sign = -1; } - temperature = ConvertTemp(sign * temp12 * 0.0625); // Divide by 16 + temperature = ConvertTemp(sign * temp12 * 0.0625f); // Divide by 16 break; } case MAX31850_CHIPID: { int16_t temp14 = (data[1] << 8) + (data[0] & 0xFC); - temperature = ConvertTemp(temp14 * 0.0625); // Divide by 16 + temperature = ConvertTemp(temp14 * 0.0625f); // Divide by 16 break; } } diff --git a/tasmota/xsns_05_esp32_ds18x20.ino b/tasmota/xsns_05_esp32_ds18x20.ino index 796036610..c0157c20a 100644 --- a/tasmota/xsns_05_esp32_ds18x20.ino +++ b/tasmota/xsns_05_esp32_ds18x20.ino @@ -130,7 +130,7 @@ bool Ds18x20Read(uint8_t sensor, float &t) { switch(ds18x20_sensor[index].address[0]) { case DS18S20_CHIPID: { int16_t tempS = (((data[1] << 8) | (data[0] & 0xFE)) << 3) | ((0x10 - data[6]) & 0x0F); - t = ConvertTemp(tempS * 0.0625 - 0.250); + t = ConvertTemp(tempS * 0.0625f - 0.250f); ds18x20_sensor[index].valid = SENSOR_MAX_MISS; return true; } @@ -141,13 +141,13 @@ bool Ds18x20Read(uint8_t sensor, float &t) { temp12 = (~temp12) +1; sign = -1; } - t = ConvertTemp(sign * temp12 * 0.0625); // Divide by 16 + t = ConvertTemp(sign * temp12 * 0.0625f); // Divide by 16 ds18x20_sensor[index].valid = SENSOR_MAX_MISS; return true; } case MAX31850_CHIPID: { int16_t temp14 = (data[1] << 8) + (data[0] & 0xFC); - t = ConvertTemp(temp14 * 0.0625); // Divide by 16 + t = ConvertTemp(temp14 * 0.0625f); // Divide by 16 ds18x20_sensor[index].valid = SENSOR_MAX_MISS; return true; } diff --git a/tasmota/xsns_06_dht.ino b/tasmota/xsns_06_dht.ino index 7da466f53..1f750a6fa 100644 --- a/tasmota/xsns_06_dht.ino +++ b/tasmota/xsns_06_dht.ino @@ -158,7 +158,7 @@ bool DhtRead(uint32_t sensor) { break; case GPIO_DHT22: // DHT21, DHT22, AM2301, AM2302, AM2321 case GPIO_SI7021: { // iTead SI7021 - humidity = ((dht_data[0] << 8) | dht_data[1]) * 0.1; + humidity = ((dht_data[0] << 8) | dht_data[1]) * 0.1f; // DHT21/22 (Adafruit): int16_t temp16 = dht_data[2] << 8 | dht_data[3]; // case 1 : signed 16 bits if ((dht_data[2] & 0xF0) == 0x80) { // case 2 : negative when high nibble = 0x80 @@ -178,14 +178,14 @@ bool DhtRead(uint32_t sensor) { float x; if (voltage < 15037) { x = voltage - 15200; - humidity = - FastPrecisePowf(0.0024 * x, 3) - 0.0004 * x + 20.1; + humidity = - FastPrecisePowf(0.0024f * x, 3) - 0.0004f * x + 20.1f; } else if (voltage < 22300) { - humidity = - 0.00069 * voltage + 30.6; + humidity = - 0.00069f * voltage + 30.6f; } else { x = voltage - 22800; - humidity = - FastPrecisePowf(0.00046 * x, 3) - 0.0004 * x + 15; + humidity = - FastPrecisePowf(0.00046f * x, 3) - 0.0004f * x + 15; } temperature = 0; Dht[sensor].raw = voltage; @@ -197,8 +197,8 @@ bool DhtRead(uint32_t sensor) { return false; } - if (humidity > 100) { humidity = 100.0; } - if (humidity < 0) { humidity = 0.1; } + if (humidity > 100) { humidity = 100.0f; } + if (humidity < 0) { humidity = 0.1f; } Dht[sensor].h = ConvertHumidity(humidity); Dht[sensor].t = ConvertTemp(temperature); Dht[sensor].lastresult = 0; diff --git a/tasmota/xsns_06_esp32_dht.ino b/tasmota/xsns_06_esp32_dht.ino index e6c6308a7..3399bebc4 100644 --- a/tasmota/xsns_06_esp32_dht.ino +++ b/tasmota/xsns_06_esp32_dht.ino @@ -58,8 +58,8 @@ bool DhtRead(uint32_t sensor) { return false; } - if (humidity > 100) { humidity = 100.0; } - if (humidity < 0) { humidity = 0.1; } + if (humidity > 100) { humidity = 100.0f; } + if (humidity < 0) { humidity = 0.1f; } Dht[sensor].h = ConvertHumidity(humidity); Dht[sensor].t = ConvertTemp(temperature); Dht[sensor].lastresult = 0; diff --git a/tasmota/xsns_07_sht1x.ino b/tasmota/xsns_07_sht1x.ino index 5b5419648..fb1b80f4a 100644 --- a/tasmota/xsns_07_sht1x.ino +++ b/tasmota/xsns_07_sht1x.ino @@ -138,14 +138,14 @@ bool ShtRead(void) float humRaw = ShtReadData(); // Temperature conversion coefficients from SHT1X datasheet for version 4 - const float d1 = -39.7; // 3.5V - const float d2 = 0.01; // 14-bit + const float d1 = -39.7f; // 3.5V + const float d2 = 0.01f; // 14-bit sht_temperature = d1 + (tempRaw * d2); - const float c1 = -2.0468; - const float c2 = 0.0367; - const float c3 = -1.5955E-6; - const float t1 = 0.01; - const float t2 = 0.00008; + const float c1 = -2.0468f; + const float c2 = 0.0367f; + const float c3 = -1.5955E-6f; + const float t1 = 0.01f; + const float t2 = 0.00008f; float rhLinear = c1 + c2 * humRaw + c3 * humRaw * humRaw; sht_humidity = (sht_temperature - 25) * (t1 + t2 * humRaw) + rhLinear; sht_temperature = ConvertTemp(sht_temperature); diff --git a/tasmota/xsns_08_htu21.ino b/tasmota/xsns_08_htu21.ino index 83a3d335f..0b9c652ae 100644 --- a/tasmota/xsns_08_htu21.ino +++ b/tasmota/xsns_08_htu21.ino @@ -167,7 +167,7 @@ bool HtuRead(void) } if (HtuCheckCrc8(sensorval) != checksum) { return false; } // Checksum mismatch - Htu.temperature = ConvertTemp(0.002681 * (float)sensorval - 46.85); + Htu.temperature = ConvertTemp(0.002681f * (float)sensorval - 46.85f); Wire.beginTransmission(HTU21_ADDR); Wire.write(HTU21_READHUM); @@ -183,15 +183,15 @@ bool HtuRead(void) if (HtuCheckCrc8(sensorval) != checksum) { return false; } // Checksum mismatch sensorval ^= 0x02; // clear status bits - Htu.humidity = 0.001907 * (float)sensorval - 6; - if (Htu.humidity > 100) { Htu.humidity = 100.0; } - if (Htu.humidity < 0) { Htu.humidity = 0.01; } + Htu.humidity = 0.001907f * (float)sensorval - 6; + if (Htu.humidity > 100) { Htu.humidity = 100.0f; } + if (Htu.humidity < 0) { Htu.humidity = 0.01f; } - if ((0.00 == Htu.humidity) && (0.00 == Htu.temperature)) { - Htu.humidity = 0.0; + if ((0.00f == Htu.humidity) && (0.00f == Htu.temperature)) { + Htu.humidity = 0.0f; } - if ((Htu.temperature > 0.00) && (Htu.temperature < 80.00)) { - Htu.humidity = (-0.15) * (25 - Htu.temperature) + Htu.humidity; + if ((Htu.temperature > 0.00f) && (Htu.temperature < 80.00f)) { + Htu.humidity = (-0.15f) * (25 - Htu.temperature) + Htu.humidity; } Htu.humidity = ConvertHumidity(Htu.humidity); diff --git a/tasmota/xsns_09_bmp.ino b/tasmota/xsns_09_bmp.ino index 149c0ded2..6846af7ae 100644 --- a/tasmota/xsns_09_bmp.ino +++ b/tasmota/xsns_09_bmp.ino @@ -167,7 +167,7 @@ void Bmp180Read(uint8_t bmp_idx) int32_t xt1 = (ut - (int32_t)bmp180_cal_data[bmp_idx].cal_ac6) * ((int32_t)bmp180_cal_data[bmp_idx].cal_ac5) >> 15; int32_t xt2 = ((int32_t)bmp180_cal_data[bmp_idx].cal_mc << 11) / (xt1 + (int32_t)bmp180_cal_data[bmp_idx].cal_md); int32_t bmp180_b5 = xt1 + xt2; - bmp_sensors[bmp_idx].bmp_temperature = ((bmp180_b5 + 8) >> 4) / 10.0; + bmp_sensors[bmp_idx].bmp_temperature = ((bmp180_b5 + 8) >> 4) / 10.0f; I2cWrite8(bmp_sensors[bmp_idx].bmp_address, BMP180_REG_CONTROL, BMP180_PRESSURE3); // Highest resolution delay(2 + (4 << BMP180_OSS)); // 26ms conversion time at ultra high resolution @@ -197,7 +197,7 @@ void Bmp180Read(uint8_t bmp_idx) x1 = (x1 * 3038) >> 16; x2 = (-7357 * p) >> 16; p += ((x1 + x2 + (int32_t)3791) >> 4); - bmp_sensors[bmp_idx].bmp_pressure = (float)p / 100.0; // convert to mbar + bmp_sensors[bmp_idx].bmp_pressure = (float)p / 100.0f; // convert to mbar } /*********************************************************************************************\ @@ -307,7 +307,7 @@ void Bme280Read(uint8_t bmp_idx) ((int32_t)Bme280CalibrationData[bmp_idx].dig_T3)) >> 14; int32_t t_fine = vart1 + vart2; float T = (t_fine * 5 + 128) >> 8; - bmp_sensors[bmp_idx].bmp_temperature = T / 100.0; + bmp_sensors[bmp_idx].bmp_temperature = T / 100.0f; int32_t adc_P = I2cRead24(bmp_sensors[bmp_idx].bmp_address, BME280_REGISTER_PRESSUREDATA); adc_P >>= 4; @@ -326,7 +326,7 @@ void Bme280Read(uint8_t bmp_idx) var1 = (((int64_t)Bme280CalibrationData[bmp_idx].dig_P9) * (p >> 13) * (p >> 13)) >> 25; var2 = (((int64_t)Bme280CalibrationData[bmp_idx].dig_P8) * p) >> 19; p = ((p + var1 + var2) >> 8) + (((int64_t)Bme280CalibrationData[bmp_idx].dig_P7) << 4); - bmp_sensors[bmp_idx].bmp_pressure = (float)p / 25600.0; + bmp_sensors[bmp_idx].bmp_pressure = (float)p / 25600.0f; if (BMP280_CHIPID == bmp_sensors[bmp_idx].bmp_type) { return; } @@ -343,7 +343,7 @@ void Bme280Read(uint8_t bmp_idx) v_x1_u32r = (v_x1_u32r < 0) ? 0 : v_x1_u32r; v_x1_u32r = (v_x1_u32r > 419430400) ? 419430400 : v_x1_u32r; float h = (v_x1_u32r >> 12); - bmp_sensors[bmp_idx].bmp_humidity = h / 1024.0; + bmp_sensors[bmp_idx].bmp_humidity = h / 1024.0f; } #ifdef USE_BME68X @@ -444,16 +444,16 @@ void Bme680Read(uint8_t bmp_idx) if (rslt != BME68X_OK) { return; } #ifdef BME68X_DO_NOT_USE_FPU - bmp_sensors[bmp_idx].bmp_temperature = data.temperature / 100.0; // Temperature in degree celsius x100 - bmp_sensors[bmp_idx].bmp_humidity = data.humidity / 1000.0; // Humidity in % relative humidity x1000 + bmp_sensors[bmp_idx].bmp_temperature = data.temperature / 100.0f; // Temperature in degree celsius x100 + bmp_sensors[bmp_idx].bmp_humidity = data.humidity / 1000.0f; // Humidity in % relative humidity x1000 #else bmp_sensors[bmp_idx].bmp_temperature = data.temperature; // Temperature in degree celsius bmp_sensors[bmp_idx].bmp_humidity = data.humidity; // Humidity in % relative humidity #endif - bmp_sensors[bmp_idx].bmp_pressure = data.pressure / 100.0; // Pressure in Pascal (converted to hPa) + bmp_sensors[bmp_idx].bmp_pressure = data.pressure / 100.0f; // Pressure in Pascal (converted to hPa) // Avoid using measurements from an unstable heating setup if (data.status & BME68X_GASM_VALID_MSK) { - bmp_sensors[bmp_idx].bmp_gas_resistance = data.gas_resistance / 1000.0; // Gas resistance in Ohms (converted to kOhm) + bmp_sensors[bmp_idx].bmp_gas_resistance = data.gas_resistance / 1000.0f; // Gas resistance in Ohms (converted to kOhm) } else { bmp_sensors[bmp_idx].bmp_gas_resistance = 0; } diff --git a/tasmota/xsns_21_sgp30.ino b/tasmota/xsns_21_sgp30.ino index e012813cb..a2509da94 100644 --- a/tasmota/xsns_21_sgp30.ino +++ b/tasmota/xsns_21_sgp30.ino @@ -62,17 +62,17 @@ float sgp30_AbsoluteHumidity(float temperature, float humidity) { //Buck (1981) 6.1121 exp(17.502 x T)/(T + 240.97) //reference https://www.eas.ualberta.ca/jdwilson/EAS372_13/Vomel_CIRES_satvpformulae.html float temp = NAN; - const float mw = 18.01534; // molar mass of water g/mol - const float r = 8.31447215; // Universal gas constant J/mol/K + const float mw = 18.01534f; // molar mass of water g/mol + const float r = 8.31447215f; // Universal gas constant J/mol/K if (isnan(temperature) || isnan(humidity) ) { return NAN; } - temp = POW_FUNC(2.718281828, (17.67 * temperature) / (temperature + 243.5)); + temp = POW_FUNC(2.718281828f, (17.67f * temperature) / (temperature + 243.5f)); //return (6.112 * temp * humidity * 2.1674) / (273.15 + temperature); //simplified version - return (6.112 * temp * humidity * mw) / ((273.15 + temperature) * r); //long version + return (6.112f * temp * humidity * mw) / ((273.15f + temperature) * r); //long version } #define SAVE_PERIOD 30 diff --git a/tasmota/xsns_26_lm75ad.ino b/tasmota/xsns_26_lm75ad.ino index 9e038dd4a..03501b9a1 100644 --- a/tasmota/xsns_26_lm75ad.ino +++ b/tasmota/xsns_26_lm75ad.ino @@ -77,7 +77,7 @@ float LM75ADGetTemp(void) sign = -1; } t = t >> 5; // shift value into place (5 LSB not used) - return ConvertTemp(sign * t * 0.125); + return ConvertTemp(sign * t * 0.125f); } void LM75ADShow(bool json) diff --git a/tasmota/xsns_37_rfsensor.ino b/tasmota/xsns_37_rfsensor.ino index 2c4d7e7f6..25db41a0c 100644 --- a/tasmota/xsns_37_rfsensor.ino +++ b/tasmota/xsns_37_rfsensor.ino @@ -479,7 +479,7 @@ void RfSnsAnalyzeAlectov2() // rfsns_raw_signal->Number = RFSNS_DKW2012_PULSECOUNT; // DKW2012 // data[8] = 11; // WSW - factor = 1.22; // (1.08) + factor = 1.22f; // (1.08) // atime = rfsns_raw_signal->Time - rfsns_alecto_time; // if ((atime > 10000) && (atime < 60000)) factor = (float)60000 / atime; // rfsns_alecto_time = rfsns_raw_signal->Time; @@ -493,7 +493,7 @@ void RfSnsAnalyzeAlectov2() // check if rain unit has been reset! if (rain < rfsns_alecto_rain_base) { rfsns_alecto_rain_base = rain; } if (rfsns_alecto_rain_base > 0) { - rfsns_alecto_v2->rain += ((float)rain - rfsns_alecto_rain_base) * 0.30; + rfsns_alecto_v2->rain += ((float)rain - rfsns_alecto_rain_base) * 0.30f; } rfsns_alecto_rain_base = rain; rfsns_alecto_v2->wind = (float)data[4] * factor; diff --git a/tasmota/xsns_39_max31855.ino b/tasmota/xsns_39_max31855.ino index 0807b6b8b..1b7bca1b3 100644 --- a/tasmota/xsns_39_max31855.ino +++ b/tasmota/xsns_39_max31855.ino @@ -89,7 +89,7 @@ float MAX31855_GetProbeTemperature(int32_t RawData) { } else { RawData >>= 18; // Positiv value - Drop lower 18 bits } - float result = (RawData * 0.25); // MAX31855 LSB resolution is 0.25°C for probe temperature + float result = (RawData * 0.25f); // MAX31855 LSB resolution is 0.25°C for probe temperature return ConvertTemp(result); // Check if we have to convert to Fahrenheit } @@ -104,7 +104,7 @@ float MAX31855_GetReferenceTemperature(int32_t RawData) { } else { RawData = (RawData >> 4) & 0x00000FFF; // Positiv value - Drop lower 4 bits and mask out remaining bits (probe temp, error bit, etc.) } - float result = (RawData * 0.0625); // MAX31855 LSB resolution is 0.0625°C for reference temperature + float result = (RawData * 0.0625f); // MAX31855 LSB resolution is 0.0625°C for reference temperature return ConvertTemp(result); // Check if we have to convert to Fahrenheit } @@ -123,7 +123,7 @@ void MAX31855_GetResult(void) { MAX31855_Result.ErrorCode = 0; MAX31855_Result.ReferenceTemperature = NAN; - MAX31855_Result.ProbeTemperature = ConvertTemp(0.25 * temp); + MAX31855_Result.ProbeTemperature = ConvertTemp(0.25f * temp); } else { int32_t RawData = MAX31855_ShiftIn(32); uint8_t probeerror = RawData & 0x7; diff --git a/tasmota/xsns_41_max44009.ino b/tasmota/xsns_41_max44009.ino index 45cb91354..0b1a4fb5a 100644 --- a/tasmota/xsns_41_max44009.ino +++ b/tasmota/xsns_41_max44009.ino @@ -54,7 +54,7 @@ bool Max4409Read_lum(void) if (I2cValidRead16((uint16_t *)®data, max44009_address, REG_LUMINANCE)) { int exponent = (regdata[0] & 0xF0) >> 4; int mantissa = ((regdata[0] & 0x0F) << 4) | (regdata[1] & 0x0F); - max44009_illuminance = (float)(((0x00000001 << exponent) * (float)mantissa) * 0.045); + max44009_illuminance = (float)(((0x00000001 << exponent) * (float)mantissa) * 0.045f); max44009_valid = 1; return true; } else { diff --git a/tasmota/xsns_42_scd30.ino b/tasmota/xsns_42_scd30.ino index 062e1d841..dc7ec35a3 100644 --- a/tasmota/xsns_42_scd30.ino +++ b/tasmota/xsns_42_scd30.ino @@ -74,8 +74,8 @@ int scd30Co2Zero_count = 0; int i2cReset_count = 0; uint16_t scd30_CO2 = 0; uint16_t scd30_CO2EAvg = 0; -float scd30_Humid = 0.0; -float scd30_Temp = 0.0; +float scd30_Humid = 0.0f; +float scd30_Temp = 0.0f; void Scd30Detect(void) { diff --git a/tasmota/xsns_43_hre.ino b/tasmota/xsns_43_hre.ino index 98e52b0ab..6ceddf43c 100644 --- a/tasmota/xsns_43_hre.ino +++ b/tasmota/xsns_43_hre.ino @@ -195,7 +195,7 @@ void hreEvery50ms(void) if (parity_errors == 0) { float curr_usage; - curr_usage = 0.01 * atol(buff+24); // useage in gal + curr_usage = 0.01f * atol(buff+24); // useage in gal if (hre_usage_time) { double dt = 1.666e-2 * (curr_start - hre_usage_time); // dt in minutes diff --git a/tasmota/xsns_46_MLX90614.ino b/tasmota/xsns_46_MLX90614.ino index a3a95600e..5cb7f65cf 100644 --- a/tasmota/xsns_46_MLX90614.ino +++ b/tasmota/xsns_46_MLX90614.ino @@ -55,14 +55,14 @@ void MLX90614_Every_Second(void) if (mlx90614.value & 0x8000) { mlx90614.obj_temp = -999; } else { - mlx90614.obj_temp = ((float)mlx90614.value * 0.02) - 273.15; + mlx90614.obj_temp = ((float)mlx90614.value * 0.02f) - 273.15f; } //mlx90614.i2c_buf = I2cRead24(I2_ADR_IRT,MLX90614_TA); mlx90614.value = MLX90614_read16(I2_ADR_IRT, MLX90614_TA); if (mlx90614.value & 0x8000) { mlx90614.amb_temp = -999; } else { - mlx90614.amb_temp = ((float)mlx90614.value * 0.02) - 273.15; + mlx90614.amb_temp = ((float)mlx90614.value * 0.02f) - 273.15f; } } diff --git a/tasmota/xsns_55_hih_series.ino b/tasmota/xsns_55_hih_series.ino index b0c8765eb..4f6cc0648 100644 --- a/tasmota/xsns_55_hih_series.ino +++ b/tasmota/xsns_55_hih_series.ino @@ -61,10 +61,10 @@ bool Hih6Read(void) // uint8_t status = data[0] >> 6; // 0 = Valid data, 1 = Stale data, 2 = Command mode, 3 = Not used - Hih6.humidity = ConvertHumidity(((float)(((data[0] & 0x3F) << 8) | data[1]) * 100.0) / 16383.0); + Hih6.humidity = ConvertHumidity(((float)(((data[0] & 0x3F) << 8) | data[1]) * 100.0f) / 16383.0f); // Convert the data to 14-bits int temp = ((data[2] << 8) | (data[3] & 0xFC)) / 4; - Hih6.temperature = ConvertTemp(((float)temp / 16384.0) * 165.0 - 40.0); + Hih6.temperature = ConvertTemp(((float)temp / 16384.0f) * 165.0f - 40.0f); Hih6.valid = SENSOR_MAX_MISS; return true; diff --git a/tasmota/xsns_59_ds1624.ino b/tasmota/xsns_59_ds1624.ino index 1640cc801..6f62b8540 100644 --- a/tasmota/xsns_59_ds1624.ino +++ b/tasmota/xsns_59_ds1624.ino @@ -127,7 +127,7 @@ bool DS1624GetTemp(float *value, int idx) uint16_t t; if (!I2cValidRead16(&t, DS1624_Idx2Addr(idx), DS1624_TEMP_REGISTER)) { return false; } if (ds1624_sns[idx].type == DS1624_TYPE_DS1624) { - *value = ((float)(int8_t)(t>>8)) + ((t>>4)&0xf)*0.0625; + *value = ((float)(int8_t)(t>>8)) + ((t>>4)&0xf)*0.0625f; } else { //type == DS1624_TYPE_DS1621 // Datasheet for ds1621 is wrong for high resolution, real is: *value = ((float)(int8_t)(t>>8)); diff --git a/tasmota/xsns_65_hdc1080.ino b/tasmota/xsns_65_hdc1080.ino index 381f1a48a..96a7be484 100644 --- a/tasmota/xsns_65_hdc1080.ino +++ b/tasmota/xsns_65_hdc1080.ino @@ -61,16 +61,16 @@ // Constants: #define HDC1080_CONV_TIME 15 // Assume 6.50 + 6.35 ms + x of conversion delay for this device -#define HDC1080_TEMP_MULT 0.0025177 -#define HDC1080_RH_MULT 0.0015258 -#define HDC1080_TEMP_OFFSET 40.0 +#define HDC1080_TEMP_MULT 0.0025177f +#define HDC1080_RH_MULT 0.0015258f +#define HDC1080_TEMP_OFFSET 40.0f const char* hdc_type_name = "HDC1080"; uint16_t hdc_manufacturer_id = 0; uint16_t hdc_device_id = 0; -float hdc_temperature = 0.0; -float hdc_humidity = 0.0; +float hdc_temperature = 0.0f; +float hdc_humidity = 0.0f; uint8_t hdc_valid = 0; @@ -221,8 +221,8 @@ bool HdcRead(void) { hdc_humidity = HDC1080_RH_MULT * (float) (rh_data); - if (hdc_humidity > 100) { hdc_humidity = 100.0; } - if (hdc_humidity < 0) { hdc_humidity = 0.01; } + if (hdc_humidity > 100) { hdc_humidity = 100.0f; } + if (hdc_humidity < 0) { hdc_humidity = 0.01f; } hdc_humidity = ConvertHumidity(hdc_humidity); hdc_valid = SENSOR_MAX_MISS; diff --git a/tasmota/xsns_88_am2320.ino b/tasmota/xsns_88_am2320.ino index 2180d2c0d..cb177987b 100644 --- a/tasmota/xsns_88_am2320.ino +++ b/tasmota/xsns_88_am2320.ino @@ -106,12 +106,12 @@ bool Am2320Read(void) unsigned int receivedCrc = (buf[7] << 8) | buf[6]; // pack high and low byte together if (receivedCrc == crc16(buf, 6)) { // preamble + data int temperature = ((buf[4] & 0x7F) << 8) | buf[5]; - AM2320.t = temperature / 10.0; + AM2320.t = temperature / 10.0f; // check for negative temp reading AM2320.t = ((buf[4] & 0x80) >> 7) == 1 ? AM2320.t * (-1) : AM2320.t; int humidity = (buf[2] << 8) | buf[3]; - AM2320.h = humidity / 10.0; + AM2320.h = humidity / 10.0f; AM2320.valid = SENSOR_MAX_MISS; // reset error counter return true;