Skip to content

#2 add threshold functionality - #3

Open
moritzNeo wants to merge 4 commits into
masterfrom
2-add-threhold-funtionality
Open

#2 add threshold functionality#3
moritzNeo wants to merge 4 commits into
masterfrom
2-add-threhold-funtionality

Conversation

@moritzNeo

Copy link
Copy Markdown

added Threshold alert reading and setting functions

@moritzNeo moritzNeo self-assigned this Jul 21, 2026
@moritzNeo moritzNeo changed the title #2 add threhold funtionality #2 add threhold functionality Jul 21, 2026
@moritzNeo moritzNeo changed the title #2 add threhold functionality #2 add threshold functionality Jul 21, 2026

@marius-meissner marius-meissner left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice PR—I especially like the added documentation, including the Doc Tests.
Since this PR also includes the commits from the other PR, I'd suggest we do the entire review here.

Comment thread src/client.rs
Comment thread src/client.rs
Comment thread src/client.rs
Comment thread src/client.rs
Comment thread src/client.rs
Comment thread src/client.rs
Comment thread src/client.rs
Comment thread src/client.rs
Comment on lines +2524 to +2533
fn positive_ratio(numerator: f32, denominator: f32) -> Result<f32, Error<B>> {
if !numerator.is_finite() || numerator <= 0.0 || !denominator.is_finite() || denominator <= 0.0 {
return Err(Error::InvalidGainCorrection);
}
let ratio = numerator / denominator;
if !ratio.is_finite() || ratio <= 0.0 {
return Err(Error::InvalidGainCorrection);
}
Ok(ratio)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here, too, the logic could be neatly encapsulated in a struct. e.g. PositiveRatio

Comment thread src/client.rs
Comment on lines +2535 to +2554
fn accumulator_lsbs(clock: AccumulatorClock) -> Result<(f64, f64, f64), Error<B>> {
match clock {
AccumulatorClock::Internal => Ok((
AccumulatedCharge::LSB_VOLT_SECONDS,
AccumulatedEnergy::LSB_VOLT_SQUARED_SECONDS,
AccumulatedTime::LSB_SECONDS,
)),
AccumulatorClock::External { frequency_hz, pre, div } => {
if !frequency_hz.is_finite() || frequency_hz <= 0.0 || pre > 7 || div > 31 {
return Err(Error::InvalidThreshold);
}
let clock_factor = f64::from(1u16 << pre) * (f64::from(div) + 1.0) / frequency_hz;
Ok((
1.21899e-5 * clock_factor,
7.4895e-5 * clock_factor,
12.8315 * clock_factor,
))
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What about moving this logic to a (maybe pub(crate)) method of AccumulatorClock?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants