Skip to content

Commit 987040b

Browse files
committed
account for negative results of operations
1 parent 715ded2 commit 987040b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/adc.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,11 @@ impl ADC {
280280
pub fn to_degrees_centigrade(&self, sample: u16) -> f32 {
281281
let sample = (u32::from(sample) * self.calibrated_vdda) / VDDA_CALIB_MV;
282282
(VtempCal130::TEMP_DEGREES - VtempCal30::TEMP_DEGREES) as f32
283-
/ (VtempCal130::get().read() - VtempCal30::get().read()) as f32
284-
* (sample - u32::from(VtempCal30::get().read())) as f32
283+
// as signed because RM0351 doesn't specify against this being an
284+
// inverse relation (which would result in a negative differential)
285+
/ (VtempCal130::get().read() as i32 - VtempCal30::get().read() as i32) as f32
286+
// this can definitely be negative so must be done as a signed value
287+
* (sample as i32 - VtempCal30::get().read() as i32) as f32
285288
+ 30.0
286289
}
287290

0 commit comments

Comments
 (0)