feat(wui): expose M0/QuickPause dialog message in /api/v1/status - #5400
Open
packerlschupfer wants to merge 2 commits into
Open
feat(wui): expose M0/QuickPause dialog message in /api/v1/status#5400packerlschupfer wants to merge 2 commits into
packerlschupfer wants to merge 2 commits into
Conversation
…alogs
Expose active printer dialogs in the /api/v1/status response, enabling
remote monitoring and response to printer prompts (filament operations,
crash recovery, warnings).
Status API change - when a dialog is active:
```json
{
"printer": { ... },
"dialog": {
"id": 12345,
"code": 31829,
"button0": "Stop",
"button1": "",
"button2": "",
"button3": ""
}
}
```
Also implements the upstream TODO in printer_state.cpp to expose
dialogs for normal (non-printing) filament load/unload operations.
Previously only load/unload dialogs during printing were reported.
Note: Dialog response functionality requires the /api/v1/control
endpoint (separate PR) with {"dialog_response": "Stop"}.
Extends the dialog object from prusa3d#5230 to include the human-readable text of an active M0/M1 (Prusa QuickPause FSM). Requested by @jabdoa2 for Home Assistant integration in prusa3d#5230. Example: `M0 Insert magnets` now produces { "dialog": { "id": 12345, "code": 31829, "message": "Insert magnets", ← NEW "button0": "Continue", ... } } Implementation: - Prusa's M0 handler in src/marlin_stubs/M0.cpp already packs the message pointer (parser.string_arg) into fsm::PhaseData via memcpy. - Unpack it in printer_state.cpp's QuickPause case using the existing fsm::deserialize_data<const char *>() helper. - Thread it through StateWithDialog::dialog::text (field already existed but was never populated) into the JSON emission via a new "message" field. - Emits an empty string when the parameter-less form of M0 was called (parser.string_arg == nullptr), to keep the JSON schema stable. The pointer stays valid across the wait because parser.string_arg lives in Marlin's global command line buffer, and M0 blocks the planner via planner.synchronize() before entering the response-wait loop — no other gcode is being parsed while the dialog is active. Depends on prusa3d#5230 for the dialog object structure.
4 tasks
Author
|
Small housekeeping update — I've moved my Core One+ to Klipper ( Heads-up: I've moved my Core One+ to Klipper as the daily-driver firmware. This PR is still ready-to-review as-is — code builds cleanly on current master, the M0-message-unpack logic is small and straightforward. If a Prusa maintainer wants to merge it, great; I just won't be iterating on it further. What this means for this PR:
Thanks for the reviews! |
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
Extends the dialog object from #5230 to include the human-readable text of an active
M0/M1(Prusa'sQuickPauseFSM).Requested by @jabdoa2 in #5230 comment for Home Assistant integration.
Example
M0 Insert magnetsnow produces:{ "dialog": { "id": 12345, "code": 31829, "message": "Insert magnets", "button0": "Continue", "button1": "", "button2": "", "button3": "" } }Motivation
Currently the message from an
M0/M1is only logged to serial once (viaSERIAL_ECHOLN(args)) and never re-emitted. Any HTTP/API client that connects AFTER the printer stopped for user input has no way to know what the printer is asking for. This is a real gap flagged by users trying to build Home Assistant / dashboard integrations.The message is already present in the firmware — Prusa's
M0handler (src/marlin_stubs/M0.cpp) packs the message pointer (parser.string_arg) intofsm::PhaseData. This PR just unpacks it and threads it into the JSON.Implementation
src/state/printer_state.cpp— in theClientFSM::QuickPausecase ofget_state_with_dialog, use the existingfsm::deserialize_data<const char *>()helper to unpack the message pointer, then setdialog->text.lib/WUI/nhttp/status_renderer.cpp— readdialog->textand emit as a"message"field in the JSON."") when the parameter-less form of M0 was called, to keep the JSON schema stable.Pointer lifetime
parser.string_argpoints into Marlin's global command-line buffer. Its lifetime is bounded by the M0 handler's scope, which is guaranteed to outlive the FSM because:planner.synchronize()empties the planner queue before entering the response-wait loop.idle(true)during the wait doesn't advance the gcode queue.parser.string_argcannot be overwritten.Dependency
Depends on #5230 for the base dialog object structure. Once #5230 lands, this PR's diff against
masterbecomes just the two-line addition of unpacking the message + emitting the JSON field.Test plan
--preset coreone --bootloader no --skip-bootstrap)M0 test message, poll/api/v1/status, confirmdialog.message == "test message"M0case: confirmdialog.message == ""Happy to bench-test on my Core One+ once #5230 is merged.