Skip to content

Commit

Permalink
Added B18 support (#6)
Browse files Browse the repository at this point in the history
* Adding B18 support

* B18 work

* Removed some debugging print

* Update readme, remove extra example image

* Add extra printer models & density check

---------

Co-authored-by: AndBondStyle <[email protected]>
  • Loading branch information
ryanrolds and AndBondStyle authored Jan 19, 2024
1 parent 2199e65 commit 14237a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 7 additions & 3 deletions niimprint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@click.option(
"-m",
"--model",
type=click.Choice(["b1", "b21", "d11"], False),
type=click.Choice(["b1", "b18", "b21", "d11", "d110"], False),
default="b21",
show_default=True,
help="Niimbot printer model",
Expand Down Expand Up @@ -73,11 +73,15 @@ 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", "b21"):
if model in ("b1", "b18", "b21"):
max_width_px = 384
if model == "d11":
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
Expand Down
10 changes: 3 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**Fork changelog & differences from original version:**

- Tested on Niimbot B21 and Python 3.11. Niimbot D11 support may be broken!
- Tested on Niimbot B1, B18, B21, D11, D110 and Python 3.11
- Added transport abstraction: switch between bluetooth and USB (serial)
- Disabled checksum calculation for image encoding (works fine without it so far)
- Switched to [click](https://click.palletsprojects.com/) CLI library instead of argparse
Expand All @@ -22,7 +22,7 @@ $ python niimprint --help
Usage: niimprint [OPTIONS]
Options:
-m, --model [b1|b21|d11] Niimbot printer model [default: b21]
-m, --model [b1|b18|b21|d11|d110] Niimbot printer model [default: b21]
-c, --conn [usb|bluetooth] Connection type [default: usb]
-a, --addr TEXT Bluetooth MAC address OR serial device path
-d, --density INTEGER RANGE Print density [default: 5; 1<=x<=5]
Expand All @@ -44,7 +44,7 @@ Generally, the image comes out of the printer with the same orientation you see

As far as we've tested, Niimbot printers have **8 pixels per mm** (~203 dpi) resolution. The CLI prints the image you provided as-is, without any checks of the actual label size, so be careful. However the script will check if the image width is too big for selected printer. The maximum width in pixels is usually slightly less than specified maximum width in mm:

- **B21, B1**: max 384 pixels (almost equal to 50 mm * 8 px/mm = 400)
- **B21, B1, B18**: max 384 pixels (almost equal to 50 mm * 8 px/mm = 400)
- **D11**: max 96 pixels (almost equal to 15 mm * 8 px/mm = 120)

### USB connection:
Expand Down Expand Up @@ -73,10 +73,6 @@ python niimprint -c bluetooth -a "E2:E1:08:03:09:87" -r 90 -i examples/B21_80x50

[![](examples/B21_80x50_result.png)]()

**D11**

Completly untested yet, however original fork supports it. If you have D11 at hand and willing to test, please open an issue!

## Licence

[MIT](https://choosealicense.com/licenses/mit/). Originally developed by [kjy00302](https://github.com/kjy00302), forked & enhanced by [AndBondStyle](https://github.com/AndBondStyle)

0 comments on commit 14237a9

Please sign in to comment.