Skip to content

Adapted for linux. #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# Application Generated Files #
###############################
*.cfg
.*

# Logs and databases #
######################
Expand Down Expand Up @@ -78,4 +79,4 @@ CVS

# Folders starting with underscore. #
#####################################
_*
_*
75 changes: 75 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#
# Makefile for Libusbpp
#
#

NAME = libusbpp
INCLUDE_PATH = ./headers

#
# Compiler
#
# By default, the GNU C++ compiler is used.
#

COMPILER = g++
LINKER = g++

#
# Compiler and linker flags
#
# This variable holds the flags that are passed to the compiler. By default,
# we include the -O2 flag. This flag tells the compiler to optimize the code,
# but it makes debugging more difficult. So if you're debugging your application,
# you probably want to remove this -O2 flag. At the same time, you can then
# add the -g flag to instruct the compiler to include debug information in
# the library (but this will make the final file much bigger, so
# you want to leave that flag out on production servers).
#
#COMPILER_FLAGS = -Wall -c -ggdb3 -fpic -I${INCLUDE_PATH} -o
COMPILER_FLAGS = -Wall -c -O2 -fpic -I${INCLUDE_PATH} -o
LINKER_FLAGS = -lusb-1.0 -lpthread

#
# Command to remove files, copy files and create directories.
#

RM = rm -f
CP = cp -f
MKDIR = mkdir -p
LS = ls -1

#
# All source files are simply all *.cpp files found in the current directory
#
# A builtin Makefile macro is used to scan the current directory and find
# all source files. The object files are all compiled versions of the source
# file, with the .cpp extension being replaced by .o.
#

SOURCES = $(wildcard ./src/*.cpp)
HEARDERS = $(wildcard ./src/*.hpp)
EXAMPELS = $(wildcard ./examples/*.cpp)
OBJECTS = $(SOURCES:%.cpp=%.o) $(EXAMPELS:%.cpp=%.o)
EXECUTABLES = $(EXAMPELS:%.cpp=%)

#
# From here the build instructions start
#
all: ${EXECUTABLES} ${OBJECTS} ${SOURCES} ${HEARDERS} ${EXAMPELS}
echo ${EXECUTABLES} ${OBJECTS} ${SOURCES} ${HEARDERS} ${EXAMPELS}

${OBJECTS}: ${SOURCES} ${HEARDERS} ${EXAMPELS}
${COMPILER} ${COMPILER_FLAGS} $@ ${@:%.o=%.cpp}

${EXECUTABLES}: ${OBJECTS}
${LINKER} -o $@ ${OBJECTS} ${LINKER_FLAGS}

test: .TEST

.TEST:
./examples/LibusbTest

clean:
echo ${RM} ${OBJECTS}
${RM} ${OBJECTS}
6 changes: 5 additions & 1 deletion src/ConfigurationImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
#include <string>
#include <map>

#include <libusb.h>
#ifdef __linux__
#include <libusb-1.0/libusb.h>
#elif _WIN32
#include <libusb.h>
#endif

#include <libusbpp/Interface.hpp>

Expand Down
8 changes: 6 additions & 2 deletions src/DeviceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
#include <sstream>
#include <cstring>

#include <libusb.h>
#ifdef __linux__
#include <libusb-1.0/libusb.h>
#elif _WIN32
#include <libusb.h>
#endif

#include <libusbpp/Configuration.hpp>
#include <libusbpp/Endpoint.hpp>
Expand Down Expand Up @@ -155,7 +159,7 @@ std::wstring LibUSB::DeviceImpl::getStringDescriptorW( uint8_t index )
std::wstring strResult;
strResult.resize((descSize-2)/2);

for (size_t i = 0; i < (descSize-2)/2; ++i) {
for (int i = 0; i < (descSize-2)/2; ++i) {
unsigned char chr1 = (unsigned char)descStr[2 * i + 2];
unsigned char chr2 = (unsigned char)descStr[2 * i + 3];

Expand Down
6 changes: 5 additions & 1 deletion src/DeviceImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
#include <string>
#include <map>

#include <libusb.h>
#ifdef __linux__
#include <libusb-1.0/libusb.h>
#elif _WIN32
#include <libusb.h>
#endif

#include <libusbpp/Device.hpp>

Expand Down
6 changes: 5 additions & 1 deletion src/EndpointImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
#include <memory>
#include <stdint.h>

#include <libusb.h>
#ifdef __linux__
#include <libusb-1.0/libusb.h>
#elif _WIN32
#include <libusb.h>
#endif

#include <libusbpp/EndpointDefs.hpp>
#include <libusbpp/Transfer.hpp>
Expand Down
6 changes: 5 additions & 1 deletion src/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

#include <sstream>

#include <libusb.h>
#ifdef __linux__
#include <libusb-1.0/libusb.h>
#elif _WIN32
#include <libusb.h>
#endif

#include <libusbpp/Exception.hpp>

Expand Down
7 changes: 5 additions & 2 deletions src/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
* along with libusbpp. If not, see <http://www.gnu.org/licenses/>.
*/

#include <libusb.h>
#ifdef __linux__
#include <libusb-1.0/libusb.h>
#elif _WIN32
#include <libusb.h>
#endif

#include <libusbpp/Interface.hpp>

Expand Down Expand Up @@ -131,4 +135,3 @@ bool LibUSB::Interface::isClaimed() const

return m_pInterfaceImpl->isClaimed();
}

2 changes: 1 addition & 1 deletion src/InterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


LibUSB::InterfaceImpl::InterfaceImpl( const libusb_interface* pInterface, std::weak_ptr<DeviceImpl> pDeviceImpl )
: m_pInterface(pInterface), m_alternateSetting(0), m_bClaimed(false)
: m_alternateSetting(0), m_pInterface(pInterface), m_bClaimed(false)
{

if (!pDeviceImpl.expired())
Expand Down
8 changes: 6 additions & 2 deletions src/InterfaceImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
#include <memory>
#include <map>

#include <libusb.h>
#ifdef __linux__
#include <libusb-1.0/libusb.h>
#elif _WIN32
#include <libusb.h>
#endif

#include <libusbpp/Endpoint.hpp>

Expand Down Expand Up @@ -74,7 +78,7 @@ namespace LibUSB

/*!
* \brief Selects an alternate interface setting.
*
*
*
* \param AlternateSetting (uint8_t): the index of the alternate setting to select/use.
* \throws (std::logic_error) if the alternate setting is out-of-range.
Expand Down
6 changes: 5 additions & 1 deletion src/LibusbImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
#include <atomic>
#include <condition_variable>

#include <libusb.h>
#ifdef __linux__
#include <libusb-1.0/libusb.h>
#elif _WIN32
#include <libusb.h>
#endif


namespace LibUSB
Expand Down
2 changes: 1 addition & 1 deletion src/Transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void LibUSB::Transfer::AsyncStart()

std::thread transferThread([=]()
{
bool Result = false;
//bool Result = false;

try
{
Expand Down
2 changes: 1 addition & 1 deletion src/TransferImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


LibUSB::TransferImpl::TransferImpl(std::weak_ptr<EndpointImpl> pEndpointImpl)
: m_Timeout(0), m_Complete(false), m_Submitted(false), m_transferSize(0)
: m_Timeout(0), m_transferSize(0), m_Complete(false), m_Submitted(false)
{

if (pEndpointImpl.expired())
Expand Down
6 changes: 5 additions & 1 deletion src/TransferImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
#include <map>
#include <atomic>

#include <libusb.h>
#ifdef __linux__
#include <libusb-1.0/libusb.h>
#elif _WIN32
#include <libusb.h>
#endif

#include <libusbpp/TransferDefs.hpp>
#include <libusbpp/Transfer.hpp>
Expand Down