Skip to content

Commit e1bd20f

Browse files
committed
Added "usb-send-delay" quirk
This quirk introduces some configurable pause after each USB URB has been sent to the device. Looks like some HP devices may fail large jobs in raster format, if data is transmitted too quickly from the host to the printer. This quirk effectively adds some transmission throttling. See #95 for discussion and details.
1 parent 6c926a1 commit e1bd20f

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

quirks.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const (
4747
QuirkNmUsbMaxInterfaces = "usb-max-interfaces"
4848
QuirkNmZlpRecvHack = "zlp-recv-hack"
4949
QuirkNmZlpSend = "zlp-send"
50+
QuirkNmUSBSendDelay = "usb-send-delay"
5051
)
5152

5253
// quirkParse maps quirk names into appropriate parsing methods,
@@ -64,6 +65,7 @@ var quirkParse = map[string]func(*Quirk) error{
6465
QuirkNmUsbMaxInterfaces: (*Quirk).parseUint,
6566
QuirkNmZlpRecvHack: (*Quirk).parseBool,
6667
QuirkNmZlpSend: (*Quirk).parseBool,
68+
QuirkNmUSBSendDelay: (*Quirk).parseDuration,
6769
}
6870

6971
// quirkDefaultStrings contains default values for quirks, in
@@ -371,6 +373,12 @@ func (quirks Quirks) GetZlpSend() bool {
371373
return quirks.Get(QuirkNmZlpSend).Parsed.(bool)
372374
}
373375

376+
// GetUSBSendDelay returns effective "usb-send-delay" parameter
377+
// taking the whole set into consideration.
378+
func (quirks Quirks) GetUSBSendDelay() time.Duration {
379+
return quirks.Get(QuirkNmUSBSendDelay).Parsed.(time.Duration)
380+
}
381+
374382
// QuirksSet represents collection of quirks
375383
type QuirksSet []*Quirks
376384

usbio_libusb.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,11 @@ func (iface *UsbInterface) Send(ctx context.Context,
809809
<-doneChan
810810
n, err = libusbTransferStatusDecode(ctx, xfer)
811811

812+
// Introduce inter-URB send delay, if configured
813+
if delay := iface.quirks.GetUSBSendDelay(); delay != 0 {
814+
time.Sleep(delay)
815+
}
816+
812817
return
813818
}
814819

0 commit comments

Comments
 (0)