Skip to content

Rework steps 0–1: safety fixes for AutoZero, link loss, restarts, RESET and the spindle card - #1

Closed
NoobyNull wants to merge 5 commits into
mainfrom
claude/project-thread-wmryym
Closed

NoobyNull wants to merge 5 commits into
mainfrom
claude/project-thread-wmryym

Conversation

@NoobyNull

Copy link
Copy Markdown
Owner

Requested by Matthew · project thread

First two steps of the rework plan. This PR fixes the bugs on the current code so the machine is safe before any restructuring starts.

Step 0: groundwork

  • test/run_host_tests.sh builds and runs every host test with plain g++ and Unity, so it does not depend on the PlatformIO registry. It uses the same sources and flags as [env:native].
  • CI (.github/workflows/ci.yml) runs the host tests, builds the bench simulator, and builds the crowadv firmware.
  • The bench simulator (sim/) builds again. sim_sd.cpp was redefining the no-card stubs.
  • Matthew's uncommitted spindle card is imported unchanged in its own commit, so the fixes below can be reviewed as a diff against it.

Step 1: safety fixes

  • AutoZero dropped its last 11 lines. Multi-line actions are now sequences. A sequence is queued whole or refused with a reason on screen. It stops at the first error: or alarm and sends a cleanup G90 instead of the remaining lines. The queue now has 48 slots. AutoZero, the flat-plate probe, the calibration move and the driver-reset relay pulse all use sequences. The flat-plate probe also used to leave the parser in G91 even when it succeeded. It now ends with G90.
  • Link loss was never detected. link_service() pings after 1 s of silence. After 4 s it shows NO LINK, flushes the queue and forgets homing. The two old priming paths are merged into one, which the panel and both simulators share.
  • Controller restarts went unseen. The banner reaches handle_signon(), which now raises the flag. A restart flushes the queue, re-primes the link and forgets homing. The exception is a restart within 3 s of the panel's own RESET, which keeps homing.
  • RESET left queued lines to run afterwards. send_reset() now flushes the queue. The vibration guard uses it too.
  • The queue now keeps its own ack gate instead of calling fnc_send_line(). Because of that, a flush takes effect immediately, and a slow G38.2 does not misattribute the acks that follow it.
  • Panel-side errors, such as a refused or stopped sequence or a full queue, now show in a strip above the safety bar. Before, they appeared only in the console.
  • Spindle card. EMPTY is enabled only once the toolsetter tap has found nothing. SKIP leaves the tool unknown, and LOAD stays locked while it is. Tapping IN SPINDLE reopens the card. The tool query no longer runs after every jog, so jog steps are no longer skipped.

Testing

  • test/run_host_tests.sh: 16 suites pass. New: test_linkwatch, and test_link, which drives the real queue and parser glue against a scripted controller (a 28-line sequence, error and alarm aborts, RESET flush, own reset vs restart, silence → NO LINK → reconnect).
  • Bench simulator: killed and restarted fluidnc_sim.py under a live panel. The panel went to NO LINK after about 4 s and re-primed once the simulator came back.
  • Not tested on hardware. I could not build the ESP32 image in my environment, so CI's firmware job is the first build check. Before using this for real, please bench-test it: run AutoZero, pull the cable, power-cycle the controller, and press RESET during a sequence.

Known limits (addressed in later steps)

  • If a sequence is stopped while the machine is in alarm, its cleanup G90 is refused with error:9. A soft reset restores G90.
  • A plain line queued just ahead of a jog chunk can still cause that chunk to be skipped. Step 4 adds a dedicated jog lane.

Generated by Claude Code

test/run_host_tests.sh builds every test_* folder with plain g++ and Unity,
using the same sources and flags as [env:native]. A CI job runs it and builds
sim/ on every push, so each step of the rework is checked before it is flashed.

sim/src/sim_sd.cpp redefined the inline no-card stubs hw/sdcard.h supplies
when HAS_SD_CARD is off, which is the firmware default, so the bench simulator
no longer built. Its card functions now follow the same switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uqr4BLDFjWoo8xWxrvcr82
… know

Imported as-is from the uncommitted work in the Gitea working copy
(2026-11-05), so the fixes that follow are reviewable against it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uqr4BLDFjWoo8xWxrvcr82
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uqr4BLDFjWoo8xWxrvcr82
…r a jog

NONE / SKIP answered M61 Q98 (empty) on the operator's say-so. With a
cartridge still in the collet, the next LOAD skips the put-back and drives it
into a full pocket. EMPTY is now enabled only after the toolsetter tap found
nothing. SKIP closes the card and leaves the tool unknown until the next link
drop, restart or lost position; the TOOLS page shows "?" and keeps LOAD locked
("spindle unknown: tap IN SPINDLE"), and tapping IN SPINDLE brings the card
back.

The card and the TOOLS page asked for the current tool on every return to
Idle, which includes the end of every jog step. The query queued ahead of the
next jog chunk, and a queued line makes send_jog_line() skip the chunk, so
jog steps went missing. Both now skip the query when coming back from Jog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uqr4BLDFjWoo8xWxrvcr82
AutoZero sent 28 lines one at a time into a 16-slot queue, so the last 11
(the Y walls, G10 and the lift out of the pocket) were dropped and the bit
stayed in the plate with the parser in G91. Multi-line actions are now
sequences (seq_begin/seq_line/seq_send): queued whole or refused with the
reason on screen, and stopped at the first error or alarm instead of probing
on from the wrong place, with a cleanup line (G90) sent instead. The queue is
48 slots. AutoZero, the flat-plate probe, the calibration move and the
driver-reset relay pulse use it. The flat-plate probe also left G91 behind on
success; it now ends in G90.

The queue now writes lines and keeps the ack gate itself instead of calling
fnc_send_line(), so the parser's own gate is never armed. That is what lets
RESET and a lost link drop queued lines immediately without the next send
spinning for 2 s, and lets sequence lines wait out a slow probe (ok arrives
only when G38.2 ends) without misattributing every ack after it.

RESET (and the vibration guard's reset) now discards everything queued, so
nothing waiting behind it runs after it.

Link loss was never detected: fnc_is_connected() had no caller. link_service()
now pings after 1 s of silence and shows NO LINK after 4 s, flushing the queue
and forgetting homing. It also replaces the two priming paths (connect_init and
prime_link_if_up both sent $G and $RI=200) with one, shared by the panel and
both simulators.

Controller restarts were never seen: GrblParserC routes the "Grbl ..." banner
to handle_signon(), not handle_other(), so the sniff never ran. handle_signon()
now raises the flag; a restart flushes the queue, re-primes and forgets homing,
unless it follows the panel's own RESET by under 3 s.

Panel-side errors (refused or stopped sequences, a full queue) used to reach
only the console. They now show in a strip above the safety bar.

New host tests: test_linkwatch, and test_link, which drives the real send
queue and parser glue against a scripted controller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uqr4BLDFjWoo8xWxrvcr82
@NoobyNull NoobyNull self-assigned this Nov 5, 2026
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9791ba0f-5d4f-4571-85ad-104e74999db2
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T05:37:33.943830Z 4f1a7c7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@NoobyNull NoobyNull closed this Nov 5, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f1a7c7c65

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/ui/spindle_card.cpp
static uint32_t epoch = UINT32_MAX;
static bool macro = false;
const bool came_to_rest = state == Idle && was != Idle && was != Jog;
if (state == Idle && (came_to_rest || epoch != homed_epoch() || !macro)) send_line(TC_ASK_CURRENT);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Refresh spindle state after every sign-on

When the panel sends RESET while FluidNC is already Idle, the reset handler re-primes without changing homed_epoch, and the machine state may remain Idle; this predicate then does not query TC_ASK_CURRENT. The cached tc_current() can remain the old tool even though the controller forgot it, so the TOOLS page shows stale spindle contents and skips the confirmation card. Invalidate or refresh the cached tool state on every sign-on, including panel-issued resets.

Useful? React with 👍 / 👎.

char* save = nullptr;
snprintf(c, sizeof(c), "%s", m.cleanup);
for (char* l = strtok_r(c, "\n", &save); l; l = strtok_r(nullptr, "\n", &save))
sendq_push(&s_sendq, l);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Defer modal cleanup until Alarm is cleared

When a probe sequence aborts on an alarm, this queues its G90 cleanup while FluidNC is still in Alarm, ahead of the operator's $X; FluidNC refuses G-code in that state, so the cleanup is lost and the sequence can leave G91 modal after unlock. A later command that assumes absolute mode can then move incorrectly. Defer cleanup until the alarm is cleared or otherwise ensure the mode is restored.

Useful? React with 👍 / 👎.

refuse("the controller is still busy with earlier commands");
return false;
}
auto& m = s_meta[s_next_seq % SEQ_META];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Refuse reuse of an occupied sequence metadata slot

If a slow controller has more than eight sequences buffered—for example, repeated PROBE or MOVE taps while those controls remain enabled—this overwrites an earlier sequence's metadata. If that earlier sequence then errors, abort_seq can drop its queued lines but no longer knows its cleanup, leaving relative mode active. Refuse new sequences when their metadata slot is occupied or track every outstanding sequence.

Useful? React with 👍 / 👎.

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.

2 participants