Add model table, PrinterError, and port upstream PRs #28/#12
Library changes on top of upstream 35c41a7:
- models.py: MODELS table (max width / density / needs_print_clear per
model) and prepare_print(), replacing the duplicated width/density
logic in the CLI. Adds d101 (192px head, tested on 12mm tape).
- _transceive raises PrinterError instead of returning None (callers
used to crash with AttributeError on a silent printer).
- PR #28: send ALLOW_PRINT_CLEAR / SET_QUANTITY for D-series models
(labels taller than ~210px failed on D11 without them) and pause 1ms
between line packets.
- PR #12: replace the fixed sleep after END_PAGE_PRINT with
get_print_status() polling (30s deadline, fallback for firmwares that
do not answer). get_print_status returns PrintStatus(finished,
progress, feed_progress, error).
- set_dimension parameter names match their use.
Verified on a D101 over Bluetooth.
This commit is contained in:
+10
-17
@@ -4,14 +4,20 @@ import re
|
||||
import click
|
||||
from PIL import Image
|
||||
|
||||
from niimprint import BluetoothTransport, PrinterClient, SerialTransport
|
||||
from niimprint import (
|
||||
MODELS,
|
||||
BluetoothTransport,
|
||||
PrinterClient,
|
||||
SerialTransport,
|
||||
prepare_print,
|
||||
)
|
||||
|
||||
|
||||
@click.command("print")
|
||||
@click.option(
|
||||
"-m",
|
||||
"--model",
|
||||
type=click.Choice(["b1", "b18", "b21", "d11", "d110"], False),
|
||||
type=click.Choice(list(MODELS), False),
|
||||
default="b21",
|
||||
show_default=True,
|
||||
help="Niimbot printer model",
|
||||
@@ -73,23 +79,10 @@ def print_cmd(model, conn, addr, density, rotate, image, verbose):
|
||||
port = addr if addr is not None else "auto"
|
||||
transport = SerialTransport(port=port)
|
||||
|
||||
if model in ("b1", "b18", "b21"):
|
||||
max_width_px = 384
|
||||
if model in ("d11", "d110"):
|
||||
max_width_px = 96
|
||||
|
||||
if model in ("b18", "d11", "d110") and density > 3:
|
||||
logging.warning(f"{model.upper()} only supports density up to 3")
|
||||
density = 3
|
||||
|
||||
image = Image.open(image)
|
||||
if rotate != "0":
|
||||
# PIL library rotates counter clockwise, so we need to multiply by -1
|
||||
image = image.rotate(-int(rotate), expand=True)
|
||||
assert image.width <= max_width_px, f"Image width too big for {model.upper()}"
|
||||
image, density = prepare_print(model, Image.open(image), density, int(rotate))
|
||||
|
||||
printer = PrinterClient(transport)
|
||||
printer.print_image(image, density=density)
|
||||
printer.print_image(image, density=density, model=model)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user