Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeanon committed Oct 14, 2023
1 parent 37a63ba commit 7930139
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/Status_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ objects:
- `enabled`: Returns True if the switch sensor is currently enabled.
- `filament_detected`: Returns True if the sensor is in a triggered
state.
- `runout_distance`: Returns the runout_distance

## filament_motion_sensor

Expand All @@ -159,6 +160,7 @@ objects:
- `enabled`: Returns True if the motion sensor is currently enabled.
- `filament_detected`: Returns True if the sensor is in a triggered
state.
- `detection_length`: Returns the detection_length

## firmware_retraction

Expand Down
5 changes: 5 additions & 0 deletions klippy/extras/filament_motion_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def get_sensor_status(self):
% (self.runout_helper.name,
'enabled' if self.runout_helper.sensor_enabled > 0
else 'disabled', self.detection_length))
def sensor_get_status(self, eventtime):
return {
"filament_detected": bool(self.runout_helper.filament_present),
"enabled": bool(self.runout_helper.sensor_enabled),
"detection_length": float(self.detection_length)}
def set_filament_sensor(self, gcmd):
enable = gcmd.get_int('ENABLE', None, minval=0, maxval=1)
reset = gcmd.get_int('RESET', None, minval=0, maxval=1)
Expand Down
17 changes: 11 additions & 6 deletions klippy/extras/filament_switch_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ def __init__(self, config, defined_sensor, runout_distance=0):
if self.runout_pause or config.get('runout_gcode', None) is not None:
self.runout_gcode = gcode_macro.load_template(
config, 'runout_gcode', '')
if config.get('immediate_runout_gcode', None) is not None:
self.immediate_runout_gcode = gcode_macro.load_template(
config, 'immediate_runout_gcode', '')
if config.get('insert_gcode', None) is not None:
self.insert_gcode = gcode_macro.load_template(
config, 'insert_gcode')
Expand Down Expand Up @@ -130,9 +127,7 @@ def note_filament_present(self, is_filament_present, force=False):
(self.name, eventtime))
self.reactor.register_callback(self._runout_event_handler)
def get_status(self, eventtime):
return {
"filament_detected": bool(self.filament_present),
"enabled": bool(self.sensor_enabled)}
return self.defined_sensor.sensor_get_status(eventtime)
cmd_QUERY_FILAMENT_SENSOR_help = "Query the status of the Filament Sensor"
def cmd_QUERY_FILAMENT_SENSOR(self, gcmd):
msg = "Filament Sensor %s: filament %s" %\
Expand All @@ -147,13 +142,18 @@ def cmd_SET_FILAMENT_SENSOR(self, gcmd):
class SwitchSensor:
def __init__(self, config):
self.printer = config.get_printer()
gcode_macro = self.printer.load_object(config, 'gcode_macro')
buttons = self.printer.load_object(config, 'buttons')
switch_pin = config.get('switch_pin')
runout_distance = config.getfloat('runout_distance', 0., minval=0.)
buttons.register_buttons([switch_pin], self._button_handler)
self.reactor = self.printer.get_reactor()
self.estimated_print_time = None
self.runout_helper = RunoutHelper(config, self, runout_distance)
if config.get('immediate_runout_gcode', None) is not None:
self.runout_helper.immediate_runout_gcode = (
gcode_macro.load_template(config, 'immediate_runout_gcode', '')
)
self.get_status = self.runout_helper.get_status
self.printer.register_event_handler('klippy:ready',
self._handle_ready)
Expand All @@ -174,6 +174,11 @@ def get_sensor_status(self):
% (self.runout_helper.name,
'enabled' if self.runout_helper.sensor_enabled
else 'disabled', self.runout_helper.runout_distance))
def sensor_get_status(self, eventtime):
return {
"filament_detected": bool(self.runout_helper.filament_present),
"enabled": bool(self.runout_helper.sensor_enabled),
"runout_distance": float(self.runout_helper.runout_distance)}
def set_filament_sensor(self, gcmd):
enable = gcmd.get_int('ENABLE', None, minval=0, maxval=1)
reset = gcmd.get_int('RESET', None, minval=0, maxval=1)
Expand Down

0 comments on commit 7930139

Please sign in to comment.