pvvx / ATC_MiThermometer

Custom firmware for the Xiaomi Thermometers and Telink Flasher
https://github.com/pvvx/pvvx.github.io/tree/master/ATC_MiThermometer
Other
2.9k stars 202 forks source link

Fix °C->°F calculation #407

Closed thedanbob closed 10 months ago

thedanbob commented 10 months ago

This can be confirmed with the following test program:

#include <stdio.h>
#include <stdint.h>

int main()
{
    int16_t temp = 2000;
    printf("%d\n", (((temp / 5) * 9) + 3200) / 10); // Old: 680
    printf("%d\n", ((int32_t)((int32_t)temp * 9)/ 50) + 3200); // New: 3560
    printf("%d\n", ((int32_t)((int32_t)temp * 9)/ 50) + 320); // Fixed: 680
    return 0;
}
pvvx commented 10 months ago

Fixed in the new version 4.6.