klippy: Convert printer_state("disconnect") to an event handler
Convert all users of the printer_state("disconnect") handler to register a "klippy:disconnect" event handler instead. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
fb7fe282c8
commit
f4be0ac7be
|
@ -17,6 +17,8 @@ class GCodeParser:
|
|||
self.printer = printer
|
||||
self.fd = fd
|
||||
printer.register_event_handler("klippy:shutdown", self.handle_shutdown)
|
||||
printer.register_event_handler("klippy:disconnect",
|
||||
self.handle_disconnect)
|
||||
# Input handling
|
||||
self.reactor = printer.get_reactor()
|
||||
self.is_processing_data = False
|
||||
|
@ -122,10 +124,10 @@ class GCodeParser:
|
|||
if self.is_fileinput:
|
||||
self.printer.request_exit('error_exit')
|
||||
self._respond_state("Shutdown")
|
||||
def handle_disconnect(self):
|
||||
self._respond_state("Disconnect")
|
||||
def printer_state(self, state):
|
||||
if state != 'ready':
|
||||
if state == 'disconnect':
|
||||
self._respond_state("Disconnect")
|
||||
return
|
||||
self.is_printer_ready = True
|
||||
self.gcode_handlers = self.ready_gcode_handlers
|
||||
|
|
|
@ -423,6 +423,8 @@ class MCU:
|
|||
if self._name.startswith('mcu '):
|
||||
self._name = self._name[4:]
|
||||
self._printer.register_event_handler("klippy:shutdown", self._shutdown)
|
||||
self._printer.register_event_handler("klippy:disconnect",
|
||||
self._disconnect)
|
||||
# Serial port
|
||||
self._serialport = config.get('serial', '/dev/ttyS0')
|
||||
baud = 0
|
||||
|
@ -768,8 +770,6 @@ class MCU:
|
|||
def printer_state(self, state):
|
||||
if state == 'connect':
|
||||
self._connect()
|
||||
elif state == 'disconnect':
|
||||
self._disconnect()
|
||||
def __del__(self):
|
||||
self._disconnect()
|
||||
|
||||
|
|
Loading…
Reference in New Issue