Skip to content

Refactor: split main.c into separate files per game#3

Open
steemandavid wants to merge 1 commit into
Tom-Michiels:mainfrom
steemandavid:pr/refactor
Open

Refactor: split main.c into separate files per game#3
steemandavid wants to merge 1 commit into
Tom-Michiels:mainfrom
steemandavid:pr/refactor

Conversation

@steemandavid

Copy link
Copy Markdown

Summary

  • Extract the monolithic 1643-line main/main.c into separate compilation units: one file per game, plus shared display.c (WS2812 LED driver) and accel.c (ADXL345 driver)
  • Add shared headers: game_common.h (types, macros, game enum), display.h, accel.h
  • main.c reduced to ~150 lines (entry point + dispatch table)
  • No behavior changes — all 9 original games work identically

Files Changed

  • main/main.c — slimmed to ~150 lines (entry point + dispatch table)
  • main/CMakeLists.txt — updated SRCS list
  • main/display.c/h — new (extracted from main.c)
  • main/accel.c/h — new (extracted from main.c)
  • main/game_common.h — new (shared types)
  • main/game_*.c — new (one per game, 9 files)

Testing

  • Built and flashed on ESP32-C3 with ESP-IDF v5.4.1
  • All 9 original games verified working
  • Binary size: ~228KB (78% free in 1MB partition)

Extract the 1643-line main.c into separate compilation units:
- display.c/h (WS2812 LED driver, pixel drawing, HSV conversion)
- accel.c/h (I2C, ADXL345 driver, calibration)
- game_common.h (shared types, macros, game enum)
- game_*.c (one file per game, 9 files)

No behavior changes. All 9 original games work identically.
CLAUDE.md and README.md updated to reflect new file structure.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant