fix: Use HalPowerManager for battery percentage#1005
fix: Use HalPowerManager for battery percentage#1005ngxson merged 2 commits intocrosspoint-reader:masterfrom
Conversation
…tteryPercentage()
|
No actionable comments were generated in the recent review. 🎉 📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (1)lib/hal/HalPowerManager.h (1)
⏰ 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). (2)
🔇 Additional comments (2)
📝 WalkthroughWalkthroughThe PR removes public Battery.h contents and replaces direct BatteryMonitor usage with HalPowerManager across several files; it updates HalPowerManager.getBatteryPercentage() signature to return uint16_t and updates callers to use powerManager.getBatteryPercentage(). Changes
Sequence Diagram(s)sequenceDiagram
participant Theme as "UI Theme\n(drawBattery)"
participant Power as "HalPowerManager"
participant Monitor as "BatteryMonitor"
Theme->>Power: getBatteryPercentage()
Note right of Power: HalPowerManager reads battery
Power->>Monitor: readPercentage() / underlying read
Monitor-->>Power: percentage (uint16_t)
Power-->>Theme: percentage (uint16_t)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/Battery.hsrc/activities/home/HomeActivity.cppsrc/components/themes/BaseTheme.cppsrc/components/themes/lyra/LyraTheme.cppsrc/main.cpp
💤 Files with no reviewable changes (3)
- src/activities/home/HomeActivity.cpp
- src/main.cpp
- src/Battery.h
⏰ 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). (2)
- GitHub Check: cppcheck
- GitHub Check: build
🔇 Additional comments (3)
src/components/themes/BaseTheme.cpp (1)
3-5: Include update looks good.
HalPowerManager include is aligned with the new battery API usage.src/components/themes/lyra/LyraTheme.cpp (2)
3-5: Include update looks good.
HalPowerManager include matches the new battery percentage API usage.
86-89: LGTM for the battery percentage swap.
This mirrors the BaseTheme update and keeps the rendering logic intact.Also applies to: 123-126
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/themes/BaseTheme.cpp`:
- Around line 48-50: The local variable in BaseTheme::drawBatteryLeft uses
uint16_t but powerManager.getBatteryPercentage() returns int, causing an
implicit narrowing/consistency mismatch; update the local to int percentage (in
BaseTheme::drawBatteryLeft and any other places such as the similar variable in
drawBatteryRight/drawBatteryIcon usages) so the variable type matches
getBatteryPercentage(), or alternatively change
HalPowerManager::getBatteryPercentage() to return uint16_t across the
codebase—but prefer the minimal change: replace uint16_t percentage with int
percentage in BaseTheme::drawBatteryLeft and related battery-drawing methods to
keep types consistent.
## Summary The introduction of `HalGPIO` moved the `BatteryMonitor battery` object into the member function `HalGPIO::getBatteryPercentage()`. Then, with the introduction of `HalPowerManager`, this function was moved to `HalPowerManager::getBatteryPercentage()`. However, the original `BatteryMonitor battery` object is still utilized by themes for displaying the battery percentage. This PR replaces these deprecated uses of `BatteryMonitor battery` with the new `HalPowerManager::getBatteryPercentage()` function. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**NO **_
Summary
The introduction of
HalGPIOmoved theBatteryMonitor batteryobject into the member functionHalGPIO::getBatteryPercentage().Then, with the introduction of
HalPowerManager, this function was moved toHalPowerManager::getBatteryPercentage().However, the original
BatteryMonitor batteryobject is still utilized by themes for displaying the battery percentage.This PR replaces these deprecated uses of
BatteryMonitor batterywith the newHalPowerManager::getBatteryPercentage()function.AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? **NO **