paneldue: Update to fetch status from Klipper's print_stats object
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
89fa9ba47e
commit
f082d4dd44
@ -260,8 +260,9 @@ 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': {}}
|
'pause_resume': {}, 'fan': {}, 'display_status': {},
|
||||||
sub_args = {'gcode': [], 'toolhead': []}
|
'print_stats': {}}
|
||||||
|
sub_args = {k: [] for k in self.printer_state.keys()}
|
||||||
self.extruder_count = 0
|
self.extruder_count = 0
|
||||||
self.heaters = []
|
self.heaters = []
|
||||||
for cfg in config:
|
for cfg in config:
|
||||||
@ -274,8 +275,6 @@ class PanelDue:
|
|||||||
self.printer_state[cfg] = {}
|
self.printer_state[cfg] = {}
|
||||||
self.heaters.append(cfg)
|
self.heaters.append(cfg)
|
||||||
sub_args[cfg] = []
|
sub_args[cfg] = []
|
||||||
elif cfg in self.printer_state:
|
|
||||||
sub_args[cfg] = []
|
|
||||||
try:
|
try:
|
||||||
await self._klippy_request(
|
await self._klippy_request(
|
||||||
"objects/subscription", method='POST', args=sub_args)
|
"objects/subscription", method='POST', args=sub_args)
|
||||||
@ -400,7 +399,7 @@ class PanelDue:
|
|||||||
|
|
||||||
def _prepare_M32(self, args):
|
def _prepare_M32(self, args):
|
||||||
filename = self._clean_filename(args[0].strip())
|
filename = self._clean_filename(args[0].strip())
|
||||||
return "M23 " + filename + "\n" + "M24"
|
return "SDCARD_PRINT_FILE FILENAME=" + filename
|
||||||
|
|
||||||
def _prepare_M98(self, args):
|
def _prepare_M98(self, args):
|
||||||
macro = args[0][1:].strip()
|
macro = args[0][1:].strip()
|
||||||
@ -498,13 +497,14 @@ class PanelDue:
|
|||||||
|
|
||||||
# Print Progress Tracking
|
# Print Progress Tracking
|
||||||
sd_status = p_state['virtual_sdcard']
|
sd_status = p_state['virtual_sdcard']
|
||||||
fname = sd_status.get('filename', "")
|
print_stats = p_state['print_stats']
|
||||||
|
fname = print_stats.get('filename', "")
|
||||||
if fname:
|
if fname:
|
||||||
# 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
|
||||||
self.file_metadata = self.file_manager.get_file_metadata(fname)
|
self.file_metadata = self.file_manager.get_file_metadata(fname)
|
||||||
progress = p_state['virtual_sdcard'].get('progress', 0)
|
progress = sd_status.get('progress', 0)
|
||||||
# progress and print tracking
|
# progress and print tracking
|
||||||
if progress:
|
if progress:
|
||||||
response['fraction_printed'] = round(progress, 3)
|
response['fraction_printed'] = round(progress, 3)
|
||||||
@ -515,7 +515,7 @@ class PanelDue:
|
|||||||
# filament estimate
|
# filament estimate
|
||||||
est_total_fil = self.file_metadata.get('filament_total')
|
est_total_fil = self.file_metadata.get('filament_total')
|
||||||
if est_total_fil:
|
if est_total_fil:
|
||||||
cur_filament = sd_status.get('filament_used', 0.)
|
cur_filament = print_stats.get('filament_used', 0.)
|
||||||
fpct = min(1., cur_filament / est_total_fil)
|
fpct = min(1., cur_filament / est_total_fil)
|
||||||
times_left.append(int(est_time - est_time * fpct))
|
times_left.append(int(est_time - est_time * fpct))
|
||||||
# object height estimate
|
# object height estimate
|
||||||
@ -527,7 +527,7 @@ class PanelDue:
|
|||||||
else:
|
else:
|
||||||
# The estimated time is not in the metadata, however we
|
# The estimated time is not in the metadata, however we
|
||||||
# can still provide an estimate based on file progress
|
# can still provide an estimate based on file progress
|
||||||
duration = sd_status.get('print_duration', 0.)
|
duration = print_stats.get('print_duration', 0.)
|
||||||
times_left = [int(duration / progress - duration)]
|
times_left = [int(duration / progress - duration)]
|
||||||
response['timesLeft'] = times_left
|
response['timesLeft'] = times_left
|
||||||
else:
|
else:
|
||||||
@ -630,12 +630,13 @@ class PanelDue:
|
|||||||
response = {}
|
response = {}
|
||||||
filename = arg_p
|
filename = arg_p
|
||||||
sd_status = self.printer_state.get('virtual_sdcard', {})
|
sd_status = self.printer_state.get('virtual_sdcard', {})
|
||||||
|
print_stats = self.printer_state.get('print_stats', {})
|
||||||
if filename is None:
|
if filename is None:
|
||||||
# PanelDue is requesting file information on a
|
# PanelDue is requesting file information on a
|
||||||
# currently printed file
|
# currently printed file
|
||||||
active = False
|
active = False
|
||||||
if sd_status:
|
if sd_status and print_stats:
|
||||||
filename = sd_status['filename']
|
filename = print_stats['filename']
|
||||||
active = sd_status['is_active']
|
active = sd_status['is_active']
|
||||||
if not filename or not active:
|
if not filename or not active:
|
||||||
# Either no file printing or no virtual_sdcard
|
# Either no file printing or no virtual_sdcard
|
||||||
|
Loading…
x
Reference in New Issue
Block a user