Skip to content

Commit ac4abf7

Browse files
authored
Fixing error when trying to turn leds back on, fixing spelling errors, and added comment for AFC_CLEAR_MESSAGE (#442)
Fixes LED reactivation errors, improves documentation for the AFC_CLEAR_MESSAGE macro, and surfaces led_state in the status API
1 parent 9dc88d8 commit ac4abf7

3 files changed

Lines changed: 37 additions & 15 deletions

File tree

extras/AFC.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def __init__(self, config):
8383
self.buffers = {}
8484
self.tool_cmds = {}
8585
self.led_obj = {}
86+
self.led_state = True
8687
self.bypass = None
8788
self.bypass_last_state = False
8889
self.message_queue = []
@@ -1584,6 +1585,7 @@ def get_status(self, eventtime=None):
15841585
str["hubs"] = list(self.hubs.keys())
15851586
str["buffers"] = list(self.buffers.keys())
15861587
str["message"] = self._get_message()
1588+
str["led_state"] = self.led_state
15871589
return str
15881590

15891591
def _webhooks_status(self, web_request):
@@ -1613,6 +1615,7 @@ def _webhooks_status(self, web_request):
16131615
str["system"]["extruders"] = {}
16141616
str["system"]["hubs"] = {}
16151617
str["system"]["buffers"] = {}
1618+
str["system"]["led_state"] = self.led_state
16161619

16171620
for extruder in self.tools.values():
16181621
str["system"]["extruders"][extruder.name] = extruder.get_status()
@@ -1712,6 +1715,7 @@ def cmd_TURN_OFF_AFC_LED(self, gcmd: Any) -> None:
17121715
TURN_OFF_AFC_LED
17131716
```
17141717
"""
1718+
self.led_state = False
17151719
for led in self.led_obj.values():
17161720
led.turn_off_leds()
17171721

@@ -1730,6 +1734,7 @@ def cmd_TURN_ON_AFC_LED(self, gcmd):
17301734
TURN_ON_AFC_LED
17311735
```
17321736
"""
1737+
self.led_state = True
17331738
for led in self.led_obj.values():
17341739
led.turn_on_leds()
17351740

@@ -1780,6 +1785,19 @@ def cmd_AFC_CHANGE_BLADE(self, gcmd):
17801785

17811786
cmd_AFC_CLEAR_MESSAGE_help = "Macro to clear error and warning message from AFC message queue"
17821787
def cmd_AFC_CLEAR_MESSAGE(self, gcmd):
1788+
"""
1789+
This macro handles clearing one message at a time for messages that show up mainsail/klipperscreen/fluidd gui's.
1790+
1791+
USAGE
1792+
-----
1793+
`AFC_CLEAR_MESSAGE`
1794+
1795+
Example
1796+
-----
1797+
```
1798+
AFC_CLEAR_MESSAGE
1799+
```
1800+
"""
17831801
self._get_message(clear=True)
17841802

17851803
cmd__AFC_TEST_MESSAGES_help = "Macro to send test messages for testing"

extras/AFC_HTLF.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def __init__(self, config):
3030
self.selector_stepper_obj = None
3131
self.current_selected_lane = None
3232
self.home_state = False
33-
self.mm_move_per_rotation = config.getint("mm_move_per_rotation", 32) # How many mm moves pully a full rotation
33+
self.mm_move_per_rotation = config.getint("mm_move_per_rotation", 32) # How many mm moves pulley a full rotation
3434
self.cam_angle = config.getint("cam_angle") # CAM lobe angle thats currently installed. 30,45,60 (recommend using 60)
3535
self.home_pin = config.get("home_pin") # Pin for homing sensor
36-
self.MAX_ANGLE_MOVEMENT = config.getint("MAX_ANGLE_MOVEMENT", 215) # Max angle to move lobes, this is when lobe 1 is fully engauged with its lane
36+
self.MAX_ANGLE_MOVEMENT = config.getint("MAX_ANGLE_MOVEMENT", 215) # Max angle to move lobes, this is when lobe 1 is fully engaged with its lane
3737
self.enable_sensors_in_gui = config.getboolean("enable_sensors_in_gui", self.afc.enable_sensors_in_gui) # Set to True to show prep and load sensors switches as filament sensors in mainsail/fluidd gui, overrides value set in AFC.cfg
3838
self.prep_homed = False
3939
self.failed_to_home = False

extras/AFC_led.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def __init__(self, config):
5151
self.last_led_color = {}
5252
self.keep_leds_off = False
5353

54+
if hasattr(self.led_helper, "_set_color"):
55+
self.ledHelper_set_color_fn = self.led_helper._set_color
56+
self.check_transmit_fn = self.led_helper._check_transmit
57+
else:
58+
self.ledHelper_set_color_fn = self.led_helper.set_color
59+
self.check_transmit_fn = self.led_helper.check_transmit
60+
5461
def build_config(self):
5562
bmt = self.mcu.seconds_to_clock(BIT_MAX_TIME)
5663
rmt = self.mcu.seconds_to_clock(RESET_MIN_TIME)
@@ -115,34 +122,31 @@ def reactor_bgfunc(eventtime):
115122
def get_status(self, eventtime=None):
116123
return self.led_helper.get_status(eventtime)
117124

118-
def led_change(self, index, status, update_last=True):
119-
if update_last: self.last_led_color[str(index)] = status
125+
def set_color_fn(self, index, color, update_last=True):
126+
if update_last: self.last_led_color[str(index)] = color
120127
if self.keep_leds_off: return
121128

129+
self.ledHelper_set_color_fn(index, color)
130+
131+
def led_change(self, index, status, update_last=True):
122132
if isinstance(status, list):
123133
colors = status
124134
else:
125135
colors=list(map(float,status.split(',')))
126136

127-
transmit = 1
137+
transmit = not self.keep_leds_off
128138
def lookahead_bgfunc(print_time):
129-
if hasattr(self.led_helper, "_set_color"):
130-
set_color_fn = self.led_helper._set_color
131-
check_transmit_fn = self.led_helper._check_transmit
132-
else:
133-
set_color_fn = self.led_helper.set_color
134-
check_transmit_fn = self.led_helper.check_transmit
135139
if isinstance(index, str) and "-" in index:
136140
start, end = map(int, index.split("-"))
137141
for i in range(start, end + 1):
138-
set_color_fn(i, colors)
142+
self.set_color_fn(i, colors, update_last)
139143
elif isinstance(index, list):
140144
for i in index:
141-
set_color_fn(i, colors)
145+
self.set_color_fn(i, colors, update_last)
142146
else:
143-
set_color_fn(int(index), colors)
147+
self.set_color_fn(int(index), colors, update_last)
144148
if transmit:
145-
check_transmit_fn(print_time)
149+
self.check_transmit_fn(print_time)
146150
toolhead = self.printer.lookup_object('toolhead')
147151
toolhead.register_lookahead_callback(lookahead_bgfunc)
148152

0 commit comments

Comments
 (0)