Skip to content

Commit

Permalink
Merge remote-tracking branch 'afc-prod/main' into noticket-add-instal…
Browse files Browse the repository at this point in the history
…l-versioning
  • Loading branch information
ejsears committed Nov 29, 2024
2 parents f7aaeaa + 11fdd86 commit d284c9d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 14 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,18 @@ gcode:

### Fixed
- Klipper erroring out when renaming `RESUME` macro when a user call's `BT_PREP` within the same reboot of klipper

## [2024-11-27]

### Added
- `self.delay` to AFC_Prep to control delay time during Prep
- Config option under `[AFC Prep]`, `delay_time: 1 # default .1`
- This can be increased if TTC occurs during prep caused by H-bridge command queue

### Changed
- Simplified enabling and disabling of the buffer
- `AFC_extruder.py` now holds the functions and controls of the buffer
- These common functions all called throughout

### Fixed
- Fixed erroring out if a buffer in not configured
13 changes: 4 additions & 9 deletions extras/AFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,7 @@ def TOOL_LOAD(self, CUR_LANE):
self.lanes[CUR_LANE.unit][CUR_LANE.name]['tool_loaded'] = True

self.current = CUR_LANE.name
if CUR_EXTRUDER.buffer_name != None:
CUR_EXTRUDER.buffer.enable_buffer()
CUR_EXTRUDER.enable_buffer()

self.afc_led(self.led_tool_loaded, CUR_LANE.led_index)
if self.poop:
Expand Down Expand Up @@ -707,8 +706,7 @@ def TOOL_UNLOAD(self, CUR_LANE):
self.heater = extruder.get_heater() #Get extruder heater
CUR_LANE.status = 'unloading'

if CUR_EXTRUDER.buffer_name != None:
CUR_EXTRUDER.buffer.disable_buffer()
CUR_EXTRUDER.disable_buffer()

self.afc_led(self.led_unloading, CUR_LANE.led_index)
CUR_LANE.extruder_stepper.sync_to_extruder(CUR_LANE.extruder_name)
Expand Down Expand Up @@ -956,11 +954,8 @@ def get_status(self, eventtime):
str["system"]["extruders"][EXTRUDE]['lane_loaded'] = self.extruders[LANE.extruder_name]['lane_loaded']
str["system"]["extruders"][EXTRUDE]['tool_start_sensor'] = True == CUR_EXTRUDER.tool_start_state if CUR_EXTRUDER.tool_start is not None else False
str["system"]["extruders"][EXTRUDE]['tool_end_sensor'] = True == CUR_EXTRUDER.tool_end_state if CUR_EXTRUDER.tool_end is not None else False
if CUR_EXTRUDER.buffer_name != None:
str["system"]["extruders"][EXTRUDE]['buffer'] = CUR_EXTRUDER.buffer_name
str["system"]["extruders"][EXTRUDE]['buffer_status'] = CUR_EXTRUDER.buffer.buffer_status()
else:
str["system"]["extruders"][EXTRUDE]['buffer'] = 'None'
str["system"]["extruders"][EXTRUDE]['buffer'] = CUR_EXTRUDER.buffer_name
str["system"]["extruders"][EXTRUDE]['buffer_status'] = CUR_EXTRUDER.buffer_status()

return str

Expand Down
2 changes: 1 addition & 1 deletion extras/AFC_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,4 @@ def cmd_QUERY_BUFFER(self, gcmd):
self.gcode.respond_info("{} : {}".format(self.name, state_info))

def load_config_prefix(config):
return AFCtrigger(config)
return AFCtrigger(config)
47 changes: 47 additions & 0 deletions extras/AFC_extruder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Armored Turtle Automated Filament Changer
#
# Copyright (C) 2024 Armored Turtle
#
# This file may be distributed under the terms of the GNU GPLv3 license.

class AFCextruder:
def __init__(self, config):
self.printer = config.get_printer()
Expand All @@ -10,6 +16,8 @@ def __init__(self, config):
self.tool_load_speed = config.getfloat("tool_load_speed", 25)
# BUFFER
self.buffer_name = config.get('buffer', None)
self.buffer = None
self.printer.register_event_handler("klippy:connect", self._handle_ready)

buttons = self.printer.load_object(config, "buttons")
self.tool_start = config.get('pin_tool_start', None)
Expand All @@ -26,5 +34,44 @@ def tool_start_callback(self, eventtime, state):
def tool_end_callback(self, eventtime, state):
self.tool_end_state = state

def get_buffer(self):
"""
Retrieve the buffer object associated with the current buffer name.
If `buffer_name` is set, this method assigns the buffer object to `self.buffer`
by looking it up using the printer's AFC buffer system.
"""
if self.buffer_name is not None:
self.buffer = self.printer.lookup_object('AFC_buffer ' + self.buffer_name)

def _handle_ready(self):
self.get_buffer()

def enable_buffer(self):
"""
Enable the buffer if `buffer_name` is set.
Retrieves the buffer object and calls its `enable_buffer()` method to activate it.
"""
if self.buffer_name is not None:
self.buffer.enable_buffer()

def disable_buffer(self):
"""
Disable the buffer if `buffer_name` is set.
Calls the buffer's `disable_buffer()` method to deactivate it.
"""
if self.buffer_name is not None:
self.buffer.disable_buffer()

def buffer_status(self):
"""
Retrieve the current status of the buffer.
If `buffer_name` is set, returns the buffer's status using `buffer_status()`.
Otherwise, returns None.
"""
if self.buffer_name is not None:
return self.buffer.buffer_status()

else: return None

def load_config_prefix(config):
return AFCextruder(config)
7 changes: 3 additions & 4 deletions extras/AFC_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, config):
self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command('PREP', self.PREP, desc=None)
self.enable = config.getboolean("enable", False)
self.delay = config.get('delay_time', .1)

# Flag to set once resume rename as occured for the first time
self.rename_occured = False
Expand Down Expand Up @@ -151,13 +152,11 @@ def PREP(self, gcmd):
check_success = False
break

if CUR_EXTRUDER.buffer_name !=None:
CUR_EXTRUDER.buffer = self.printer.lookup_object('AFC_buffer ' + CUR_EXTRUDER.buffer_name)
# Run test reverse/forward on each lane
if check_success == True:
CUR_LANE.extruder_stepper.sync_to_extruder(None)
CUR_LANE.move( 5, self.AFC.short_moves_speed, self.AFC.short_moves_accel, True)
self.reactor.pause(self.reactor.monotonic() + 1)
self.reactor.pause(self.reactor.monotonic() + self.delay)
CUR_LANE.move( -5, self.AFC.short_moves_speed, self.AFC.short_moves_accel, True)
msg = ''
if CUR_LANE.prep_state == False:
Expand Down Expand Up @@ -188,7 +187,7 @@ def PREP(self, gcmd):
self.AFC.afc_led(self.AFC.led_tool_loaded, CUR_LANE.led_index)
if len(self.AFC.extruders) == 1:
self.AFC.current = CUR_LANE.name
if CUR_EXTRUDER.buffer_name is not None: CUR_EXTRUDER.buffer.enable_buffer()
CUR_EXTRUDER.enable_buffer()
else:
lane_check=self.error_tool_unload(CUR_LANE)
if lane_check != True:
Expand Down

0 comments on commit d284c9d

Please sign in to comment.