feat: add imageMode configuration option for raster and column image … - #7
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
@point-of-sale/receipt-printer-encoderdefaults to the legacy
ESC *"column" band format unless arecognized
printerModelis set, and only then switches to thesingle-shot
GS v 0"raster" format. This project never exposedthat knob, so it was always silently on
columnfor unrecognizedprinters. Turned out not to be the cause here: forcing
rasterproduced byte-for-byte identical corruption on this hardware.
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.
corrupted the same way as a full-size photo.
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
imageModeknob anyway, since it'sa legitimate config option other clone printers may need even though
it wasn't the fix here.
Summary
imageMode: 'column' | 'raster'config option (constructor and per-job), passed straight through toReceiptPrinterEncoder— lets consumers force the single-shotGS v 0raster wire format instead of the encoder's default legacyESC *column/band format, for clone printers whose firmware handles one better than the other.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.docs/notes/13, referenced fromAGENTS.mdandREADME.md): on the MTP-II/MP58C7 clone family, image printing over Bluetooth is unreliable regardless ofimageMode, 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.test/Images/image.test.ts) asserting the actual emitted command bytes differ between the twoimageModevalues (ESC 3 36/ESC * 33forcolumnvs.GS v 0forraster), closing a gap where no test previously checked image command bytes at all.