paneldue: use the new "print_stats" module to check printing state
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
4f97ebb28d
commit
d235139e6b
|
@ -153,13 +153,14 @@ class PanelDue:
|
||||||
# Initialize tracked state.
|
# Initialize tracked state.
|
||||||
self.printer_state = {
|
self.printer_state = {
|
||||||
'gcode': {}, 'toolhead': {}, 'virtual_sdcard': {},
|
'gcode': {}, 'toolhead': {}, 'virtual_sdcard': {},
|
||||||
'pause_resume': {}, 'fan': {}, 'display_status': {}}
|
'fan': {}, 'display_status': {}, 'print_stats': {}}
|
||||||
self.available_macros = {}
|
self.available_macros = {}
|
||||||
self.non_trivial_keys = []
|
self.non_trivial_keys = []
|
||||||
self.extruder_count = 0
|
self.extruder_count = 0
|
||||||
self.heaters = []
|
self.heaters = []
|
||||||
self.is_ready = False
|
self.is_ready = False
|
||||||
self.is_shutdown = False
|
self.is_shutdown = False
|
||||||
|
self.last_printer_state = 'C'
|
||||||
|
|
||||||
# Register server events
|
# Register server events
|
||||||
self.server.register_event_handler(
|
self.server.register_event_handler(
|
||||||
|
@ -231,6 +232,7 @@ class PanelDue:
|
||||||
async def _process_klippy_ready(self):
|
async def _process_klippy_ready(self):
|
||||||
# Request "info" and "configfile" status
|
# Request "info" and "configfile" status
|
||||||
retries = 10
|
retries = 10
|
||||||
|
printer_info = cfg_status = {}
|
||||||
while retries:
|
while retries:
|
||||||
try:
|
try:
|
||||||
printer_info = await self._klippy_request("info")
|
printer_info = await self._klippy_request("info")
|
||||||
|
@ -260,8 +262,7 @@ class PanelDue:
|
||||||
# Initalize printer state and make subscription request
|
# Initalize printer state and make subscription request
|
||||||
self.printer_state = {
|
self.printer_state = {
|
||||||
'gcode': {}, 'toolhead': {}, 'virtual_sdcard': {},
|
'gcode': {}, 'toolhead': {}, 'virtual_sdcard': {},
|
||||||
'pause_resume': {}, 'fan': {}, 'display_status': {},
|
'fan': {}, 'display_status': {}, 'print_stats': {}}
|
||||||
'print_stats': {}}
|
|
||||||
sub_args = {k: [] for k in self.printer_state.keys()}
|
sub_args = {k: [] for k in self.printer_state.keys()}
|
||||||
self.extruder_count = 0
|
self.extruder_count = 0
|
||||||
self.heaters = []
|
self.heaters = []
|
||||||
|
@ -440,18 +441,25 @@ class PanelDue:
|
||||||
return 'S'
|
return 'S'
|
||||||
|
|
||||||
printer_state = self.printer_state
|
printer_state = self.printer_state
|
||||||
is_active = printer_state['virtual_sdcard'].get('is_active', False)
|
th_busy = printer_state['toolhead'].get(
|
||||||
paused = printer_state['pause_resume'].get('is_paused', False)
|
'status', 'Ready') == "Printing"
|
||||||
if paused:
|
sd_state = printer_state['print_stats'].get('state', "standby")
|
||||||
if is_active:
|
if sd_state == "printing":
|
||||||
|
if self.last_printer_state == 'A':
|
||||||
|
# Resuming
|
||||||
|
return 'R'
|
||||||
|
# Printing
|
||||||
|
return 'P'
|
||||||
|
elif sd_state == "paused":
|
||||||
|
if th_busy and self.last_printer_state != 'A':
|
||||||
|
# Pausing
|
||||||
return 'D'
|
return 'D'
|
||||||
else:
|
else:
|
||||||
|
# Paused
|
||||||
return 'A'
|
return 'A'
|
||||||
|
|
||||||
if is_active:
|
if th_busy:
|
||||||
return 'P'
|
# Printer is "busy"
|
||||||
|
|
||||||
if printer_state['gcode'].get('busy', False):
|
|
||||||
return 'B'
|
return 'B'
|
||||||
|
|
||||||
return 'I'
|
return 'I'
|
||||||
|
@ -463,7 +471,8 @@ class PanelDue:
|
||||||
|
|
||||||
if not self.is_ready:
|
if not self.is_ready:
|
||||||
# Klipper is still starting up, do not query status
|
# Klipper is still starting up, do not query status
|
||||||
response['status'] = 'S' if self.is_shutdown else 'C'
|
self.last_printer_state = 'S' if self.is_shutdown else 'C'
|
||||||
|
response['status'] = self.last_printer_state
|
||||||
await self.write_response(response)
|
await self.write_response(response)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -482,8 +491,8 @@ class PanelDue:
|
||||||
response['axes'] = 3
|
response['axes'] = 3
|
||||||
|
|
||||||
p_state = self.printer_state
|
p_state = self.printer_state
|
||||||
status = self._get_printer_status()
|
self.last_printer_state = self._get_printer_status()
|
||||||
response['status'] = status
|
response['status'] = self.last_printer_state
|
||||||
response['babystep'] = round(p_state['gcode'].get(
|
response['babystep'] = round(p_state['gcode'].get(
|
||||||
'homing_zpos', 0.), 3)
|
'homing_zpos', 0.), 3)
|
||||||
|
|
||||||
|
@ -499,7 +508,8 @@ class PanelDue:
|
||||||
sd_status = p_state['virtual_sdcard']
|
sd_status = p_state['virtual_sdcard']
|
||||||
print_stats = p_state['print_stats']
|
print_stats = p_state['print_stats']
|
||||||
fname = print_stats.get('filename', "")
|
fname = print_stats.get('filename', "")
|
||||||
if fname:
|
sd_print_state = print_stats.get('state')
|
||||||
|
if sd_print_state in ['printing', 'paused']:
|
||||||
# We know a file has been loaded, initialize metadata
|
# We know a file has been loaded, initialize metadata
|
||||||
if self.current_file != fname:
|
if self.current_file != fname:
|
||||||
self.current_file = fname
|
self.current_file = fname
|
||||||
|
|
Loading…
Reference in New Issue