Skip to content

feat: add imageMode configuration option for raster and column image … - #7

Merged
GomdimApps merged 1 commit into
mainfrom
hotfix
Sep 22, 2026
Merged

GomdimApps merged 1 commit into
mainfrom
hotfix

Conversation

@GomdimApps

Copy link
Copy Markdown
Owner

Background

A user printing to a real MP58C7 (58mm clone thermal printer, connected
over Bluetooth) got images back as heavy banded/sheared garbage, while
text, barcode and QR printed perfectly fine on the exact same
connection. The on-screen preview looked correct — only the physical
print was broken.

Investigation ruled out, in order:

  1. Image wire format — the underlying @point-of-sale/receipt-printer-encoder
    defaults to the legacy ESC * "column" band format unless a
    recognized printerModel is set, and only then switches to the
    single-shot GS v 0 "raster" format. This project never exposed
    that knob, so it was always silently on column for unrecognized
    printers. Turned out not to be the cause here: forcing raster
    produced byte-for-byte identical corruption on this hardware.
  2. Bluetooth write chunking/pacing — tried the default (100
    bytes/write, no delay), smaller chunks (20, 8 bytes), and added
    inter-write delays (10-20ms), independently and combined. None of it
    changed the outcome; some combinations made it visibly worse.
  3. Payload size — even a small synthetic ~256-byte test image
    corrupted the same way as a full-size photo.
  4. The printer's firmware itself — turned out to be fine: the
    exact same encoded bytes (either wire format) printed perfectly
    when sent over Serial/USB instead of Bluetooth.

Conclusion: this printer family (MP58C7, also sold as MTP-II / HPRT
HM-A200U / PixPos MP58C7 — same underlying hardware) has a Bluetooth
transport-layer issue with image-sized payloads, most likely in its
BLE-to-serial bridge chip, that no amount of chunk-size/pacing tuning
from the browser side could work around. Since the library can't fix
that, this PR documents it as a known hardware limitation (with the
confirmed workaround) and adds the imageMode knob anyway, since it's
a legitimate config option other clone printers may need even though
it wasn't the fix here.

Summary

  • Add an opt-in imageMode: 'column' | 'raster' config option (constructor and per-job), passed straight through to ReceiptPrinterEncoder — lets consumers force the single-shot GS v 0 raster wire format instead of the encoder's default legacy ESC * column/band format, for clone printers whose firmware handles one better than the other.
  • Add two demo-only diagnostic tools (demo/index.html + demo/app.js): an "Image mode" selector, and "Print diagnostic pattern" / "Print diagnostic pattern (tiny)" buttons that print a known vertical-stripe test pattern at two payload sizes — used to pin down exactly how a printer garbles image output, independent of any real source image.
  • Document the investigation above as a new gotcha (docs/notes/13, referenced from AGENTS.md and README.md): on the MTP-II/MP58C7 clone family, image printing over Bluetooth is unreliable regardless of imageMode, BLE write chunk size, or inter-write pacing. The same encoded bytes print correctly over Serial/USB, so that's the recommended transport for image content on this hardware family.
  • Add a regression test (test/Images/image.test.ts) asserting the actual emitted command bytes differ between the two imageMode values (ESC 3 36/ESC * 33 for column vs. GS v 0 for raster), closing a gap where no test previously checked image command bytes at all.

@GomdimApps
GomdimApps merged commit 6460254 into main Sep 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant