fix: clarify and document CTMU temperature calibration logic#282
Open
saad-aids wants to merge 2 commits intofossasia:mainfrom
Open
fix: clarify and document CTMU temperature calibration logic#282saad-aids wants to merge 2 commits intofossasia:mainfrom
saad-aids wants to merge 2 commits intofossasia:mainfrom
Conversation
- Extract magic numbers into named module-level constants - Add _CTMU_CURRENT_RANGE_55UA constant for 0b11110 value - Add _TEMP_CALIB dict with documented calibration values - Expand temperature property docstring with full explanation Fixes fossasia#272
Reviewer's GuideRefactors the MCU temperature measurement to replace embedded magic numbers with named calibration constants and an explanatory docstring, while keeping behavior identical. Class diagram for updated ScienceLab temperature calibration logicclassDiagram
class ScienceLab {
+ConnectionHandler device
+str firmware
+LogicAnalyzer logic_analyzer
+Oscilloscope oscilloscope
+WaveformGenerator waveform_generator
+PWMGenerator pwm_generator
+Multimeter multimeter
+PowerSupply power_supply
+float temperature
+__init__(ConnectionHandler device)
+float temperature()
-float _get_ctmu_voltage(int channel, int current_range, bool tgen)
}
class CTMUCalibration {
<<module>>
+int _CTMU_CURRENT_RANGE_55UA
+dict _TEMP_CALIB
}
ScienceLab ..> CTMUCalibration : uses
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- There are now two
ScienceLabclass definitions in this module; please consolidate the changes into the existing class and remove the duplicate definition to avoid one silently shadowing the other. - The CTMU constant
_CTMU_CURRENT_RANGE_55UAis named as a current range but is passed as thechannelargument to_get_ctmu_voltage; consider renaming the constant or adjusting the call/signature so the naming clearly matches the parameter being set. - The module-level
_CTMU_CURRENT_RANGE_55UAdeclaration has an extra leading space before the comment, which makes it appear visually (and potentially syntactically, depending on context) tied to the preceding class; move these constants clearly outside/above the class with consistent top-level indentation.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- There are now two `ScienceLab` class definitions in this module; please consolidate the changes into the existing class and remove the duplicate definition to avoid one silently shadowing the other.
- The CTMU constant `_CTMU_CURRENT_RANGE_55UA` is named as a current range but is passed as the `channel` argument to `_get_ctmu_voltage`; consider renaming the constant or adjusting the call/signature so the naming clearly matches the parameter being set.
- The module-level `_CTMU_CURRENT_RANGE_55UA` declaration has an extra leading space before the comment, which makes it appear visually (and potentially syntactically, depending on context) tied to the preceding class; move these constants clearly outside/above the class with consistent top-level indentation.
## Individual Comments
### Comment 1
<location path="pslab/sciencelab.py" line_range="22-31" />
<code_context>
+class ScienceLab:
</code_context>
<issue_to_address>
**issue (bug_risk):** Two ScienceLab classes are now defined; this will shadow the later definition and is likely unintended.
The duplicate `ScienceLab` definition in this module will shadow the other one and can cause subtle bugs if callers rely on the behavior in the existing class (e.g., `temperature` property and `_get_ctmu_voltage`). Please fold the new initialization logic into the existing `ScienceLab` instead of defining a second class.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Fixes #272
Testing
ScienceLabsuccessfully with no errorsSummary by Sourcery
Document CTMU-based MCU temperature measurement and centralize its calibration constants.
Enhancements: