Skip to content

Commit

Permalink
- Fixed printer stickers not printing completely (AndBondStyle#12)
Browse files Browse the repository at this point in the history
- Added basic error checking before attempting to print (Open paper compartment and busy)
- Unpacking on get_print_status() now works. Tagged unknown values for the time being.
- Added two unknown values to InfoEnum
  • Loading branch information
TheZoc committed Apr 23, 2024
1 parent bffeff5 commit 7d096a2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
8 changes: 8 additions & 0 deletions niimprint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ def print_cmd(model, conn, addr, density, rotate, image, verbose):
assert image.width <= supported_models[model]["max_width"], f"Image width too big for {model.upper()}"

printer = PrinterClient(transport)
printer_status = printer.get_print_status()
if printer_status["open_paper_compartment"]:
raise RuntimeError("Printer paper compartment is open, close before proceeding")
if not printer_status["idle"]:
raise RuntimeError("Printer is busy")
if printer_status["error"]:
logging.warning(f"Printer has error code {printer_status["error_code"]} set - Attempting to ignore.")

printer.print_image(image, density=density)


Expand Down
28 changes: 25 additions & 3 deletions niimprint/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class InfoEnum(enum.IntEnum):
BATTERY = 10
DEVICESERIAL = 11
HARDVERSION = 12
UNKNOWN_1 = 13

This comment has been minimized.

Copy link
@MultiMote

MultiMote Aug 1, 2024

13 is BluetoothAddress
15 is Area

UNKNOWN_2 = 15


class RequestCodeEnum(enum.IntEnum):
Expand Down Expand Up @@ -163,7 +165,12 @@ 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:
printer_status = self.get_print_status()
if printer_status["idle"]:
break

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

Expand Down Expand Up @@ -336,5 +343,20 @@ 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}
unknown0, idle, progress1, progress2, unknown1, unknown2, error, unknown3, unknown4, unknown5 = struct.unpack(">BBBBBBBBBB", packet.data)

assert 0 <= idle <= 1, "Unexpected value received for idle"
return {
"unknown0": unknown0,
"idle": bool(idle),
"progress1": progress1,
"progress2": progress2,
"unknown1": unknown1,
"unknown2": unknown2,
"error": bool(error),
"error_code": error,
"open_paper_compartment": error == 1,
"unknown3": unknown3,
"unknown4": unknown4,
"unknown5": unknown5
}

0 comments on commit 7d096a2

Please sign in to comment.