Repository navigation
[Knock to trigger macros] Beat your printer into obedience! - #403
Open
shawn-makes-stuff wants to merge 1 commit into
Open
shawn-makes-stuff wants to merge 1 commit into
shawn-makes-stuff wants to merge 1 commit into
Conversation
New klippy extra (knock.py) that uses the toolhead LIS2DW12 tap engine to detect knocks on the frame while the printer is idle. Knocks are grouped into patterns matched by the proportions of the gaps between them, so a pattern can be knocked faster or slower. One console command, KNOCK, records patterns (knock, knock again to confirm), binds them to a macro, a console message and/or "parrot" playback of the rhythm by the toolhead, lists, deletes, reminds, calibrates tempo, and enables/disables. Only runs while idle: during prints, moves and resonance tests the accelerometer is powered down and the task sleeps on idle_timeout events. Idle cost is one register read per 50 ms (about 2% of one core); memory is bounded. Disabled via cosmos.conf [klipper] knock = False, in which case the module is not loaded. Ships a default double-tap that toggles the case and toolhead lights. Recorded patterns persist in /user-resource/knock/knock.json.
This branch was successfully deployed
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.
Reopened from #326, which closed when I deleted my fork by accident. Same feature, rebased onto current main and fitted to the CC1/CC2 split. Earlier discussion is in #326.
Knock gestures: knock a rhythm on the frame to run a macro
Knock on the printer frame and COSMOS runs a macro. Uses the accelerometer already on the toolhead, no extra hardware. Only active while the printer is idle. Centauri Carbon 1 only (it uses the LIS2DW12 tap engine; the CC2 has a LIS3DH).
How it works
The LIS2DW12 on the toolhead has a hardware tap detector. While the printer is idle the module runs it at 1600 Hz; every knock latches a flag, and a small poll reads the flag 20 times a second, counts knocks and times the gaps between them. A second of silence closes the pattern. Patterns are matched by the proportions of their gaps, so the same rhythm knocked faster or slower still matches (tolerance configurable, 35% default). Two-knock patterns compare short vs long gap instead.
Recording is knock-and-confirm: knock the rhythm, the console asks for it again, a match saves it. Recorded patterns live in
/user-resource/knock/knock.jsonand take precedence over the built-in[knock_pattern]sections.Commands
One console command,
KNOCK:KNOCKKNOCK ENABLED=0/ENABLED=1KNOCK CALIBRATE=1KNOCK RECORD=1 NAME=x MACRO=<gcode>MACRO="M117 hi"with quotes for arguments)KNOCK RECORD=1 NAME=x PARROT=1KNOCK RECORD=1 NAME=x PRINT="text"KNOCK REMIND=xKNOCK DELETE=xBuilt in: a double tap toggles the case and toolhead lights (
[knock_pattern lights]inextras-readonly/knock.cfg).Setup
KNOCKshows "enabled". Knock the frame twice, lights toggle.KNOCK CALIBRATE=1, follow the prompts. Once.KNOCK RECORD=1 NAME=home MACRO=G28, knock a rhythm, knock it again. Done.Performance and safety
idle_timeoutstate and on the accelerometer not being in use by a measurement. During prints, moves and resonance tests the chip is powered down and the task sleeps on theidle_timeout:ready/idle_timeout:idleevents. No polling, no SPI, no CPU while printing (one state check every 5 s). Measured on the CC1: klippy at its normal baseline while busy.cosmos.conf[klipper] knock = False(default True on the CC1) removes the include, module not loaded.KNOCK ENABLED=0at runtime.Changes
recipes-apps/klipper/files/centauri-carbon-1/knock.py: the klippy extra, installed toklippy/extras/recipes-apps/klipper/files/centauri-carbon-1/knock.cfg:[knock]options and the default lights pattern, installed toextras-readonly/kalico_2026.02.00.bb: install both, CC1 onlyknockvalidator (falls back to False),knock = Truein the CC1default-machine.conf, andbuild-klipper-var-config.shemits the include intozextras.cfgwhen Truedocs/knock.md, README bulletNotes for review
lis2dwobject'sset_reg/read_regand its bulk helper'sis_startedflag to detect measurements. Deliberate; commented in the source.bulk_sensor) because SPI reads block.🤖 Generated with Claude Code