Added conditional beeping.

This commit is contained in:
Bassam Husain
2023-03-12 01:53:44 -05:00
parent 69a5cbc45c
commit 5ccabd1a3d
3 changed files with 34 additions and 52 deletions

View File

@@ -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

View File

@@ -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 %}
{% 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 %}

View File

@@ -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.