From 5ccabd1a3d425ec0575b98dac3515432a4917c20 Mon Sep 17 00:00:00 2001 From: Bassam Husain Date: Sun, 12 Mar 2023 01:53:44 -0500 Subject: [PATCH] Added conditional beeping. --- cfgs/beeper.cfg | 47 -------------------------------------------- cfgs/misc-macros.cfg | 36 ++++++++++++++++++++++++++++++--- printer.cfg | 3 +-- 3 files changed, 34 insertions(+), 52 deletions(-) delete mode 100644 cfgs/beeper.cfg diff --git a/cfgs/beeper.cfg b/cfgs/beeper.cfg deleted file mode 100644 index 2454d26..0000000 --- a/cfgs/beeper.cfg +++ /dev/null @@ -1,47 +0,0 @@ -[gcode_macro BEEP] -description: BEEP I=3 DUR=200 FREQ=2000: Beep 3 times, for 200ms each, at 2kHz frequency. -gcode: - # Parameters - {% set i = params.I|default(1)|int %} ; Iterations (number of times to beep). - {% set dur = params.DUR|default(100)|int %} ; Duration/wait of each beep in ms. Default 100ms. - {% set freq = params.FREQ|default(2000)|int %} ; Frequency in Hz. Default 2kHz. - - {% for iteration in range(i|int) %} - SET_PIN PIN=beeper VALUE=0.8 CYCLE_TIME={ 1.0/freq if freq > 0 else 1 } - G4 P{dur} - SET_PIN PIN=beeper VALUE=0 - G4 P{dur} - {% endfor %} - -# [gcode_macro M300] -# gcode: -# {% set S = params.S|default(1000)|int %} -# {% set P = params.P|default(100)|int %} - -# SET_PIN PIN=beeper VALUE=0.5 CYCLE_TIME={ 1.0/S if S > 0 else 1 } -# G4 P{P} -# SET_PIN PIN=beeper VALUE=0 - -# [gcode_macro SONG_SINGLE_BEEP] -# gcode: -# M300 S830.61 P137 - -# [gcode_macro TOGGLE_BEEPER] -# description: Toggle the printer beeper on and off. -# gcode: -# {% set beeper_state = printer.save_variables.variables.beeper_state|lower %} - -# {% if printer['gcode_macro _USER_VARIABLE'].debug == 1 %} -# {action_respond_info('==== TOGGLE_BEEPER ====')} -# {action_respond_info("beeper_state: %s" % (beeper_state))} -# {action_respond_info('===============')} -# {% endif %} - -# {% if beeper_state == "off" %} -# {action_respond_info('beeper is off, turning it on')} -# SAVE_VARIABLE VARIABLE=beeper_state VALUE='"on"' -# {% else %} -# {action_respond_info('beeper is on= turning it off')} -# SAVE_VARIABLE VARIABLE=beeper_state VALUE='"off"' -# {% endif %} -# SONG_SINGLE_BEEP \ No newline at end of file diff --git a/cfgs/misc-macros.cfg b/cfgs/misc-macros.cfg index 9fa3d76..7b45e4a 100644 --- a/cfgs/misc-macros.cfg +++ b/cfgs/misc-macros.cfg @@ -20,11 +20,26 @@ gcode: SET_FILAMENT_SENSOR SENSOR=filament_sensor ENABLE=0 [gcode_macro _globals] -variable_pre_purge_prime_length: 1.4 variable_filament_sensor_enabled: 0 # NOTE Enable(1) or disable(0) the filament sensor, if one is connected +variable_beeping_enabled: 1 # NOTE Enable(1) or disable(0) beeping everywhere except during gantry calibration +variable_pre_purge_prime_length: 1.4 gcode: SET_GCODE_VARIABLE MACRO=_globals VARIABLE=pre_purge_prime_length VALUE={ variable_pre_purge_prime_length } SET_GCODE_VARIABLE MACRO=_globals VARIABLE=filament_sensor_enabled VALUE={ variable_filament_sensor_enabled } + SET_GCODE_VARIABLE MACRO=_globals VARIABLE=beeping_enabled VALUE={ variable_beeping_enabled } + +[gcode_macro CONDITIONAL_BEEP] +gcode: + # Parameters + {% set i = params.I|default(1)|int %} ; Iterations (number of times to beep). + {% set dur = params.DUR|default(100)|int %} ; Duration/wait of each beep in ms. Default 100ms. + {% set freq = params.FREQ|default(2000)|int %} ; Frequency in Hz. Default 2kHz. + + {% set BEEPING_ENABLED=printer["gcode_macro _globals"].beeping_enabled|default(-1)|int %} + + {% if BEEPING_ENABLED == 1 %} + BEEP I=i DUR=dur FREQ=freq + {% endif %} [gcode_macro ADJUST_FILAMENT_SENSOR_STATUS] gcode: @@ -115,7 +130,7 @@ gcode: [gcode_macro PRINT_END] gcode: ADJUST_FILAMENT_SENSOR_STATUS ENABLE=0 - BEEP I=2 DUR=30 FREQ=8500 ; NOTE Comment out this line to stop the beeps at the end of a print + CONDITIONAL_BEEP I=2 DUR=30 FREQ=8500 ; NOTE Comment out this line to stop the beeps at the end of a print {% set PRE_PURGE_PRIME_LENGTH=printer["gcode_macro _globals"].pre_purge_prime_length|default(1.40)|float %} M400 ; wait for buffer to clear G92 E0 ; zero the extruder @@ -231,4 +246,19 @@ gcode: gcode: {% if "xyz" not in printer.toolhead.homed_axes %} G28 - {% endif %} \ No newline at end of file + {% endif %} + +[gcode_macro BEEP] +description: BEEP I=3 DUR=200 FREQ=2000: Beep 3 times, for 200ms each, at 2kHz frequency. +gcode: + # Parameters + {% set i = params.I|default(1)|int %} ; Iterations (number of times to beep). + {% set dur = params.DUR|default(100)|int %} ; Duration/wait of each beep in ms. Default 100ms. + {% set freq = params.FREQ|default(2000)|int %} ; Frequency in Hz. Default 2kHz. + + {% for iteration in range(i|int) %} + SET_PIN PIN=beeper VALUE=0.8 CYCLE_TIME={ 1.0/freq if freq > 0 else 1 } + G4 P{dur} + SET_PIN PIN=beeper VALUE=0 + G4 P{dur} + {% endfor %} \ No newline at end of file diff --git a/printer.cfg b/printer.cfg index 976e116..ca71ee7 100644 --- a/printer.cfg +++ b/printer.cfg @@ -8,7 +8,6 @@ [include ./cfgs/TEST_SPEED.cfg] [include ./cfgs/PARKING.cfg] [include ./cfgs/MECHANICAL_GANTRY_CALIBRATION.cfg] -[include ./cfgs/beeper.cfg] # NOTE Uncomment the ONE of the following lines if you're using an adxl345 # [include ./cfgs/adxl-rp2040.cfg] @@ -227,7 +226,7 @@ insert_gcode: M117 Insert Detected runout_gcode: M117 Runout Detected - BEEP i=3 dur=300 freq=400 + CONDITIONAL_BEEP i=3 dur=300 freq=400 #*# <---------------------- SAVE_CONFIG ----------------------> #*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.