Skip to content

Commit

Permalink
clean up and add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bwnance committed Feb 4, 2024
1 parent 8f8e644 commit bfd8a42
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions klippy/mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ def __init__(self, config, clocksync):
self.reconnect_interval = (
config.getfloat("reconnect_interval", 2.0) + 0.12
) # add small change to not collide with other events

self.gcode = printer.lookup_object("gcode")
# Register handlers
printer.register_event_handler(
"klippy:firmware_restart", self._firmware_restart
Expand Down Expand Up @@ -917,15 +917,16 @@ def handle_non_critical_disconnect(self):
self.non_critical_recon_timer,
self._reactor.NOW + self.reconnect_interval,
)
logging.info("mcu: '%s' disconnected", self._name)
self.gcode.respond_info(f"mcu: '{self._name}' disconnected!", log=True)

def non_critical_recon_event(self, eventtime):
success = self.recon_mcu()
if success:
logging.info(f"mcu: '{self._name}' reconnected!")
self.gcode.respond_info(
f"mcu: '{self._name}' reconnected!", log=True
)
return self._reactor.NEVER
else:
logging.info(f"mcu: '{self._name}' not connected!")
return eventtime + self.reconnect_interval

def _send_config(self, prev_crc):
Expand Down Expand Up @@ -1028,10 +1029,6 @@ def recon_mcu(self):
self.reset_to_initial_state()
self.non_critical_disconnected = False
self._connect()
# self._reactor.update_timer(
# self.non_critical_recon_timer, self._reactor.NEVER
# )
# self._reactor.unregister_timer(self.non_critical_recon_timer)
return True

def reset_to_initial_state(self):
Expand All @@ -1045,10 +1042,6 @@ def reset_to_initial_state(self):

def _connect(self):
if self.non_critical_disconnected:
# self.non_critical_recon_timer = self._reactor.register_timer(
# self.non_critical_recon_event,
# self._reactor.NOW + self.reconnect_interval,
# )
self._reactor.update_timer(
self.non_critical_recon_timer,
self._reactor.NOW + self.reconnect_interval,
Expand Down

0 comments on commit bfd8a42

Please sign in to comment.