Refactor monolithic firmware into manager-based architecture and fix SD/AI bugs#55
Draft
Refactor monolithic firmware into manager-based architecture and fix SD/AI bugs#55
Conversation
- Changed board from esp32-s3-devkitc-1 to m5stack-stamps3 - Fixed flash size from 16MB to 8MB (actual hardware spec) - Removed PSRAM config (device has no PSRAM) - Upgraded M5Unified to 0.2.11 and M5GFX to 0.2.17 - Added M5Cardputer library 1.1.1 for TCA8418 keyboard support - Moved driver from drivers/ to lib/cardputer_driver/ - Added GPIO38 backlight control for Cardputer ADV - Restored original clean firmware display - Note: Keyboard hardware may have defect (TCA8418 detected at 0x55 but not responding to keypresses)
Co-authored-by: Crashkeyz <186653592+Crashkeyz@users.noreply.github.com>
Co-authored-by: Crashkeyz <186653592+Crashkeyz@users.noreply.github.com>
Co-authored-by: Crashkeyz <186653592+Crashkeyz@users.noreply.github.com>
Co-authored-by: Crashkeyz <186653592+Crashkeyz@users.noreply.github.com>
Co-authored-by: Crashkeyz <186653592+Crashkeyz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor firmware for maintainable architecture and fix bugs
Refactor monolithic firmware into manager-based architecture and fix SD/AI bugs
Jan 4, 2026
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.
Monolithic 2,167-line
main.cppcaused maintenance issues and contained unreliable SD initialization (5-retry logic failing) and buggy AI mode (glitchy keyboard input, inconsistent response display).Architecture
Extracted manager classes using singleton pattern:
SDManager - Centralized file operations
readFile(),writeFile(),loadAPIKey()WiFiManager - Network operations
connect(),autoConnect(),saveNetwork()AIManager - Query processing and patterns
processQuery(),callDeepSeekAPI(),learnPattern()Utility classes
DisplayUtils- Text wrapping with word boundariesKeyboardUtils- Centralized keymap and modifier handlingAI Mode Fix
Implemented state machine to replace inline if-else processing:
Previously, characters were lost due to unbuffered input during
processAIQuery()execution.Impact
main.cpp: 2,167 → 1,855 lines (14% reduction)Files
New:
src/managers/{SD,WiFi,AI}Manager.{cpp,h}src/screens/{Base,Menu,AI}Screen.{cpp,h}src/utils/{Display,Keyboard}Utils.{cpp,h}REFACTORING_SUMMARY.mdMIGRATION_GUIDE.mdModified:
src/main.cpp- Integrated managers, removed duplicate logicREADME.md- Updated architecture sectionWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.registry.nm1.platformio.org/home/REDACTED/.local/bin/platformio platformio run(dns block)api.registry.platformio.org/home/REDACTED/.local/bin/platformio platformio run(dns block)collector.platformio.org/home/REDACTED/.local/bin/platformio platformio run(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Created from VS Code via the GitHub Pull Request extension.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.