Skip to content

Commit

Permalink
Updates to spoolman
Browse files Browse the repository at this point in the history
- When lane is unloaded with BT_TOOL_UNLOAD active spool is set to none
- When lane is ejected spool is removed from variables and saved
  • Loading branch information
jimmyjon711 committed Dec 8, 2024
1 parent b34ec6d commit 3bfcbcf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
7 changes: 7 additions & 0 deletions extras/AFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ def cmd_LANE_UNLOAD(self, gcmd):
self.lanes[CUR_LANE.unit][CUR_LANE.name]['hub_loaded'] = CUR_LANE.hub_load
self.save_vars()
CUR_LANE.status = None

# Removing spool from vars since it was ejected
self.SPOOL.set_spoolID( CUR_LANE, "")

else:
self.gcode.respond_info('LANE ' + CUR_LANE.name + ' IS TOOL LOADED')

Expand Down Expand Up @@ -684,6 +688,9 @@ def cmd_TOOL_UNLOAD(self, gcmd):
CUR_LANE = self.printer.lookup_object('AFC_stepper '+ lane)
self.TOOL_UNLOAD(CUR_LANE)

# User manually unloaded spool from toolhead, remove spool from active status
self.SPOOL.set_active_spool( None )

def TOOL_UNLOAD(self, CUR_LANE):
"""
This function handles the unloading of a specified lane from the tool. It performs
Expand Down
2 changes: 1 addition & 1 deletion extras/AFC_NightOwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def handle_connect(self):
self.AFC = self.printer.lookup_object('AFC')

self.logo = '<span class=success--text>Night Owl Ready</span>'
self.logo ='R , ,\n'
self.logo ='<span class=success--text>R , ,\n'
self.logo+='E )\___/(\n'
self.logo+='A {(@)v(@)}\n'
self.logo+='D {|~~~|}\n'
Expand Down
4 changes: 4 additions & 0 deletions extras/AFC_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def PREP(self, gcmd):
if not self.AFC.extruders[EXTRUDE]['lane_loaded']:
self.AFC.gcode.respond_info("<span class=error--text>{} loaded with out identifying lane in AFC.vars.tool file<span>".format(EXTRUDE))

# Defaulting to no active spool, putting at end so endpoint has time to register
if self.AFC.current is None:
self.AFC.SPOOL.set_active_spool( None )

def load_config(config):
return afcPrep(config)

26 changes: 17 additions & 9 deletions extras/AFC_spool.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def handle_connect(self):
self.gcode.register_mux_command('SET_RUNOUT',None,None, self.cmd_SET_RUNOUT, desc=self.cmd_SET_RUNOUT_help)
self.gcode.register_mux_command('SET_MAP',None,None, self.cmd_SET_MAP, desc=self.cmd_SET_MAP_help)

self.URL = 'http://{}:{}/api/v1/spool/'.format(self.AFC.spoolman_ip, self.AFC.spoolman_port)


cmd_SET_MAP_help = "change filaments color"
def cmd_SET_MAP(self, gcmd):
Expand Down Expand Up @@ -99,14 +101,16 @@ def cmd_SET_COLOR(self, gcmd):
def set_active_spool(self, ID):
webhooks = self.printer.lookup_object('webhooks')
if self.AFC.spoolman_ip != None:
if ID:
args = {'spool_id' : int(ID)}
try:
webhooks.call_remote_method("spoolman_set_active_spool", **args)
except self.printer.command_error:
self.gcode._respond_error("Error trying to set active spool")
if ID and ID is not None:
id = int(ID)
else:
self.gcode.respond_info("Spool ID not set, cannot update spoolman with active spool")
id = None

args = {'spool_id' : id }
try:
webhooks.call_remote_method("spoolman_set_active_spool", **args)
except self.printer.command_error as e:
self.gcode._respond_error("Error trying to set active spool \n{}".format(e))

cmd_SET_SPOOLID_help = "change filaments ID"
def cmd_SET_SPOOLID(self, gcmd):
Expand Down Expand Up @@ -134,14 +138,18 @@ def cmd_SET_SPOOLID(self, gcmd):
return
SpoolID = gcmd.get('SPOOL_ID', '')
CUR_LANE = self.printer.lookup_object('AFC_stepper ' + lane)
self.set_spoolID(CURLANE, SpoolID)

def set_spoolID(self, CUR_LANE, SpoolID):
if self.AFC.spoolman_ip !=None:
if SpoolID !='':
try:
url = 'http://' + self.AFC.spoolman_ip + ':'+ self.AFC.spoolman_port +"/api/v1/spool/" + SpoolID
url = "{}{}".format(self.URL, SpoolID)
result = json.load(urlopen(url))
self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['spool_id'] = SpoolID
self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['material'] = result['filament']['material']
self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['color'] = '#' + result['filament']['color_hex']
self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['weight'] = result['remaining_weight']
if 'remaining_weight' in result: self.AFC.lanes[CUR_LANE.unit][CUR_LANE.name]['weight'] = result['remaining_weight']
except:
self.AFC.ERROR.AFC_error("Error when trying to get Spoolman data for ID:{}".format(SpoolID))
else:
Expand Down

0 comments on commit 3bfcbcf

Please sign in to comment.