Skip to content

Fix headless (-y) mode, CLI overrides and generator escaping - #450

Closed
Banabas wants to merge 1 commit into
OpenNeptune3D:devfrom
Banabas:fix/headless-cli-and-generator
Closed

Banabas wants to merge 1 commit into
OpenNeptune3D:devfrom
Banabas:fix/headless-cli-and-generator

Conversation

@Banabas

@Banabas Banabas commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes several issues in OpenNept4une.sh that mostly affect non-interactive (-y) and direct CLI usage, plus a latent bug in generate_conf.py.

OpenNept4une.sh

  • -y no longer blocks in install_printer_cfg: the "compare/diff printer.cfg" prompt was shown even in non-interactive mode.
  • -y no longer opens the menu in install_configs: with -y all configs are installed directly instead of waiting for menu input.
  • CLI commands now set current_branch: e.g. opennept4une install_screen_service previously ran git clone -b "" and failed.
  • --printer_model / --motor_current override the stored flag: once /boot/.OpenNept4une.txt contained a model, CLI values were silently overwritten by extract_model_and_motor. motor_current is cleared for n4plus/n4max so the generator isn't called with a current override that doesn't exist for those models.
  • power_monitor.service uses $HOME instead of a hardcoded /home/mks (matches the intent of the comment in run_fixes).
  • Display migration runs the installer with bash instead of eval.
  • toggle_branch warns before reset --hard + clean -fd discards local changes.

printer-confs/generate_conf.py

  • Placeholder values and section_*.cfg contents were passed as re.sub replacement strings, so a backslash (e.g. \d, \1) raised re.error: bad escape or silently altered the value. Values are now inserted literally.
  • Placeholders without a value are reported instead of their lines being removed silently.

Testing

  • Generated output.cfg is byte-identical to before for all six model/current combinations (n4 0.8/1.2, n4pro 0.8/1.2, n4plus, n4max).
  • bash tests/smoke.sh passes; shellcheck -S warning OpenNept4une.sh is clean.
  • New regression test test_backslashes_in_values_are_literal fails on the old generator and passes with this change.
  • CLI-override logic exercised against stored flags (N4Pro-0.8A-v1.1-tribbon, N4Max-v2.0-tusbc, CLI --printer_model=n4plus over an n4pro flag).

Not tested on hardware.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CY4TFmR6KmW1LUStEaYvjV

- install_printer_cfg: skip diff prompt with -y (previously blocked)
- install_configs: with -y install all configs instead of opening the menu
- CLI commands: set current_branch so install_screen_service can clone
- --printer_model/--motor_current now override the stored model flag
- power_monitor.service: use $HOME instead of hardcoded /home/mks
- display migration: run installer with bash instead of eval
- toggle_branch: warn before local changes are discarded
- generate_conf.py: insert values literally (no re.sub escape parsing),
  report placeholders without a value; add regression test

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

Copy link
Copy Markdown
Collaborator

Appreciate the contribution! Your changes are in dev as part of the lib/ split of OpenNept4une.sh (functions moved to lib/*.sh), ported verbatim with you as co-author. The backslash test is adapted to the rewritten generate_conf.py.

halfmanbear added a commit that referenced this pull request Oct 29, 2026
…switch warning, power_monitor $HOME; adapt backslash test

Co-authored-by: Sven <saiansupa@gmx.net>
halfmanbear added a commit that referenced this pull request Oct 29, 2026
Changes were ported into lib/ in the previous commit; this merge keeps that tree.
halfmanbear added a commit that referenced this pull request Nov 18, 2026
* Remove SDCARD_RESET_FILE from base.cfg

Removed SDCARD_RESET_FILE command from gcode section.

#430

* Clean up usb_c_toolhead.config

Removed unnecessary configuration options for STM32.

* Remove unnecessary whitespace in usb_c_toolhead.config

* Add USB-C Toolhead support to firmware update script

* Add USB-C toolhead variant support to firmware build scritp and printer.cfg generator

* Add v2.2 PCB selection

* pcb version error changed v2.2 references to v2.3

* Update PCB version options for printer models

* corrected PCB version for n4 / n4pro usb-c variant

* add hardware check before confirming usb-c toolhead machine option

* fix(418): Target temp not restored after filament runout (#419)

* fix(418): Target temp not restored after filament runout

Add gcode variables similar to what PAUSE macro uses, to restore
target temperature after loading and resuming after filament runout.

* Refactor GCODE variable settings for filament handling

---------

Co-authored-by: HalfManBear <89969229+halfmanbear@users.noreply.github.com>

* Update incorrect USB toolhead config file path 

Credit @ggggcodes
#417 (comment)

#417

* Add CI smoke tests and an optional Klipper host sandbox. (#438)

Catch installer and generate_conf.py regressions in GitHub Actions
without printer hardware. Also add optional Ubuntu/Pi provision
scripts for Fluidd, Moonraker, HTTPS, and generated model configs
so host-side work can be tested in a VM.

* Add support for RP2350 based Pico boards (#439)

Adds support for the RP2350 chip used in Raspberry Pi Pico 2 boards when flashing the PICO USB Accelerometer firmware.

RP2040 uses a device ID of 2e8a:0003
RP2350 uses a device ID of 2e8a:000f

* Fix headless (-y) mode, CLI overrides and generator escaping

- install_printer_cfg: skip diff prompt with -y (previously blocked)
- install_configs: with -y install all configs instead of opening the menu
- CLI commands: set current_branch so install_screen_service can clone
- --printer_model/--motor_current now override the stored model flag
- power_monitor.service: use $HOME instead of hardcoded /home/mks
- display migration: run installer with bash instead of eval
- toggle_branch: warn before local changes are discarded
- generate_conf.py: insert values literally (no re.sub escape parsing),
  report placeholders without a value; add regression test

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

* Display connector: restart service after update, branch fallback on clone, reuse clone on reinstall

* Split OpenNept4une.sh functions into lib/*.sh (no behaviour change)

* base.cfg: rework RESUME purge via _RESUME_PURGE, track filament state, shorten load/purge, cap extruder max_temp at 300

* generate_conf.py: argparse CLI, strict placeholder checks, SAVE_CONFIG rewrite, --validate-all; isolate HOME in tests

* Port PR #450: headless -y fixes, CLI model/current overrides, branch-switch warning, power_monitor $HOME; adapt backslash test

Co-authored-by: Sven <saiansupa@gmx.net>

* power_monitor: stop monitors before verifying and re-arm in-process after a glitch (#442)

The monitor that did not fire kept its line requested, so gpioget failed with 'Device or resource busy' and a real power cut could never be confirmed. The glitch path's exec skipped the EXIT trap, so the new instance could not claim the lines and exited. Also keep log output out of read_states, debounce v2 monitors, back off on repeated glitches, and ignore lines that were abnormal at startup.

Co-authored-by: Bruno Oliveira <bruno.scherer@gmail.com>

* Only offer an update when the repo is behind its remote

HEAD != @{u} also matched repos with unpushed local commits, so every run offered a no-op pull that reported success.

* Disable DMA on the Klipper MCU UART at boot on 6.14-6.17 kernels (#444)

Linux 6.14-6.17 can deadlock 8250 TX DMA (fixed upstream by a424a34b8fad, not backported to 6.16), which shows up as Lost communication / Timer too close / Missed scheduling MCU shutdowns. run_fixes installs a U-Boot /boot/fixup.scr that removes dmas/dma-names from serial@ff110000 before boot; DTB files are untouched. Skipped on fixed kernels, when DMA is already off, or when a foreign fixup.scr exists.

Co-authored-by: matthewdva <15670286+matthewdva@users.noreply.github.com>

Co-authored-by: IPv777 <19636346+IPv777@users.noreply.github.com>

* Power the USB-C toolhead via GPIO82 and allow selecting it before it enumerates (#417)

The USB-C printhead's 24 V rail is switched by SoC GPIO82; stock firmware raises it from rc.local. A oneshot service, installed only when the model flag is -tusbc and removed otherwise, raises it before Klipper and waits for the toolhead to enumerate. Selecting usb-c no longer requires the toolhead to be detected, since it cannot appear until powered.

Co-authored-by: Darren Gibbard <1159620+dalgibbard@users.noreply.github.com>
Co-authored-by: Vladimir Savitskii <6356445+vsavitskii@users.noreply.github.com>

* Flash the USB-C toolhead through its MKS bootloader with n4flash (#417)

The toolhead bootloader is MKS DRIVER_BOOT (1d50:018a), entered by power-cycling GPIO82, and speaks a custom protocol; the 1200-baud request and HID flash never worked. Vendor ggggcodes' n4flash unmodified (686c3bf, MIT) and wrap it: GD32F303 build flags, 96 KiB size check, a single by-id bootloader device, and success only once the Klipper application re-enumerates.

Co-authored-by: ggggcodes <307509430+ggggcodes@users.noreply.github.com>
Co-authored-by: Darren Gibbard <1159620+dalgibbard@users.noreply.github.com>

* USB-C toolhead config and v1.4/v2.3 PMIC interrupt fixes (#417)

Map the RK805 interrupt to GPIO2_A6 (matching its pinctrl) in the v1.4 and v2.3 trees. USB-C: frame light on rpi:gpiochip2/gpio2, part light as a plain THR:PB10 output instead of a neopixel, and both N4/N4 Pro part-cooling blowers driven by [fan] through multi_pin.

Co-authored-by: Darren Gibbard <1159620+dalgibbard@users.noreply.github.com>
Co-authored-by: ggggcodes <307509430+ggggcodes@users.noreply.github.com>
Co-authored-by: Mike Knights <1823177+mcknight89@users.noreply.github.com>

* removed LINE_PWRGOOD monitor on GPIO 19 as some boards use this for filament sensor, retained monitoring on known LINE_PWRLOSS (GPIO 19)

* improve clean image config

* add initial support for 3rd party probe config

* create image releas creation script and improve image cleanup before release

* improved gh cleanup in img-config/dev-image-cleanup.sh

* update naming for usb-c versions

---------

Co-authored-by: Morten Sjøgren <m_abs@mabs.dk>
Co-authored-by: Dan Rosser <danoli3@gmail.com>
Co-authored-by: David Long <me@davejlong.com>
Co-authored-by: Sven <saiansupa@gmx.net>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Bruno Oliveira <bruno.scherer@gmail.com>
Co-authored-by: IPv777 <19636346+IPv777@users.noreply.github.com>
Co-authored-by: Darren Gibbard <1159620+dalgibbard@users.noreply.github.com>
Co-authored-by: Vladimir Savitskii <6356445+vsavitskii@users.noreply.github.com>
Co-authored-by: ggggcodes <307509430+ggggcodes@users.noreply.github.com>
Co-authored-by: Mike Knights <1823177+mcknight89@users.noreply.github.com>
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