fix: use int64 in ReadTemperature to avoid overflow

This commit is contained in:
rdon
2025-09-18 19:21:46 +09:00
committed by Ron Evans
parent 310df7acb5
commit e29e583919
+2 -1
View File
@@ -100,7 +100,8 @@ func ReadTemperature() (millicelsius int32) {
rp.ADC.CS.SetBits(rp.ADC_CS_TS_EN)
// T = 27 - (ADC_voltage - 0.706)/0.001721
return (27000<<16 - (int32(thermChan.getVoltage())-706<<16)*581) >> 16
// 1/0.001721 ≈ 581
return int32(((int64(27000) << 16) - ((int64(thermChan.getVoltage()) - (int64(706) << 16)) * 581)) >> 16)
}
// waitForReady spins waiting for the ADC peripheral to become ready.