Skip to content

Commit

Permalink
Add print state reporting for printer print statistics to work
Browse files Browse the repository at this point in the history
  • Loading branch information
TojikCZ committed Nov 23, 2023
1 parent e5f61fa commit 79979f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Support the new multi-level telemetry data structure
* Don't send over serial when temperature calibration is running
* Periodically send a keepalive gcode to keep the printer in PrusaLink mode
* Add gcodes that flag the state of a usb print for the printer statistics to get saved

0.7.1rc1 (2023-08-10)
* Fixed HTTP response status on HEAD request for non-existing files
Expand Down
16 changes: 15 additions & 1 deletion prusa/link/printer_adapter/file_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def _print(self, from_line=0):
self.data.gcode_number = 0
self.data.enqueued.clear()
line_index = 0

self.do_instruction("M75") # start printer's print timer
while True:
line = file.readline()

Expand All @@ -148,12 +150,14 @@ def _print(self, from_line=0):

if self.data.paused:
log.debug("Pausing USB print")
self.do_instruction("M76") # pause printer's print timer
self.wait_for_unpause()

if not self.data.printing:
break

log.debug("Resuming USB print")
self.do_instruction("M75") # resume printer's print timer

# Trigger cameras on layer change
if ";LAYER_CHANGE" in line:
Expand All @@ -171,6 +175,7 @@ def _print(self, from_line=0):
if not self.data.printing:
break

self.do_instruction("M77") # stop printer's print timer
log.debug("Print ended")

if self.pp_exists:
Expand All @@ -191,6 +196,15 @@ def _print(self, from_line=0):

self.print_stats.reset_stats()

def do_instruction(self, message):
"""Shorthand for enqueueing and waiting for an instruction
Enqueues everything to front as commands have a higher priority"""
instruction = enqueue_instruction(self.serial_queue,
message,
to_front=True)
wait_for_instruction(instruction, lambda: self.data.printing)
return instruction

def print_gcode(self, gcode):
"""Sends a gcode to print, keeps a small buffer of gcodes
and inlines print stats for files without them
Expand All @@ -199,7 +213,7 @@ def print_gcode(self, gcode):

divisible = self.data.gcode_number % STATS_EVERY == 0
if divisible:
time_printing = self.print_stats.get_time_printing()
time_printing = int(self.print_stats.get_time_printing())
self.time_printing_signal.send(self, time_printing=time_printing)

if self.to_print_stats(self.data.gcode_number):
Expand Down

0 comments on commit 79979f3

Please sign in to comment.