Precise temperature without pow

Implement TuyaAdjustedTemperature which takes precision to offset the integer value. 
Using TempRes parameter as these should align
This commit is contained in:
jaymemaurice 2021-02-11 14:48:55 -05:00 committed by GitHub
parent caecc5cb33
commit 5e9fe677f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 3 deletions

View File

@ -318,6 +318,23 @@ int StrCmpNoCase(char const *Str1, char const *Str2) // Compare case sensistive
}
}
float TuyaAdjustedTemperature(uint8_t packetValue, uint8_t res)
{
switch (res)
{
case 1:
return packetValue/10;
break;
case 2:
return packetValue/100;
break;
case 3:
return packetValue/1000;
break;
default:
return (float)packetValue;
}
}
/*********************************************************************************************\
* Internal Functions
\*********************************************************************************************/
@ -1295,7 +1312,7 @@ void TuyaSensorsShow(bool json)
GetTextIndexed(sname, sizeof(sname), (sensor-71), kTuyaSensors);
ResponseAppend_P(PSTR("\"%s\":%s"), sname,
(Tuya.SensorsValid[sensor-71] ? dtostrfd((float)Tuya.Sensors[sensor-71] / pow(10, res), res, tempval) : PSTR("null")));
(Tuya.SensorsValid[sensor-71] ? dtostrfd(TuyaAdjustedTemperature(Tuya.Sensors[sensor-71], res), res, tempval) : PSTR("null")));
added = true;
}
#ifdef USE_WEBSERVER
@ -1303,11 +1320,11 @@ void TuyaSensorsShow(bool json)
if (TuyaGetDpId(sensor) != 0) {
switch (sensor) {
case 71:
WSContentSend_Temp("", (float)Tuya.Sensors[0] / pow(10, Settings.flag2.temperature_resolution));
WSContentSend_Temp("", TuyaAdjustedTemperature(Tuya.Sensors[0], Settings.flag2.temperature_resolution));
break;
case 72:
WSContentSend_PD(PSTR("{s}" D_TEMPERATURE " Set{m}%s " D_UNIT_DEGREE "%c{e}"),
dtostrfd((float)Tuya.Sensors[1] / pow(10, Settings.flag2.temperature_resolution), Settings.flag2.temperature_resolution, tempval), TempUnit());
dtostrfd(TuyaAdjustedTemperature(Tuya.Sensors[1], Settings.flag2.temperature_resolution), Settings.flag2.temperature_resolution, tempval), TempUnit());
break;
case 73:
WSContentSend_PD(HTTP_SNS_HUM, "", dtostrfd(Tuya.Sensors[2], Settings.flag2.temperature_resolution, tempval));