Skip to content

Replace strcmp state checks with GcodeState enum#45

Draft
theNailz wants to merge 1 commit intoKeralots:mainfrom
theNailz:feature/gcode-state-enum
Draft

Replace strcmp state checks with GcodeState enum#45
theNailz wants to merge 1 commit intoKeralots:mainfrom
theNailz:feature/gcode-state-enum

Conversation

@theNailz
Copy link
Copy Markdown
Contributor

@theNailz theNailz commented Apr 1, 2026

Summary

  • Introduce GcodeState enum parsed once in MQTT handler, replacing 18 strcmp() calls across 3 files with compile-time safe enum comparisons
  • Add gcodeStateLabel() for consistent human-readable display text: "Ready", "Running", "Paused", "Preparing", "Finished", "Error"
  • Fix inconsistent display labels: "PAUSED" → "Paused", "ERROR!" → "Error", "Print Complete!" → "Print complete"
  • Add stateLabel field to /status JSON API (backward compatible — state still returns raw MQTT value)
  • Deduplicate days[] and months[] arrays into shared DAYS_SHORT/MONTHS_SHORT constants

Test plan

  • All three environments build clean (esp32s3 67%, cyd 69%, esp32c3 68%)
  • Flashed and verified on S3 — finish screen shows "Print complete", API returns stateLabel
  • Verify idle screen shows "Ready" (not "IDLE")
  • Verify printing badge shows "Running"/"Paused" (not "RUNNING"/"PAUSE")
  • Verify error buzzer still triggers on FAILED transition
  • Verify clock screens show correct day-of-week from shared arrays

…abels

Introduce GcodeState enum parsed once in MQTT handler, replacing 18
scattered strcmp() calls across 3 files with compile-time safe enum
comparisons. Add gcodeStateLabel() for consistent display text.

- STATE_IDLE → "Ready", STATE_RUNNING → "Running", STATE_PAUSE → "Paused"
  STATE_PREPARE → "Preparing", STATE_FINISH → "Finished", STATE_FAILED → "Error"
- Fix inconsistent display: "PAUSED" → "Paused", "ERROR!" → "Error",
  "Print Complete!" → "Print complete"
- Add stateLabel field to /status JSON API (backward compatible)
- Deduplicate days[] and months[] arrays into shared DAYS_SHORT/MONTHS_SHORT
@theNailz theNailz marked this pull request as ready for review April 1, 2026 13:59
@theNailz theNailz marked this pull request as draft April 1, 2026 18:22
@theNailz
Copy link
Copy Markdown
Contributor Author

theNailz commented Apr 1, 2026

Two things I noticed in this refactoring:

1. UI labels changed silently
The printing screen badge previously showed raw MQTT state strings (RUNNING, PAUSE, PREPARE, etc.) and the ETA area showed PAUSED and ERROR!. After this PR, those now display the human-friendly labels from gcodeStateLabel(): "Running", "Paused", "Preparing", "Error".

This is arguably an improvement, but it's a user-visible behavior change bundled into what reads as a pure refactoring. In particular, the exclamation mark on ERROR! was intentional UI emphasis that's now gone. Worth a quick sanity check on-screen to make sure the new labels look right in context.

2. Day/month arrays in bambu_state.h
DAYS_SHORT and MONTHS_SHORT are declared in bambu_state.h and defined in gcode_state.cpp, but they have nothing to do with gcode state — they're date formatting helpers used by the clock screens. Consider whether they'd be better placed in a small shared header or alongside the clock code. Not a blocker, just a coupling nit.

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