Skip to content

Commit

Permalink
Added doc and fixed reset behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeanon authored and rogerlz committed Apr 7, 2024
1 parent 01e89a8 commit cd53016
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
8 changes: 8 additions & 0 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -4807,6 +4807,13 @@ more information.
# If set to true the sensor will use the virtual_sd_card module to determine
# whether the printer is printing which is more reliable but will not work
# when streaming a print over usb or similar.
#always_fire_events:
# If set to true, runout events will always fire no matter whether the sensor
# is enabled or disabled. Usefull for MMUs
#check_on_print_start:
# If set to true, the sensor will be reevaluated when a print starts and if
# no filament is detected the runout_gcode will be run no matter the defined
# runout_distance(immediate_runout_gcode will not be run in this case)
```

### [filament_motion_sensor]
Expand Down Expand Up @@ -4834,6 +4841,7 @@ switch_pin:
#event_delay:
#pause_delay:
#smart:
#always_fire_events:
# See the "filament_switch_sensor" section for a description of the
# above parameters.
```
Expand Down
21 changes: 13 additions & 8 deletions docs/G-Codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,29 +549,34 @@ depend on the sensor type defined in the configuration.
#### SET_FILAMENT_SENSOR
###### For filament_switch_sensor:
`SET_FILAMENT_SENSOR SENSOR=<sensor_name> [ENABLE=0|1] [RESET=0|1]
[RUNOUT_DISTANCE=<mm>] [SMART=0|1]`: Sets values for the
filament sensor. If all parameters are omitted, the current stats will
be reported. <br>
[RUNOUT_DISTANCE=<mm>] [SMART=0|1] [ALWAYS_FIRE_EVENTS=0|1] [CHECK_ON_PRINT_START=0|1]`:
Sets values for the filament sensor.
If all parameters are omitted, the current stats will be reported. <br>
ENABLE sets the filament sensor on/off. If ENABLE is set to 0, the
filament sensor will be disabled, if set to 1 it is enabled. If the state
of the sensor changes, a reset will be triggered. <br>
RESET removes all pending runout_gcodes and pauses and force a reevaluation
of the sensor state. <br>
RUNOUT_DISTANCE sets the runout_distance. <br>
SMART sets the smart parameter.
SMART sets the smart parameter. <br>
ALWAYS_FIRE_EVENTS sets the always_fire_events parameter, if set to true,
a reset of the sensor will be triggered. <br>
CHECK_ON_PRINT_START sets the check_on_print_start parameter.

###### For filament_motion_sensor:
`SET_FILAMENT_SENSOR SENSOR=<sensor_name> [ENABLE=0|1] [RESET=0|1]
[DETECTION_LENGTH=<mm>] [SMART=0|1]`: Sets values for the
filament sensor. If all parameters are omitted, the current stats will
be reported. <br>
[DETECTION_LENGTH=<mm>] [SMART=0|1] [ALWAYS_FIRE_EVENTS=0|1]`:
Sets values for the filament sensor.
If all parameters are omitted, the current stats will be reported. <br>
ENABLE sets the filament sensor on/off. If ENABLE is set to 0, the
filament sensor will be disabled, if set to 1 it is enabled. If the sensor
was previously disabled and gets enabled, a reset will be triggered. <br>
RESET resets the state of the sensor and sets it to filament detected. <br>
DETECTION_LENGTH sets the detection_length, if the new detection length is
different from the old one, a reset will be triggered. <br>
SMART sets the smart parameter.
SMART sets the smart parameter. <br>
ALWAYS_FIRE_EVENTS sets the always_fire_events parameter, no reset will
be triggered.

### [firmware_retraction]

Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/filament_motion_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def get_info(self, gcmd):
return True
return False

def reset_needed(self, enable):
def reset_needed(self, enable=None, always_fire_events=None):
if enable and not self.runout_helper.sensor_enabled:
return True
return False
Expand Down
12 changes: 8 additions & 4 deletions klippy/extras/filament_switch_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ def cmd_SET_FILAMENT_SENSOR(self, gcmd):
):
return
if enable is not None:
if self.defined_sensor.reset_needed(enable):
reset_needed = True
self.sensor_enabled = enable
if reset is not None and reset:
reset_needed = True
Expand All @@ -221,6 +219,10 @@ def cmd_SET_FILAMENT_SENSOR(self, gcmd):
self.always_fire_events = always_fire_events
if self.defined_sensor.set_filament_sensor(gcmd):
reset_needed = True
if self.defined_sensor.reset_needed(
enable=enable, always_fire_events=always_fire_events
):
reset_needed = True
if reset_needed:
self.defined_sensor.reset()

Expand Down Expand Up @@ -306,8 +308,10 @@ def get_info(self, gcmd):
return True
return False

def reset_needed(self, enable):
if enable != self.runout_helper.sensor_enabled:
def reset_needed(self, enable=None, always_fire_events=None):
if enable is not None and enable != self.runout_helper.sensor_enabled:
return True
if always_fire_events is not None and always_fire_events:
return True
return False

Expand Down

0 comments on commit cd53016

Please sign in to comment.