[Knock to trigger macros] Beat your printer into obedience! - #326
Open
shawn-makes-stuff wants to merge 1 commit into
Open
[Knock to trigger macros] Beat your printer into obedience!#326shawn-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.
Member
|
Me likey 😋 |
shawn-makes-stuff
marked this pull request as ready for review
September 13, 2026 15:34
Contributor
Author
|
I'm aware that its real world use is probably a bit limited, but its a cool gimmick so I'm leaving it here. If you decide that you don't want it just close the pr and I'll whine in discord later. |
Collaborator
|
cursed |
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.
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.
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. Measured on the CC1: klippy at its normal baseline while busy.cosmos.conf[klipper] knock = False(default True) removes the include, module not loaded.KNOCK ENABLED=0at runtime.Changes
recipes-apps/klipper/files/knock.py: the klippy extra, installed toklippy/extras/recipes-apps/klipper/files/knock.cfg:[knock]options and the default lights pattern, installed toextras-readonly/kalico_2026.02.00.bb: install bothknockoption indefault.conf, validator, 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.