Skip to content

Add a battery check and minor refactoring of main.cpp. - #145

Open
Charles-Mahoudeau wants to merge 6 commits into
mainfrom
feat/battery-fault-check
Open

Add a battery check and minor refactoring of main.cpp.#145
Charles-Mahoudeau wants to merge 6 commits into
mainfrom
feat/battery-fault-check

Conversation

@Charles-Mahoudeau

Copy link
Copy Markdown
Member

This pull request refactors the initialization process, improves logging capabilities, and enhances battery management logic. Key changes include splitting the init function into modular components, introducing new logging methods, and refining battery level handling.

Refactoring Initialization Process:

  • src/main.cpp: Split the init function into modular components (initGraphics, checkBattery, initStorage, initLibSystem, and registerEventHandlers) for better readability and maintainability. Added conditional checks to handle initialization errors gracefully. [1] [2]

Logging Enhancements:

  • lib/system/libsystem.cpp: Introduced new logging methods (info, warn, error) to replace the generic log function. Updated existing calls to use these methods for better log categorization.
  • lib/system/libsystem.hpp: Deprecated the log function and added documentation for the new logging methods.

Battery Management Improvements:

Minor Fixes and Code Cleanup:

@Charles-Mahoudeau Charles-Mahoudeau self-assigned this Jun 27, 2025
@Charles-Mahoudeau Charles-Mahoudeau added the enhancement New feature or request label Jun 27, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the startup sequence into modular functions, upgrades logging with distinct levels, and improves battery error handling/display.

  • Modularized init into initGraphics, checkBattery, initStorage, initLibSystem, and registerEventHandlers
  • Replaced the generic log function with info, warn, and error, and deprecated the old API
  • Changed battery API to return -1.0 on error and show “X” in the UI when level is invalid

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/main.cpp Broke init into smaller functions and added battery checks
lib/system/libsystem.hpp Deprecated log, added info, warn, error declarations
lib/system/libsystem.cpp Implemented new logging methods and updated registerBootError
lib/gsm/src/gsm2.cpp Return -1.0 for invalid battery voltage
lib/applications/src/launcher.cpp Display “X” when battery level is invalid

Comment thread src/main.cpp
Comment thread src/main.cpp
Comment thread lib/system/libsystem.cpp
Comment thread lib/applications/src/launcher.cpp
@Charles-Mahoudeau

Copy link
Copy Markdown
Member Author

This is not working due to the fact that the GSM module is taking up to 15 seconds to initialize, making the use of battery level invalid before that.

Comment thread src/main.cpp
libsystem::info("Battery check skipped by HOME button press.");
return true;
}
if (Gsm::getBatteryLevel() < 0.0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il faudrait enlever le check de la batterie pour valider la PR, tu peux corriger ça?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants