Skip to content

M591 Configurable Filament Runout Sensor#28445

Open
thinkyhead wants to merge 7 commits into
MarlinFirmware:bugfix-2.1.xfrom
thinkyhead:M591-runout-config
Open

M591 Configurable Filament Runout Sensor#28445
thinkyhead wants to merge 7 commits into
MarlinFirmware:bugfix-2.1.xfrom
thinkyhead:M591-runout-config

Conversation

@thinkyhead

Copy link
Copy Markdown
Member

Built using Hermes Agent with Sonnet 4.6 and "marlin-fork-harvesting" skill to import and update code from https://github.com/InsanityAutomation/Marlin/tree/M591_RRFRunoutParity by @InsanityAutomation

Not a bad starting-point but no doubt needs manual fixup. Since M412 is retained it does not necessarily need to be a separate option, but if doing so would save some space then it should be done.

  • Add M591 G-code for per-extruder runout sensor configuration
  • Add RunoutMode enum: RM_NONE (0), RM_OUT_ON_LOW (1), RM_OUT_ON_HIGH (2), RM_MOTION_SENSOR (7)
  • Per-sensor enabled[], mode[] arrays replace single bool runout.enabled
  • EEPROM saves/restores per-sensor enabled, distance, and mode
  • M412 preserved as a backward-compatible shim using M591 infrastructure
  • FIL_RUNOUT_STATE mapped to FIL_RUNOUT_MODE
  • FIL_RUNOUT_ENABLED_DEFAULT, FILAMENT_MOTION_SENSOR, FILAMENT_SWITCH_AND_MOTION accepted for backward compat (SanityCheck informs users of new array syntax)
  • FIL_RUNOUT_MODE and FIL_RUNOUT_ENABLED arrays for new per-sensor config
  • SanityCheck updated with migration guidance for deprecated options

- Add M591 G-code for per-extruder runout sensor configuration
- Add RunoutMode enum: RM_NONE (0), RM_OUT_ON_LOW (1), RM_OUT_ON_HIGH (2), RM_MOTION_SENSOR (7)
- Per-sensor enabled[], mode[] arrays replace single bool runout.enabled
- EEPROM saves/restores per-sensor enabled, distance, and mode
- M412 preserved as a backward-compatible shim using M591 infrastructure
- FIL_RUNOUT_STATE accepted for backward compat (auto-mapped to FIL_RUNOUT_MODE)
- FIL_RUNOUT_ENABLED_DEFAULT, FILAMENT_MOTION_SENSOR, FILAMENT_SWITCH_AND_MOTION
  accepted for backward compat (SanityCheck informs users of new array syntax)
- FIL_RUNOUT_MODE[] and FIL_RUNOUT_ENABLED[] arrays for new per-sensor config
- SanityCheck updated with migration guidance for deprecated options

Based on InsanityAutomation/M591_RRFRunoutParity

Copilot AI 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.

Pull request overview

This PR introduces M591 as a new G-code to configure filament runout behavior per runout sensor / extruder, including per-sensor enable state, runout distance, and a new runout mode enum (switch polarity vs motion sensor). It also updates EEPROM persistence and keeps M412 as a backward-compatibility shim intended to reuse the new infrastructure.

Changes:

  • Add M591 / M591_report and route G-code dispatch for M591 (with M412 treated as an alias/shim).
  • Convert filament runout configuration from single values to per-sensor arrays and persist them via EEPROM (bumping EEPROM version).
  • Add conditional-layer shims/migration logic for legacy config defines and update runout logic to consult a per-sensor mode.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 19 comments.

Show a summary per file
File Description
Marlin/src/module/settings.cpp Bumps EEPROM version and changes EEPROM save/load/reset/M503 reporting to use per-sensor runout arrays and M591 reporting.
Marlin/src/inc/SanityCheck.h Adds migration/deprecation checks for legacy runout config defines.
Marlin/src/inc/Conditionals-4-adv.h Forces HAS_FILAMENT_RUNOUT_DISTANCE to be defined when runout is enabled.
Marlin/src/inc/Conditionals-3-etc.h Adds shims to derive new array-based runout config from legacy defines; ensures distance/state defaults exist.
Marlin/src/gcode/gcode.h Declares M591 / M591_report.
Marlin/src/gcode/gcode.cpp Dispatches M-code 591 to GcodeSuite::M591() and annotates M412 as alias.
Marlin/src/gcode/feature/runout/M591.cpp Implements M591 parameter handling and reporting.
Marlin/src/gcode/feature/runout/M412.cpp Reworks M412 to behave as a shim over M591.
Marlin/src/feature/runout.h Introduces RunoutMode, converts enable/mode/runout-distance handling to per-sensor arrays, and updates polling logic.
Marlin/src/feature/runout.cpp Updates static storage for per-sensor enabled/mode/runout-distance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Marlin/src/module/settings.cpp
Comment thread Marlin/src/module/settings.cpp
Comment thread Marlin/src/module/settings.cpp Outdated
Comment thread Marlin/src/gcode/feature/runout/M412.cpp
Comment thread Marlin/src/gcode/feature/runout/M412.cpp
Comment thread Marlin/src/inc/SanityCheck.h Outdated
Comment thread Marlin/src/inc/SanityCheck.h Outdated
Comment thread Marlin/src/feature/runout.h
Comment thread Marlin/src/feature/runout.h
Comment thread Marlin/src/gcode/feature/runout/M412.cpp
@thinkyhead thinkyhead force-pushed the M591-runout-config branch 4 times, most recently from 1a3d1c4 to 2dfda67 Compare May 26, 2026 04:31
@thinkyhead thinkyhead force-pushed the M591-runout-config branch from 2dfda67 to 0dd0797 Compare May 26, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants