Skip to content

Add USB transport support#41

Open
cal-brmmr wants to merge 1 commit into
eljojo:mainfrom
cal-brmmr:add-usb-transport
Open

Add USB transport support#41
cal-brmmr wants to merge 1 commit into
eljojo:mainfrom
cal-brmmr:add-usb-transport

Conversation

@cal-brmmr
Copy link
Copy Markdown

Summary

Adds a UsbTransport for USB printer class devices (e.g. /dev/usb/lp0) alongside the existing BluetoothTransport. USB printer devices don't support TTY ioctls (tcgetattr/tcdrain), so this transport skips all TTY configuration and uses simple flush() pacing instead.

Changes

New: src/transport/usb.rs

  • UsbTransport struct that opens device files in write-only mode
  • Writes data in 4KB chunks with flush() between each (no tcdrain)
  • write_all() and send_programs() matching BluetoothTransport interface
  • JOB_DELAY_MS pause between programs (same as Bluetooth)

New: Transport trait in src/transport/mod.rs

  • Common trait implemented by both BluetoothTransport and UsbTransport
  • open_transport(device) helper that auto-detects:
    • Path contains rfcommBluetoothTransport (TTY config + tcdrain)
    • Everything else → UsbTransport (no TTY ioctls)

Updated: src/main.rs + server handlers

  • All BluetoothTransport::open() calls replaced with transport::open_transport()
  • Transparent: existing Bluetooth users see no behavior change
  • USB users (e.g. --device /dev/usb/lp0) now work automatically

Why

The current Bluetooth transport uses tcgetattr/tcsetattr/tcdrain which fail on USB printer devices with "Inappropriate ioctl for device". USB printer class devices (/dev/usb/lp*) are not TTY devices and need a simpler write path.

Testing

  • Compiles with cargo build --release --no-default-features
  • Bluetooth path unchanged (auto-detected by rfcomm in device path)
  • USB path tested with /dev/usb/lp0 on a Star TSP143

Add a UsbTransport for USB printer class devices (e.g. /dev/usb/lp0)
that don't support TTY ioctls like tcgetattr/tcdrain.

Changes:
- Add src/transport/usb.rs: UsbTransport that opens devices in
  write-only mode, writes in chunks with flush() pacing (no tcdrain),
  and supports send_programs() with JOB_DELAY_MS between jobs
- Add Transport trait in src/transport/mod.rs with open_transport()
  helper that auto-detects: rfcomm paths use BluetoothTransport,
  everything else uses UsbTransport
- Update main.rs and all server handlers to use open_transport()
  instead of directly constructing BluetoothTransport

This enables estrella to work with Star printers connected via USB
in addition to Bluetooth RFCOMM.
@eljojo
Copy link
Copy Markdown
Owner

eljojo commented Mar 17, 2026

@cal-brmmr hey! amazing work! I've authorized CI to run, I see that linting needs to be fixed, but the code looks good to me! would you mind addressing?

great implementation, I like that it's automatic.

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.

2 participants