USB transport addon: support for alternate interfaces.

* Tested with a Profilic USB-Parallel adapter and a Laserjet printer.
This commit is contained in:
Jérôme Duval
2012-05-03 22:25:40 +02:00
parent 408c7ab11d
commit 91bc463512
@@ -112,29 +112,37 @@ USBPrinterRoster::DeviceAdded(BUSBDevice *dev)
// Try to find a working printer interface in this device // Try to find a working printer interface in this device
if (config) { if (config) {
for (uint32 idx = 0; printer == NULL && idx < config->CountInterfaces(); idx++) { for (uint32 idx = 0; printer == NULL
&& idx < config->CountInterfaces(); idx++) {
const BUSBInterface *interface = config->InterfaceAt(idx); const BUSBInterface *interface = config->InterfaceAt(idx);
if (interface->Class() == PRINTER_INTERFACE_CLASS for (uint32 alt = 0; alt < interface->CountAlternates(); alt++) {
&& interface->Subclass() == PRINTER_INTERFACE_SUBCLASS const BUSBInterface *alternate = interface->AlternateAt(alt);
&& (interface->Protocol() == PIT_UNIDIRECTIONAL if (alternate->Class() == PRINTER_INTERFACE_CLASS
|| interface->Protocol() == PIT_BIDIRECTIONAL && alternate->Subclass() == PRINTER_INTERFACE_SUBCLASS
|| interface->Protocol() == PIT_1284_4_COMPATIBLE)) { && (alternate->Protocol() == PIT_UNIDIRECTIONAL
// Found a usable Printer interface! || alternate->Protocol() == PIT_BIDIRECTIONAL
for (uint32 endpointIdx = 0; endpointIdx < interface->CountEndpoints(); endpointIdx++) { || alternate->Protocol() == PIT_1284_4_COMPATIBLE)) {
const BUSBEndpoint *endpoint = interface->EndpointAt(endpointIdx); // Found a usable Printer interface!
if (!endpoint->IsBulk()) for (uint32 endpointIdx = 0;
continue; endpointIdx < alternate->CountEndpoints();
endpointIdx++) {
const BUSBEndpoint *endpoint =
alternate->EndpointAt(endpointIdx);
if (!endpoint->IsBulk())
continue;
if (endpoint->IsInput()) if (endpoint->IsInput())
in = endpoint; in = endpoint;
else if (endpoint->IsOutput()) else if (endpoint->IsOutput())
out = endpoint; out = endpoint;
if (!in || !out) if (!in || !out)
continue; continue;
printer = interface; printer = alternate;
break; ((BUSBInterface*)interface)->SetAlternate(alt);
break;
}
} }
} }
} }