Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for finish to send end_print #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's made this strongly typed? Like, def get_print_status(self) -> Progress:, and

@dataclass
class Progress:
    finished: int  # or whatever

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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right place for bumping a version - that should probably be a separate commit with a GitHub release attached to it

description = ""
authors = []

Expand Down