Fix charging detection when usb-c cable is plugged in#119
Open
marcoag wants to merge 2 commits intofossasia:masterfrom
Open
Fix charging detection when usb-c cable is plugged in#119marcoag wants to merge 2 commits intofossasia:masterfrom
marcoag wants to merge 2 commits intofossasia:masterfrom
Conversation
Signed-off-by: Marco A. Gutierrez <marcogg@marcogg.com>
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds a periodic charging detection task that monitors USB power state and automatically transitions the device into charging (BOOT) mode when a cable is connected during operation, then returns to normal mode after displaying the charging screen. Sequence diagram for DETECT_CHARGING task and charging mode transitionsequenceDiagram
participant TMOS as TMOS_scheduler
participant Common as common_tasks
participant Power as charging_status
participant Display as disp_charging
participant Mode as mode_setup_normal
TMOS->>Common: DETECT_CHARGING event (every 500ms)
Common->>Power: charging_status()
Power-->>Common: is_charging
alt transition from not charging to charging
Common->>Common: mode = BOOT
Common->>Display: disp_charging()
Display-->>Common: charging_animation_complete
Common->>Mode: mode_setup_normal()
else no transition to charging
Common->>Common: update was_charging
end
Common-->>TMOS: clear DETECT_CHARGING flag
Flow diagram for DETECT_CHARGING periodic task logicflowchart TD
A[DETECT_CHARGING event triggered every 500ms] --> B[Read charging_status and assign is_charging]
B --> C{is_charging == 1 and was_charging == 0}
C -- Yes --> D[Set mode to BOOT]
D --> E[Call disp_charging to show charging animation]
E --> F[Call mode_setup_normal to restore normal operation]
C -- No --> G[Skip charging transition]
F --> H[Set was_charging = is_charging]
G --> H[Set was_charging = is_charging]
H --> I[Clear DETECT_CHARGING event flag and return]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider extracting the
500000 / 625interval forDETECT_CHARGINGinto a named constant (similar toANI_FLASH_SPEED_Tetc.) so the charging detection cadence is self-documenting and easier to tweak. - If
disp_charging()can block for a noticeable duration, calling it directly fromcommon_tasksmay delay handling of other events; you might want to move the charging animation to its own task or makedisp_charging()non-blocking.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the `500000 / 625` interval for `DETECT_CHARGING` into a named constant (similar to `ANI_FLASH_SPEED_T` etc.) so the charging detection cadence is self-documenting and easier to tweak.
- If `disp_charging()` can block for a noticeable duration, calling it directly from `common_tasks` may delay handling of other events; you might want to move the charging animation to its own task or make `disp_charging()` non-blocking.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Signed-off-by: Marco A. Gutierrez <marcogg@marcogg.com>
bessman
reviewed
Dec 30, 2025
Contributor
bessman
left a comment
There was a problem hiding this comment.
When transitioning from normal mode to the charge screen, pixels which were lit in normal mode are not turned off unless they are touched by the charging animation.
bessman
reviewed
Dec 30, 2025
|
|
||
| if (is_charging && !was_charging) { | ||
| mode = BOOT; | ||
| disp_charging(); |
Contributor
There was a problem hiding this comment.
This fixes the leftover lit pixels:
Suggested change
| disp_charging(); | |
| fb_fill(fb, 0); | |
| disp_charging(); |
|
When unplugging, the battery icon gets drawn on top of the text and it looks jank. |
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.
Summary
Adds automatic USB charging detection that enters charging mode when cable is connected during operation.
Changes
DETECT_CHARGINGevent flag and periodic task (500ms interval)disp_charging()functionBehavior
Technical Implementation
The
DETECT_CHARGINGtask runs every 500ms and tracks charging state transitions using a staticwas_chargingflag. When it detects a transition from not charging to charging (is_charging && !was_charging), it:disp_charging()to show charging animationmode_setup_normal()to restore normal operation after charging display completesTest Plan
Dependencies
Might require #117.
Summary by Sourcery
Introduce periodic USB charging detection to automatically enter charging mode when power is connected during operation.
Bug Fixes:
Enhancements: