-
-
Notifications
You must be signed in to change notification settings - Fork 9
Move from main to module IO #90
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
Conversation
|
Note
|
| Cohort / File(s) | Summary |
|---|---|
Battery subsystem integration in ModuleIO src/MoonBase/Modules/ModuleIO.h |
Introduced battery support with new public members (pinVoltage, pinCurrent, pinBattery), public method loop1s() for periodic battery updates, helper function adc_get_adjusted_gain() for dynamic ADC attenuation adjustment, and state tracking members for voltage/current ADC attenuation. Added discovery logic for battery-related pins and runtime pin control with logging. |
Main application simplification src/main.cpp |
Removed battery/voltage/current ADC declarations, adc_get_adjusted_gain() helper, and all FT_BATTERY related setup/loop logic. Simplified runtime to delegate battery handling via calls to moduleIO.loop1s(), moduleDevices.loop1s(), and moduleTasks.loop1s(). |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
- voltage & current readout for lightcrafter16 #89: Modifies pin_High/pin_Low initialization and ADC/battery readout logic including adc_get_adjusted_gain and attenuation state tracking — aligns with this PR's refactoring of battery/ADC functionality into ModuleIO.
Poem
🐰 Battery now lives in its rightful place,
ModuleIO holds it with care and grace,
ADC attunement dances with might,
loop1s() calls keep measurements tight! ⚡
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately summarizes the main change: moving battery and ADC handling logic from main.cpp to the ModuleIO class via a new loop1s() method. |
✨ Finishing touches
- 📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/MoonBase/Modules/ModuleIO.h (2)
687-689: UseUINT8_MAXinstead of-1for unsigned type initialization.Assigning
-1touint8_trelies on implicit wraparound to 255. For clarity and consistency with the comparison at line 719 (!= UINT8_MAX), use the explicit constant.🔎 Proposed fix
- uint8_t pinVoltage = -1; - uint8_t pinCurrent = -1; - uint8_t pinBattery = -1; + uint8_t pinVoltage = UINT8_MAX; + uint8_t pinCurrent = UINT8_MAX; + uint8_t pinBattery = UINT8_MAX;
726-737: Consider per-pin ADC attenuation for cleaner code patterns.The current code uses
analogSetAttenuation()to set global ADC attenuation before each read, then resets it afterward. While this works in the single-threaded context of this codebase, Arduino ESP32 providesanalogSetPinAttenuation(pin, attenuation)for more direct per-pin control, which avoids the set-read-reset pattern.Alternative approach
if (pinVoltage != UINT8_MAX) { - analogSetAttenuation(voltage_readout_current_adc_attenuation); + analogSetPinAttenuation(pinVoltage, voltage_readout_current_adc_attenuation); uint32_t adc_mv_vinput = analogReadMilliVolts(pinVoltage); - analogSetAttenuation(ADC_11db); float volts = ((float)adc_mv_vinput) * 11.43 / (1.43 * 1000); batteryService->updateVoltage(volts); voltage_readout_current_adc_attenuation = adc_get_adjusted_gain(voltage_readout_current_adc_attenuation, adc_mv_vinput); } if (pinCurrent != UINT8_MAX) { - analogSetAttenuation(current_readout_current_adc_attenuation); + analogSetPinAttenuation(pinCurrent, current_readout_current_adc_attenuation); uint32_t adc_mv_cinput = analogReadMilliVolts(pinCurrent); - analogSetAttenuation(ADC_11db); current_readout_current_adc_attenuation = adc_get_adjusted_gain(current_readout_current_adc_attenuation, adc_mv_cinput);
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/MoonBase/Modules/ModuleIO.hsrc/main.cpp
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-25T13:34:40.097Z
Learnt from: ewowi
Repo: MoonModules/MoonLight PR: 0
File: :0-0
Timestamp: 2025-12-25T13:34:40.097Z
Learning: For the MoonLight LED system: Effects task can run on Core 0 (PRO_CPU) since it only performs computation (calculating colors, writing to channels array) without timing-critical hardware interaction. WiFi preemption is acceptable for pure computation tasks. Only the driver task (using DMA, I2S, LCD, PARLIO) requires Core 1 (APP_CPU) for uninterrupted timing-critical hardware operations.
Applied to files:
src/main.cpp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (3)
src/MoonBase/Modules/ModuleIO.h (2)
316-329: LGTM!The explicit
gpio_set_direction/gpio_set_levelcalls for pin 3 are correctly retained here for early boot initialization beforereadPins()runs. The comments clearly document this requirement for the ethernet module. The pin assignments for SE16V2 board look correct.
653-684: LGTM!The battery pin discovery logic correctly iterates through the pins array and extracts the voltage, current, and battery pins. The
pin_High/pin_Lowhandling includes proper GPIO validation before setting direction and level.src/main.cpp (1)
356-358: LGTM!The delegation of per-second battery monitoring to
moduleIO.loop1s()is a clean refactor that properly encapsulates IO-related functionality within the ModuleIO module. The call order withmoduleDevices.loop1s()andmoduleTasks.loop1s()is appropriate.
Summary by CodeRabbit
New Features
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.