Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cycle CS pin in case of checksum error #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ where

let pec = PEC15::calc(&result[0..6]);
if pec[0] != result[6] || pec[1] != result[7] {
self.cs.set_high().map_err(Error::CSPinError)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my point of view, it's the correct & expected behavior for setting the CS pine state here.
As the only upper method calling read() is within read_daisy_chain(), which is managing the CS pin state (except the case you just found).

return Err(Error::ChecksumMismatch);
}

Expand Down Expand Up @@ -973,13 +974,13 @@ where
}

// Constant of 276 °C, which needs to be subtracted
const TEMP_SUB: i16 = 20976;
const TEMP_SUB: i32 = 20976;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!
Please try to add a unit test.


// Check if temperature is negative
let temp_i32: i16 = if value >= TEMP_SUB as u16 {
value as i16 - TEMP_SUB
let temp_i32: i32 = if value >= TEMP_SUB as u16 {
value as i32 - TEMP_SUB
} else {
0 - TEMP_SUB + value as i16
0 - TEMP_SUB + value as i32
};

// Applying factor 100 uV/7.6 mV
Expand Down