This example demonstrates how to use the EspUsbHost library to control a USB receipt printer (e.g., Xprinter XP-C58K) using the ESC/POS command language. It covers printing Japanese text (Shift-JIS), barcodes, QR codes, and using the auto-cutter.
Key Components
PrinterProtocol.hpp: Defines USB Printer class requests (GET_DEVICE_ID, GET_PORT_STATUS, SOFT_RESET) and IEEE 1284 device ID parsing.EscPos.hpp: A command builder for ESC/POS with range checking and real-time status handling.PrinterDevice.hpp: Handles device discovery, USB interface claiming via Vendor Bulk API, and data transmission.ReceiptJa.hpp: Provides Shift-JIS encoded byte arrays for Japanese receipt layouts.EspUsbHostPrinterEscPos.ino: The main entry point for connecting, checking status, and printing a sample receipt.
// Example usage pattern from EspUsbHostPrinterEscPos.ino
// 1. Open the interface using Vendor Bulk API
// Note: interfaceNumber is explicitly provided to allow claiming non-vendor (0x07) classes.
// READ_ON_DEMAND is used because status is read only on request.
// usb.vendorOpen(address, interfaceNumber, ESP_USB_HOST_VENDOR_READ_ON_DEMAND);
// 2. Print a receipt (sent in a single vendorWrite call to prevent stuttering/timeouts)
// usb.vendorWrite(receipt, length, address);