-
Notifications
You must be signed in to change notification settings - Fork 241
fix: clarify and document CTMU temperature calibration logic - #282
fix: clarify and document CTMU temperature calibration logic #282saad-aids wants to merge 2 commits into
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Refactors and documents ScienceLab.temperature CTMU-based MCU temperature measurement by centralizing calibration constants and expanding inline documentation (per issue #272).
Changes:
- Introduces module-level constants for CTMU configuration and temperature calibration parameters.
- Updates
ScienceLab.temperatureto use the centralized calibration mapping and expanded docstring.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot flagged the following:
_CTMU_CURRENT_RANGE_55UA = 0b11110is passed as the channel argument, whilecs=3is the current range — name/docstring contradict the call site.
Uh oh!
There was an error while loading. Please reload this page.
Fixes #272
Testing
ScienceLabsuccessfully with no errorsSummary by Sourcery
Document CTMU-based MCU temperature measurement and centralize its calibration constants.
Enhancements: