#2 add threshold functionality - #3
Open
moritzNeo wants to merge 4 commits into
Open
Conversation
marius-meissner
requested changes
Jul 28, 2026
marius-meissner
left a comment
There was a problem hiding this comment.
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 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) | ||
| } |
There was a problem hiding this comment.
Here, too, the logic could be neatly encapsulated in a struct. e.g. PositiveRatio
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, | ||
| )) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
What about moving this logic to a (maybe pub(crate)) method of AccumulatorClock?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
added Threshold alert reading and setting functions