Skip to content

Commit

Permalink
Wait for finish to send end_print (AndBondStyle#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
glaserL committed Feb 23, 2024
1 parent 14237a9 commit f3ad2f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions niimprint/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ def print_image(self, image: Image, density: int = 3):
for pkt in self._encode_image(image):
self._send(pkt)
self.end_page_print()
time.sleep(0.3) # FIXME: Check get_print_status()
while True:
status = self.get_print_status()
if status["error"]:
raise RuntimeError("Failure during print")
if status["finished"] == 1:
break
print(f"Progress: {status['progress']}")

while not self.end_print():
time.sleep(0.1)

Expand Down Expand Up @@ -284,5 +291,11 @@ def set_quantity(self, n):

def get_print_status(self):
packet = self._transceive(RequestCodeEnum.GET_PRINT_STATUS, b"\x01", 16)
page, progress1, progress2 = struct.unpack(">HBB", packet.data)
return {"page": page, "progress1": progress1, "progress2": progress2}
finished = bool(packet.data[1])
progress = packet.data[2]
error = packet.data[6]
return {
"finished": finished,
"progress": progress,
"error": error,
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "niimprint"
version = "0.1.0"
version = "0.1.1"
description = ""
authors = []

Expand Down

0 comments on commit f3ad2f1

Please sign in to comment.