forked from zarthcode/Libusbpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a translator from endpoint index to number
LibUSB::InterfaceImpl::getEndpoint() throws a logic_error exception if the index and endpoint number are not equal. This presents a problem communicating with a USB device, based on the Cypress CY7C68001 chip which only implements endpoint numbers 2, 4, 6 and 8 in addition to 0. Libusbpp had incorrectly made a assumption that all USB devices have linear endpoint numbering. The Libusbpp should be handled the linear and non linear numbering in same way. LibUSB::Interface{Impl}::getEndpoint() has been refectored to expect a number (not a index) explicitly. LibUSB::Interface{Impl}::getEPNumberByIndex() is a new public method to translate a given endpoint index to the corresponding endpoint number. This number can be used together with getEndpoint() to get the corresponding endpoint object in a fast way. Example: std::shared_ptr<LibUSB::Interface> pInterface = /* ... */ for (int epidx = 1; epidx <= pInterface->NumEndpoints(); epidx++) { std::shared_ptr<LibUSB::Endpoint> pEndpoint; pEndpoint = pInterface->getEndpoint( pInterface->getEPNumberByIndex(epidx) ); /* ... */ } A new use case for getEPNumberByIndex() is the creation of a map of endpoint numbers by it corresponding index as a key. Walk throught such a list gives access to all available endpoint numbers independent of a specific context. Example: typedef std::map<int, int> EndpointNumbers_t; EndpointNumbers_t mEndpointNumbers; std::shared_ptr<LibUSB::Interface> pInterface = /* ... */ for (int epidx = 1; epidx <= pInterface->NumEndpoints(); epidx++) { mEndpointNumbers.insert( std::make_pair( epidx, pInterface->getEPNumberByIndex( epidx ) ) ); } /* ... */ for (const auto &epnum : mEndpointNumbers) { std::shared_ptr<LibUSB::Endpoint> pEndpoint; pEndpoint =pInterface->getEndpoint(epnum.second); /* ... */ } Based on this concept the interface class provides the new public method LibUSB::Interface::getEndpointNumbers() to reduce the effort for the user. Example (the same as befor, but just simpler): std::shared_ptr<LibUSB::Interface> pInterface = /* ... */ LibUSB::Interface::EndpointNumbers_t mEndpointNumbers; mEndpointNumbers = pInterface->getEndpointNumbers(); /* ... */ for (const auto &epnum : mEndpointNumbers) { std::shared_ptr<LibUSB::Endpoint> pEndpoint; pEndpoint =pInterface->getEndpoint(epnum.second); /* ... */ } Related-to-issue: zarthcode#3 Signed-off-by: Stephan Linz <[email protected]>
- Loading branch information
Showing
5 changed files
with
89 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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