Skip to content

Commit

Permalink
Merge pull request #1 from sensestage/master
Browse files Browse the repository at this point in the history
report descriptor parser
  • Loading branch information
tonyrog committed Sep 14, 2013
2 parents 193637b + 14e6389 commit d3a31ae
Show file tree
Hide file tree
Showing 29 changed files with 3,078 additions and 73 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
Makefile.in
aclocal.m4
autom4te.cache/
config.guess
config.h.in
config.sub
config.*
configure
depcomp
install-sh
Expand All @@ -18,8 +16,5 @@ testgui/Makefile.in
windows/Makefile.in

Makefile
config.h
config.log
config.status
stamp-h1
libtool
74 changes: 74 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
cmake_minimum_required(VERSION 2.8)

project(hidapi)

set(VERSION_MAJOR "0")
set(VERSION_MINOR "7")
set(VERSION_PATCH "1")
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")


option(DEBUG_PARSER "verbose parser debuggint output" OFF)

option(LIBUSB "use libusb backend" OFF)
option(HIDRAW "use hidraw backend (linux/freebsd)" ON)

option(EXAMPLE_TEST "build test example" ON)
option(EXAMPLE_OSC "build osc example" ON)


# add our own cmake-modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake_modules/")

if( DEBUG_PARSER )
add_definitions( -DDEBUG_PARSER )
endif()

# some default libraries
if (NOT WIN32)
find_package(Pthreads)
if (NOT PTHREADS_FOUND)
message(SEND_ERROR "cannot find libpthreads")
endif()
endif()


# directories
add_subdirectory(hidapi)

if(LIBUSB)
add_subdirectory(libusb)
# set( hidapi_source ${hidapi_SOURCE_DIR}/libusb )
link_directories( ${LIBUSB_1_LIBRARIES} ${PTHREADS_LIBRARIES} )
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND HIDRAW)
add_subdirectory(linux)
# set( hidapi_source ${hidapi_SOURCE_DIR}/linux )
link_directories( ${UDEV_LIBRARIES} )
endif()

if(WIN32)
add_subdirectory(windows)
# set( hidapi_source ${hidapi_SOURCE_DIR}/windows )
#todo: add library dependencies
endif()
if(APPLE)
add_subdirectory(mac)
# set( hidapi_source ${hidapi_SOURCE_DIR}/mac )
#todo: add library dependencies - TEST
link_directories("-framework IOKit -framework CoreFoundation")
endif()

add_subdirectory(hidapi_parser)

# message( "main: hidapi source dir: ${hidapi_source}" )

if( EXAMPLE_TEST )
add_subdirectory(hidtest)
add_subdirectory(hidparsertest)
endif()

if( EXAMPLE_OSC )
add_subdirectory(hidapi2osc)
endif()
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ if OS_WINDOWS
SUBDIRS += windows
endif

# SUBDIRS += hidapi_parser
SUBDIRS += hidparsertest
SUBDIRS += hidapi2osc
SUBDIRS += hidtest


if BUILD_TESTGUI
SUBDIRS += testgui
endif
Expand Down
33 changes: 32 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
HIDAPI + parser library for Windows, Linux, FreeBSD and Mac OS X
=========================================================
This version [1] is an extension of the original HIDAPI library, based on Tony Roggs fork [2],
which reads the report descriptor of the device.

The main addition is a parser which parses the retrieved report descriptor, populates a struct
with the element descriptors, and finally provides a data parsing function based on this.

In addition, a CMake build system has been made.

Some test examples are available:
* hidparsertest will list all devices and optionally open one, displaying the element information, and the incoming data
* hidapi2osc will send out the data via OSC (OpenSoundControl), and provides an OSC interface for listing, opening and closing devices (see the supercollider script for testing the interface)

[1] https://github.com/sensestage/hidapi
[2] https://github.com/tonyrog/hidapi

TODO:
- creating + sending output reports
- creating + sending/reading + parsing feature reports
- reading windows report descriptor
- cmake lists for OSX, Windows and FreeBSD


Copyright (C) 2013, Marije Baalman <nescivi _at_ gmail.com>
This work was funded by a crowd-funding initiative for SuperCollider's [1] HID implementation
including a substantial donation from BEK, Bergen Center for Electronic Arts, Norway

[1] http://supercollider.sourceforge.net
[2] http://www.bek.no

HIDAPI library for Windows, Linux, FreeBSD and Mac OS X
=========================================================

Expand Down Expand Up @@ -154,7 +185,7 @@ Prerequisites:

If you downloaded the source directly from the git repository (using
git clone), you'll need Autotools:
sudo apt-get install autotools-dev
sudo apt-get install autotools-dev autoconf automake libtool

FreeBSD:
---------
Expand Down
43 changes: 43 additions & 0 deletions cmake_modules/FindIConv.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Find iconv library
#
# Author: Eddy Xu <eddyxu at gmail.com>
#
# Released under BSD license
#
# ICONV_INCLUDE_DIRS - where to find iconv.h, etc
# ICONV_LIBRARIES - Lists of libraries when using iconv
# ICONV_FOUND - True if iconv found


# Look for the header file
FIND_PATH( ICONV_INCLUDE_DIR NAMES iconv.h )
MARK_AS_ADVANCED( ICONV_INCLUDE_DIR )

# Look for the library
FIND_LIBRARY( ICONV_LIBRARY NAMES iconv )
MARK_AS_ADVANCED( ICONV_LIBRARY )

# Copy the result to output variables
IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARY)
SET(ICONV_FOUND 1)
SET(ICONV_LIBRARIES ${ICONV_LIBRARY})
SET(ICONV_INCLUDE_DIRS ${ICONV_INCLUDE_DIR})
ELSE(ICONV_INCLUDE_DIR AND ICONV_LIBRARY)
SET(ICONV_FOUND 0)
SET(ICONV_LIBRARIES)
SET(ICONV_INCLUDE_DIRS)
ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARY)

# Report results
IF(NOT ICONV_FOUND)
SET(ICONV_DIR_MESSAGE
"Iconv was not found. Make sure ICONV_LIBRARY and ICONV_INCLUDE_DIR are
set.")
IF(NOT ICONV_FIND_QUIETLY)
MESSAGE(STATUS ${ICONV_DIR_MESSAGE})
ELSE(NOT ICONV_FIND_QUIETLY)
IF(ICONV_FIND_REQUIRED)
MESSAGE(FETAL_ERROR ${ICONV_DIR_MESSAGE})
ENDIF(ICONV_FIND_REQUIRED)
ENDIF(NOT ICONV_FIND_QUIETLY)
ENDIF(NOT ICONV_FOUND)
104 changes: 104 additions & 0 deletions cmake_modules/FindPthreads.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# - Find the Pthreads library
# This module searches for the Pthreads library (including the
# pthreads-win32 port).
#
# This module defines these variables:
#
# PTHREADS_FOUND
# True if the Pthreads library was found
# PTHREADS_LIBRARY
# The location of the Pthreads library
# PTHREADS_INCLUDE_DIR
# The include directory of the Pthreads library
# PTHREADS_DEFINITIONS
# Preprocessor definitions to define (HAVE_PTHREAD_H is a fairly common
# one)
#
# This module responds to the PTHREADS_EXCEPTION_SCHEME
# variable on Win32 to allow the user to control the
# library linked against. The Pthreads-win32 port
# provides the ability to link against a version of the
# library with exception handling. IT IS NOT RECOMMENDED
# THAT YOU CHANGE PTHREADS_EXCEPTION_SCHEME TO ANYTHING OTHER THAN
# "C" because most POSIX thread implementations do not support stack
# unwinding.
#
# PTHREADS_EXCEPTION_SCHEME
# C = no exceptions (default)
# (NOTE: This is the default scheme on most POSIX thread
# implementations and what you should probably be using)
# CE = C++ Exception Handling
# SE = Structure Exception Handling (MSVC only)
#

#
# Define a default exception scheme to link against
# and validate user choice.
#

IF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
SET(PTHREADS_DEFINITIONS -DHAVE_PTHREAD_H)
SET(PTHREADS_INCLUDE_DIRS ${PTHREADS_INCLUDE_DIR})
SET(PTHREADS_LIBRARIES ${PTHREADS_LIBRARY})
SET(FOUND_PTHREADS TRUE)
ENDIF()

IF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
# Assign default if needed
SET(PTHREADS_EXCEPTION_SCHEME "C")
ELSE(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
# Validate
IF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")

MESSAGE(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed")

ENDIF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")

IF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
MESSAGE(FATAL_ERROR "Structured Exception Handling is only allowed for MSVC")
ENDIF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")

ENDIF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)

#
# Find the header file
#
FIND_PATH(PTHREADS_INCLUDE_DIR pthread.h)

#
# Find the library
#
SET(names)
IF(MSVC)
SET(names
pthreadV${PTHREADS_EXCEPTION_SCHEME}2
pthread
)
ELSEIF(MINGW)
SET(names
pthreadG${PTHREADS_EXCEPTION_SCHEME}2
pthread
)
ELSE(MSVC) # Unix / Cygwin / Apple / Etc.
SET(names pthread)
ENDIF(MSVC)

FIND_LIBRARY(PTHREADS_LIBRARY NAMES ${names}
DOC "The Portable Threads Library")

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Pthreads DEFAULT_MSG
PTHREADS_LIBRARY PTHREADS_INCLUDE_DIR)

IF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
SET(PTHREADS_DEFINITIONS -DHAVE_PTHREAD_H)
SET(PTHREADS_INCLUDE_DIRS ${PTHREADS_INCLUDE_DIR})
SET(PTHREADS_LIBRARIES ${PTHREADS_LIBRARY})
ENDIF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)

MARK_AS_ADVANCED(PTHREADS_INCLUDE_DIR)
MARK_AS_ADVANCED(PTHREADS_LIBRARY)
53 changes: 53 additions & 0 deletions cmake_modules/FindUDev.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# razor-de: Configure libudev environment
#
# UDEV_FOUND - system has a libudev
# UDEV_INCLUDE_DIR - where to find header files
# UDEV_LIBRARIES - the libraries to link against udev
# UDEV_STABLE - it's true when is the version greater or equals to 143 - version when the libudev was stabilized in its API
#
# copyright (c) 2011 Petr Vanek <[email protected]>
# Redistribution and use is allowed according to the terms of the BSD license.
#

FIND_PATH(
UDEV_INCLUDE_DIR
libudev.h
/usr/include
/usr/local/include
${UDEV_PATH_INCLUDES}
)

FIND_LIBRARY(
UDEV_LIBRARIES
NAMES udev libudev
PATHS
/usr/lib${LIB_SUFFIX}
/usr/local/lib${LIB_SUFFIX}
${UDEV_PATH_LIB}
)

IF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR)
SET(UDEV_FOUND "YES")
execute_process(COMMAND pkg-config --atleast-version=143 libudev RESULT_VARIABLE UDEV_STABLE)
# retvale is 0 of the condition is "true" so we need to negate the value...
if (UDEV_STABLE)
set(UDEV_STABLE 0)
else (UDEV_STABLE)
set(UDEV_STABLE 1)
endif (UDEV_STABLE)
message(STATUS "libudev stable: ${UDEV_STABLE}")
ENDIF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR)

IF (UDEV_FOUND)
MESSAGE(STATUS "Found UDev: ${UDEV_LIBRARIES}")
MESSAGE(STATUS " include: ${UDEV_INCLUDE_DIR}")
ELSE (UDEV_FOUND)
MESSAGE(STATUS "UDev not found.")
MESSAGE(STATUS "UDev: You can specify includes: -DUDEV_PATH_INCLUDES=/opt/udev/include")
MESSAGE(STATUS " currently found includes: ${UDEV_INCLUDE_DIR}")
MESSAGE(STATUS "UDev: You can specify libs: -DUDEV_PATH_LIB=/opt/udev/lib")
MESSAGE(STATUS " currently found libs: ${UDEV_LIBRARIES}")
IF (UDev_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find UDev library")
ENDIF (UDev_FIND_REQUIRED)
ENDIF (UDEV_FOUND)
Loading

0 comments on commit d3a31ae

Please sign in to comment.