Merge pull request #30 from lysannkessler/osx-refactor_sync-mplus
Synchronous motion plus init & OSX Refactoring. Incorporates work by lysannkessler, janoc, and jscasallas.
This commit is contained in:
@@ -57,6 +57,7 @@ Additional Contributors:
|
||||
- Jan Ciger - Reviatech SAS <jan.ciger@reviatech.com>
|
||||
- Gabriele Randelli and the WiiC project <http://wiic.sourceforge.net/>
|
||||
- Juan Sebastian Casallas <https://github.com/jscasallas/wiiuse>
|
||||
- Lysann Schlegel <https://github.com/lysannkessler/wiiuse>
|
||||
|
||||
|
||||
License
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
# need to call:
|
||||
# include(BoostTestTargets)
|
||||
#
|
||||
# For more information, see the documentation for individual modules, the
|
||||
# For more information, see the documentation for individual modules, the
|
||||
# cmake-modules github page, and/or the upstream CMake documentation at
|
||||
# http://www.cmake.org/cmake/help/cmake-2-8-docs.html
|
||||
#
|
||||
|
||||
@@ -31,7 +31,7 @@ function(_osgbundle_split_debug_versions releasevar debugvar)
|
||||
set(debug)
|
||||
foreach(fn ${ARGN})
|
||||
get_filename_component(name "${fn}" NAME_WE)
|
||||
if(${name} MATCHES "d$")
|
||||
if("${name}" MATCHES "d$")
|
||||
list(APPEND debug "${fn}")
|
||||
else()
|
||||
list(APPEND release "${fn}")
|
||||
@@ -75,9 +75,21 @@ endif()
|
||||
function(install_osg_plugins var)
|
||||
set(INSTALLEDPLUGINS)
|
||||
foreach(plugin ${OSGDB_PLUGINS_RELEASE} ${OSGWRAPPER_PLUGINS_RELEASE})
|
||||
install(FILES "${plugin}" DESTINATION "${OSG_PATH_TO_PLUGINS}")
|
||||
install(FILES "${plugin}"
|
||||
DESTINATION "${OSG_PATH_TO_PLUGINS}"
|
||||
CONFIGURATIONS Release RelWithDebInfo MinSizeRel)
|
||||
get_filename_component(name "${plugin}" NAME)
|
||||
list(APPEND INSTALLEDPLUGINS "${OSG_PATH_TO_PLUGINS}/${name}")
|
||||
endforeach()
|
||||
foreach(plugin ${OSGDB_PLUGINS_DEBUG} ${OSGWRAPPER_PLUGINS_DEBUG})
|
||||
install(FILES
|
||||
"${plugin}"
|
||||
DESTINATION
|
||||
"${OSG_PATH_TO_PLUGINS}"
|
||||
CONFIGURATIONS
|
||||
Debug)
|
||||
#get_filename_component(name "${plugin}" NAME)
|
||||
#list(APPEND INSTALLEDPLUGINS "${OSG_PATH_TO_PLUGINS}/${name}")
|
||||
endforeach()
|
||||
set(${var} ${INSTALLEDPLUGINS} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
@@ -35,8 +35,6 @@ int main(int argc, char* argv[]) {
|
||||
#if defined(__APPLE__)
|
||||
io_object_t _ioObject;
|
||||
IOHIDDeviceInterface122 **_interface;
|
||||
bool _gotdata;
|
||||
int _gotsize;
|
||||
unsigned char _buffer[512];
|
||||
IOReturn result = (*_interface)->setInterruptReportHandlerCallback(_interface,
|
||||
_buffer, 512,
|
||||
|
||||
@@ -165,7 +165,7 @@ function(create_dashboard_scripts)
|
||||
endif()
|
||||
|
||||
set(_msg)
|
||||
|
||||
|
||||
if(NOT DASHBOARDSCRIPT_BUILD_CONFIGURATION)
|
||||
set(DASHBOARDSCRIPT_BUILD_CONFIGURATION "RelWithDebInfo")
|
||||
endif()
|
||||
|
||||
@@ -97,7 +97,7 @@ macro(_launcher_system_settings)
|
||||
set(LAUNCHERS_GOT_GDB YES)
|
||||
if(GDB_HAS_RETURN_CHILD_RESULT)
|
||||
set(LAUNCHERS_GDB_ARG --return-child-result)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
set(LAUNCHERS_GOT_GDB)
|
||||
endif()
|
||||
|
||||
@@ -213,6 +213,7 @@ function(add_doxygen _doxyfile)
|
||||
else()
|
||||
add_custom_target(${DOC_TARGET} ALL)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
if(NOT IS_ABSOLUTE "${OUTPUT_DIRECTORY}")
|
||||
@@ -228,6 +229,28 @@ function(add_doxygen _doxyfile)
|
||||
"${OUTPUT_DIRECTORY}/html"
|
||||
"${OUTPUT_DIRECTORY}/latex")
|
||||
|
||||
if(NOT TARGET ${DOC_TARGET}_open)
|
||||
# Create a target to open the generated HTML file.
|
||||
if(WIN32)
|
||||
set(DOXYGEN_LAUNCHER_COMMAND start "Documentation")
|
||||
elseif(NOT APPLE)
|
||||
set(DOXYGEN_LAUNCHER_COMMAND xdg-open)
|
||||
endif()
|
||||
if(DOXYGEN_LAUNCHER_COMMAND)
|
||||
add_custom_target(${DOC_TARGET}_open
|
||||
COMMAND ${DOXYGEN_LAUNCHER_COMMAND} "${OUTPUT_DIRECTORY}/html/index.html")
|
||||
set_target_properties(${DOC_TARGET}_open
|
||||
PROPERTIES
|
||||
EXCLUDE_FROM_ALL
|
||||
TRUE)
|
||||
set_target_properties(${DOC_TARGET}_open
|
||||
PROPERTIES
|
||||
EXCLUDE_FROM_DEFAULT_BUILD
|
||||
TRUE)
|
||||
add_dependencies(${DOC_TARGET}_open ${DOC_TARGET})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
get_filename_component(_doxyfileabs "${_doxyfile}" ABSOLUTE)
|
||||
get_filename_component(INCLUDE_FILE "${_doxyfileabs}" NAME)
|
||||
get_filename_component(INCLUDE_PATH "${_doxyfileabs}" PATH)
|
||||
|
||||
@@ -31,8 +31,29 @@ macro(_enable_extra_compiler_warnings_flags)
|
||||
if(COMPILER_WARNINGS_EXTREME)
|
||||
set(_flags "${_flags} /Wall /wd4619 /wd4668 /wd4820 /wd4571 /wd4710")
|
||||
endif()
|
||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(_flags "-W -Wall")
|
||||
else()
|
||||
include(CheckCXXCompilerFlag)
|
||||
set(_flags)
|
||||
|
||||
check_cxx_compiler_flag(-W SUPPORTS_W_FLAG)
|
||||
if(SUPPORTS_W_FLAG)
|
||||
set(_flags "${_flags} -W")
|
||||
endif()
|
||||
|
||||
check_cxx_compiler_flag(-Wall SUPPORTS_WALL_FLAG)
|
||||
if(SUPPORTS_WALL_FLAG)
|
||||
set(_flags "${_flags} -Wall")
|
||||
endif()
|
||||
|
||||
check_cxx_compiler_flag(-Wextra SUPPORTS_WEXTRA_FLAG)
|
||||
if(SUPPORTS_WEXTRA_FLAG)
|
||||
set(_flags "${_flags} -Wextra")
|
||||
endif()
|
||||
|
||||
check_cxx_compiler_flag(-Weffc++ SUPPORTS_WEFFCXX_FLAG)
|
||||
if(SUPPORTS_WEFFCXX_FLAG)
|
||||
set(_flags "${_flags} -Weffc++")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
@@ -54,7 +54,9 @@ function(add_file_copy_target _target _dest)
|
||||
get_filename_component(fullpath "${fn}" ABSOLUTE)
|
||||
get_filename_component(fn "${fn}" NAME)
|
||||
else()
|
||||
get_filename_component(fullpath "${CMAKE_CURRENT_SOURCE_DIR}/${fn}" ABSOLUTE)
|
||||
get_filename_component(fullpath
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${fn}"
|
||||
ABSOLUTE)
|
||||
endif()
|
||||
|
||||
# Clean up output file name
|
||||
|
||||
202
cmake/FindAdrienne.cmake
Normal file
202
cmake/FindAdrienne.cmake
Normal file
@@ -0,0 +1,202 @@
|
||||
# - try to find Adrienne Electronics Corporation timecode card library
|
||||
#
|
||||
# SDK available from the manufacturer: http://www.adrielec.com/
|
||||
#
|
||||
# Cache Variables: (probably not for direct use in your scripts)
|
||||
# ADRIENNE_INCLUDE_DIR
|
||||
# ADRIENNE_LIBRARY
|
||||
# ADRIENNE_RUNTIME_LIBRARY
|
||||
# ADRIENNE_INCLUDE_FILE
|
||||
#
|
||||
# Variables you might use in your CMakeLists.txt:
|
||||
# ADRIENNE_FOUND
|
||||
# ADRIENNE_INCLUDE_DIRS
|
||||
# ADRIENNE_LIBRARIES
|
||||
# ADRIENNE_RUNTIME_LIBRARIES - the AEC_NTTC.dll file
|
||||
# ADRIENNE_RUNTIME_LIBRARY_DIRS
|
||||
#
|
||||
# ADRIENNE_INCLUDE_FILENAME - this is probably AEC_NTTC.h, but it might also
|
||||
# be AECINTTC.H.
|
||||
#
|
||||
# ADRIENNE_INCLUDE_HAS_EXTERN_C - Some (most) versions of the header already
|
||||
# wrap their definitions in extern "C" { }, but some do not.
|
||||
#
|
||||
# ADRIENNE_DEFINITIONS - defines a quoted ADRIENNE_INCLUDE_FILENAME as above,
|
||||
# so you can write a line like #include ADRIENNE_INCLUDE_FILENAME
|
||||
# Also defines ADRIENNE_BEFORE_INCLUDE and ADRIENNE_AFTER_INCLUDE to handle
|
||||
# adding extern "C" { and } if the header file doesn't do so itself.
|
||||
#
|
||||
# Variables that might be set by the user in the gui/command line to help
|
||||
# find the library:
|
||||
# ADRIENNE_ROOT_DIR - root of an Adrienne CD, disk, or extracted/copied contents
|
||||
# thereof.
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
#
|
||||
# Original Author:
|
||||
# 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# Apparently Windows only.
|
||||
if(WIN32 OR CYGWIN)
|
||||
set(ADRIENNE_ROOT_DIR
|
||||
"${ADRIENNE_ROOT_DIR}"
|
||||
CACHE
|
||||
PATH
|
||||
"Directory to search for Adrienne Electronics Timecode data - root of a software distribution or extracted download from http://www.adrielec.com/")
|
||||
|
||||
set(ADRIENNE_DEFINITIONS)
|
||||
|
||||
set(ADRIENNE_INCLUDE_SEARCH
|
||||
# from AecPCIeTC_8-12a: contains AEC_NTTC.h with extern "C" and three extra functions:
|
||||
# AEC_PCTC_OPEN_ALL, AEC_PCTC_CLOSE_ALL, AEC_PCTC_INITIALIZE_EVENT
|
||||
"SDK_SourceCode"
|
||||
|
||||
# from AecPci6_02_CD - called AECINTTC.H but otherwise essentially identical to earlier versions
|
||||
"TestPrograms_WithDLL/DLL_API_INFO"
|
||||
# A zipped development project contains essentially the same, named AEC_NTTC.h so we'll add this in case it's unzipped.
|
||||
"TestPrograms_WithDLL/ZippedDevelopmentProjects/AecMfc32_Rel504"
|
||||
|
||||
# from pc-ltc - called AECINTTC.H and lacks extern "C"
|
||||
"NT-CODE/C40-APP1"
|
||||
)
|
||||
set(ADRIENNE_HEADER_NAMES
|
||||
AEC_NTTC.H
|
||||
AEC_NTTC.h
|
||||
Aec_nttc.h
|
||||
AECINTTC.H)
|
||||
|
||||
set(ADRIENNE_LIB_SEARCH)
|
||||
set(ADRIENNE_DLL_SEARCH)
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
# 64 bit code - apparently initially packaged only in the
|
||||
# PCIe version of their software
|
||||
list(APPEND ADRIENNE_LIB_SEARCH
|
||||
# from AecPCIeTC_8-12a
|
||||
"64BitOS_files/DLL Versions")
|
||||
|
||||
list(APPEND ADRIENNE_DLL_SEARCH
|
||||
# from AecPCIeTC_8-12a
|
||||
"64BitOS_files/DLL Versions")
|
||||
else()
|
||||
# 32-bit code, much more prevalent.
|
||||
list(APPEND ADRIENNE_LIB_SEARCH
|
||||
# from AecPCIeTC_8-12a
|
||||
"32BitOS_files/DLLversions"
|
||||
|
||||
# from AecPci6_02_CD
|
||||
"TestPrograms_WithDLL/DLL_API_INFO"
|
||||
|
||||
# from pc-ltc
|
||||
"NT-CODE/DLL"
|
||||
)
|
||||
|
||||
list(APPEND ADRIENNE_DLL_SEARCH
|
||||
# from AecPCIeTC_8-12a
|
||||
"32BitOS_files/DLLversions"
|
||||
|
||||
# from AecPci6_02_CD
|
||||
"TestPrograms_WithDLL"
|
||||
|
||||
# from pc-ltc
|
||||
"NT-CODE/DLL")
|
||||
endif()
|
||||
|
||||
find_library(ADRIENNE_LIBRARY
|
||||
NAMES
|
||||
AEC_NTTC
|
||||
PATHS
|
||||
"${ADRIENNE_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${ADRIENNE_LIB_SEARCH})
|
||||
|
||||
find_path(ADRIENNE_INCLUDE_DIR
|
||||
NAMES
|
||||
${ADRIENNE_HEADER_NAMES}
|
||||
PATHS
|
||||
"${ADRIENNE_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${ADRIENNE_INCLUDE_SEARCH})
|
||||
|
||||
if(ADRIENNE_INCLUDE_DIR)
|
||||
find_file(ADRIENNE_INCLUDE_FILE
|
||||
NAMES
|
||||
${ADRIENNE_HEADER_NAMES}
|
||||
HINTS
|
||||
${ADRIENNE_INCLUDE_DIR})
|
||||
|
||||
# Get include filename
|
||||
get_filename_component(ADRIENNE_INCLUDE_FILENAME
|
||||
"${ADRIENNE_INCLUDE_FILE}"
|
||||
NAME)
|
||||
list(APPEND ADRIENNE_DEFINITIONS -DADRIENNE_INCLUDE_FILENAME="ADRIENNE_INCLUDE_FILENAME")
|
||||
|
||||
# Find out if it has extern "C" in it.
|
||||
file(STRINGS "${ADRIENNE_INCLUDE_FILE}" strings)
|
||||
set(ADRIENNE_INCLUDE_HAS_EXTERN_C OFF)
|
||||
foreach(_line ${strings})
|
||||
if("${_line}" STREQUAL "extern \"C\"")
|
||||
set(ADRIENNE_INCLUDE_HAS_EXTERN_C ON)
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(ADRIENNE_INCLUDE_HAS_EXTERN_C)
|
||||
list(APPEND ADRIENNE_DEFINITIONS -DADRIENNE_BEFORE_INCLUDE -DADRIENNE_AFTER_INCLUDE)
|
||||
else()
|
||||
list(APPEND ADRIENNE_DEFINITIONS "-DADRIENNE_BEFORE_INCLUDE=extern \"C\" {" "-DADRIENNE_AFTER_INCLUDE=}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
get_filename_component(_adrienne_libdir "${ADRIENNE_LIBRARY}" PATH)
|
||||
find_file(ADRIENNE_RUNTIME_LIBRARY
|
||||
NAMES
|
||||
AEC_NTTC.dll
|
||||
HINTS
|
||||
"${_adrienne_libdir}"
|
||||
"${_adrienne_libdir}/.."
|
||||
PATHS
|
||||
"${ADRIENNE_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${ADRIENNE_DLL_SEARCH})
|
||||
|
||||
|
||||
set(ADRIENNE_RUNTIME_LIBRARIES "${ADRIENNE_RUNTIME_LIBRARY}")
|
||||
get_filename_component(ADRIENNE_RUNTIME_LIBRARY_DIRS
|
||||
"${ADRIENNE_RUNTIME_LIBRARY}"
|
||||
PATH)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Adrienne
|
||||
DEFAULT_MSG
|
||||
ADRIENNE_LIBRARY
|
||||
ADRIENNE_RUNTIME_LIBRARY
|
||||
ADRIENNE_INCLUDE_DIR
|
||||
ADRIENNE_INCLUDE_FILENAME)
|
||||
|
||||
if(ADRIENNE_FOUND)
|
||||
set(ADRIENNE_LIBRARIES "${ADRIENNE_LIBRARY}")
|
||||
set(ADRIENNE_INCLUDE_DIRS "${ADRIENNE_INCLUDE_DIR}")
|
||||
mark_as_advanced(ADRIENNE_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(
|
||||
ADRIENNE_LIBRARY
|
||||
ADRIENNE_RUNTIME_LIBRARY
|
||||
ADRIENNE_INCLUDE_DIR
|
||||
ADRIENNE_INCLUDE_FILE)
|
||||
else()
|
||||
set(ADRIENNE_FOUND OFF)
|
||||
set(ADRIENNE_SDK_IS_WINDOWS_ONLY NOTFOUND)
|
||||
find_package_handle_standard_args(Adrienne
|
||||
DEFAULT_MSG
|
||||
ADRIENNE_SDK_IS_WINDOWS_ONLY)
|
||||
endif()
|
||||
@@ -10,7 +10,7 @@
|
||||
# Useful configuration variables you might want to add to your cache:
|
||||
# CPPDOM_ROOT_DIR - A directory prefix to search
|
||||
# (a path that contains include/ as a subdirectory)
|
||||
# CPPDOM_ADDITIONAL_VERSIONS - Additional versions (outside of 0.7.8 to 1.0.0)
|
||||
# CPPDOM_ADDITIONAL_VERSIONS - Additional versions (outside of 0.7.8 to 1.2.0)
|
||||
# to use when constructing search names and paths
|
||||
#
|
||||
# This script will use Flagpoll, if found, to provide hints to the location
|
||||
@@ -26,11 +26,11 @@
|
||||
# and trigger an automatic re-run.
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# 2009-2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2009-2010.
|
||||
# Copyright Iowa State University 2009-2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -41,6 +41,8 @@ set(_FP_PKG_NAME cppdom)
|
||||
|
||||
set(CPPDOM_VERSIONS
|
||||
${CPPDOM_ADDITIONAL_VERSIONS}
|
||||
1.3.0
|
||||
1.2.0
|
||||
1.1.2
|
||||
1.1.1
|
||||
1.1.0
|
||||
@@ -99,6 +101,28 @@ endif()
|
||||
|
||||
set(_ROOT_DIR "${CPPDOM_ROOT_DIR}")
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
set(_VRJ_LIBSUFFIXES lib64 lib)
|
||||
set(_VRJ_LIBDSUFFIXES
|
||||
debug
|
||||
lib64/x86_64/debug
|
||||
lib64/debug
|
||||
lib64
|
||||
lib/x86_64/debug
|
||||
lib/debug
|
||||
lib)
|
||||
set(_VRJ_LIBDSUFFIXES_ONLY
|
||||
debug
|
||||
lib64/x86_64/debug
|
||||
lib64/debug
|
||||
lib/x86_64/debug
|
||||
lib/debug)
|
||||
else()
|
||||
set(_VRJ_LIBSUFFIXES lib)
|
||||
set(_VRJ_LIBDSUFFIXES debug lib/i686/debug lib/debug lib)
|
||||
set(_VRJ_LIBDSUFFIXES_ONLY debug lib/i686/debug lib/debug)
|
||||
endif()
|
||||
|
||||
find_path(CPPDOM_INCLUDE_DIR
|
||||
${_HEADER}
|
||||
HINTS
|
||||
|
||||
@@ -184,6 +184,7 @@ if(DCUBED_FOUND)
|
||||
set(DCUBED_INCLUDE_DIRS
|
||||
"${DCUBED_CORE_INCLUDE_DIR}"
|
||||
"${DCUBED_CORE_INCLUDE_DIR}/if3"
|
||||
"${DCUBED_CORE_INCLUDE_DIR}/.."
|
||||
"${DCUBED_WRAPPER_INCLUDE_DIR}")
|
||||
mark_as_advanced(DCUBED_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
180
cmake/FindDirectInput.cmake
Normal file
180
cmake/FindDirectInput.cmake
Normal file
@@ -0,0 +1,180 @@
|
||||
# - try to find DirectInput library (part of DirectX SDK)
|
||||
#
|
||||
# Cache Variables: (probably not for direct use in your scripts)
|
||||
# DIRECTINPUT_DXGUID_LIBRARY
|
||||
# DIRECTINPUT_DXERR_LIBRARY
|
||||
# DIRECTINPUT_DINPUT_LIBRARY
|
||||
# DIRECTINPUT_INCLUDE_DIR
|
||||
#
|
||||
# Non-cache variables you should use in your CMakeLists.txt:
|
||||
# DIRECTINPUT_LIBRARIES
|
||||
# DIRECTINPUT_INCLUDE_DIRS
|
||||
# DIRECTINPUT_FOUND - if this is not true, do not attempt to use this library
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
#
|
||||
# Original Author:
|
||||
# 2011 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2011.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
|
||||
set(DIRECTINPUT_ROOT_DIR
|
||||
"${DIRECTINPUT_ROOT_DIR}"
|
||||
CACHE
|
||||
PATH
|
||||
"Root directory to search for DirectX/DirectInput")
|
||||
|
||||
if(MSVC)
|
||||
file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _PROG_FILES)
|
||||
file(TO_CMAKE_PATH "$ENV{ProgramFiles(x86)}" _PROG_FILES_X86)
|
||||
if(_PROG_FILES_X86)
|
||||
set(_PROG_FILES "${_PROG_FILES_X86}")
|
||||
endif()
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(_lib_suffixes lib/x64 lib)
|
||||
else()
|
||||
set(_lib_suffixes lib/x86 lib)
|
||||
endif()
|
||||
macro(_append_dxsdk_in_inclusive_range _low _high)
|
||||
if((NOT MSVC_VERSION LESS ${_low}) AND (NOT MSVC_VERSION GREATER ${_high}))
|
||||
list(APPEND DXSDK_DIRS ${ARGN})
|
||||
endif()
|
||||
endmacro()
|
||||
_append_dxsdk_in_inclusive_range(1500 1600 "${_PROG_FILES}/Microsoft DirectX SDK (June 2010)")
|
||||
_append_dxsdk_in_inclusive_range(1400 1600
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (February 2010)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (August 2009)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (March 2009)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (November 2008)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (August 2008)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (June 2008)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (March 2008)")
|
||||
_append_dxsdk_in_inclusive_range(1310 1500
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (November 2007)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (August 2007)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (June 2007)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (April 2007)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (February 2007)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (December 2006)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (October 2006)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (August 2006)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (June 2006)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (April 2006)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (February 2006)")
|
||||
|
||||
file(TO_CMAKE_PATH "$ENV{DXSDK_DIR}" ENV_DXSDK_DIR)
|
||||
if(ENV_DXSDK_DIR)
|
||||
list(APPEND DXSDK_DIRS ${ENV_DXSDK_DIR})
|
||||
endif()
|
||||
else()
|
||||
set(_lib_suffixes lib)
|
||||
set(DXSDK_DIRS /mingw)
|
||||
endif()
|
||||
|
||||
find_path(DIRECTINPUT_INCLUDE_DIR
|
||||
NAMES
|
||||
dinput.h
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${DIRECTINPUT_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
include)
|
||||
|
||||
find_library(DIRECTINPUT_DXGUID_LIBRARY
|
||||
NAMES
|
||||
dxguid
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${DIRECTINPUT_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${_lib_suffixes})
|
||||
|
||||
if(DIRECTINPUT_DXGUID_LIBRARY)
|
||||
get_filename_component(_dinput_lib_dir
|
||||
${DIRECTINPUT_DXGUID_LIBRARY}
|
||||
PATH)
|
||||
endif()
|
||||
|
||||
find_library(DIRECTINPUT_DINPUT_LIBRARY
|
||||
NAMES
|
||||
dinput8
|
||||
dinput
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${_dinput_lib_dir}"
|
||||
"${DIRECTINPUT_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${_lib_suffixes})
|
||||
|
||||
find_library(DIRECTINPUT_DXERR_LIBRARY
|
||||
NAMES
|
||||
dxerr
|
||||
dxerr9
|
||||
dxerr8
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${_dinput_lib_dir}"
|
||||
"${DIRECTINPUT_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${_lib_suffixes})
|
||||
set(DIRECTINPUT_EXTRA_CHECK)
|
||||
if(DIRECTINPUT_INCLUDE_DIR)
|
||||
if(MSVC80)
|
||||
set(DXSDK_DEPRECATION_BUILD 1962)
|
||||
endif()
|
||||
|
||||
if(DXSDK_DEPRECATION_BUILD)
|
||||
include(CheckCSourceCompiles)
|
||||
set(_dinput_old_includes ${CMAKE_REQUIRED_INCLUDES})
|
||||
set(CMAKE_REQUIRED_INCLUDES "${DIRECTINPUT_INCLUDE_DIR}")
|
||||
check_c_source_compiles(
|
||||
"
|
||||
#include <dxsdkver.h>
|
||||
#if _DXSDK_BUILD_MAJOR >= ${DXSDK_DEPRECATION_BUILD}
|
||||
#error
|
||||
#else
|
||||
int main(int argc, char * argv[]) {
|
||||
return 0;
|
||||
}
|
||||
"
|
||||
DIRECTINPUT_SDK_SUPPORTS_COMPILER)
|
||||
set(DIRECTINPUT_EXTRA_CHECK DIRECTINPUT_SDK_SUPPORTS_COMPILER)
|
||||
set(CMAKE_REQUIRED_INCLUDES "${_dinput_old_includes}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(DirectInput
|
||||
DEFAULT_MSG
|
||||
DIRECTINPUT_DINPUT_LIBRARY
|
||||
DIRECTINPUT_DXGUID_LIBRARY
|
||||
DIRECTINPUT_DXERR_LIBRARY
|
||||
DIRECTINPUT_INCLUDE_DIR
|
||||
${DIRECTINPUT_EXTRA_CHECK})
|
||||
|
||||
if(DIRECTINPUT_FOUND)
|
||||
set(DIRECTINPUT_LIBRARIES
|
||||
"${DIRECTINPUT_DXGUID_LIBRARY}"
|
||||
"${DIRECTINPUT_DXERR_LIBRARY}"
|
||||
"${DIRECTINPUT_DINPUT_LIBRARY}")
|
||||
|
||||
set(DIRECTINPUT_INCLUDE_DIRS "${DIRECTINPUT_INCLUDE_DIR}")
|
||||
|
||||
mark_as_advanced(DIRECTINPUT_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(DIRECTINPUT_DINPUT_LIBRARY
|
||||
DIRECTINPUT_DXGUID_LIBRARY
|
||||
DIRECTINPUT_DXERR_LIBRARY
|
||||
DIRECTINPUT_INCLUDE_DIR)
|
||||
126
cmake/FindDirectShow.cmake
Normal file
126
cmake/FindDirectShow.cmake
Normal file
@@ -0,0 +1,126 @@
|
||||
# - Find Microsoft DirectShow sample files, library, and headers.
|
||||
#
|
||||
# DIRECTSHOW_INCLUDE_DIRS - where to find needed include file
|
||||
# DIRECTSHOW_BASECLASS_DIR- Directory containing the DirectShow baseclass sample code.
|
||||
# DIRECTSHOW_FOUND - True if DirectShow found.
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
#
|
||||
# Initially in VRPN - Distributed under the Boost Software License, Version 1.0.
|
||||
#
|
||||
# Almost entirely re-written by:
|
||||
# 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# Look for one of the sample files.
|
||||
|
||||
find_package(WindowsSDK)
|
||||
find_package(DirectX QUIET)
|
||||
|
||||
set(DIRECTSHOW_WINDOWSSDK_ROOT
|
||||
"${DIRECTSHOW_WINDOWSSDK_ROOT}"
|
||||
CACHE
|
||||
PATH
|
||||
"A specific Windows SDK to use for DirectShow.")
|
||||
|
||||
if(MSVC AND CMAKE_CL_64)
|
||||
set(DIRECTSHOW_LIB_SUBDIR /x64)
|
||||
else()
|
||||
set(DIRECTSHOW_LIB_SUBDIR)
|
||||
endif()
|
||||
|
||||
set(_acceptable_winsdk)
|
||||
if(WINDOWSSDK_FOUND)
|
||||
foreach(_sdkdir ${WINDOWSSDK_DIRS})
|
||||
if(EXISTS "${_sdkdir}/Samples/Multimedia/DirectShow/BaseClasses/streams.h"
|
||||
AND EXISTS "${_sdkdir}/Lib${DIRECTSHOW_LIB_SUBDIR}/strmiids.lib"
|
||||
AND EXISTS "${_sdkdir}/Include/DShow.h")
|
||||
list(APPEND _acceptable_winsdk "${_sdkdir}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
find_path(DIRECTSHOW_BASECLASS_DIR
|
||||
NAMES
|
||||
streams.h
|
||||
HINTS
|
||||
"${DIRECTSHOW_WINDOWSSDK_ROOT}"
|
||||
PATHS
|
||||
${_acceptable_winsdk}
|
||||
PATH_SUFFIXES
|
||||
"Samples/Multimedia/DirectShow/BaseClasses")
|
||||
|
||||
find_path(DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR
|
||||
NAMES
|
||||
DShow.h
|
||||
HINTS
|
||||
"${DIRECTSHOW_WINDOWSSDK_ROOT}"
|
||||
PATHS
|
||||
${_acceptable_winsdk}
|
||||
PATH_SUFFIXES
|
||||
"Include")
|
||||
|
||||
# This one we can grab from another SDK version.
|
||||
find_path(DIRECTSHOW_QEDIT_INCLUDE_DIR
|
||||
NAMES
|
||||
qedit.h
|
||||
HINTS
|
||||
"${DIRECTSHOW_WINDOWSSDK_ROOT}"
|
||||
PATHS
|
||||
${WINDOWSSDK_DIRS}
|
||||
PATH_SUFFIXES
|
||||
"Include")
|
||||
|
||||
find_library(DIRECTSHOW_STRMIIDS_LIBRARY
|
||||
NAMES
|
||||
strmiids
|
||||
HINTS
|
||||
"${DIRECTSHOW_WINDOWSSDK_ROOT}"
|
||||
PATHS
|
||||
${_acceptable_winsdk}
|
||||
PATH_SUFFIXES
|
||||
"Lib${DIRECTSHOW_LIB_SUBDIR}")
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(DirectShow
|
||||
DEFAULT_MSG
|
||||
DIRECTSHOW_BASECLASS_DIR
|
||||
DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR
|
||||
DIRECTSHOW_QEDIT_INCLUDE_DIR
|
||||
DIRECTX_INCLUDE_DIR
|
||||
DIRECTX_FOUND
|
||||
DIRECTSHOW_STRMIIDS_LIBRARY)
|
||||
|
||||
if(DIRECTSHOW_FOUND)
|
||||
set(DIRECTSHOW_INCLUDE_DIRS
|
||||
# Baseclass must be before SDK so it gets the correct refclock.h
|
||||
"${DIRECTSHOW_BASECLASS_DIR}"
|
||||
"${DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR}"
|
||||
"${DIRECTX_INCLUDE_DIR}"
|
||||
)
|
||||
if(EXISTS "${DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR}/atl/atlbase.h")
|
||||
list(APPEND
|
||||
DIRECTSHOW_INCLUDE_DIRS
|
||||
"${DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR}/atl")
|
||||
endif()
|
||||
if(NOT "${DIRECTSHOW_QEDIT_INCLUDE_DIR}" STREQUAL "${DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR}")
|
||||
# QEdit include dir might be an older SDK, so put it last.
|
||||
list(APPEND DIRECTSHOW_INCLUDE_DIRS "${DIRECTSHOW_QEDIT_INCLUDE_DIR}")
|
||||
endif()
|
||||
|
||||
set(DIRECTSHOW_LIBRARIES "${DIRECTSHOW_STRMIIDS_LIBRARY}")
|
||||
|
||||
mark_as_advanced(DIRECTSHOW_WINDOWSSDK_ROOT)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(DIRECTSHOW_BASECLASS_DIR
|
||||
DIRECTSHOW_WINDOWSSDK_INCLUDE_DIR
|
||||
DIRECTSHOW_QEDIT_INCLUDE_DIR
|
||||
DIRECTSHOW_STRMIIDS_LIBRARY)
|
||||
244
cmake/FindDirectX.cmake
Normal file
244
cmake/FindDirectX.cmake
Normal file
@@ -0,0 +1,244 @@
|
||||
# - try to find part of DirectX SDK
|
||||
#
|
||||
# Cache Variables: (probably not for direct use in your scripts)
|
||||
# DIRECTX_INCLUDE_DIR
|
||||
#
|
||||
# Variables you should use in your CMakeLists.txt:
|
||||
# DIRECTX_DXGUID_LIBRARY
|
||||
# DIRECTX_DXERR_LIBRARY
|
||||
# DIRECTX_DINPUT_LIBRARY
|
||||
# DIRECTX_DINPUT_INCLUDE_DIR
|
||||
# DIRECTX_D3D9_LIBRARY
|
||||
# DIRECTX_D3DXOF_LIBRARY
|
||||
# DIRECTX_D3DX9_LIBRARIES
|
||||
# DIRECTX_INCLUDE_DIRS
|
||||
# DIRECTX_FOUND - if this is not true, do not attempt to use this library
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
# SelectLibraryConfigurations
|
||||
#
|
||||
# Original Author:
|
||||
# 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
|
||||
set(DIRECTX_ROOT_DIR
|
||||
"${DIRECTX_ROOT_DIR}"
|
||||
CACHE
|
||||
PATH
|
||||
"Root directory to search for DirectX")
|
||||
|
||||
if(MSVC)
|
||||
file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _PROG_FILES)
|
||||
file(TO_CMAKE_PATH "$ENV{ProgramFiles(x86)}" _PROG_FILES_X86)
|
||||
if(_PROG_FILES_X86)
|
||||
set(_PROG_FILES "${_PROG_FILES_X86}")
|
||||
endif()
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(_lib_suffixes lib/x64 lib)
|
||||
else()
|
||||
set(_lib_suffixes lib/x86 lib)
|
||||
endif()
|
||||
macro(_append_dxsdk_in_inclusive_range _low _high)
|
||||
if((NOT MSVC_VERSION LESS ${_low}) AND (NOT MSVC_VERSION GREATER ${_high}))
|
||||
list(APPEND DXSDK_DIRS ${ARGN})
|
||||
endif()
|
||||
endmacro()
|
||||
_append_dxsdk_in_inclusive_range(1500 1600 "${_PROG_FILES}/Microsoft DirectX SDK (June 2010)")
|
||||
_append_dxsdk_in_inclusive_range(1400 1600
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (February 2010)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (August 2009)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (March 2009)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (November 2008)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (August 2008)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (June 2008)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (March 2008)")
|
||||
_append_dxsdk_in_inclusive_range(1310 1500
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (November 2007)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (August 2007)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (June 2007)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (April 2007)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (February 2007)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (December 2006)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (October 2006)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (August 2006)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (June 2006)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (April 2006)"
|
||||
"${_PROG_FILES}/Microsoft DirectX SDK (February 2006)")
|
||||
|
||||
file(TO_CMAKE_PATH "$ENV{DXSDK_DIR}" ENV_DXSDK_DIR)
|
||||
if(ENV_DXSDK_DIR)
|
||||
list(APPEND DXSDK_DIRS ${ENV_DXSDK_DIR})
|
||||
endif()
|
||||
else()
|
||||
set(_lib_suffixes lib)
|
||||
set(DXSDK_DIRS /mingw)
|
||||
endif()
|
||||
|
||||
find_path(DIRECTX_INCLUDE_DIR
|
||||
NAMES
|
||||
dxdiag.h
|
||||
dinput.h
|
||||
dxerr8.h
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${DIRECTX_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
include)
|
||||
find_path(DIRECTX_DINPUT_INCLUDE_DIR
|
||||
NAMES
|
||||
dinput.h
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${DIRECTX_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
include)
|
||||
|
||||
find_library(DIRECTX_DXGUID_LIBRARY
|
||||
NAMES
|
||||
dxguid
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${DIRECTX_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${_lib_suffixes})
|
||||
|
||||
if(DIRECTX_DXGUID_LIBRARY)
|
||||
get_filename_component(_dxsdk_lib_dir ${DIRECTX_DXGUID_LIBRARY} PATH)
|
||||
endif()
|
||||
|
||||
find_library(DIRECTX_DINPUT_LIBRARY
|
||||
NAMES
|
||||
dinput8
|
||||
dinput
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${_dxsdk_lib_dir}"
|
||||
"${DIRECTX_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${_lib_suffixes})
|
||||
|
||||
find_library(DIRECTX_DXERR_LIBRARY
|
||||
NAMES
|
||||
dxerr
|
||||
dxerr9
|
||||
dxerr8
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${_dxsdk_lib_dir}"
|
||||
"${DIRECTX_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${_lib_suffixes})
|
||||
|
||||
find_library(DIRECTX_D3D9_LIBRARY
|
||||
NAMES
|
||||
d3d9
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${_dxsdk_lib_dir}"
|
||||
"${DIRECTX_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${_lib_suffixes})
|
||||
|
||||
find_library(DIRECTX_D3DXOF_LIBRARY
|
||||
NAMES
|
||||
d3dxof
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${_dxsdk_lib_dir}"
|
||||
"${DIRECTX_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${_lib_suffixes})
|
||||
|
||||
find_library(DIRECTX_D3DX9_LIBRARY_RELEASE
|
||||
NAMES
|
||||
d3dx9
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${_dxsdk_lib_dir}"
|
||||
"${DIRECTX_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${_lib_suffixes})
|
||||
|
||||
find_library(DIRECTX_D3DX9_LIBRARY_DEBUG
|
||||
NAMES
|
||||
d3dx9d
|
||||
PATHS
|
||||
${DXSDK_DIRS}
|
||||
HINTS
|
||||
"${_dxsdk_lib_dir}"
|
||||
"${DIRECTX_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
${_lib_suffixes})
|
||||
|
||||
include(SelectLibraryConfigurations)
|
||||
select_library_configurations(DIRECTX_D3DX9)
|
||||
|
||||
set(DIRECTX_EXTRA_CHECK)
|
||||
if(DIRECTX_INCLUDE_DIR)
|
||||
if(MSVC80)
|
||||
set(DXSDK_DEPRECATION_BUILD 1962)
|
||||
endif()
|
||||
|
||||
if(DXSDK_DEPRECATION_BUILD)
|
||||
include(CheckCSourceCompiles)
|
||||
set(_dinput_old_includes ${CMAKE_REQUIRED_INCLUDES})
|
||||
set(CMAKE_REQUIRED_INCLUDES "${DIRECTX_INCLUDE_DIR}")
|
||||
check_c_source_compiles("
|
||||
#include <dxsdkver.h>
|
||||
#if _DXSDK_BUILD_MAJOR >= ${DXSDK_DEPRECATION_BUILD}
|
||||
#error
|
||||
#else
|
||||
int main(int argc, char * argv[]) {
|
||||
return 0;
|
||||
}
|
||||
"
|
||||
DIRECTX_SDK_SUPPORTS_COMPILER)
|
||||
set(DIRECTX_EXTRA_CHECK DIRECTX_SDK_SUPPORTS_COMPILER)
|
||||
set(CMAKE_REQUIRED_INCLUDES "${_dinput_old_includes}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(DirectX
|
||||
DEFAULT_MSG
|
||||
DIRECTX_DXGUID_LIBRARY
|
||||
DIRECTX_DINPUT_LIBRARY
|
||||
DIRECTX_DXERR_LIBRARY
|
||||
DIRECTX_INCLUDE_DIR
|
||||
${DIRECTX_EXTRA_CHECK})
|
||||
|
||||
if(DIRECTX_FOUND)
|
||||
set(DIRECTX_LIBRARIES
|
||||
"${DIRECTX_DXGUID_LIBRARY}"
|
||||
"${DIRECTX_DXERR_LIBRARY}"
|
||||
"${DIRECTX_DINPUT_LIBRARY}")
|
||||
|
||||
set(DIRECTX_INCLUDE_DIRS "${DIRECTX_INCLUDE_DIR}")
|
||||
|
||||
mark_as_advanced(DIRECTX_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(DIRECTX_DINPUT_LIBRARY
|
||||
DIRECTX_DXGUID_LIBRARY
|
||||
DIRECTX_DXERR_LIBRARY
|
||||
DIRECTX_D3D9_LIBRARY
|
||||
DIRECTX_D3DXOF_LIBRARY
|
||||
DIRECTX_D3DX9_LIBRARY_RELEASE
|
||||
DIRECTX_D3DX9_LIBRARY_DEBUG
|
||||
DIRECTX_INCLUDE_DIR)
|
||||
@@ -36,17 +36,31 @@ find_program(GDB_COMMAND
|
||||
libexec)
|
||||
|
||||
if(GDB_COMMAND)
|
||||
execute_process(COMMAND gdb --version
|
||||
COMMAND head -n 1
|
||||
OUTPUT_VARIABLE GDB_VERSION
|
||||
execute_process(COMMAND
|
||||
gdb
|
||||
--version
|
||||
COMMAND
|
||||
head
|
||||
-n
|
||||
1
|
||||
OUTPUT_VARIABLE
|
||||
GDB_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REGEX REPLACE "[^0-9]*([0-9]+[0-9.]*).*" "\\1" GDB_VERSION "${GDB_VERSION}")
|
||||
string(REGEX
|
||||
REPLACE
|
||||
"[^0-9]*([0-9]+[0-9.]*).*"
|
||||
"\\1"
|
||||
GDB_VERSION
|
||||
"${GDB_VERSION}")
|
||||
endif()
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(GDB DEFAULT_MSG GDB_COMMAND GDB_VERSION)
|
||||
find_package_handle_standard_args(GDB
|
||||
DEFAULT_MSG
|
||||
GDB_COMMAND
|
||||
GDB_VERSION)
|
||||
|
||||
if(GDB_FOUND)
|
||||
mark_as_advanced(GDB_ROOT_DIR)
|
||||
|
||||
@@ -40,6 +40,7 @@ find_path(GHOST_INCLUDE_DIR
|
||||
|
||||
find_library(GHOST_LIBRARY
|
||||
GHOST40
|
||||
GHOST31
|
||||
PATHS
|
||||
${_dirs}
|
||||
HINTS
|
||||
@@ -47,20 +48,27 @@ find_library(GHOST_LIBRARY
|
||||
PATH_SUFFIXES
|
||||
lib)
|
||||
|
||||
if(MSVC_VERSION GREATER 1300)
|
||||
# .NET and newer: fake the STL headers
|
||||
get_filename_component(_moddir "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
set(GHOST_STL_INCLUDE_DIR "${_moddir}/ghost-fake-stl")
|
||||
if(MSVC)
|
||||
if(MSVC_VERSION GREATER 1300)
|
||||
# .NET and newer: fake the STL headers
|
||||
get_filename_component(_moddir "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
set(GHOST_STL_INCLUDE_DIR "${_moddir}/ghost-fake-stl")
|
||||
else()
|
||||
# 6.0 and earlier - use GHOST-provided STL
|
||||
find_path(GHOST_STL_INCLUDE_DIR
|
||||
vector.h
|
||||
PATHS
|
||||
${_dirs}
|
||||
HINTS
|
||||
"${GHOST_ROOT_DIR}"
|
||||
"${GHOST_INCLUDE_DIR}"
|
||||
PATH_SUFFIXES
|
||||
external/stl
|
||||
stl)
|
||||
endif()
|
||||
set(_deps_check GHOST_STL_INCLUDE_DIR)
|
||||
else()
|
||||
# 6.0 and earlier - use GHOST-provided STL
|
||||
find_path(GHOST_STL_INCLUDE_DIR
|
||||
vector.h
|
||||
PATHS
|
||||
${_dirs}
|
||||
HINTS
|
||||
"${GHOST_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
external/stl)
|
||||
set(_deps_check)
|
||||
endif()
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
|
||||
@@ -69,18 +77,14 @@ include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(GHOST
|
||||
DEFAULT_MSG
|
||||
GHOST_LIBRARY
|
||||
GHOST_STL_INCLUDE_DIR
|
||||
${_deps_check}
|
||||
GHOST_INCLUDE_DIR)
|
||||
|
||||
if(GHOST_FOUND)
|
||||
set(GHOST_LIBRARIES "${GHOST_LIBRARY}")
|
||||
set(GHOST_INCLUDE_DIRS
|
||||
"${GHOST_STL_INCLUDE_DIR}"
|
||||
"${GHOST_INCLUDE_DIR}")
|
||||
set(GHOST_INCLUDE_DIRS "${GHOST_INCLUDE_DIR}")
|
||||
|
||||
mark_as_advanced(GHOST_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(GHOST_LIBRARY
|
||||
GHOST_STL_INCLUDE_DIR
|
||||
GHOST_INCLUDE_DIR)
|
||||
mark_as_advanced(GHOST_LIBRARY GHOST_STL_INCLUDE_DIR GHOST_INCLUDE_DIR)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# Useful configuration variables you might want to add to your cache:
|
||||
# GMTL_ROOT_DIR - A directory prefix to search
|
||||
# (a path that contains include/ as a subdirectory)
|
||||
# GMTL_ADDITIONAL_VERSIONS - Additional versions (outside of 0.5.1 to 0.6.2)
|
||||
# GMTL_ADDITIONAL_VERSIONS - Additional versions (outside of 0.5.1 to 0.7.0)
|
||||
# to use when constructing search names and paths
|
||||
#
|
||||
# This script will use Flagpoll, if found, to provide hints to the location
|
||||
@@ -24,11 +24,11 @@
|
||||
# and trigger an automatic re-run.
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# 2009-2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2009-2010.
|
||||
# Copyright Iowa State University 2009-2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -41,6 +41,7 @@ include(CheckVersion)
|
||||
|
||||
set(GMTL_VERSIONS
|
||||
${GMTL_ADDITIONAL_VERSIONS}
|
||||
0.7.0
|
||||
0.6.2
|
||||
0.6.1
|
||||
0.6.0
|
||||
|
||||
@@ -37,11 +37,15 @@
|
||||
# Brandon Newendorp <brandon@newendorp.com>
|
||||
|
||||
set(_HUMAN "Gadgeteer 2.0")
|
||||
set(_RELEASE_NAMES gadget-2_0 libgadget-2_0 gadget-2_0_0)
|
||||
set(_DEBUG_NAMES gadget_d-2_0 libgadget_d-2_0 gadget_d-2_0_0)
|
||||
set(_FP_PKG_NAME gadgeteer)
|
||||
set(_RELEASE_NAMES)
|
||||
set(_DEBUG_NAMES)
|
||||
foreach(VER 2_0 2_0_0 2_0_1 2_0_2)
|
||||
list(APPEND _RELEASE_NAMES gadget-${VER})
|
||||
list(APPEND _DEBUG_NAMES gadget_d-${VER})
|
||||
endforeach()
|
||||
set(_DIR gadgeteer-2.0)
|
||||
set(_HEADER gadget/gadgetConfig.h)
|
||||
set(_FP_PKG_NAME gadgeteer)
|
||||
|
||||
include(SelectLibraryConfigurations)
|
||||
include(CreateImportedTarget)
|
||||
|
||||
92
cmake/FindIDLJ.cmake
Normal file
92
cmake/FindIDLJ.cmake
Normal file
@@ -0,0 +1,92 @@
|
||||
# - try to find Java's IDLJ Interface Definition Language compiler.
|
||||
#
|
||||
# Ideally used with CMake 2.8.5 or newer for Java support using FindJava.cmake
|
||||
# and UseJava.cmake
|
||||
#
|
||||
# Variables:
|
||||
# Java_IDLJ_COMMAND, executable for idlj
|
||||
# IDLJ_FOUND, If false, do not try to use this
|
||||
#
|
||||
# Function:
|
||||
# java_idlj(varname idlfile [extra idlj args]) - Generates
|
||||
# the Java source files from the IDL file you indicate, and
|
||||
# appends filenames suitable to add to a add_jar() call to the
|
||||
# variable you specified.
|
||||
#
|
||||
# Because the files generated from an IDL file are not entirely predictable,
|
||||
# java_idlj runs idlj in the cmake step, rather than the build step, and triggers
|
||||
# a CMake re-run when an idl file is modified. Already up-to-date generated source
|
||||
# is not re-generated, however.
|
||||
#
|
||||
# Files are generated in a directory created specifically for
|
||||
# the particular IDL file and the particular call, in the build directory -
|
||||
# there should be no worries about overwriting files or picking up too much
|
||||
# with the wildcard.
|
||||
#
|
||||
# You may wish to add the IDL file to your list of sources if you want it
|
||||
# to appear in your IDE, but it is not necessary.
|
||||
#
|
||||
# Original Author:
|
||||
# 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
if(NOT JAVA_FOUND)
|
||||
find_package(Java QUIET)
|
||||
endif()
|
||||
|
||||
if(JAVA_FOUND)
|
||||
get_filename_component(JAVA_BIN_DIR "${Java_JAVAC_EXECUTABLE}" PATH)
|
||||
find_program(Java_IDLJ_COMMAND
|
||||
idlj
|
||||
HINTS
|
||||
${JAVA_BIN_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(IDLJ
|
||||
DEFAULT_MSG
|
||||
Java_IDLJ_COMMAND
|
||||
JAVA_FOUND)
|
||||
|
||||
if(IDLJ_FOUND)
|
||||
function(java_idlj _varname _idlfile)
|
||||
# Get some unique value we can use in a directory name
|
||||
# TODO would be better to somehow munge the full path relative to CMAKE_CURRENT_SOURCE_DIR
|
||||
# in case somebody has multiple idl files with the same name
|
||||
get_filename_component(_idl_name "${_idlfile}" NAME_WE)
|
||||
get_filename_component(_idl_abs "${_idlfile}" ABSOLUTE)
|
||||
|
||||
# Compute directory name and stamp filename
|
||||
set(outdir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/idlj/${_idl_name}.dir")
|
||||
set(stampfile "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/idlj/${_idl_name}.stamp")
|
||||
|
||||
# Force re-cmake if idl file changes
|
||||
configure_file("${_idl_abs}" "${stampfile}" COPY_ONLY)
|
||||
|
||||
if((NOT EXISTS "${outdir}") OR ("${_idl_abs}" IS_NEWER_THAN "${outdir}"))
|
||||
file(REMOVE_RECURSE "${outdir}")
|
||||
message(STATUS "Processing ${_idlfile} with Java's idlj")
|
||||
execute_process(COMMAND
|
||||
"${Java_IDLJ_COMMAND}" -fclient -fallTIE -td "${outdir}" ${ARGN} "${_idlfile}"
|
||||
WORKING_DIRECTORY
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
endif()
|
||||
file(GLOB_RECURSE _idl_output "${outdir}/*")
|
||||
|
||||
set(${_varname} ${_idl_output} PARENT_SCOPE)
|
||||
|
||||
# Clean up after ourselves on make clean
|
||||
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${outdir}" "${stampfile}")
|
||||
endfunction()
|
||||
endif()
|
||||
|
||||
mark_as_advanced(Java_IDLJ_COMMAND)
|
||||
@@ -37,11 +37,15 @@
|
||||
|
||||
|
||||
set(_HUMAN "JCCL 1.4")
|
||||
set(_RELEASE_NAMES jccl-1_4 libjccl-1_4 jccl-1_4_0)
|
||||
set(_DEBUG_NAMES jccl_d-1_4 libjccl_d-1_4 jccl_d-1_4_0)
|
||||
set(_FP_PKG_NAME jccl)
|
||||
set(_RELEASE_NAMES)
|
||||
set(_DEBUG_NAMES)
|
||||
foreach(VER 1_4 1_4_0 1_4_1 1_4_2)
|
||||
list(APPEND _RELEASE_NAMES ${_FP_PKG_NAME}-${VER})
|
||||
list(APPEND _DEBUG_NAMES ${_FP_PKG_NAME}_d-${VER})
|
||||
endforeach()
|
||||
set(_DIR jccl-1.4)
|
||||
set(_HEADER jccl/jcclConfig.h)
|
||||
set(_FP_PKG_NAME jccl)
|
||||
|
||||
include(SelectLibraryConfigurations)
|
||||
include(CreateImportedTarget)
|
||||
|
||||
@@ -144,13 +144,15 @@ elseif(UNIX)
|
||||
string(TOLOWER "${CMAKE_SYSTEM_NAME}" _sysname)
|
||||
file(TO_CMAKE_PATH "$ENV{JTTK_DEV_PATH}" _envloc)
|
||||
prefix_list_glob(_jttklibs
|
||||
"lib/${_sysname}_${BITS}${_compiler}/libJtTk*"
|
||||
"/lib/${_sysname}_${BITS}${_compiler}/libJtTk*"
|
||||
"${JTTK_ROOT_DIR}"
|
||||
"/usr/"
|
||||
"/usr/local/"
|
||||
"/usr/local/siemens/"
|
||||
"/usr/local/ugs/")
|
||||
prefix_list_glob(_jttklibs2
|
||||
"dev/lib/${_sysname}_${BITS}${_compiler}/libJtTk*"
|
||||
"/dev/lib/${_sysname}_${BITS}${_compiler}/libJtTk*"
|
||||
"${JTTK_ROOT_DIR}"
|
||||
"/usr/"
|
||||
"/usr/local/"
|
||||
"/usr/local/siemens/"
|
||||
|
||||
@@ -29,7 +29,7 @@ set(LIBUSB1_ROOT_DIR
|
||||
CACHE
|
||||
PATH
|
||||
"Root directory to search for libusb-1")
|
||||
|
||||
|
||||
if(WIN32)
|
||||
include(ProgramFilesGlob)
|
||||
program_files_fallback_glob(_dirs "LibUSB-Win32")
|
||||
@@ -42,7 +42,7 @@ if(WIN32)
|
||||
set(_lib_suffixes lib/msvc)
|
||||
elseif(COMPILER_IS_GNUCXX)
|
||||
set(_lib_suffixes lib/gcc)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
set(_lib_suffixes)
|
||||
@@ -81,11 +81,9 @@ find_package_handle_standard_args(Libusb1
|
||||
LIBUSB1_INCLUDE_DIR)
|
||||
|
||||
if(LIBUSB1_FOUND)
|
||||
set(LIBUSB1_LIBRARIES
|
||||
"${LIBUSB1_LIBRARY}")
|
||||
set(LIBUSB1_LIBRARIES "${LIBUSB1_LIBRARY}")
|
||||
|
||||
set(LIBUSB1_INCLUDE_DIRS
|
||||
"${LIBUSB1_INCLUDE_DIR}")
|
||||
set(LIBUSB1_INCLUDE_DIRS "${LIBUSB1_INCLUDE_DIR}")
|
||||
|
||||
mark_as_advanced(LIBUSB1_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
@@ -65,9 +65,7 @@ mark_as_advanced(LYX_COMMAND)
|
||||
function(lyx_export _format _extension _outvar)
|
||||
set(_nowhere)
|
||||
set(_curdest _nowhere)
|
||||
set(_val_args
|
||||
EXTRA_DEPS
|
||||
INPUT)
|
||||
set(_val_args EXTRA_DEPS INPUT)
|
||||
set(_bool_args OUTPUT_TO_SOURCE_DIR)
|
||||
foreach(_arg ${_val_args} ${_bool_args})
|
||||
set(${_arg})
|
||||
@@ -99,7 +97,7 @@ function(lyx_export _format _extension _outvar)
|
||||
else()
|
||||
set(_outname "${CMAKE_CURRENT_SOURCE_DIR}/${_base}.${_extension}")
|
||||
endif()
|
||||
|
||||
|
||||
list(APPEND _out "${_outname}")
|
||||
if(LYX_COMMAND)
|
||||
add_custom_command(OUTPUT "${_outname}"
|
||||
|
||||
56
cmake/FindMarkdown.cmake
Normal file
56
cmake/FindMarkdown.cmake
Normal file
@@ -0,0 +1,56 @@
|
||||
# - try to find Markdown tool
|
||||
#
|
||||
# Cache Variables:
|
||||
# MARKDOWN_EXECUTABLE
|
||||
#
|
||||
# Non-cache variables you might use in your CMakeLists.txt:
|
||||
# MARKDOWN_FOUND
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
#
|
||||
# Original Author:
|
||||
# 2011 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2011.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
file(TO_CMAKE_PATH "${MARKDOWN_ROOT_DIR}" MARKDOWN_ROOT_DIR)
|
||||
set(MARKDOWN_ROOT_DIR
|
||||
"${MARKDOWN_ROOT_DIR}"
|
||||
CACHE
|
||||
PATH
|
||||
"Path to search for Markdown")
|
||||
|
||||
if(MARKDOWN_EXECUTABLE AND NOT EXISTS "${MARKDOWN_EXECUTABLE}")
|
||||
set(MARKDOWN_EXECUTABLE "notfound" CACHE PATH FORCE "")
|
||||
endif()
|
||||
|
||||
# If we have a custom path, look there first.
|
||||
if(MARKDOWN_ROOT_DIR)
|
||||
find_program(MARKDOWN_EXECUTABLE
|
||||
NAMES
|
||||
markdown
|
||||
PATHS
|
||||
"${MARKDOWN_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
bin
|
||||
NO_DEFAULT_PATH)
|
||||
endif()
|
||||
|
||||
find_program(MARKDOWN_EXECUTABLE NAMES markdown)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Markdown
|
||||
DEFAULT_MSG
|
||||
MARKDOWN_EXECUTABLE)
|
||||
|
||||
if(MARKDOWN_FOUND)
|
||||
mark_as_advanced(MARKDOWN_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(MARKDOWN_EXECUTABLE)
|
||||
@@ -73,7 +73,11 @@ else()
|
||||
otherlibs/_graphics/include)
|
||||
|
||||
# library linkdir suffixes appended to OPENCV_BASE_DIR
|
||||
set(OPENCV_LIBDIR_SUFFIXES lib lib64 OpenCV/lib otherlibs/_graphics/lib)
|
||||
set(OPENCV_LIBDIR_SUFFIXES
|
||||
lib
|
||||
lib64
|
||||
OpenCV/lib
|
||||
otherlibs/_graphics/lib)
|
||||
|
||||
|
||||
#
|
||||
|
||||
@@ -3,12 +3,16 @@
|
||||
# Cache Variables: (probably not for direct use in your scripts)
|
||||
# HDAPI_INCLUDE_DIR
|
||||
# HDAPI_LIBRARY
|
||||
# HDAPI_LIBRARY_RELEASE
|
||||
# HDAPI_LIBRARY_DEBUG
|
||||
# HDAPI_HDU_INCLUDE_DIR
|
||||
# HDAPI_HDU_LIBRARY
|
||||
# HDAPI_HDU_LIBRARY_RELEASE
|
||||
# HDAPI_HDU_LIBRARY_DEBUG
|
||||
# HLAPI_INCLUDE_DIR
|
||||
# HLAPI_LIBRARY
|
||||
# HLAPI_LIBRARY_RELEASE
|
||||
# HLAPI_LIBRARY_DEBUG
|
||||
# HLAPI_HLU_INCLUDE_DIR
|
||||
# HLAPI_HLU_LIBRARY
|
||||
# HLAPI_HLU_LIBRARY_RELEASE
|
||||
@@ -40,7 +44,7 @@
|
||||
# CMake 2.6.3 (uses "unset")
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# 2009-2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
@@ -77,8 +81,20 @@ set(_libsearchdirs)
|
||||
set(OPENHAPTICS_ENVIRONMENT)
|
||||
set(OPENHAPTICS_RUNTIME_LIBRARY_DIRS)
|
||||
|
||||
set(_dirs)
|
||||
if(NOT "$ENV{OH_SDK_BASE}" STREQUAL "")
|
||||
list(APPEND _dirs "$ENV{OH_SDK_BASE}")
|
||||
elseif(NOT "$ENV{3DTOUCH_BASE}" STREQUAL "")
|
||||
list(APPEND _dirs "$ENV{3DTOUCH_BASE}")
|
||||
endif()
|
||||
if(WIN32)
|
||||
program_files_fallback_glob(_dirs "/Sensable/3DTouch*/")
|
||||
program_files_fallback_glob(_pfdirs "/Sensable/3DTouch*/")
|
||||
foreach(_OH_DEFAULT_LOCATION "C:/OpenHaptics/3.1" "C:/OpenHaptics/Academic/3.1")
|
||||
if(EXISTS "${_OH_DEFAULT_LOCATION}")
|
||||
list(APPEND _dirs "${_OH_DEFAULT_LOCATION}")
|
||||
endif()
|
||||
endforeach()
|
||||
set(_dirs "${_dirs};${_pfdirs}")
|
||||
if(MSVC60)
|
||||
set(_vc "vc6")
|
||||
elseif(MSVC70 OR MSVC71)
|
||||
@@ -160,12 +176,26 @@ find_path(HDAPI_INCLUDE_DIR
|
||||
HINTS
|
||||
${_incsearchdirs})
|
||||
|
||||
find_library(HDAPI_LIBRARY
|
||||
find_library(HDAPI_LIBRARY_RELEASE
|
||||
NAMES
|
||||
HD
|
||||
PATH_SUFFIXES
|
||||
ReleaseAcademicEdition
|
||||
Release
|
||||
HINTS
|
||||
${_libsearchdirs})
|
||||
|
||||
find_library(HDAPI_LIBRARY_DEBUG
|
||||
NAMES
|
||||
HD
|
||||
PATH_SUFFIXES
|
||||
DebugAcademicEdition
|
||||
Debug
|
||||
HINTS
|
||||
${_libsearchdirs})
|
||||
|
||||
select_library_configurations(HDAPI)
|
||||
|
||||
###
|
||||
# HDAPI: HDU
|
||||
###
|
||||
@@ -230,6 +260,7 @@ if(OPENHAPTICS_NESTED_TARGETS OR NOT HDAPI_HDU_LIBRARY)
|
||||
STRING
|
||||
"We will build the OpenHaptics HDU lib."
|
||||
FORCE)
|
||||
set(HDAPI_HDU_LIBRARIES ${HDAPI_HDU_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -243,12 +274,25 @@ find_path(HLAPI_INCLUDE_DIR
|
||||
HINTS
|
||||
${_incsearchdirs})
|
||||
|
||||
find_library(HLAPI_LIBRARY
|
||||
find_library(HLAPI_LIBRARY_RELEASE
|
||||
NAMES
|
||||
HL
|
||||
PATH_SUFFIXES
|
||||
ReleaseAcademicEdition
|
||||
Release
|
||||
HINTS
|
||||
${_libsearchdirs})
|
||||
|
||||
find_library(HLAPI_LIBRARY_DEBUG
|
||||
NAMES
|
||||
HL
|
||||
PATH_SUFFIXES
|
||||
DebugAcademicEdition
|
||||
Debug
|
||||
HINTS
|
||||
${_libsearchdirs})
|
||||
|
||||
select_library_configurations(HLAPI)
|
||||
|
||||
###
|
||||
# HLAPI: HLU
|
||||
@@ -314,63 +358,10 @@ if(OPENHAPTICS_NESTED_TARGETS OR NOT HLAPI_HLU_LIBRARY)
|
||||
STRING
|
||||
"We will build the OpenHaptics HLU lib."
|
||||
FORCE)
|
||||
set(HLAPI_HLU_LIBRARIES ${HLAPI_HLU_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
###
|
||||
# Unix: check stdc++ version
|
||||
###
|
||||
|
||||
if(UNIX
|
||||
AND
|
||||
HDAPI_LIBRARY
|
||||
AND
|
||||
HDAPI_PHANToMIO_LIBRARY
|
||||
AND
|
||||
HDAPI_INCLUDE_DIR)
|
||||
find_file(OPENHAPTICS_LINKTEST_FILE
|
||||
FindOpenHaptics.cpp
|
||||
PATHS
|
||||
${CMAKE_MODULE_PATH})
|
||||
mark_as_advanced(OPENHAPTICS_LINKTEST_FILE)
|
||||
|
||||
try_compile(_result
|
||||
${CMAKE_CURRENT_BINARY_DIR}/FindOpenHaptics
|
||||
"${OPENHAPTICS_LINKTEST_FILE}"
|
||||
CMAKE_FLAGS
|
||||
"-DLINK_LIBRARIES=${HDAPI_LIBRARY}\;${HDAPI_PHANToMIO_LIBRARY} -DINCLUDE_DIRECTORIES=${HDAPI_INCLUDE_DIR}")
|
||||
if(NOT _result)
|
||||
set(OPENHAPTICS_LIBSTDCPP_DIR
|
||||
"${OPENHAPTICS_LIBSTDCPP_DIR}"
|
||||
CACHE
|
||||
PATH
|
||||
"The path to search for a libstdc++ with GLIBCXX_3.4.9 defined.")
|
||||
if(OPENHAPTICS_LIBSTDCPP_DIR)
|
||||
mark_as_advanced(OPENHAPTICS_LIBSTDCPP_DIR)
|
||||
endif()
|
||||
find_library(OPENHAPTICS_LIBSTDCPP_LIBRARY
|
||||
libstdc++
|
||||
PATHS
|
||||
${OPENHAPTICS_LIBSTDCPP_DIR}
|
||||
NO_DEFAULT_PATH)
|
||||
if(OPENHAPTICS_LIBSTDCPP_LIBRARY)
|
||||
mark_as_advanced(OPENHAPTICS_LIBSTDCPP_LIBRARY)
|
||||
endif()
|
||||
list(APPEND _deps_check OPENHAPTICS_LIBSTDCPP_LIBRARY)
|
||||
list(APPEND _deps_libs "${OPENHAPTICS_LIBSTDCPP_LIBRARY}")
|
||||
|
||||
get_filename_component(_stdcppdir
|
||||
"${OPENHAPTICS_LIBSTDCPP_LIBRARY}"
|
||||
PATH)
|
||||
list(APPEND
|
||||
OPENHAPTICS_ENVIRONMENT
|
||||
"LD_LIBRARY_PATH=${_stdcppdir}:$LD_LIBRARY_PATH")
|
||||
list(APPEND OPENHAPTICS_RUNTIME_LIBRARY_DIRS "${_stdcppdir}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
###
|
||||
# Add dependencies: Libraries
|
||||
###
|
||||
@@ -448,10 +439,12 @@ if(OPENHAPTICS_FOUND)
|
||||
set(OPENHAPTICS_LIBRARY_DIRS)
|
||||
foreach(_lib
|
||||
${_deps_check}
|
||||
HDAPI_LIBRARY
|
||||
HDAPI_LIBRARY_RELEASE
|
||||
HDAPI_LIBRARY_DEBUG
|
||||
HDAPI_HDU_LIBRARY_RELEASE
|
||||
HDAPI_HDU_LIBRARY_DEBUG
|
||||
HLAPI_LIBRARY
|
||||
HLAPI_LIBRARY_RELEASE
|
||||
HLAPI_LIBRARY_DEBUG
|
||||
HLAPI_HLU_LIBRARY_RELEASE
|
||||
HLAPI_HLU_LIBRARY_DEBUG)
|
||||
get_filename_component(_libdir ${${_lib}} PATH)
|
||||
@@ -475,12 +468,14 @@ if(OPENHAPTICS_FOUND)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(HDAPI_INCLUDE_DIR
|
||||
HDAPI_LIBRARY
|
||||
HDAPI_LIBRARY_RELEASE
|
||||
HDAPI_LIBRARY_DEBUG
|
||||
HDAPI_HDU_INCLUDE_DIR
|
||||
HDAPI_HDU_LIBRARY_RELEASE
|
||||
HDAPI_HDU_LIBRARY_DEBUG
|
||||
HLAPI_INCLUDE_DIR
|
||||
HLAPI_LIBRARY
|
||||
HLAPI_LIBRARY_RELEASE
|
||||
HLAPI_LIBRARY_DEBUG
|
||||
HLAPI_HLU_INCLUDE_DIR
|
||||
HLAPI_HLU_LIBRARY_RELEASE
|
||||
HLAPI_HLU_LIBRARY_DEBUG)
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/**
|
||||
* \file FindOpenHaptics.cpp
|
||||
* \brief C++ source file used by CMake module FindOpenHaptics.cmake
|
||||
*
|
||||
* \author
|
||||
* Ryan Pavlik, 2009-2010
|
||||
* <rpavlik@iastate.edu>
|
||||
* http://academic.cleardefinition.com/
|
||||
*
|
||||
* Used to check stdc++ version
|
||||
*
|
||||
*/
|
||||
|
||||
#include <HD/hd.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
}
|
||||
153
cmake/FindPerformer.cmake
Normal file
153
cmake/FindPerformer.cmake
Normal file
@@ -0,0 +1,153 @@
|
||||
# - try to find the OpenGL Performer library
|
||||
#
|
||||
# Users may optionally supply:
|
||||
# PERFORMER_ROOT_DIR - a prefix to start searching.
|
||||
#
|
||||
# Cache Variables: (probably not for direct use in your scripts)
|
||||
# PERFORMER_INCLUDE_DIR
|
||||
# PERFORMER_LIBRARY
|
||||
# PERFORMER_PFUI_LIBRARY - doesn't get included in PERFORMER_LIBRARIES
|
||||
# PERFORMER_PFDU_UTIL_LIBRARY - doesn't get included in PERFORMER_LIBRARIES
|
||||
# PERFORMER_PFV_LIBRARY - doesn't get included in PERFORMER_LIBRARIES
|
||||
#
|
||||
# Non-cache variables you might use in your CMakeLists.txt:
|
||||
# PERFORMER_FOUND
|
||||
# PERFORMER_INCLUDE_DIRS
|
||||
# PERFORMER_LIBRARIES
|
||||
# PERFORMER_RUNTIME_LIBRARY_DIRS
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
#
|
||||
# Original Author:
|
||||
# 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
set(PERFORMER_ROOT_DIR
|
||||
"${PERFORMER_ROOT_DIR}"
|
||||
CACHE
|
||||
PATH
|
||||
"Path to search for OpenGL Performer library")
|
||||
|
||||
|
||||
find_path(PERFORMER_INCLUDE_DIR
|
||||
NAMES
|
||||
pf.h
|
||||
HINTS
|
||||
"${PERFORMER_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
include
|
||||
include/Performer
|
||||
Performer
|
||||
PATHS
|
||||
$ENV{PFROOT})
|
||||
mark_as_advanced(PERFORMER_INCLUDE_DIR)
|
||||
|
||||
if(WIN32)
|
||||
set(_pf_libnameprefix lib)
|
||||
find_library(PERFORMER_PFDU_UTIL_LIBRARY
|
||||
NAMES
|
||||
libpfdu-util
|
||||
HINTS
|
||||
"${PERFORMER_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
lib
|
||||
PATHS
|
||||
$ENV{PFROOT})
|
||||
else()
|
||||
set(_pf_libnameprefix)
|
||||
find_library(PERFORMER_PFDU_LIBRARY
|
||||
NAMES
|
||||
pfdu
|
||||
HINTS
|
||||
"${PERFORMER_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
lib
|
||||
PATHS
|
||||
$ENV{PFROOT})
|
||||
find_library(PERFORMER_PFUTIL_LIBRARY
|
||||
NAMES
|
||||
pfutil
|
||||
HINTS
|
||||
"${PERFORMER_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
lib
|
||||
PATHS
|
||||
$ENV{PFROOT})
|
||||
if(PERFORMER_PFDU_LIBRARY AND PERFORMER_PFUTIL_LIBRARY)
|
||||
set(PERFORMER_PFDU_UTIL_LIBRARY
|
||||
${PERFORMER_PFDU_LIBRARY}
|
||||
${PERFORMER_PFUTIL_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_library(PERFORMER_LIBRARY
|
||||
NAMES
|
||||
${_pf_libnameprefix}pf
|
||||
HINTS
|
||||
"${PERFORMER_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
lib
|
||||
PATHS
|
||||
$ENV{PFROOT})
|
||||
find_library(PERFORMER_PFUI_LIBRARY
|
||||
NAMES
|
||||
${_pf_libnameprefix}pfui
|
||||
HINTS
|
||||
"${PERFORMER_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
lib
|
||||
PATHS
|
||||
$ENV{PFROOT})
|
||||
find_library(PERFORMER_PFV_LIBRARY
|
||||
NAMES
|
||||
${_pf_libnameprefix}pfv
|
||||
HINTS
|
||||
"${PERFORMER_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
lib
|
||||
PATHS
|
||||
$ENV{PFROOT})
|
||||
|
||||
###
|
||||
# Prereq: OpenGL
|
||||
###
|
||||
|
||||
find_package(OpenGL QUIET)
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Performer
|
||||
DEFAULT_MSG
|
||||
PERFORMER_LIBRARY
|
||||
PERFORMER_PFUI_LIBRARY
|
||||
PERFORMER_PFV_LIBRARY
|
||||
PERFORMER_PFDU_UTIL_LIBRARY
|
||||
PERFORMER_INCLUDE_DIR
|
||||
OPENGL_FOUND)
|
||||
|
||||
if(PERFORMER_FOUND)
|
||||
set(PERFORMER_INCLUDE_DIRS
|
||||
"${OPENGL_INCLUDE_DIR}"
|
||||
"${PERFORMER_INCLUDE_DIR}")
|
||||
if(PERFORMER_INCLUDE_DIR MATCHES ".*Performer.*")
|
||||
list(APPEND PERFORMER_INCLUDE_DIRS "${PERFORMER_INCLUDE_DIR}/..")
|
||||
endif()
|
||||
set(PERFORMER_LIBRARIES "${OPENGL_LIBRARY}" "${PERFORMER_LIBRARY}")
|
||||
mark_as_advanced(PERFORMER_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(PERFORMER_LIBRARY
|
||||
PERFORMER_PFUI_LIBRARY
|
||||
PERFORMER_PFV_LIBRARY
|
||||
PERFORMER_PFDU_LIBRARY
|
||||
PERFORMER_PFUTIL_LIBRARY
|
||||
PERFORMER_PFDU_UTIL_LIBRARY
|
||||
PERFORMER_INCLUDE_DIR)
|
||||
78
cmake/FindPerlModules.cmake
Normal file
78
cmake/FindPerlModules.cmake
Normal file
@@ -0,0 +1,78 @@
|
||||
# - try to find perl modules, passed as COMPONENTS
|
||||
#
|
||||
# Non-cache variable you might use in your CMakeLists.txt:
|
||||
# PERLMODULES_FOUND
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
#
|
||||
# Original Author:
|
||||
# 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
if(NOT PERL_FOUND)
|
||||
find_package(Perl QUIET)
|
||||
endif()
|
||||
|
||||
set(_deps_check)
|
||||
if(PERL_FOUND)
|
||||
foreach(module ${PerlModules_FIND_COMPONENTS})
|
||||
string(REPLACE "::" "/" modfilename "${module}.pm")
|
||||
string(REPLACE "::" "_" modvarname "PERLMODULES_${module}_MODULE")
|
||||
string(TOUPPER "${modvarname}" modvarname)
|
||||
list(APPEND _deps_check ${modvarname})
|
||||
if(NOT ${modvarname})
|
||||
if(NOT PerlModules_FIND_QUIETLY)
|
||||
message(STATUS "Checking for perl module ${module}")
|
||||
endif()
|
||||
execute_process(COMMAND
|
||||
"${PERL_EXECUTABLE}"
|
||||
"-e"
|
||||
"use ${module}; print \$INC{\"${modfilename}\"}"
|
||||
RESULT_VARIABLE result_code
|
||||
OUTPUT_VARIABLE filename
|
||||
ERROR_VARIABLE error_info
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(result_code EQUAL 0)
|
||||
if(NOT PerlModules_FIND_QUIETLY)
|
||||
message(STATUS
|
||||
"Checking for perl module ${module} - found at ${filename}")
|
||||
endif()
|
||||
set(${modvarname}
|
||||
"${filename}"
|
||||
CACHE
|
||||
FILEPATH
|
||||
"Location found for module ${module}"
|
||||
FORCE)
|
||||
mark_as_advanced(${modvarname})
|
||||
else()
|
||||
if(NOT PerlModules_FIND_QUIETLY)
|
||||
message(STATUS "Checking for perl module ${module} - failed")
|
||||
endif()
|
||||
set(${modvarname}
|
||||
"NOTFOUND"
|
||||
CACHE
|
||||
FILEPATH
|
||||
"No location found for module ${module}"
|
||||
FORCE)
|
||||
file(APPEND
|
||||
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
"Determining if the Perl module ${module} exists failed with the following error output:\n"
|
||||
"${error_info}\n\n")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(PerlModules
|
||||
DEFAULT_MSG
|
||||
PERL_FOUND
|
||||
${_deps_check})
|
||||
|
||||
81
cmake/FindQVRPN.cmake
Normal file
81
cmake/FindQVRPN.cmake
Normal file
@@ -0,0 +1,81 @@
|
||||
# - try to find QVRPN library
|
||||
#
|
||||
# Of course, you may also just choose to make QVRPN a submodule of your
|
||||
# project itself.
|
||||
#
|
||||
# Cache Variables:
|
||||
# QVRPN_LIBRARY
|
||||
# QVRPN_INCLUDE_DIR
|
||||
#
|
||||
# Non-cache variables you might use in your CMakeLists.txt:
|
||||
# QVRPN_FOUND
|
||||
# QVRPN_LIBRARIES
|
||||
# QVRPN_INCLUDE_DIRS
|
||||
#
|
||||
# QVRPN_ROOT_DIR is searched preferentially for these files
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
#
|
||||
# Refactored from FindVRPN.cmake by:
|
||||
# Juan Sebastian Casallas <casallas@iastate.edu>
|
||||
#
|
||||
# FindVRPN.cmake Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2009-2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
set(QVRPN_ROOT_DIR
|
||||
"${QVRPN_ROOT_DIR}"
|
||||
CACHE
|
||||
PATH
|
||||
"Root directory to search for QVRPN")
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
set(_LIBSUFFIXES /lib64 /lib)
|
||||
else()
|
||||
set(_LIBSUFFIXES /lib)
|
||||
endif()
|
||||
|
||||
###
|
||||
# Configure QVRPN
|
||||
###
|
||||
|
||||
find_path(QVRPN_INCLUDE_DIR
|
||||
NAMES
|
||||
vrpn_QMainloopContainer.h
|
||||
PATH_SUFFIXES
|
||||
include
|
||||
include/qvrpn
|
||||
HINTS
|
||||
"${QVRPN_ROOT_DIR}")
|
||||
|
||||
find_library(QVRPN_LIBRARY
|
||||
NAMES
|
||||
qvrpn
|
||||
PATH_SUFFIXES
|
||||
${_libsuffixes}
|
||||
HINTS
|
||||
"${QVRPN_ROOT_DIR}")
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(QVRPN
|
||||
DEFAULT_MSG
|
||||
QVRPN_LIBRARY
|
||||
QVRPN_INCLUDE_DIR)
|
||||
|
||||
if(QVRPN_FOUND)
|
||||
set(QVRPN_INCLUDE_DIRS "${QVRPN_INCLUDE_DIR}")
|
||||
set(QVRPN_LIBRARIES "${QVRPN_LIBRARY}")
|
||||
|
||||
mark_as_advanced(QVRPN_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(QVRPN_LIBRARY QVRPN_INCLUDE_DIR)
|
||||
@@ -37,11 +37,15 @@
|
||||
|
||||
|
||||
set(_HUMAN "Sonix 1.4")
|
||||
set(_RELEASE_NAMES sonix-1_4 libsonix-1_4 sonix-1_4_0)
|
||||
set(_DEBUG_NAMES sonix_d-1_4 libsonix_d-1_4 sonix_d-1_4_0)
|
||||
set(_FP_PKG_NAME sonix)
|
||||
set(_RELEASE_NAMES)
|
||||
set(_DEBUG_NAMES)
|
||||
foreach(VER 1_4 1_4_0 1_4_1 1_4_2)
|
||||
list(APPEND _RELEASE_NAMES ${_FP_PKG_NAME}-${VER})
|
||||
list(APPEND _DEBUG_NAMES ${_FP_PKG_NAME}_d-${VER})
|
||||
endforeach()
|
||||
set(_DIR sonix-1.4)
|
||||
set(_HEADER snx/sonix.h)
|
||||
set(_FP_PKG_NAME sonix)
|
||||
|
||||
include(SelectLibraryConfigurations)
|
||||
include(CreateImportedTarget)
|
||||
|
||||
@@ -70,7 +70,4 @@ endif()
|
||||
# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(TR1
|
||||
DEFAULT_MSG
|
||||
PLATFORM
|
||||
${_check})
|
||||
find_package_handle_standard_args(TR1 DEFAULT_MSG PLATFORM ${_check})
|
||||
|
||||
@@ -37,11 +37,15 @@
|
||||
|
||||
|
||||
set(_HUMAN "Tweek 1.4")
|
||||
set(_RELEASE_NAMES tweek-1_4 libtweek-1_4 tweek-1_4_0)
|
||||
set(_DEBUG_NAMES tweek_d-1_4 libtweek_d-1_4 tweek_d-1_4_0)
|
||||
set(_FP_PKG_NAME sonix)
|
||||
set(_RELEASE_NAMES)
|
||||
set(_DEBUG_NAMES)
|
||||
foreach(VER 1_4 1_4_0 1_4_1 1_4_2)
|
||||
list(APPEND _RELEASE_NAMES ${_FP_PKG_NAME}-${VER})
|
||||
list(APPEND _DEBUG_NAMES ${_FP_PKG_NAME}_d-${VER})
|
||||
endforeach()
|
||||
set(_DIR tweek-1.4)
|
||||
set(_HEADER tweek/tweek.h)
|
||||
set(_FP_PKG_NAME tweek)
|
||||
|
||||
include(SelectLibraryConfigurations)
|
||||
include(CreateImportedTarget)
|
||||
|
||||
@@ -40,11 +40,15 @@
|
||||
# Brandon Newendorp <brandon@newendorp.com>
|
||||
|
||||
set(_HUMAN "VPR 2.2")
|
||||
set(_RELEASE_NAMES vpr-2_2 libvpr-2_2 vpr-2_2_0)
|
||||
set(_DEBUG_NAMES vpr_d-2_2 libvpr_d-2_2 vpr_d-2_2_0)
|
||||
set(_FP_PKG_NAME vpr)
|
||||
set(_RELEASE_NAMES)
|
||||
set(_DEBUG_NAMES)
|
||||
foreach(VER 2_2 2_2_0 2_2_1 2_2_2)
|
||||
list(APPEND _RELEASE_NAMES ${_FP_PKG_NAME}-${VER})
|
||||
list(APPEND _DEBUG_NAMES ${_FP_PKG_NAME}_d-${VER})
|
||||
endforeach()
|
||||
set(_DIR vpr-2.2)
|
||||
set(_HEADER vpr/vpr.h)
|
||||
set(_FP_PKG_NAME vpr)
|
||||
|
||||
include(SelectLibraryConfigurations)
|
||||
include(CreateImportedTarget)
|
||||
@@ -193,8 +197,9 @@ if(UNIX AND NOT WIN32)
|
||||
if(NOT APPLE)
|
||||
find_library(VPR22_libuuid_LIBRARY NAMES uuid)
|
||||
mark_as_advanced(VPR22_libuuid_LIBRARY)
|
||||
list(APPEND _deps_check VPR22_libuuid_LIBRARY)
|
||||
list(APPEND _deps_libs ${VPR22_libuuid_LIBRARY})
|
||||
if(VPR22_libuuid_LIBRARY)
|
||||
list(APPEND _deps_libs ${VPR22_libuuid_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
@@ -45,11 +45,15 @@
|
||||
|
||||
|
||||
set(_HUMAN "VR Juggler 3.0 Core")
|
||||
set(_RELEASE_NAMES vrj-3_0 libvrj-3_0 vrj-3_0_0)
|
||||
set(_DEBUG_NAMES vrj_d-3_0 libvrj_d-3_0 vrj_d-3_0_0)
|
||||
set(_FP_PKG_NAME vrjuggler)
|
||||
set(_RELEASE_NAMES)
|
||||
set(_DEBUG_NAMES)
|
||||
foreach(VER 3_0 3_0_0 3_0_1 3_0_2)
|
||||
list(APPEND _RELEASE_NAMES vrj-${VER})
|
||||
list(APPEND _DEBUG_NAMES vrj_d-${VER})
|
||||
endforeach()
|
||||
set(_DIR vrjuggler-3.0)
|
||||
set(_HEADER vrj/Kernel/Kernel.h)
|
||||
set(_FP_PKG_NAME vrjuggler)
|
||||
|
||||
include(SelectLibraryConfigurations)
|
||||
include(CreateImportedTarget)
|
||||
|
||||
@@ -38,10 +38,14 @@
|
||||
|
||||
|
||||
set(_HUMAN "VR Juggler 3.0 OpenGL Core")
|
||||
set(_RELEASE_NAMES vrj_ogl-3_0 libvrj_ogl-3_0 vrj_ogl-3_0_0)
|
||||
set(_DEBUG_NAMES vrj_ogl_d-3_0 libvrj_ogl_d-3_0 vrj_ogl_d-3_0_0)
|
||||
set(_DIR vrjuggler-3.0)
|
||||
set(_FP_PKG_NAME vrjuggler-opengl)
|
||||
set(_RELEASE_NAMES)
|
||||
set(_DEBUG_NAMES)
|
||||
foreach(VER 3_0 3_0_0 3_0_1 3_0_2)
|
||||
list(APPEND _RELEASE_NAMES vrj_ogl-${VER})
|
||||
list(APPEND _DEBUG_NAMES vrj_ogl_d-${VER})
|
||||
endforeach()
|
||||
set(_DIR vrjuggler-3.0)
|
||||
|
||||
include(SelectLibraryConfigurations)
|
||||
include(CreateImportedTarget)
|
||||
|
||||
@@ -171,7 +171,10 @@ endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(VRJuggler
|
||||
DEFAULT_MSG VRJUGGLER_VERSION VRJUGGLER_LIBRARIES VRJUGGLER_FOUND)
|
||||
DEFAULT_MSG
|
||||
VRJUGGLER_VERSION
|
||||
VRJUGGLER_LIBRARIES
|
||||
VRJUGGLER_FOUND)
|
||||
|
||||
if(VRJUGGLER_FOUND)
|
||||
mark_as_advanced(VRJUGGLER_ROOT_DIR)
|
||||
|
||||
@@ -334,6 +334,20 @@ if(VRJUGGLER30_FOUND)
|
||||
list(APPEND _plugin_dirs "${_libdir}/sonix-1.4/plugins/dbg")
|
||||
list(APPEND _plugin_dirs "${_libdir}/sonix-1.4/plugins/opt")
|
||||
endif()
|
||||
|
||||
# Find directories of JCCL plugins
|
||||
if(EXISTS "${_libdir}/jccl/plugins")
|
||||
list(APPEND _plugin_dirs "${_libdir}/jccl/plugins")
|
||||
elseif(EXISTS "${_libdir}/jccl-1.4/plugins")
|
||||
list(APPEND _plugin_dirs "${_libdir}/jccl-1.4/plugins")
|
||||
endif()
|
||||
|
||||
# Find directories of VR Juggler plugins
|
||||
if(EXISTS "${_libdir}/vrjuggler/plugins")
|
||||
list(APPEND _plugin_dirs "${_libdir}/vrjuggler/plugins")
|
||||
elseif(EXISTS "${_libdir}/vrjuggler-3.0/plugins")
|
||||
list(APPEND _plugin_dirs "${_libdir}/vrjuggler-3.0/plugins")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Grab the actual plugins
|
||||
@@ -341,7 +355,13 @@ if(VRJUGGLER30_FOUND)
|
||||
if(EXISTS "${_libdir}")
|
||||
list(APPEND VRJUGGLER30_RUNTIME_LIBRARY_DIRS "${_libdir}")
|
||||
file(GLOB _plugins "${_libdir}/*${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||
list(APPEND VRJUGGLER30_BUNDLE_PLUGINS ${_plugins})
|
||||
foreach(_plugin ${_plugins})
|
||||
if("${_plugin}" MATCHES "_d${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||
list(APPEND VRJUGGLER30_BUNDLE_PLUGINS_DEBUG ${_plugin})
|
||||
else()
|
||||
list(APPEND VRJUGGLER30_BUNDLE_PLUGINS ${_plugin})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
@@ -391,19 +411,23 @@ function(install_vrjuggler30_data_files prefix)
|
||||
install(FILES "${base}/calibration.table" DESTINATION "${DEST}")
|
||||
endfunction()
|
||||
|
||||
function(install_vrjuggler30_plugins prefix varForFilenames)
|
||||
set(DEST "${prefix}")
|
||||
|
||||
set(out)
|
||||
foreach(plugin ${VRJUGGLER30_BUNDLE_PLUGINS})
|
||||
macro(_vrjuggler30_plugin_install _VAR)
|
||||
foreach(plugin ${${_VAR}})
|
||||
get_filename_component(full "${plugin}" ABSOLUTE)
|
||||
file(RELATIVE_PATH relloc "${VRJUGGLER30_VJ_BASE_DIR}" "${full}")
|
||||
set(filedest "${DEST}/${relloc}")
|
||||
get_filename_component(path "${filedest}" PATH)
|
||||
list(APPEND out "${filedest}")
|
||||
install(FILES "${full}" DESTINATION "${path}")
|
||||
install(FILES "${full}" DESTINATION "${path}" ${ARGN})
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
function(install_vrjuggler30_plugins prefix varForFilenames)
|
||||
set(DEST "${prefix}")
|
||||
|
||||
set(out)
|
||||
_vrjuggler30_plugin_install(VRJUGGLER30_BUNDLE_PLUGINS)
|
||||
_vrjuggler30_plugin_install(VRJUGGLER30_BUNDLE_PLUGINS_DEBUG CONFIGURATIONS DEBUG)
|
||||
set(${varForFilenames} ${out} PARENT_SCOPE)
|
||||
|
||||
endfunction()
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
#
|
||||
# Non-cache variables you might use in your CMakeLists.txt:
|
||||
# VRPN_FOUND
|
||||
# VRPN_SERVER_LIBRARIES
|
||||
# VRPN_LIBRARIES
|
||||
# VRPN_SERVER_LIBRARIES - server libraries
|
||||
# VRPN_LIBRARIES - client libraries
|
||||
# VRPN_CLIENT_DEFINITIONS - definitions if you only use the client library
|
||||
# VRPN_DEFINITIONS - Client-only definition if all we found was the client library.
|
||||
# VRPN_INCLUDE_DIRS
|
||||
#
|
||||
# VRPN_ROOT_DIR is searched preferentially for these files
|
||||
@@ -17,11 +19,11 @@
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# 2009-2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2009-2010.
|
||||
# Copyright Iowa State University 2009-2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
@@ -116,9 +118,19 @@ if(VRPN_FOUND)
|
||||
set(VRPN_LIBRARIES "${VRPN_LIBRARY}" ${_deps_libs})
|
||||
set(VRPN_SERVER_LIBRARIES "${VRPN_SERVER_LIBRARY}" ${_deps_libs})
|
||||
|
||||
if(VRPN_LIBRARY)
|
||||
set(VRPN_CLIENT_DEFINITIONS -DVRPN_CLIENT_ONLY)
|
||||
else()
|
||||
unset(VRPN_CLIENT_DEFINITIONS)
|
||||
endif()
|
||||
|
||||
if(VRPN_LIBRARY AND NOT VRPN_SERVER_LIBRARY)
|
||||
set(VRPN_DEFINITIONS -DVRPN_CLIENT_ONLY)
|
||||
else()
|
||||
unset(VRPN_DEFINITIONS)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(VRPN_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(VRPN_LIBRARY
|
||||
VRPN_SERVER_LIBRARY
|
||||
VRPN_INCLUDE_DIR)
|
||||
mark_as_advanced(VRPN_LIBRARY VRPN_SERVER_LIBRARY VRPN_INCLUDE_DIR)
|
||||
|
||||
94
cmake/FindViewPoint.cmake
Normal file
94
cmake/FindViewPoint.cmake
Normal file
@@ -0,0 +1,94 @@
|
||||
# - try to find Arrington Research ViewPoint EyeTracker SDK
|
||||
#
|
||||
# Cache Variables: (probably not for direct use in your scripts)
|
||||
# VIEWPOINT_INCLUDE_DIR
|
||||
# VIEWPOINT_LIBRARY
|
||||
# VIEWPOINT_RUNTIME_LIBRARY
|
||||
#
|
||||
# Non-cache variables you might use in your CMakeLists.txt:
|
||||
# VIEWPOINT_FOUND
|
||||
# VIEWPOINT_INCLUDE_DIRS
|
||||
# VIEWPOINT_LIBRARIES
|
||||
# VIEWPOINT_RUNTIME_LIBRARIES - aka the dll for installing
|
||||
# VIEWPOINT_RUNTIME_LIBRARY_DIRS
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
#
|
||||
# Original Author:
|
||||
# 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
set(VIEWPOINT_ROOT_DIR
|
||||
"${VIEWPOINT_ROOT_DIR}"
|
||||
CACHE
|
||||
PATH
|
||||
"Directory to search for Arrington Research ViewPoint EyeTracker SDK")
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
set(_LIBSUFFIXES /lib64 /lib)
|
||||
else()
|
||||
set(_LIBSUFFIXES /lib)
|
||||
endif()
|
||||
|
||||
find_library(VIEWPOINT_LIBRARY
|
||||
NAMES
|
||||
VPX_InterApp
|
||||
PATHS
|
||||
"${VIEWPOINT_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
"${_LIBSUFFIXES}")
|
||||
|
||||
get_filename_component(_libdir "${VIEWPOINT_LIBRARY}" PATH)
|
||||
|
||||
find_path(VIEWPOINT_INCLUDE_DIR
|
||||
NAMES
|
||||
vpx.h
|
||||
HINTS
|
||||
"${_libdir}"
|
||||
PATHS
|
||||
"${VIEWPOINT_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
include/)
|
||||
|
||||
set(_deps_check)
|
||||
if(WIN32)
|
||||
find_file(VIEWPOINT_RUNTIME_LIBRARY
|
||||
NAMES
|
||||
VPX_InterApp.dll
|
||||
HINTS
|
||||
"${_libdir}")
|
||||
|
||||
set(VIEWPOINT_RUNTIME_LIBRARIES "${VIEWPOINT_RUNTIME_LIBRARY}")
|
||||
get_filename_component(VIEWPOINT_RUNTIME_LIBRARY_DIRS
|
||||
"${VIEWPOINT_RUNTIME_LIBRARY}"
|
||||
PATH)
|
||||
list(APPEND _deps_check VIEWPOINT_RUNTIME_LIBRARY)
|
||||
else()
|
||||
get_filename_component(VIEWPOINT_RUNTIME_LIBRARY_DIRS
|
||||
"${VIEWPOINT_LIBRARY}"
|
||||
PATH)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(ViewPoint
|
||||
DEFAULT_MSG
|
||||
VIEWPOINT_LIBRARY
|
||||
VIEWPOINT_INCLUDE_DIR
|
||||
${_deps_check})
|
||||
|
||||
if(VIEWPOINT_FOUND)
|
||||
set(VIEWPOINT_LIBRARIES "${VIEWPOINT_LIBRARY}")
|
||||
set(VIEWPOINT_INCLUDE_DIRS "${VIEWPOINT_INCLUDE_DIR}")
|
||||
mark_as_advanced(VIEWPOINT_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(VIEWPOINT_INCLUDE_DIR
|
||||
VIEWPOINT_LIBRARY
|
||||
VIEWPOINT_RUNTIME_LIBRARY)
|
||||
@@ -74,6 +74,8 @@ if(WIN32)
|
||||
PATH)
|
||||
list(APPEND _deps_check WIIUSE_RUNTIME_LIBRARY)
|
||||
else()
|
||||
set(WIIUSE_RUNTIME_LIBRARY "${WIIUSE_LIBRARY}")
|
||||
set(WIIUSE_RUNTIME_LIBRARIES "${WIIUSE_RUNTIME_LIBRARY}")
|
||||
get_filename_component(WIIUSE_RUNTIME_LIBRARY_DIRS
|
||||
"${WIIUSE_LIBRARY}"
|
||||
PATH)
|
||||
|
||||
@@ -51,7 +51,10 @@ endif()
|
||||
if(MSVC)
|
||||
include(PrefixListGlob)
|
||||
include(CleanDirectoryList)
|
||||
prefix_list_glob(_prefixed "*/" "$ENV{SYSTEMDRIVE}/WinDDK/" "c:/WinDDK/")
|
||||
prefix_list_glob(_prefixed
|
||||
"*/"
|
||||
"$ENV{SYSTEMDRIVE}/WinDDK/"
|
||||
"c:/WinDDK/")
|
||||
clean_directory_list(_prefixed)
|
||||
find_library(WINHID_LIBRARY
|
||||
NAMES
|
||||
@@ -138,13 +141,16 @@ if(WINHID_FOUND)
|
||||
endif()
|
||||
if(NOT "${WINHID_MIN_WINDOWS_VER}" STREQUAL "${_winreq}")
|
||||
if(NOT WinHID_FIND_QUIETLY)
|
||||
message(STATUS "Linking against WINHID_LIBRARY will enforce this minimum version: ${_winreq}")
|
||||
message(STATUS
|
||||
"Linking against WINHID_LIBRARY will enforce this minimum version: ${_winreq}")
|
||||
endif()
|
||||
set(WINHID_MIN_WINDOWS_VER "${_winreq}" CACHE INTERNAL "" FORCE)
|
||||
endif()
|
||||
endif()
|
||||
set(WINHID_LIBRARIES "${WINHID_LIBRARY}")
|
||||
set(WINHID_INCLUDE_DIRS "${WINHID_CRT_INCLUDE_DIR}" "${WINHID_INCLUDE_DIR}")
|
||||
set(WINHID_INCLUDE_DIRS
|
||||
"${WINHID_CRT_INCLUDE_DIR}"
|
||||
"${WINHID_INCLUDE_DIR}")
|
||||
mark_as_advanced(WINHID_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
|
||||
163
cmake/FindWindowsSDK.cmake
Normal file
163
cmake/FindWindowsSDK.cmake
Normal file
@@ -0,0 +1,163 @@
|
||||
# - Find the Windows SDK aka Platform SDK
|
||||
#
|
||||
# Variables:
|
||||
# WINDOWSSDK_FOUND - if any version of the windows or platform SDK was found that is usable with the current version of visual studio
|
||||
# WINDOWSSDK_LATEST_DIR
|
||||
# WINDOWSSDK_LATEST_NAME
|
||||
# WINDOWSSDK_FOUND_PREFERENCE - if we found an entry indicating a "preferred" SDK listed for this visual studio version
|
||||
# WINDOWSSDK_PREFERRED_DIR
|
||||
# WINDOWSSDK_PREFERRED_NAME
|
||||
#
|
||||
# WINDOWSSDK_DIRS - contains no duplicates, ordered most recent first.
|
||||
# WINDOWSSDK_PREFERRED_FIRST_DIRS - contains no duplicates, ordered with preferred first, followed by the rest in descending recency
|
||||
#
|
||||
# Functions:
|
||||
# windowssdk_name_lookup(<directory> <output variable>) - Find the name corresponding with the SDK directory you pass in, or
|
||||
# NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work.
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
#
|
||||
# Original Author:
|
||||
# 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
set(_preferred_sdk_dirs)
|
||||
set(_win_sdk_dirs)
|
||||
set(_win_sdk_versanddirs)
|
||||
if(MSVC_VERSION GREATER 1310) # Newer than VS .NET/VS Toolkit 2003
|
||||
|
||||
# Environment variable for SDK dir
|
||||
if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL ""))
|
||||
message(STATUS "Got $ENV{WindowsSDKDir} - Windows/Platform SDK directories: ${_win_sdk_dirs}")
|
||||
list(APPEND _preferred_sdk_dirs "$ENV{WindowsSDKDir}")
|
||||
endif()
|
||||
|
||||
if(MSVC_VERSION LESS 1600)
|
||||
# Per-user current Windows SDK for VS2005/2008
|
||||
get_filename_component(_sdkdir
|
||||
"[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
|
||||
ABSOLUTE)
|
||||
if(EXISTS "${_sdkdir}")
|
||||
list(APPEND _preferred_sdk_dirs "${_sdkdir}")
|
||||
endif()
|
||||
|
||||
# System-wide current Windows SDK for VS2005/2008
|
||||
get_filename_component(_sdkdir
|
||||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
|
||||
ABSOLUTE)
|
||||
if(EXISTS "${_sdkdir}")
|
||||
list(APPEND _preferred_sdk_dirs "${_sdkdir}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
foreach(_winsdkver v8.0A v7.1 v7.0A v6.1 v6.0A v6.0)
|
||||
get_filename_component(_sdkdir
|
||||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\${_winsdkver};InstallationFolder]"
|
||||
ABSOLUTE)
|
||||
if(EXISTS "${_sdkdir}")
|
||||
list(APPEND _win_sdk_dirs "${_sdkdir}")
|
||||
list(APPEND
|
||||
_win_sdk_versanddirs
|
||||
"Windows SDK ${_winsdkver}"
|
||||
"${_sdkdir}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
if(MSVC_VERSION GREATER 1200)
|
||||
foreach(_platformsdkinfo
|
||||
"D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1_Microsoft Platform SDK for Windows Server 2003 R2"
|
||||
"8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3_Microsoft Platform SDK for Windows Server 2003 SP1")
|
||||
string(SUBSTRING "${_platformsdkinfo}" 0 36 _platformsdkguid)
|
||||
string(SUBSTRING "${_platformsdkinfo}" 37 -1 _platformsdkname)
|
||||
get_filename_component(_sdkdir
|
||||
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\${_platformsdkguid};Install Dir]"
|
||||
ABSOLUTE)
|
||||
if(EXISTS "${_sdkdir}")
|
||||
list(APPEND _win_sdk_dirs "${_sdkdir}")
|
||||
list(APPEND _win_sdk_versanddirs "${_platformsdkname}" "${_sdkdir}")
|
||||
endif()
|
||||
|
||||
get_filename_component(_sdkdir
|
||||
"[HKEY_CURRENT_USER\\Software\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\${_platformsdkguid};Install Dir]"
|
||||
ABSOLUTE)
|
||||
if(EXISTS "${_sdkdir}")
|
||||
list(APPEND _win_sdk_dirs "${_sdkdir}")
|
||||
list(APPEND _win_sdk_versanddirs "${_platformsdkname}" "${_sdkdir}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
set(_win_sdk_versanddirs
|
||||
"${_win_sdk_versanddirs}"
|
||||
CACHE
|
||||
INTERNAL
|
||||
"mapping between windows sdk version locations and names"
|
||||
FORCE)
|
||||
|
||||
function(windowssdk_name_lookup _dir _outvar)
|
||||
list(FIND _win_sdk_versanddirs "${_dir}" _diridx)
|
||||
math(EXPR _nameidx "${_diridx} - 1")
|
||||
if(${_nameidx} GREATER -1)
|
||||
list(GET _win_sdk_versanddirs ${_nameidx} _sdkname)
|
||||
else()
|
||||
set(_sdkname "NOTFOUND")
|
||||
endif()
|
||||
set(${_outvar} "${_sdkname}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
if(_win_sdk_dirs)
|
||||
# Remove duplicates
|
||||
list(REMOVE_DUPLICATES _win_sdk_dirs)
|
||||
list(GET _win_sdk_dirs 0 WINDOWSSDK_LATEST_DIR)
|
||||
windowssdk_name_lookup("${WINDOWSSDK_LATEST_DIR}"
|
||||
WINDOWSSDK_LATEST_NAME)
|
||||
set(WINDOWSSDK_DIRS ${_win_sdk_dirs})
|
||||
endif()
|
||||
if(_preferred_sdk_dirs)
|
||||
list(GET _preferred_sdk_dirs 0 WINDOWSSDK_PREFERRED_DIR)
|
||||
windowssdk_name_lookup("${WINDOWSSDK_LATEST_DIR}"
|
||||
WINDOWSSDK_PREFERRED_NAME)
|
||||
set(WINDOWSSDK_PREFERRED_FIRST_DIRS
|
||||
${_preferred_sdk_dirs}
|
||||
${_win_sdk_dirs})
|
||||
list(REMOVE_DUPLICATES WINDOWSSDK_PREFERRED_FIRST_DIRS)
|
||||
set(WINDOWSSDK_FOUND_PREFERENCE ON)
|
||||
|
||||
# In case a preferred dir was found that isn't found otherwise
|
||||
#set(WINDOWSSDK_DIRS ${WINDOWSSDK_DIRS} ${WINDOWSSDK_PREFERRED_FIRST_DIRS})
|
||||
#list(REMOVE_DUPLICATES WINDOWSSDK_DIRS)
|
||||
else()
|
||||
set(WINDOWSSDK_PREFERRED_DIR "${WINDOWSSDK_LATEST_DIR}")
|
||||
set(WINDOWSSDK_PREFERRED_NAME "${WINDOWSSDK_LATEST_NAME}")
|
||||
set(WINDOWSSDK_PREFERRED_FIRST_DIRS ${WINDOWSSDK_DIRS})
|
||||
set(WINDOWSSDK_FOUND_PREFERENCE OFF)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(WindowsSDK
|
||||
"No compatible version of the Windows SDK or Platform SDK found."
|
||||
WINDOWSSDK_DIRS)
|
||||
|
||||
if(WINDOWSSDK_FOUND)
|
||||
if(NOT _winsdk_remembered_dirs STREQUAL WINDOWSSDK_DIRS)
|
||||
set(_winsdk_remembered_dirs
|
||||
"${WINDOWSSDK_DIRS}"
|
||||
CACHE
|
||||
INTERNAL
|
||||
""
|
||||
FORCE)
|
||||
if(NOT WindowsSDK_FIND_QUIETLY)
|
||||
foreach(_sdkdir ${WINDOWSSDK_DIRS})
|
||||
windowssdk_name_lookup("${_sdkdir}" _sdkname)
|
||||
message(STATUS " - Found ${_sdkname} at ${_sdkdir}")
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
@@ -39,6 +39,10 @@ set(CPPCHECK_ROOT_DIR
|
||||
set(_oldappbundlesetting ${CMAKE_FIND_APPBUNDLE})
|
||||
set(CMAKE_FIND_APPBUNDLE NEVER)
|
||||
|
||||
if(CPPCHECK_EXECUTABLE AND NOT EXISTS "${CPPCHECK_EXECUTABLE}")
|
||||
set(CPPCHECK_EXECUTABLE "notfound" CACHE PATH FORCE "")
|
||||
endif()
|
||||
|
||||
# If we have a custom path, look there first.
|
||||
if(CPPCHECK_ROOT_DIR)
|
||||
find_program(CPPCHECK_EXECUTABLE
|
||||
@@ -57,37 +61,61 @@ find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)
|
||||
# Restore original setting for appbundle finding
|
||||
set(CMAKE_FIND_APPBUNDLE ${_oldappbundlesetting})
|
||||
|
||||
# Find out where our test file is
|
||||
get_filename_component(_cppcheckmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
|
||||
set(_cppcheckdummyfile "${_cppcheckmoddir}/Findcppcheck.cpp")
|
||||
if(NOT EXISTS "${_cppcheckdummyfile}")
|
||||
message(FATAL_ERROR
|
||||
"Missing file ${_cppcheckdummyfile} - should be alongside Findcppcheck.cmake, can be found at https://github.com/rpavlik/cmake-modules")
|
||||
endif()
|
||||
|
||||
function(_cppcheck_test_arg _resultvar _arg)
|
||||
if(NOT CPPCHECK_EXECUTABLE)
|
||||
set(${_resultvar} NO)
|
||||
return()
|
||||
endif()
|
||||
execute_process(COMMAND
|
||||
"${CPPCHECK_EXECUTABLE}"
|
||||
"${_arg}"
|
||||
"--quiet"
|
||||
"${_cppcheckdummyfile}"
|
||||
RESULT_VARIABLE
|
||||
_cppcheck_result
|
||||
OUTPUT_QUIET
|
||||
ERROR_QUIET)
|
||||
if("${_cppcheck_result}" EQUAL 0)
|
||||
set(${_resultvar} YES PARENT_SCOPE)
|
||||
else()
|
||||
set(${_resultvar} NO PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(_cppcheck_set_arg_var _argvar _arg)
|
||||
if("${${_argvar}}" STREQUAL "")
|
||||
_cppcheck_test_arg(_cppcheck_arg "${_arg}")
|
||||
if(_cppcheck_arg)
|
||||
set(${_argvar} "${_arg}" PARENT_SCOPE)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(CPPCHECK_EXECUTABLE)
|
||||
# Find out where our test file is
|
||||
get_filename_component(_cppcheckmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
|
||||
set(_cppcheckdummyfile "${_cppcheckmoddir}/Findcppcheck.cpp")
|
||||
|
||||
# Check for the two types of command line arguments by just trying them
|
||||
execute_process(COMMAND
|
||||
"${CPPCHECK_EXECUTABLE}"
|
||||
"--enable=style"
|
||||
"--quiet"
|
||||
"${_cppcheckdummyfile}"
|
||||
RESULT_VARIABLE
|
||||
_cppcheck_new_result
|
||||
OUTPUT_QUIET
|
||||
ERROR_QUIET)
|
||||
execute_process(COMMAND
|
||||
"${CPPCHECK_EXECUTABLE}"
|
||||
"--style"
|
||||
"--quiet"
|
||||
"${_cppcheckdummyfile}"
|
||||
RESULT_VARIABLE
|
||||
_cppcheck_old_result
|
||||
OUTPUT_QUIET
|
||||
ERROR_QUIET)
|
||||
if("${_cppcheck_new_result}" EQUAL 0)
|
||||
# New arguments
|
||||
set(CPPCHECK_UNUSEDFUNC_ARG "--enable=unusedFunctions")
|
||||
set(CPPCHECK_POSSIBLEERROR_ARG "--enable=possibleError")
|
||||
set(CPPCHECK_STYLE_ARG "--enable=style")
|
||||
set(CPPCHECK_QUIET_ARG "--quiet")
|
||||
set(CPPCHECK_INCLUDEPATH_ARG "-I")
|
||||
_cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--enable=style")
|
||||
_cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--style")
|
||||
if("${CPPCHECK_STYLE_ARG}" STREQUAL "--enable=style")
|
||||
|
||||
_cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG
|
||||
"--enable=unusedFunctions")
|
||||
_cppcheck_set_arg_var(CPPCHECK_INFORMATION_ARG "--enable=information")
|
||||
_cppcheck_set_arg_var(CPPCHECK_MISSINGINCLUDE_ARG
|
||||
"--enable=missingInclude")
|
||||
_cppcheck_set_arg_var(CPPCHECK_POSIX_ARG "--enable=posix")
|
||||
_cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG
|
||||
"--enable=possibleError")
|
||||
_cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--enable=all")
|
||||
|
||||
if(MSVC)
|
||||
set(CPPCHECK_TEMPLATE_ARG --template vs)
|
||||
set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]")
|
||||
@@ -97,19 +125,14 @@ if(CPPCHECK_EXECUTABLE)
|
||||
set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
|
||||
set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
|
||||
else()
|
||||
message(STATUS
|
||||
"Warning: FindCppcheck doesn't know how to format error messages for your compiler!")
|
||||
set(CPPCHECK_TEMPLATE_ARG --template gcc)
|
||||
set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
|
||||
set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
|
||||
endif()
|
||||
elseif("${_cppcheck_old_result}" EQUAL 0)
|
||||
elseif("${CPPCHECK_STYLE_ARG}" STREQUAL "--style")
|
||||
# Old arguments
|
||||
set(CPPCHECK_UNUSEDFUNC_ARG "--unused-functions")
|
||||
set(CPPCHECK_POSSIBLEERROR_ARG "--all")
|
||||
set(CPPCHECK_STYLE_ARG "--style")
|
||||
set(CPPCHECK_QUIET_ARG "--quiet")
|
||||
set(CPPCHECK_INCLUDEPATH_ARG "-I")
|
||||
_cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG "--unused-functions")
|
||||
_cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--all")
|
||||
set(CPPCHECK_FAIL_REGULAR_EXPRESSION "error:")
|
||||
set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
|
||||
else()
|
||||
@@ -118,6 +141,8 @@ if(CPPCHECK_EXECUTABLE)
|
||||
"WARNING: Can't detect whether CPPCHECK wants new or old-style arguments!")
|
||||
endif()
|
||||
|
||||
set(CPPCHECK_QUIET_ARG "--quiet")
|
||||
set(CPPCHECK_INCLUDEPATH_ARG "-I")
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ include(SelectLibraryConfigurations)
|
||||
select_library_configurations(CPPUNIT)
|
||||
|
||||
# Might want to look close to the library first for the includes.
|
||||
get_filename_component(_libdir "${MYSIMPLEPACKAGE_LIBRARY}" PATH)
|
||||
get_filename_component(_libdir "${CPPUNIT_LIBRARY_RELEASE}" PATH)
|
||||
|
||||
find_path(CPPUNIT_INCLUDE_DIR
|
||||
NAMES
|
||||
|
||||
@@ -23,19 +23,27 @@ find_package(CUDA QUIET)
|
||||
file(TO_CMAKE_PATH "${CUDA_SDK_ROOT_DIR}/C/common" CUTIL_ROOT_DIR)
|
||||
|
||||
if(NOT EXISTS "${CUTIL_ROOT_DIR}/src/cutil.cpp")
|
||||
set(CUDA_SDK_ROOT_DIR SDKDIR-NOTFOUND CACHE PATH "NVIDIA GPU Computing SDK dir" FORCE)
|
||||
set(CUDA_SDK_ROOT_DIR
|
||||
SDKDIR-NOTFOUND
|
||||
CACHE
|
||||
PATH
|
||||
"NVIDIA GPU Computing SDK dir"
|
||||
FORCE)
|
||||
endif()
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(cutil DEFAULT_MSG CUDA_SDK_ROOT_DIR CUDA_FOUND)
|
||||
find_package_handle_standard_args(cutil
|
||||
DEFAULT_MSG
|
||||
CUDA_SDK_ROOT_DIR
|
||||
CUDA_FOUND)
|
||||
|
||||
if(CUTIL_FOUND)
|
||||
if(CUTIL_FOUND)
|
||||
get_filename_component(_moddir "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
add_subdirectory("${_moddir}/nested_targets/cutil")
|
||||
|
||||
|
||||
|
||||
|
||||
function(install_cutil dest)
|
||||
install(TARGETS cutil
|
||||
RUNTIME DESTINATION "${dest}"
|
||||
|
||||
@@ -106,11 +106,9 @@ function(get_compiler_info_string _var)
|
||||
set(_verstring "gcc${_gccver}")
|
||||
|
||||
else()
|
||||
# Some other compiler we don't handle yet.
|
||||
message(STATUS
|
||||
"WARNING: Not GCC or MSVC, so we invented a messy compiler info string")
|
||||
# Some other compiler we don't handle in more detail yet.
|
||||
string(REGEX REPLACE " " "_" _verstring "${CMAKE_GENERATOR}")
|
||||
set(_verstring "generator:${_verstring}")
|
||||
set(_verstring "${CMAKE_CXX_COMPILER_ID}:generator:${_verstring}")
|
||||
endif()
|
||||
|
||||
# Return _verstring
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
# These functions force a re-configure on each git commit so that you can
|
||||
# trust the values of the variables in your build system.
|
||||
#
|
||||
# get_git_head_revision(<refspecvar> <hashvar> [<additonal arguments to git describe> ...])
|
||||
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the refspec and sha hash of the current head revision
|
||||
#
|
||||
# git_describe(<var> [<additonal arguments to git describe> ...])
|
||||
# git_describe(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe on the source tree, and adjusting
|
||||
# the output so that it tests false if an error occurs.
|
||||
#
|
||||
# git_get_exact_tag(<var> [<additonal arguments to git describe> ...])
|
||||
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe --exact-match on the source tree,
|
||||
# and adjusting the output so that it tests false if there was no exact
|
||||
@@ -40,21 +40,33 @@ set(__get_git_revision_description YES)
|
||||
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
|
||||
|
||||
function(get_git_head_revision _refspecvar _hashvar)
|
||||
set(GIT_DIR "${CMAKE_SOURCE_DIR}/.git")
|
||||
if(NOT EXISTS "${GIT_DIR}")
|
||||
# not in git
|
||||
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
|
||||
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
set(GIT_PARENT_DIR "${CMAKE_SOURCE_DIR}")
|
||||
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
|
||||
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
|
||||
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
|
||||
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
|
||||
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
|
||||
# We have reached the root directory, we are not in git
|
||||
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
|
||||
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
|
||||
endwhile()
|
||||
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
|
||||
if(NOT EXISTS "${GIT_DATA}")
|
||||
file(MAKE_DIRECTORY "${GIT_DATA}")
|
||||
endif()
|
||||
|
||||
if(NOT EXISTS "${GIT_DIR}/HEAD")
|
||||
return()
|
||||
endif()
|
||||
set(HEAD_FILE "${GIT_DATA}/HEAD")
|
||||
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
|
||||
|
||||
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" "${GIT_DATA}/grabRef.cmake" @ONLY)
|
||||
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
|
||||
"${GIT_DATA}/grabRef.cmake"
|
||||
@ONLY)
|
||||
include("${GIT_DATA}/grabRef.cmake")
|
||||
|
||||
set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
|
||||
@@ -67,11 +79,11 @@ function(git_describe _var)
|
||||
endif()
|
||||
get_git_head_revision(refspec hash)
|
||||
if(NOT GIT_FOUND)
|
||||
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
|
||||
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
if(NOT hash)
|
||||
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
|
||||
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
@@ -85,10 +97,17 @@ function(git_describe _var)
|
||||
|
||||
#message(STATUS "Arguments to execute_process: ${ARGN}")
|
||||
|
||||
execute_process(COMMAND "${GIT_EXECUTABLE}" describe ${hash} ${ARGN}
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
RESULT_VARIABLE res
|
||||
OUTPUT_VARIABLE out
|
||||
execute_process(COMMAND
|
||||
"${GIT_EXECUTABLE}"
|
||||
describe
|
||||
${hash}
|
||||
${ARGN}
|
||||
WORKING_DIRECTORY
|
||||
"${CMAKE_SOURCE_DIR}"
|
||||
RESULT_VARIABLE
|
||||
res
|
||||
OUTPUT_VARIABLE
|
||||
out
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT res EQUAL 0)
|
||||
|
||||
@@ -13,18 +13,26 @@
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
set(HEAD_HASH)
|
||||
|
||||
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
|
||||
|
||||
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
|
||||
if(HEAD_CONTENTS MATCHES "ref")
|
||||
# named branch
|
||||
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
|
||||
|
||||
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
|
||||
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}")
|
||||
configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
set(HEAD_HASH "${HEAD_REF}")
|
||||
endif()
|
||||
else()
|
||||
# detached HEAD
|
||||
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
endif()
|
||||
|
||||
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
|
||||
string(STRIP "${HEAD_HASH}" HEAD_HASH)
|
||||
if(NOT HEAD_HASH)
|
||||
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
|
||||
string(STRIP "${HEAD_HASH}" HEAD_HASH)
|
||||
endif()
|
||||
|
||||
@@ -40,15 +40,15 @@ function(add_lua_target _target _dest)
|
||||
if(NOT LUA_TARGET_LUAC_EXECUTABLE)
|
||||
if(TARGET luac)
|
||||
set(LUA_TARGET_LUAC_EXECUTABLE luac)
|
||||
mark_as_advanced(LUA_TARGET_LUAC_EXECUTABLE)
|
||||
else()
|
||||
find_program(LUA_TARGET_LUAC_EXECUTABLE
|
||||
NAMES
|
||||
luac)
|
||||
find_program(LUA_TARGET_LUAC_EXECUTABLE NAMES luac)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT LUA_TARGET_LUAC_EXECUTABLE)
|
||||
message(FATAL_ERROR "Can't find luac: please give LUA_TARGET_LUAC_EXECUTABLE a useful value - currently ${LUA_TARGET_LUAC_EXECUTABLE}")
|
||||
message(FATAL_ERROR
|
||||
"Can't find luac: please give LUA_TARGET_LUAC_EXECUTABLE a useful value - currently ${LUA_TARGET_LUAC_EXECUTABLE}")
|
||||
endif()
|
||||
mark_as_advanced(LUA_TARGET_LUAC_EXECUTABLE)
|
||||
|
||||
@@ -60,7 +60,9 @@ function(add_lua_target _target _dest)
|
||||
get_filename_component(fullpath "${fn}" ABSOLUTE)
|
||||
get_filename_component(fn "${fn}" NAME)
|
||||
else()
|
||||
get_filename_component(fullpath "${CMAKE_CURRENT_SOURCE_DIR}/${fn}" ABSOLUTE)
|
||||
get_filename_component(fullpath
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${fn}"
|
||||
ABSOLUTE)
|
||||
endif()
|
||||
|
||||
# Clean up output file name
|
||||
@@ -88,7 +90,11 @@ function(add_lua_target _target _dest)
|
||||
SOURCES ${SOURCES}
|
||||
DEPENDS ${ALLFILES})
|
||||
if(TARGET "${LUA_TARGET_LUAC_EXECUTABLE}")
|
||||
get_property(_luac_imported TARGET "${LUA_TARGET_LUAC_EXECUTABLE}" PROPERTY IMPORTED)
|
||||
get_property(_luac_imported
|
||||
TARGET
|
||||
"${LUA_TARGET_LUAC_EXECUTABLE}"
|
||||
PROPERTY
|
||||
IMPORTED)
|
||||
if(NOT _luac_imported)
|
||||
add_dependencies(${_target} ${LUA_TARGET_LUAC_EXECUTABLE})
|
||||
endif()
|
||||
|
||||
@@ -21,7 +21,7 @@ function(option_requires name desc)
|
||||
list(REMOVE_AT args ${_off_found})
|
||||
set(OFF_BY_DEFAULT true)
|
||||
endif()
|
||||
|
||||
|
||||
set(found)
|
||||
set(missing)
|
||||
foreach(var ${args})
|
||||
@@ -31,22 +31,23 @@ function(option_requires name desc)
|
||||
list(APPEND missing ${var})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
|
||||
if(NOT missing)
|
||||
set(OK TRUE)
|
||||
else()
|
||||
set(OK FALSE)
|
||||
endif()
|
||||
|
||||
|
||||
set(default ${OK})
|
||||
if(OFF_BY_DEFAULT)
|
||||
set(default OFF)
|
||||
endif()
|
||||
|
||||
|
||||
option(${name} "${desc}" ${default})
|
||||
|
||||
|
||||
if(${name} AND (NOT OK))
|
||||
message(FATAL_ERROR "${name} enabled but these dependencies were not valid: ${missing}")
|
||||
message(FATAL_ERROR
|
||||
"${name} enabled but these dependencies were not valid: ${missing}")
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
||||
@@ -72,7 +72,7 @@ Licenses
|
||||
|
||||
The modules that I wrote myself are all subject to this license:
|
||||
|
||||
> Copyright Iowa State University 2009-2010
|
||||
> Copyright Iowa State University 2009-2012
|
||||
>
|
||||
> Distributed under the Boost Software License, Version 1.0.
|
||||
>
|
||||
|
||||
116
cmake/UseMarkdown.cmake
Normal file
116
cmake/UseMarkdown.cmake
Normal file
@@ -0,0 +1,116 @@
|
||||
# - Convert markdown source files to HTML as a custom target
|
||||
#
|
||||
# include(UseMarkdown)
|
||||
# add_markdown_target(<target_name> <directory to copy to> <markdownfile> [<markdownfile>...] [RENAME <newname>])
|
||||
# Relative paths for the destination directory are considered with
|
||||
# with respect to CMAKE_CURRENT_BINARY_DIR. The RENAME argument is only
|
||||
# valid with a single markdown file as input.
|
||||
#
|
||||
#
|
||||
# install_markdown_target(<target_name> [extra arguments to INSTALL(FILES ...) ])
|
||||
#
|
||||
#
|
||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||
#
|
||||
# Original Author:
|
||||
# 2011 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2011-2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
if(__add_markdown_target)
|
||||
return()
|
||||
endif()
|
||||
set(__add_markdown_target YES)
|
||||
|
||||
define_property(TARGET
|
||||
PROPERTY
|
||||
MARKDOWN_TARGET_OUTPUTS
|
||||
BRIEF_DOCS
|
||||
"Markdown target outputs"
|
||||
FULL_DOCS
|
||||
"Output files of a target created by add_markdown_target")
|
||||
|
||||
function(add_markdown_target _target _dest)
|
||||
|
||||
if(NOT ARGN)
|
||||
message(WARNING
|
||||
"In add_markdown_target call for target ${_target}, no source files were specified!")
|
||||
return()
|
||||
endif()
|
||||
|
||||
find_package(Markdown QUIET)
|
||||
if(NOT MARKDOWN_EXECUTABLE)
|
||||
message(FATAL_ERROR "Can't find a markdown conversion tool!")
|
||||
endif()
|
||||
|
||||
set(NEW_NAME)
|
||||
list(FIND ARGN "RENAME" _renameloc)
|
||||
if(_renameloc GREATER -1)
|
||||
list(LENGTH ARGN _len)
|
||||
if(NOT _len EQUAL 3)
|
||||
message(FATAL_ERROR
|
||||
"Specifying RENAME requires 1 input file and 1 output name!")
|
||||
endif()
|
||||
list(GET ARGN 2 NEW_NAME)
|
||||
list(GET ARGN 0 ARGN)
|
||||
endif()
|
||||
|
||||
set(ALLFILES)
|
||||
set(SOURCES)
|
||||
foreach(fn ${ARGN})
|
||||
# Produce an absolute path to the input file
|
||||
if(IS_ABSOLUTE "${fn}")
|
||||
get_filename_component(fullpath "${fn}" ABSOLUTE)
|
||||
get_filename_component(fn "${fn}" NAME)
|
||||
else()
|
||||
get_filename_component(fullpath
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${fn}"
|
||||
ABSOLUTE)
|
||||
endif()
|
||||
get_filename_component(fn_noext "${fn}" NAME_WE)
|
||||
|
||||
# Clean up output file name
|
||||
if(NEW_NAME)
|
||||
get_filename_component(absout "${_dest}/${NEW_NAME}" ABSOLUTE)
|
||||
else()
|
||||
get_filename_component(absout "${_dest}/${fn_noext}.html" ABSOLUTE)
|
||||
endif()
|
||||
|
||||
add_custom_command(OUTPUT "${absout}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
ARGS -E make_directory "${_dest}"
|
||||
COMMAND
|
||||
${MARKDOWN_EXECUTABLE}
|
||||
ARGS "${fullpath}" > "${absout}"
|
||||
MAIN_DEPENDENCY "${fullpath}"
|
||||
VERBATIM
|
||||
COMMENT "Converting Markdown ${fn} to HTML in ${absout}...")
|
||||
list(APPEND SOURCES "${fullpath}")
|
||||
list(APPEND ALLFILES "${absout}")
|
||||
endforeach()
|
||||
|
||||
# Custom target depending on all the file copy commands
|
||||
add_custom_target(${_target}
|
||||
ALL
|
||||
SOURCES ${SOURCES}
|
||||
DEPENDS ${ALLFILES})
|
||||
set_property(TARGET ${_target} PROPERTY MARKDOWN_TARGET_OUTPUTS "${ALLFILES}")
|
||||
endfunction()
|
||||
|
||||
function(install_markdown_target _target)
|
||||
get_target_property(_mtoutputs ${_target} MARKDOWN_TARGET_OUTPUTS)
|
||||
if(NOT _mtoutputs)
|
||||
message(WARNING
|
||||
"install_markdown_target called on a target not created with add_markdown_target!")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Forward the call to install
|
||||
install(FILES ${_mtoutputs} ${ARGN})
|
||||
endfunction()
|
||||
254
cmake/cmake-2.8.10-modules/CMakePackageConfigHelpers.cmake
Normal file
254
cmake/cmake-2.8.10-modules/CMakePackageConfigHelpers.cmake
Normal file
@@ -0,0 +1,254 @@
|
||||
# - CONFIGURE_PACKAGE_CONFIG_FILE(), WRITE_BASIC_PACKAGE_VERSION_FILE()
|
||||
#
|
||||
# CONFIGURE_PACKAGE_CONFIG_FILE(<input> <output> INSTALL_DESTINATION <path>
|
||||
# [PATH_VARS <var1> <var2> ... <varN>]
|
||||
# [NO_SET_AND_CHECK_MACRO]
|
||||
# [NO_CHECK_REQUIRED_COMPONENTS_MACRO])
|
||||
#
|
||||
# CONFIGURE_PACKAGE_CONFIG_FILE() should be used instead of the plain
|
||||
# configure_file() command when creating the <Name>Config.cmake or <Name>-config.cmake
|
||||
# file for installing a project or library. It helps making the resulting package
|
||||
# relocatable by avoiding hardcoded paths in the installed Config.cmake file.
|
||||
#
|
||||
# In a FooConfig.cmake file there may be code like this to make the
|
||||
# install destinations know to the using project:
|
||||
# set(FOO_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@" )
|
||||
# set(FOO_DATA_DIR "@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@" )
|
||||
# set(FOO_ICONS_DIR "@CMAKE_INSTALL_PREFIX@/share/icons" )
|
||||
# ...logic to determine installedPrefix from the own location...
|
||||
# set(FOO_CONFIG_DIR "${installedPrefix}/@CONFIG_INSTALL_DIR@" )
|
||||
# All 4 options shown above are not sufficient, since the first 3 hardcode
|
||||
# the absolute directory locations, and the 4th case works only if the logic
|
||||
# to determine the installedPrefix is correct, and if CONFIG_INSTALL_DIR contains
|
||||
# a relative path, which in general cannot be guaranteed.
|
||||
# This has the effect that the resulting FooConfig.cmake file would work poorly
|
||||
# under Windows and OSX, where users are used to choose the install location
|
||||
# of a binary package at install time, independent from how CMAKE_INSTALL_PREFIX
|
||||
# was set at build/cmake time.
|
||||
#
|
||||
# Using CONFIGURE_PACKAGE_CONFIG_FILE() helps. If used correctly, it makes the
|
||||
# resulting FooConfig.cmake file relocatable.
|
||||
# Usage:
|
||||
# 1. write a FooConfig.cmake.in file as you are used to
|
||||
# 2. insert a line containing only the string "@PACKAGE_INIT@"
|
||||
# 3. instead of set(FOO_DIR "@SOME_INSTALL_DIR@"), use set(FOO_DIR "@PACKAGE_SOME_INSTALL_DIR@")
|
||||
# (this must be after the @PACKAGE_INIT@ line)
|
||||
# 4. instead of using the normal configure_file(), use CONFIGURE_PACKAGE_CONFIG_FILE()
|
||||
#
|
||||
# The <input> and <output> arguments are the input and output file, the same way
|
||||
# as in configure_file().
|
||||
#
|
||||
# The <path> given to INSTALL_DESTINATION must be the destination where the FooConfig.cmake
|
||||
# file will be installed to. This can either be a relative or absolute path, both work.
|
||||
#
|
||||
# The variables <var1> to <varN> given as PATH_VARS are the variables which contain
|
||||
# install destinations. For each of them the macro will create a helper variable
|
||||
# PACKAGE_<var...>. These helper variables must be used
|
||||
# in the FooConfig.cmake.in file for setting the installed location. They are calculated
|
||||
# by CONFIGURE_PACKAGE_CONFIG_FILE() so that they are always relative to the
|
||||
# installed location of the package. This works both for relative and also for absolute locations.
|
||||
# For absolute locations it works only if the absolute location is a subdirectory
|
||||
# of CMAKE_INSTALL_PREFIX.
|
||||
#
|
||||
# By default configure_package_config_file() also generates two helper macros,
|
||||
# set_and_check() and check_required_components() into the FooConfig.cmake file.
|
||||
#
|
||||
# set_and_check() should be used instead of the normal set()
|
||||
# command for setting directories and file locations. Additionally to setting the
|
||||
# variable it also checks that the referenced file or directory actually exists
|
||||
# and fails with a FATAL_ERROR otherwise. This makes sure that the created
|
||||
# FooConfig.cmake file does not contain wrong references.
|
||||
# When using the NO_SET_AND_CHECK_MACRO, this macro is not generated into the
|
||||
# FooConfig.cmake file.
|
||||
#
|
||||
# check_required_components(<package_name>) should be called at the end of the
|
||||
# FooConfig.cmake file if the package supports components.
|
||||
# This macro checks whether all requested, non-optional components have been found,
|
||||
# and if this is not the case, sets the Foo_FOUND variable to FALSE, so that the package
|
||||
# is considered to be not found.
|
||||
# It does that by testing the Foo_<Component>_FOUND variables for all requested
|
||||
# required components.
|
||||
# When using the NO_CHECK_REQUIRED_COMPONENTS option, this macro is not generated
|
||||
# into the FooConfig.cmake file.
|
||||
#
|
||||
# For an example see below the documentation for WRITE_BASIC_PACKAGE_VERSION_FILE().
|
||||
#
|
||||
#
|
||||
# WRITE_BASIC_PACKAGE_VERSION_FILE( filename VERSION major.minor.patch COMPATIBILITY (AnyNewerVersion|SameMajorVersion|ExactVersion) )
|
||||
#
|
||||
# Writes a file for use as <package>ConfigVersion.cmake file to <filename>.
|
||||
# See the documentation of find_package() for details on this.
|
||||
# filename is the output filename, it should be in the build tree.
|
||||
# major.minor.patch is the version number of the project to be installed
|
||||
# The COMPATIBILITY mode AnyNewerVersion means that the installed package version
|
||||
# will be considered compatible if it is newer or exactly the same as the requested version.
|
||||
# This mode should be used for packages which are fully backward compatible,
|
||||
# also across major versions.
|
||||
# If SameMajorVersion is used instead, then the behaviour differs from AnyNewerVersion
|
||||
# in that the major version number must be the same as requested, e.g. version 2.0 will
|
||||
# not be considered compatible if 1.0 is requested.
|
||||
# This mode should be used for packages which guarantee backward compatibility within the
|
||||
# same major version.
|
||||
# If ExactVersion is used, then the package is only considered compatible if the requested
|
||||
# version matches exactly its own version number (not considering the tweak version).
|
||||
# For example, version 1.2.3 of a package is only considered compatible to requested version 1.2.3.
|
||||
# This mode is for packages without compatibility guarantees.
|
||||
# If your project has more elaborated version matching rules, you will need to write your
|
||||
# own custom ConfigVersion.cmake file instead of using this macro.
|
||||
#
|
||||
# Internally, this macro executes configure_file() to create the resulting
|
||||
# version file. Depending on the COMPATIBLITY, either the file
|
||||
# BasicConfigVersion-SameMajorVersion.cmake.in or BasicConfigVersion-AnyNewerVersion.cmake.in
|
||||
# is used. Please note that these two files are internal to CMake and you should
|
||||
# not call configure_file() on them yourself, but they can be used as starting
|
||||
# point to create more sophisticted custom ConfigVersion.cmake files.
|
||||
#
|
||||
#
|
||||
# Example using both configure_package_config_file() and write_basic_package_version_file():
|
||||
# CMakeLists.txt:
|
||||
# set(INCLUDE_INSTALL_DIR include/ ... CACHE )
|
||||
# set(LIB_INSTALL_DIR lib/ ... CACHE )
|
||||
# set(SYSCONFIG_INSTALL_DIR etc/foo/ ... CACHE )
|
||||
# ...
|
||||
# include(CMakePackageConfigHelpers)
|
||||
# configure_package_config_file(FooConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake
|
||||
# INSTALL_DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake
|
||||
# PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR)
|
||||
# write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake
|
||||
# VERSION 1.2.3
|
||||
# COMPATIBILITY SameMajorVersion )
|
||||
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake
|
||||
# DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake )
|
||||
#
|
||||
# With a FooConfig.cmake.in:
|
||||
# set(FOO_VERSION x.y.z)
|
||||
# ...
|
||||
# @PACKAGE_INIT@
|
||||
# ...
|
||||
# set_and_check(FOO_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
|
||||
# set_and_check(FOO_SYSCONFIG_DIR "@PACKAGE_SYSCONFIG_INSTALL_DIR@")
|
||||
#
|
||||
# check_required_components(Foo)
|
||||
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2012 Alexander Neundorf <neundorf@kde.org>
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see below.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the names of Kitware, Inc., the Insight Software Consortium,
|
||||
# nor the names of their contributors may be used to endorse or promote
|
||||
# products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#=============================================================================
|
||||
|
||||
include(CMakeParseArguments)
|
||||
|
||||
include(WriteBasicConfigVersionFile)
|
||||
|
||||
macro(WRITE_BASIC_PACKAGE_VERSION_FILE)
|
||||
write_basic_config_version_file(${ARGN})
|
||||
endmacro()
|
||||
|
||||
|
||||
function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile)
|
||||
set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)
|
||||
set(oneValueArgs INSTALL_DESTINATION )
|
||||
set(multiValueArgs PATH_VARS )
|
||||
|
||||
cmake_parse_arguments(CCF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(CCF_UNPARSED_ARGUMENTS)
|
||||
message(FATAL_ERROR "Unknown keywords given to CONFIGURE_PACKAGE_CONFIG_FILE(): \"${CCF_UNPARSED_ARGUMENTS}\"")
|
||||
endif()
|
||||
|
||||
if(NOT CCF_INSTALL_DESTINATION)
|
||||
message(FATAL_ERROR "No INSTALL_DESTINATION given to CONFIGURE_PACKAGE_CONFIG_FILE()")
|
||||
endif()
|
||||
|
||||
if(IS_ABSOLUTE "${CCF_INSTALL_DESTINATION}")
|
||||
set(absInstallDir "${CCF_INSTALL_DESTINATION}")
|
||||
else()
|
||||
set(absInstallDir "${CMAKE_INSTALL_PREFIX}/${CCF_INSTALL_DESTINATION}")
|
||||
endif()
|
||||
file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${absInstallDir}" "${CMAKE_INSTALL_PREFIX}" )
|
||||
|
||||
foreach(var ${CCF_PATH_VARS})
|
||||
if(NOT DEFINED ${var})
|
||||
message(FATAL_ERROR "Variable ${var} does not exist")
|
||||
else()
|
||||
if(IS_ABSOLUTE "${${var}}")
|
||||
string(REPLACE "${CMAKE_INSTALL_PREFIX}" "\${PACKAGE_PREFIX_DIR}"
|
||||
PACKAGE_${var} "${${var}}")
|
||||
else()
|
||||
set(PACKAGE_${var} "\${PACKAGE_PREFIX_DIR}/${${var}}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(PACKAGE_INIT "
|
||||
####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
|
||||
get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE_RELATIVE_PATH}\" ABSOLUTE)
|
||||
")
|
||||
|
||||
if(NOT CCF_NO_SET_AND_CHECK_MACRO)
|
||||
set(PACKAGE_INIT "${PACKAGE_INIT}
|
||||
macro(set_and_check _var _file)
|
||||
set(\${_var} \"\${_file}\")
|
||||
if(NOT EXISTS \"\${_file}\")
|
||||
message(FATAL_ERROR \"File or directory \${_file} referenced by variable \${_var} does not exist !\")
|
||||
endif()
|
||||
endmacro()
|
||||
")
|
||||
endif()
|
||||
|
||||
|
||||
if(NOT CCF_NO_CHECK_REQUIRED_COMPONENTS_MACRO)
|
||||
set(PACKAGE_INIT "${PACKAGE_INIT}
|
||||
macro(check_required_components _NAME)
|
||||
foreach(comp \${\${_NAME}_FIND_COMPONENTS})
|
||||
if(NOT \${_NAME}_\${comp}_FOUND)
|
||||
if(\${_NAME}_FIND_REQUIRED_\${comp})
|
||||
set(\${_NAME}_FOUND FALSE)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
")
|
||||
endif()
|
||||
|
||||
set(PACKAGE_INIT "${PACKAGE_INIT}
|
||||
####################################################################################")
|
||||
|
||||
configure_file("${_inputFile}" "${_outputFile}" @ONLY)
|
||||
|
||||
endfunction()
|
||||
@@ -1,4 +1,4 @@
|
||||
/** @file list.h
|
||||
/** @file
|
||||
@brief Fake header to allow GHOST 4.09 use with MSVC 2005
|
||||
|
||||
@date 2010
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** @file list.h
|
||||
/** @file
|
||||
@brief Fake header to allow GHOST 4.09 use with MSVC 2005
|
||||
|
||||
@date 2010
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** @file set.h
|
||||
/** @file
|
||||
@brief Fake header to allow GHOST 4.09 use with MSVC 2005
|
||||
|
||||
@date 2010
|
||||
@@ -14,4 +14,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <set>
|
||||
using std::set;
|
||||
#include <functional>
|
||||
using std::set;
|
||||
using std::less;
|
||||
@@ -1,4 +1,4 @@
|
||||
/** @file vector.h
|
||||
/** @file
|
||||
@brief Fake header to allow GHOST 4.09 use with MSVC 2005
|
||||
|
||||
@date 2010
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
||||
cmake version 2.8.3
|
||||
cmake version 2.8.6
|
||||
------------------------------------------------------------------------------
|
||||
Introduction
|
||||
|
||||
@@ -645,6 +645,71 @@ a few.
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindAdrienne
|
||||
try to find Adrienne Electronics Corporation timecode card library
|
||||
|
||||
|
||||
|
||||
SDK available from the manufacturer: http://www.adrielec.com/
|
||||
|
||||
Cache Variables: (probably not for direct use in your scripts)
|
||||
|
||||
ADRIENNE_INCLUDE_DIR
|
||||
ADRIENNE_LIBRARY
|
||||
ADRIENNE_RUNTIME_LIBRARY
|
||||
ADRIENNE_INCLUDE_FILE
|
||||
|
||||
|
||||
|
||||
Variables you might use in your CMakeLists.txt:
|
||||
|
||||
ADRIENNE_FOUND
|
||||
ADRIENNE_INCLUDE_DIRS
|
||||
ADRIENNE_LIBRARIES
|
||||
ADRIENNE_RUNTIME_LIBRARIES - the AEC_NTTC.dll file
|
||||
ADRIENNE_RUNTIME_LIBRARY_DIRS
|
||||
|
||||
|
||||
|
||||
ADRIENNE_INCLUDE_FILENAME - this is probably AEC_NTTC.h, but it might also
|
||||
be AECINTTC.H.
|
||||
|
||||
|
||||
|
||||
ADRIENNE_INCLUDE_HAS_EXTERN_C - Some (most) versions of the header already
|
||||
wrap their definitions in extern "C" { }, but some do not.
|
||||
|
||||
|
||||
|
||||
ADRIENNE_DEFINITIONS - defines a quoted ADRIENNE_INCLUDE_FILENAME as above,
|
||||
so you can write a line like #include ADRIENNE_INCLUDE_FILENAME
|
||||
Also defines ADRIENNE_BEFORE_INCLUDE and ADRIENNE_AFTER_INCLUDE to handle
|
||||
adding extern "C" { and } if the header file doesn't do so itself.
|
||||
|
||||
|
||||
|
||||
Variables that might be set by the user in the gui/command line to
|
||||
help find the library:
|
||||
|
||||
ADRIENNE_ROOT_DIR - root of an Adrienne CD, disk, or extracted/copied contents
|
||||
thereof.
|
||||
|
||||
|
||||
|
||||
Requires these CMake modules:
|
||||
|
||||
FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
|
||||
|
||||
|
||||
Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2012. Distributed under the Boost
|
||||
Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindBluez
|
||||
try to find Bluez
|
||||
|
||||
@@ -696,7 +761,7 @@ a few.
|
||||
|
||||
CPPDOM_ROOT_DIR - A directory prefix to search
|
||||
(a path that contains include/ as a subdirectory)
|
||||
CPPDOM_ADDITIONAL_VERSIONS - Additional versions (outside of 0.7.8 to 1.0.0)
|
||||
CPPDOM_ADDITIONAL_VERSIONS - Additional versions (outside of 0.7.8 to 1.2.0)
|
||||
to use when constructing search names and paths
|
||||
|
||||
|
||||
@@ -713,11 +778,11 @@ a few.
|
||||
change this environment variable, because it cannot auto-detect this
|
||||
change and trigger an automatic re-run.
|
||||
|
||||
Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
Original Author: 2009-2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2009-2010. Distributed under the
|
||||
Copyright Iowa State University 2009-2012. Distributed under the
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
@@ -752,6 +817,110 @@ a few.
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindDirectInput
|
||||
try to find DirectInput library (part of DirectX SDK)
|
||||
|
||||
|
||||
|
||||
Cache Variables: (probably not for direct use in your scripts)
|
||||
|
||||
DIRECTINPUT_DXGUID_LIBRARY
|
||||
DIRECTINPUT_DXERR_LIBRARY
|
||||
DIRECTINPUT_DINPUT_LIBRARY
|
||||
DIRECTINPUT_INCLUDE_DIR
|
||||
|
||||
|
||||
|
||||
Non-cache variables you should use in your CMakeLists.txt:
|
||||
|
||||
DIRECTINPUT_LIBRARIES
|
||||
DIRECTINPUT_INCLUDE_DIRS
|
||||
DIRECTINPUT_FOUND - if this is not true, do not attempt to use this library
|
||||
|
||||
|
||||
|
||||
Requires these CMake modules:
|
||||
|
||||
FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
|
||||
|
||||
|
||||
Original Author: 2011 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2011. Distributed under the Boost
|
||||
Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindDirectShow
|
||||
Find Microsoft DirectShow sample files, library, and headers.
|
||||
|
||||
|
||||
|
||||
DIRECTSHOW_INCLUDE_DIRS - where to find needed include file
|
||||
DIRECTSHOW_BASECLASS_DIR- Directory containing the DirectShow baseclass sample code.
|
||||
DIRECTSHOW_FOUND - True if DirectShow found.
|
||||
|
||||
|
||||
|
||||
Requires these CMake modules:
|
||||
|
||||
FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
|
||||
|
||||
|
||||
Initially in VRPN - Distributed under the Boost Software License,
|
||||
Version 1.0.
|
||||
|
||||
Almost entirely re-written by: 2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2012. Distributed under the Boost
|
||||
Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindDirectX
|
||||
try to find part of DirectX SDK
|
||||
|
||||
|
||||
|
||||
Cache Variables: (probably not for direct use in your scripts)
|
||||
|
||||
DIRECTX_INCLUDE_DIR
|
||||
|
||||
|
||||
|
||||
Variables you should use in your CMakeLists.txt:
|
||||
|
||||
DIRECTX_DXGUID_LIBRARY
|
||||
DIRECTX_DXERR_LIBRARY
|
||||
DIRECTX_DINPUT_LIBRARY
|
||||
DIRECTX_DINPUT_INCLUDE_DIR
|
||||
DIRECTX_D3D9_LIBRARY
|
||||
DIRECTX_D3DXOF_LIBRARY
|
||||
DIRECTX_D3DX9_LIBRARIES
|
||||
DIRECTX_INCLUDE_DIRS
|
||||
DIRECTX_FOUND - if this is not true, do not attempt to use this library
|
||||
|
||||
|
||||
|
||||
Requires these CMake modules:
|
||||
|
||||
FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
SelectLibraryConfigurations
|
||||
|
||||
|
||||
|
||||
Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2012. Distributed under the Boost
|
||||
Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindFlagpoll
|
||||
try to find Flagpoll application, and offer package-finding services
|
||||
|
||||
@@ -913,7 +1082,7 @@ a few.
|
||||
|
||||
GMTL_ROOT_DIR - A directory prefix to search
|
||||
(a path that contains include/ as a subdirectory)
|
||||
GMTL_ADDITIONAL_VERSIONS - Additional versions (outside of 0.5.1 to 0.6.2)
|
||||
GMTL_ADDITIONAL_VERSIONS - Additional versions (outside of 0.5.1 to 0.7.0)
|
||||
to use when constructing search names and paths
|
||||
|
||||
|
||||
@@ -930,11 +1099,11 @@ a few.
|
||||
change this environment variable, because it cannot auto-detect this
|
||||
change and trigger an automatic re-run.
|
||||
|
||||
Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
Original Author: 2009-2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2009-2010. Distributed under the
|
||||
Copyright Iowa State University 2009-2012. Distributed under the
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
@@ -1139,6 +1308,51 @@ a few.
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindIDLJ
|
||||
try to find Java's IDLJ Interface Definition Language compiler.
|
||||
|
||||
|
||||
|
||||
Ideally used with CMake 2.8.5 or newer for Java support using
|
||||
FindJava.cmake and UseJava.cmake
|
||||
|
||||
Variables:
|
||||
|
||||
Java_IDLJ_COMMAND, executable for idlj
|
||||
IDLJ_FOUND, If false, do not try to use this
|
||||
|
||||
|
||||
|
||||
Function:
|
||||
|
||||
java_idlj(varname idlfile [extra idlj args]) - Generates
|
||||
the Java source files from the IDL file you indicate, and
|
||||
appends filenames suitable to add to a add_jar() call to the
|
||||
variable you specified.
|
||||
|
||||
|
||||
|
||||
Because the files generated from an IDL file are not entirely
|
||||
predictable, java_idlj runs idlj in the cmake step, rather than the
|
||||
build step, and triggers a CMake re-run when an idl file is modified.
|
||||
Already up-to-date generated source is not re-generated, however.
|
||||
|
||||
Files are generated in a directory created specifically for the
|
||||
particular IDL file and the particular call, in the build directory -
|
||||
there should be no worries about overwriting files or picking up too
|
||||
much with the wildcard.
|
||||
|
||||
You may wish to add the IDL file to your list of sources if you want
|
||||
it to appear in your IDE, but it is not necessary.
|
||||
|
||||
Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2012. Distributed under the Boost
|
||||
Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindJCCL12
|
||||
try to find JCCL 1.2 library
|
||||
|
||||
@@ -1451,6 +1665,37 @@ a few.
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindMarkdown
|
||||
try to find Markdown tool
|
||||
|
||||
|
||||
|
||||
Cache Variables:
|
||||
|
||||
MARKDOWN_EXECUTABLE
|
||||
|
||||
|
||||
|
||||
Non-cache variables you might use in your CMakeLists.txt:
|
||||
|
||||
MARKDOWN_FOUND
|
||||
|
||||
|
||||
|
||||
Requires these CMake modules:
|
||||
|
||||
FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
|
||||
|
||||
|
||||
Original Author: 2011 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2011. Distributed under the Boost
|
||||
Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindOpenCV
|
||||
------------------------------
|
||||
|
||||
@@ -1493,12 +1738,16 @@ a few.
|
||||
|
||||
HDAPI_INCLUDE_DIR
|
||||
HDAPI_LIBRARY
|
||||
HDAPI_LIBRARY_RELEASE
|
||||
HDAPI_LIBRARY_DEBUG
|
||||
HDAPI_HDU_INCLUDE_DIR
|
||||
HDAPI_HDU_LIBRARY
|
||||
HDAPI_HDU_LIBRARY_RELEASE
|
||||
HDAPI_HDU_LIBRARY_DEBUG
|
||||
HLAPI_INCLUDE_DIR
|
||||
HLAPI_LIBRARY
|
||||
HLAPI_LIBRARY_RELEASE
|
||||
HLAPI_LIBRARY_DEBUG
|
||||
HLAPI_HLU_INCLUDE_DIR
|
||||
HLAPI_HLU_LIBRARY
|
||||
HLAPI_HLU_LIBRARY_RELEASE
|
||||
@@ -1537,7 +1786,7 @@ a few.
|
||||
|
||||
|
||||
|
||||
Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
Original Author: 2009-2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
@@ -1581,6 +1830,118 @@ a few.
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindPerformer
|
||||
try to find the OpenGL Performer library
|
||||
|
||||
|
||||
|
||||
Users may optionally supply:
|
||||
|
||||
PERFORMER_ROOT_DIR - a prefix to start searching.
|
||||
|
||||
|
||||
|
||||
Cache Variables: (probably not for direct use in your scripts)
|
||||
|
||||
PERFORMER_INCLUDE_DIR
|
||||
PERFORMER_LIBRARY
|
||||
PERFORMER_PFUI_LIBRARY - doesn't get included in PERFORMER_LIBRARIES
|
||||
PERFORMER_PFDU_UTIL_LIBRARY - doesn't get included in PERFORMER_LIBRARIES
|
||||
PERFORMER_PFV_LIBRARY - doesn't get included in PERFORMER_LIBRARIES
|
||||
|
||||
|
||||
|
||||
Non-cache variables you might use in your CMakeLists.txt:
|
||||
|
||||
PERFORMER_FOUND
|
||||
PERFORMER_INCLUDE_DIRS
|
||||
PERFORMER_LIBRARIES
|
||||
PERFORMER_RUNTIME_LIBRARY_DIRS
|
||||
|
||||
|
||||
|
||||
Requires these CMake modules:
|
||||
|
||||
FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
|
||||
|
||||
|
||||
Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2012. Distributed under the Boost
|
||||
Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindPerlModules
|
||||
try to find perl modules, passed as COMPONENTS
|
||||
|
||||
|
||||
|
||||
Non-cache variable you might use in your CMakeLists.txt:
|
||||
|
||||
PERLMODULES_FOUND
|
||||
|
||||
|
||||
|
||||
Requires these CMake modules:
|
||||
|
||||
FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
|
||||
|
||||
|
||||
Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2012. Distributed under the Boost
|
||||
Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindQVRPN
|
||||
try to find QVRPN library
|
||||
|
||||
|
||||
|
||||
Of course, you may also just choose to make QVRPN a submodule of your
|
||||
project itself.
|
||||
|
||||
Cache Variables:
|
||||
|
||||
QVRPN_LIBRARY
|
||||
QVRPN_INCLUDE_DIR
|
||||
|
||||
|
||||
|
||||
Non-cache variables you might use in your CMakeLists.txt:
|
||||
|
||||
QVRPN_FOUND
|
||||
QVRPN_LIBRARIES
|
||||
QVRPN_INCLUDE_DIRS
|
||||
|
||||
|
||||
|
||||
QVRPN_ROOT_DIR is searched preferentially for these files
|
||||
|
||||
Requires these CMake modules:
|
||||
|
||||
FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
|
||||
|
||||
|
||||
Refactored from FindVRPN.cmake by: Juan Sebastian Casallas
|
||||
<casallas@iastate.edu>
|
||||
|
||||
FindVRPN.cmake Original Author: 2009-2010 Ryan Pavlik
|
||||
<rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
http://academic.cleardefinition.com Iowa State University HCI Graduate
|
||||
Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2009-2012. Distributed under the
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindSonix12
|
||||
try to find Sonix 1.2 library
|
||||
|
||||
@@ -2416,8 +2777,10 @@ a few.
|
||||
Non-cache variables you might use in your CMakeLists.txt:
|
||||
|
||||
VRPN_FOUND
|
||||
VRPN_SERVER_LIBRARIES
|
||||
VRPN_LIBRARIES
|
||||
VRPN_SERVER_LIBRARIES - server libraries
|
||||
VRPN_LIBRARIES - client libraries
|
||||
VRPN_CLIENT_DEFINITIONS - definitions if you only use the client library
|
||||
VRPN_DEFINITIONS - Client-only definition if all we found was the client library.
|
||||
VRPN_INCLUDE_DIRS
|
||||
|
||||
|
||||
@@ -2430,14 +2793,51 @@ a few.
|
||||
|
||||
|
||||
|
||||
Original Author: 2009-2010 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
Original Author: 2009-2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2009-2010. Distributed under the
|
||||
Copyright Iowa State University 2009-2012. Distributed under the
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindViewPoint
|
||||
try to find Arrington Research ViewPoint EyeTracker SDK
|
||||
|
||||
|
||||
|
||||
Cache Variables: (probably not for direct use in your scripts)
|
||||
|
||||
VIEWPOINT_INCLUDE_DIR
|
||||
VIEWPOINT_LIBRARY
|
||||
VIEWPOINT_RUNTIME_LIBRARY
|
||||
|
||||
|
||||
|
||||
Non-cache variables you might use in your CMakeLists.txt:
|
||||
|
||||
VIEWPOINT_FOUND
|
||||
VIEWPOINT_INCLUDE_DIRS
|
||||
VIEWPOINT_LIBRARIES
|
||||
VIEWPOINT_RUNTIME_LIBRARIES - aka the dll for installing
|
||||
VIEWPOINT_RUNTIME_LIBRARY_DIRS
|
||||
|
||||
|
||||
|
||||
Requires these CMake modules:
|
||||
|
||||
FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
|
||||
|
||||
|
||||
Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2012. Distributed under the Boost
|
||||
Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindVirtuoseAPI
|
||||
try to find Haption VirtuoseAPI library and include files
|
||||
|
||||
@@ -2578,6 +2978,48 @@ a few.
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
FindWindowsSDK
|
||||
Find the Windows SDK aka Platform SDK
|
||||
|
||||
|
||||
|
||||
Variables:
|
||||
|
||||
WINDOWSSDK_FOUND - if any version of the windows or platform SDK was found that is usable with the current version of visual studio
|
||||
WINDOWSSDK_LATEST_DIR
|
||||
WINDOWSSDK_LATEST_NAME
|
||||
WINDOWSSDK_FOUND_PREFERENCE - if we found an entry indicating a "preferred" SDK listed for this visual studio version
|
||||
WINDOWSSDK_PREFERRED_DIR
|
||||
WINDOWSSDK_PREFERRED_NAME
|
||||
|
||||
|
||||
|
||||
WINDOWSSDK_DIRS - contains no duplicates, ordered most recent first.
|
||||
WINDOWSSDK_PREFERRED_FIRST_DIRS - contains no duplicates, ordered with preferred first, followed by the rest in descending recency
|
||||
|
||||
|
||||
|
||||
Functions:
|
||||
|
||||
windowssdk_name_lookup(<directory> <output variable>) - Find the name corresponding with the SDK directory you pass in, or
|
||||
NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work.
|
||||
|
||||
|
||||
|
||||
Requires these CMake modules:
|
||||
|
||||
FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
|
||||
|
||||
|
||||
Original Author: 2012 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2012. Distributed under the Boost
|
||||
Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
Findargp
|
||||
try to find the argp library/component of glibc
|
||||
|
||||
@@ -3002,20 +3444,20 @@ a few.
|
||||
These functions force a re-configure on each git commit so that you
|
||||
can trust the values of the variables in your build system.
|
||||
|
||||
get_git_head_revision(<refspecvar> <hashvar> [<additonal arguments to git describe> ...])
|
||||
get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
|
||||
|
||||
|
||||
|
||||
Returns the refspec and sha hash of the current head revision
|
||||
|
||||
git_describe(<var> [<additonal arguments to git describe> ...])
|
||||
git_describe(<var> [<additional arguments to git describe> ...])
|
||||
|
||||
|
||||
|
||||
Returns the results of git describe on the source tree, and adjusting
|
||||
the output so that it tests false if an error occurs.
|
||||
|
||||
git_get_exact_tag(<var> [<additonal arguments to git describe> ...])
|
||||
git_get_exact_tag(<var> [<additional arguments to git describe> ...])
|
||||
|
||||
|
||||
|
||||
@@ -3463,6 +3905,37 @@ a few.
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
UseMarkdown
|
||||
Convert markdown source files to HTML as a custom target
|
||||
|
||||
|
||||
|
||||
include(UseMarkdown)
|
||||
add_markdown_target(<target_name> <directory to copy to> <markdownfile> [<markdownfile>...] [RENAME <newname>])
|
||||
Relative paths for the destination directory are considered with
|
||||
with respect to CMAKE_CURRENT_BINARY_DIR. The RENAME argument is only
|
||||
valid with a single markdown file as input.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
install_markdown_target(<target_name> [extra arguments to INSTALL(FILES ...) ])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Requires CMake 2.6 or newer (uses the 'function' command)
|
||||
|
||||
Original Author: 2011 Ryan Pavlik <rpavlik@iastate.edu>
|
||||
<abiryan@ryand.net> http://academic.cleardefinition.com Iowa State
|
||||
University HCI Graduate Program/VRAC
|
||||
|
||||
Copyright Iowa State University 2011-2012. Distributed under the
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
UseTR1
|
||||
Use settings to enable access to C++ TR1
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ foreach(filename ansi.hxx
|
||||
ehlc_timer.hxx
|
||||
face.cpp
|
||||
face.hxx
|
||||
files.txt
|
||||
frustum.cpp
|
||||
frustum.hxx
|
||||
hldeb.hxx
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# 2009-2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2009-2010.
|
||||
# Copyright Iowa State University 2009-2012.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file ../LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
add_proprietary_license("VR JuggLua"
|
||||
"Based in part on VR JuggLua, Copyright 2010 Iowa State University. This version of VR JuggLua is unreleased research software - NOT FOR REDISTRIBUTION.")
|
||||
add_redistribution_warning("This version of VR JuggLua is unreleased research software - NOT FOR REDISTRIBUTION.")
|
||||
add_permissive_license("VR JuggLua"
|
||||
"Based in part on VR JuggLua, Copyright 2010-2012 Iowa State University. VR JuggLua is distributed under the Boost Software License, Version 1.0. See copy at http://www.boost.org/LICENSE_1_0.txt"
|
||||
"<https://github.com/vance-group/vr-jugglua>")
|
||||
include("package-licensing/VRJuggler")
|
||||
include("package-licensing/OpenSceneGraph")
|
||||
include("package-licensing/Lua")
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
#define MAX_WIIMOTES 2
|
||||
|
||||
GLint width = 1024, height = 768;
|
||||
GLfloat backColor[4] = {1.0,1.0,1.0,1.0};
|
||||
GLfloat backColor[4] = {1.0, 1.0, 1.0, 1.0};
|
||||
|
||||
wiimote** wiimotes = NULL;
|
||||
|
||||
@@ -65,11 +65,11 @@ int xcoord = 0;
|
||||
int ycoord = 0;
|
||||
|
||||
#ifdef WIN32
|
||||
DWORD last_render;
|
||||
DWORD last_render;
|
||||
#else
|
||||
struct timeval last_render;
|
||||
int last_sec = 0;
|
||||
int fps = 0;
|
||||
struct timeval last_render;
|
||||
int last_sec = 0;
|
||||
int fps = 0;
|
||||
#endif
|
||||
|
||||
enum render_mode_t {
|
||||
@@ -123,39 +123,45 @@ void set_material(struct material_t* mptr);
|
||||
void resize_window(GLint new_width, GLint new_height);
|
||||
|
||||
void handle_event(struct wiimote_t* wm) {
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) {
|
||||
wiiuse_motion_sensing(wm, 1);
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
|
||||
}
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) {
|
||||
wiiuse_motion_sensing(wm, 0);
|
||||
}
|
||||
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP))
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP)) {
|
||||
wiiuse_set_ir(wm, 1);
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
|
||||
}
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) {
|
||||
wiiuse_set_ir(wm, 0);
|
||||
}
|
||||
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B))
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B)) {
|
||||
wiiuse_toggle_rumble(wm);
|
||||
}
|
||||
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
|
||||
int level;
|
||||
WIIUSE_GET_IR_SENSITIVITY(wm, &level);
|
||||
wiiuse_set_ir_sensitivity(wm, level+1);
|
||||
wiiuse_set_ir_sensitivity(wm, level + 1);
|
||||
}
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_TWO)) {
|
||||
int level;
|
||||
WIIUSE_GET_IR_SENSITIVITY(wm, &level);
|
||||
wiiuse_set_ir_sensitivity(wm, level-1);
|
||||
wiiuse_set_ir_sensitivity(wm, level - 1);
|
||||
}
|
||||
|
||||
#if 0
|
||||
#if 0
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_A)) {
|
||||
if (render_mode == IR)
|
||||
if (render_mode == IR) {
|
||||
render_mode = TEAPOT;
|
||||
else
|
||||
} else {
|
||||
render_mode = IR;
|
||||
}
|
||||
resize_window(width, height);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#define DRAW_TRIANGLE(x, y, z, s) do { \
|
||||
@@ -166,52 +172,57 @@ void handle_event(struct wiimote_t* wm) {
|
||||
|
||||
int can_render() {
|
||||
/* quick fps limit to ~60fps -- not too fancy, could be better */
|
||||
#ifdef WIN32
|
||||
if (GetTickCount() < (last_render + 16))
|
||||
return 0;
|
||||
last_render = GetTickCount();
|
||||
return 1;
|
||||
#else
|
||||
struct timeval now;
|
||||
long elapsed_usec = 0;
|
||||
#ifdef WIN32
|
||||
if (GetTickCount() < (last_render + 16)) {
|
||||
return 0;
|
||||
}
|
||||
last_render = GetTickCount();
|
||||
return 1;
|
||||
#else
|
||||
struct timeval now;
|
||||
long elapsed_usec = 0;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
if (now.tv_usec > 1000000) {
|
||||
now.tv_usec -= 1000000;
|
||||
++now.tv_sec;
|
||||
}
|
||||
if (now.tv_usec > 1000000) {
|
||||
now.tv_usec -= 1000000;
|
||||
++now.tv_sec;
|
||||
}
|
||||
|
||||
if (now.tv_sec > last_render.tv_sec)
|
||||
elapsed_usec = ((now.tv_sec - last_render.tv_sec) * 1000000);
|
||||
if (now.tv_sec > last_render.tv_sec) {
|
||||
elapsed_usec = ((now.tv_sec - last_render.tv_sec) * 1000000);
|
||||
}
|
||||
|
||||
if (now.tv_usec > last_render.tv_usec)
|
||||
elapsed_usec += now.tv_usec - last_render.tv_usec;
|
||||
else
|
||||
elapsed_usec += last_render.tv_usec - now.tv_usec;
|
||||
if (now.tv_usec > last_render.tv_usec) {
|
||||
elapsed_usec += now.tv_usec - last_render.tv_usec;
|
||||
} else {
|
||||
elapsed_usec += last_render.tv_usec - now.tv_usec;
|
||||
}
|
||||
|
||||
if (time(NULL) > last_sec) {
|
||||
printf("fps: %i\n", fps);
|
||||
fps = 0;
|
||||
last_sec = time(NULL);
|
||||
}
|
||||
if (time(NULL) > last_sec) {
|
||||
printf("fps: %i\n", fps);
|
||||
fps = 0;
|
||||
last_sec = time(NULL);
|
||||
}
|
||||
|
||||
if (elapsed_usec < 16000)
|
||||
return 0;
|
||||
if (elapsed_usec < 16000) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
last_render = now;
|
||||
++fps;
|
||||
last_render = now;
|
||||
++fps;
|
||||
|
||||
return 1;
|
||||
#endif
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void display() {
|
||||
int i, wm;
|
||||
float size = 5;
|
||||
|
||||
if (!can_render())
|
||||
if (!can_render()) {
|
||||
return;
|
||||
}
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
@@ -223,37 +234,39 @@ void display() {
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
/* green center */
|
||||
glColor3f(0.0, 1.0, 0.0);
|
||||
DRAW_TRIANGLE(width/2, height/2, 0, size);
|
||||
/* green center */
|
||||
glColor3f(0.0, 1.0, 0.0);
|
||||
DRAW_TRIANGLE(width / 2, height / 2, 0, size);
|
||||
glEnd();
|
||||
|
||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
|
||||
glBegin(GL_TRIANGLES);
|
||||
/* red ir */
|
||||
glColor3f(1.0, 0.0, 0.0);
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (wiimotes[wm]->ir.dot[i].visible)
|
||||
DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].rx, wiimotes[wm]->ir.dot[i].ry, 0, size);
|
||||
/* red ir */
|
||||
glColor3f(1.0, 0.0, 0.0);
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (wiimotes[wm]->ir.dot[i].visible) {
|
||||
DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].rx, wiimotes[wm]->ir.dot[i].ry, 0, size);
|
||||
}
|
||||
}
|
||||
|
||||
/* yellow corrected ir */
|
||||
glColor3f(1.0, 1.0, 0.0);
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (wiimotes[wm]->ir.dot[i].visible)
|
||||
DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].x, wiimotes[wm]->ir.dot[i].y, 0, size);
|
||||
/* yellow corrected ir */
|
||||
glColor3f(1.0, 1.0, 0.0);
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (wiimotes[wm]->ir.dot[i].visible) {
|
||||
DRAW_TRIANGLE(wiimotes[wm]->ir.dot[i].x, wiimotes[wm]->ir.dot[i].y, 0, size);
|
||||
}
|
||||
}
|
||||
|
||||
/* blue cursor */
|
||||
glColor3f(0.0, 0.0, 1.0);
|
||||
DRAW_TRIANGLE(wiimotes[wm]->ir.x, wiimotes[wm]->ir.y-size, 0, size);
|
||||
/* blue cursor */
|
||||
glColor3f(0.0, 0.0, 1.0);
|
||||
DRAW_TRIANGLE(wiimotes[wm]->ir.x, wiimotes[wm]->ir.y - size, 0, size);
|
||||
glEnd();
|
||||
}
|
||||
} else {
|
||||
/* draw the teapot */
|
||||
gluLookAt(0.0, 0.0, -5.0,
|
||||
0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0);
|
||||
0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
@@ -300,8 +313,9 @@ void resize_window(GLint new_width, GLint new_height) {
|
||||
width = new_width;
|
||||
height = new_height;
|
||||
|
||||
if (new_height == 0)
|
||||
if (new_height == 0) {
|
||||
new_height = 1;
|
||||
}
|
||||
|
||||
SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL);
|
||||
|
||||
@@ -310,10 +324,11 @@ void resize_window(GLint new_width, GLint new_height) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
if (render_mode == IR)
|
||||
if (render_mode == IR) {
|
||||
gluOrtho2D(0, width, height, 0);
|
||||
else
|
||||
gluPerspective(60.0f, (float)new_width/(float)new_height, 0.1f, 100.0f);
|
||||
} else {
|
||||
gluPerspective(60.0f, (float)new_width / (float)new_height, 0.1f, 100.0f);
|
||||
}
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
@@ -321,8 +336,9 @@ void resize_window(GLint new_width, GLint new_height) {
|
||||
width = new_width;
|
||||
height = new_height;
|
||||
|
||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm)
|
||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
|
||||
wiiuse_set_ir_vres(wiimotes[wm], width, height);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
@@ -337,12 +353,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
|
||||
wiimotes = wiiuse_init(MAX_WIIMOTES);
|
||||
found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5);
|
||||
if (!found)
|
||||
if (!found) {
|
||||
return 0;
|
||||
}
|
||||
connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
|
||||
if (connected)
|
||||
if (connected) {
|
||||
printf("Connected to %i wiimotes (of %i found).\n", connected, found);
|
||||
else {
|
||||
} else {
|
||||
printf("Failed to connect to any wiimote.\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -350,11 +367,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
wiiuse_set_leds(wiimotes[1], WIIMOTE_LED_2 | WIIMOTE_LED_4);
|
||||
wiiuse_rumble(wiimotes[0], 1);
|
||||
|
||||
#ifndef WIN32
|
||||
usleep(200000);
|
||||
#else
|
||||
Sleep(200);
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
usleep(200000);
|
||||
#else
|
||||
Sleep(200);
|
||||
#endif
|
||||
|
||||
wiiuse_rumble(wiimotes[0], 0);
|
||||
|
||||
@@ -379,49 +396,47 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
height = wiimotes[0]->ir.vres[1];
|
||||
SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL);
|
||||
|
||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm)
|
||||
for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
|
||||
wiiuse_set_ir_vres(wiimotes[wm], width, height);
|
||||
}
|
||||
|
||||
/* set OpenGL stuff */
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_NORMALIZE);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
|
||||
/* set the size of the window */
|
||||
resize_window(width, height);
|
||||
|
||||
display();
|
||||
|
||||
#ifdef WIN32
|
||||
last_render = GetTickCount();
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
last_render = GetTickCount();
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
SDL_Event event;
|
||||
|
||||
if (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_VIDEORESIZE:
|
||||
{
|
||||
/* resize the window */
|
||||
resize_window(event.resize.w, event.resize.h);
|
||||
break;
|
||||
}
|
||||
case SDL_QUIT:
|
||||
{
|
||||
/* shutdown */
|
||||
SDL_Quit();
|
||||
wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
{
|
||||
}
|
||||
case SDL_VIDEORESIZE: {
|
||||
/* resize the window */
|
||||
resize_window(event.resize.w, event.resize.h);
|
||||
break;
|
||||
}
|
||||
case SDL_QUIT: {
|
||||
/* shutdown */
|
||||
SDL_Quit();
|
||||
wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
|
||||
return 0;
|
||||
}
|
||||
default: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,12 +36,11 @@
|
||||
|
||||
#include <stdio.h> /* for printf */
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h> /* for usleep */
|
||||
#endif
|
||||
|
||||
#include "wiiuse.h" /* for wiimote_t, classic_ctrl_t, etc */
|
||||
|
||||
#ifndef WIIUSE_WIN32
|
||||
#include <unistd.h> /* for usleep */
|
||||
#endif
|
||||
|
||||
#define MAX_WIIMOTES 4
|
||||
|
||||
@@ -58,59 +57,85 @@ void handle_event(struct wiimote_t* wm) {
|
||||
printf("\n\n--- EVENT [id %i] ---\n", wm->unid);
|
||||
|
||||
/* if a button is pressed, report it */
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_A)) printf("A pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) printf("B pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP)) printf("UP pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) printf("DOWN pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) printf("LEFT pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) printf("RIGHT pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) printf("MINUS pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) printf("PLUS pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) printf("ONE pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) printf("TWO pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) printf("HOME pressed\n");
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_A)) {
|
||||
printf("A pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) {
|
||||
printf("B pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP)) {
|
||||
printf("UP pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) {
|
||||
printf("DOWN pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) {
|
||||
printf("LEFT pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) {
|
||||
printf("RIGHT pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) {
|
||||
printf("MINUS pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) {
|
||||
printf("PLUS pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
|
||||
printf("ONE pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) {
|
||||
printf("TWO pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) {
|
||||
printf("HOME pressed\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Pressing minus will tell the wiimote we are no longer interested in movement.
|
||||
* This is useful because it saves battery power.
|
||||
*/
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) {
|
||||
wiiuse_motion_sensing(wm, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pressing plus will tell the wiimote we are interested in movement.
|
||||
*/
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) {
|
||||
wiiuse_motion_sensing(wm, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pressing B will toggle the rumble
|
||||
*
|
||||
* if B is pressed but is not held, toggle the rumble
|
||||
*/
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B))
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B)) {
|
||||
wiiuse_toggle_rumble(wm);
|
||||
}
|
||||
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP))
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP)) {
|
||||
wiiuse_set_ir(wm, 1);
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
|
||||
}
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) {
|
||||
wiiuse_set_ir(wm, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Motion+ support
|
||||
*/
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE))
|
||||
{
|
||||
if(WIIUSE_USING_EXP(wm))
|
||||
wiiuse_set_motion_plus(wm, 2); // nunchuck pass-through
|
||||
else
|
||||
wiiuse_set_motion_plus(wm, 1); // standalone
|
||||
}
|
||||
/*
|
||||
* Motion+ support
|
||||
*/
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
|
||||
if (WIIUSE_USING_EXP(wm)) {
|
||||
wiiuse_set_motion_plus(wm, 2); // nunchuck pass-through
|
||||
} else {
|
||||
wiiuse_set_motion_plus(wm, 1); // standalone
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_TWO))
|
||||
{
|
||||
wiiuse_set_motion_plus(wm, 0); // off
|
||||
}
|
||||
if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_TWO)) {
|
||||
wiiuse_set_motion_plus(wm, 0); // off
|
||||
}
|
||||
|
||||
/* if the accelerometer is turned on then print angles */
|
||||
if (WIIUSE_USING_ACC(wm)) {
|
||||
@@ -131,8 +156,9 @@ void handle_event(struct wiimote_t* wm) {
|
||||
/* go through each of the 4 possible IR sources */
|
||||
for (; i < 4; ++i) {
|
||||
/* check if the source is visible */
|
||||
if (wm->ir.dot[i].visible)
|
||||
if (wm->ir.dot[i].visible) {
|
||||
printf("IR source %i: (%u, %u)\n", i, wm->ir.dot[i].x, wm->ir.dot[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
printf("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y);
|
||||
@@ -144,8 +170,12 @@ void handle_event(struct wiimote_t* wm) {
|
||||
/* nunchuk */
|
||||
struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk;
|
||||
|
||||
if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) printf("Nunchuk: C pressed\n");
|
||||
if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) printf("Nunchuk: Z pressed\n");
|
||||
if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) {
|
||||
printf("Nunchuk: C pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) {
|
||||
printf("Nunchuk: Z pressed\n");
|
||||
}
|
||||
|
||||
printf("nunchuk roll = %f\n", nc->orient.roll);
|
||||
printf("nunchuk pitch = %f\n", nc->orient.pitch);
|
||||
@@ -157,21 +187,51 @@ void handle_event(struct wiimote_t* wm) {
|
||||
/* classic controller */
|
||||
struct classic_ctrl_t* cc = (classic_ctrl_t*)&wm->exp.classic;
|
||||
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZL)) printf("Classic: ZL pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_B)) printf("Classic: B pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_Y)) printf("Classic: Y pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_A)) printf("Classic: A pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_X)) printf("Classic: X pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZR)) printf("Classic: ZR pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_LEFT)) printf("Classic: LEFT pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_UP)) printf("Classic: UP pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_RIGHT)) printf("Classic: RIGHT pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_DOWN)) printf("Classic: DOWN pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_L)) printf("Classic: FULL L pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_MINUS)) printf("Classic: MINUS pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_HOME)) printf("Classic: HOME pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_PLUS)) printf("Classic: PLUS pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_R)) printf("Classic: FULL R pressed\n");
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZL)) {
|
||||
printf("Classic: ZL pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_B)) {
|
||||
printf("Classic: B pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_Y)) {
|
||||
printf("Classic: Y pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_A)) {
|
||||
printf("Classic: A pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_X)) {
|
||||
printf("Classic: X pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZR)) {
|
||||
printf("Classic: ZR pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_LEFT)) {
|
||||
printf("Classic: LEFT pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_UP)) {
|
||||
printf("Classic: UP pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_RIGHT)) {
|
||||
printf("Classic: RIGHT pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_DOWN)) {
|
||||
printf("Classic: DOWN pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_L)) {
|
||||
printf("Classic: FULL L pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_MINUS)) {
|
||||
printf("Classic: MINUS pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_HOME)) {
|
||||
printf("Classic: HOME pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_PLUS)) {
|
||||
printf("Classic: PLUS pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_R)) {
|
||||
printf("Classic: FULL R pressed\n");
|
||||
}
|
||||
|
||||
printf("classic L button pressed: %f\n", cc->l_shoulder);
|
||||
printf("classic R button pressed: %f\n", cc->r_shoulder);
|
||||
@@ -183,15 +243,33 @@ void handle_event(struct wiimote_t* wm) {
|
||||
/* guitar hero 3 guitar */
|
||||
struct guitar_hero_3_t* gh3 = (guitar_hero_3_t*)&wm->exp.gh3;
|
||||
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP)) printf("Guitar: Strum Up pressed\n");
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN)) printf("Guitar: Strum Down pressed\n");
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_YELLOW)) printf("Guitar: Yellow pressed\n");
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_GREEN)) printf("Guitar: Green pressed\n");
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_BLUE)) printf("Guitar: Blue pressed\n");
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_RED)) printf("Guitar: Red pressed\n");
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE)) printf("Guitar: Orange pressed\n");
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_PLUS)) printf("Guitar: Plus pressed\n");
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_MINUS)) printf("Guitar: Minus pressed\n");
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP)) {
|
||||
printf("Guitar: Strum Up pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN)) {
|
||||
printf("Guitar: Strum Down pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_YELLOW)) {
|
||||
printf("Guitar: Yellow pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_GREEN)) {
|
||||
printf("Guitar: Green pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_BLUE)) {
|
||||
printf("Guitar: Blue pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_RED)) {
|
||||
printf("Guitar: Red pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE)) {
|
||||
printf("Guitar: Orange pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_PLUS)) {
|
||||
printf("Guitar: Plus pressed\n");
|
||||
}
|
||||
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_MINUS)) {
|
||||
printf("Guitar: Minus pressed\n");
|
||||
}
|
||||
|
||||
printf("Guitar whammy bar: %f\n", gh3->whammy_bar);
|
||||
printf("Guitar joystick angle: %f\n", gh3->js.ang);
|
||||
@@ -207,15 +285,14 @@ void handle_event(struct wiimote_t* wm) {
|
||||
/* printf("Raw: TL:%d TR:%d BL:%d BR:%d\n", wb->rtl, wb->rtr, wb->rbl, wb->rbr); */
|
||||
}
|
||||
|
||||
if(wm->exp.type == EXP_MOTION_PLUS ||
|
||||
wm->exp.type == EXP_MOTION_PLUS_NUNCHUK)
|
||||
{
|
||||
printf("Motion+ angular rates (deg/sec): pitch:%03.2f roll:%03.2f yaw:%03.2f\n",
|
||||
wm->exp.mp.angle_rate_gyro.pitch,
|
||||
wm->exp.mp.angle_rate_gyro.roll,
|
||||
wm->exp.mp.angle_rate_gyro.yaw);
|
||||
}
|
||||
}
|
||||
if (wm->exp.type == EXP_MOTION_PLUS ||
|
||||
wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) {
|
||||
printf("Motion+ angular rates (deg/sec): pitch:%03.2f roll:%03.2f yaw:%03.2f\n",
|
||||
wm->exp.mp.angle_rate_gyro.pitch,
|
||||
wm->exp.mp.angle_rate_gyro.roll,
|
||||
wm->exp.mp.angle_rate_gyro.yaw);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Callback that handles a read event.
|
||||
@@ -241,8 +318,9 @@ void handle_read(struct wiimote_t* wm, byte* data, unsigned short len) {
|
||||
printf("\n\n--- DATA READ [wiimote id %i] ---\n", wm->unid);
|
||||
printf("finished read of size %i\n", len);
|
||||
for (; i < len; ++i) {
|
||||
if (!(i%16))
|
||||
if (!(i % 16)) {
|
||||
printf("\n");
|
||||
}
|
||||
printf("%x ", data[i]);
|
||||
}
|
||||
printf("\n\n");
|
||||
@@ -294,6 +372,20 @@ void test(struct wiimote_t* wm, byte* data, unsigned short len) {
|
||||
printf("test: %i [%x %x %x %x]\n", len, data[0], data[1], data[2], data[3]);
|
||||
}
|
||||
|
||||
short any_wiimote_connected(wiimote** wm, int wiimotes) {
|
||||
int i;
|
||||
if (!wm) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < wiimotes; i++) {
|
||||
if (wm[i] && WIIMOTE_IS_CONNECTED(wm[i])) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -326,7 +418,7 @@ int main(int argc, char** argv) {
|
||||
*/
|
||||
found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5);
|
||||
if (!found) {
|
||||
printf ("No wiimotes found.\n");
|
||||
printf("No wiimotes found.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -340,9 +432,9 @@ int main(int argc, char** argv) {
|
||||
* This will return the number of established connections to the found wiimotes.
|
||||
*/
|
||||
connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
|
||||
if (connected)
|
||||
if (connected) {
|
||||
printf("Connected to %i wiimotes (of %i found).\n", connected, found);
|
||||
else {
|
||||
} else {
|
||||
printf("Failed to connect to any wiimote.\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -358,15 +450,22 @@ int main(int argc, char** argv) {
|
||||
wiiuse_rumble(wiimotes[0], 1);
|
||||
wiiuse_rumble(wiimotes[1], 1);
|
||||
|
||||
#ifndef WIN32
|
||||
usleep(200000);
|
||||
#else
|
||||
Sleep(200);
|
||||
#endif
|
||||
#ifndef WIIUSE_WIN32
|
||||
usleep(200000);
|
||||
#else
|
||||
Sleep(200);
|
||||
#endif
|
||||
|
||||
wiiuse_rumble(wiimotes[0], 0);
|
||||
wiiuse_rumble(wiimotes[1], 0);
|
||||
|
||||
printf("\nControls:\n");
|
||||
printf("\tB toggles rumble.\n");
|
||||
printf("\t+ to start Wiimote accelerometer reporting, - to stop\n");
|
||||
printf("\tUP to start IR camera (sensor bar mode), DOWN to stop.\n");
|
||||
printf("\t1 to start Motion+ reporting, 2 to stop.\n");
|
||||
printf("\n\n");
|
||||
|
||||
/*
|
||||
* Maybe I'm interested in the battery power of the 0th
|
||||
* wiimote. This should be WIIMOTE_ID_1 but to be sure
|
||||
@@ -390,7 +489,7 @@ int main(int argc, char** argv) {
|
||||
* This function will set the event flag for each wiimote
|
||||
* when the wiimote has things to report.
|
||||
*/
|
||||
while (1) {
|
||||
while (any_wiimote_connected(wiimotes, MAX_WIIMOTES)) {
|
||||
if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) {
|
||||
/*
|
||||
* This happens if something happened on any wiimote.
|
||||
@@ -430,8 +529,8 @@ int main(int argc, char** argv) {
|
||||
* threshold values. By default they are the same
|
||||
* as the wiimote.
|
||||
*/
|
||||
/* wiiuse_set_nunchuk_orient_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 90.0f); */
|
||||
/* wiiuse_set_nunchuk_accel_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 100); */
|
||||
/* wiiuse_set_nunchuk_orient_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 90.0f); */
|
||||
/* wiiuse_set_nunchuk_accel_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 100); */
|
||||
printf("Nunchuk inserted.\n");
|
||||
break;
|
||||
|
||||
@@ -449,15 +548,15 @@ int main(int argc, char** argv) {
|
||||
printf("Guitar Hero 3 controller inserted.\n");
|
||||
break;
|
||||
|
||||
case WIIUSE_MOTION_PLUS_ACTIVATED:
|
||||
printf("Motion+ was activated\n");
|
||||
break;
|
||||
case WIIUSE_MOTION_PLUS_ACTIVATED:
|
||||
printf("Motion+ was activated\n");
|
||||
break;
|
||||
|
||||
case WIIUSE_NUNCHUK_REMOVED:
|
||||
case WIIUSE_CLASSIC_CTRL_REMOVED:
|
||||
case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
|
||||
case WIIUSE_WII_BOARD_CTRL_REMOVED:
|
||||
case WIIUSE_MOTION_PLUS_REMOVED:
|
||||
case WIIUSE_MOTION_PLUS_REMOVED:
|
||||
/* some expansion was removed */
|
||||
handle_ctrl_status(wiimotes[i]);
|
||||
printf("An expansion was removed.\n");
|
||||
|
||||
@@ -10,6 +10,7 @@ set(SOURCES
|
||||
wiiboard.c
|
||||
classic.h
|
||||
definitions.h
|
||||
definitions_os.h
|
||||
dynamics.h
|
||||
events.h
|
||||
guitar_hero_3.h
|
||||
@@ -26,13 +27,22 @@ set(API
|
||||
wiiuse.h)
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND SOURCES io_win.c)
|
||||
list(APPEND SOURCES os_win.c)
|
||||
set(CMAKE_DEBUG_POSTFIX _debug)
|
||||
elseif(APPLE)
|
||||
list(APPEND SOURCES io_mac.h)
|
||||
list(APPEND SOURCES io_mac.m)
|
||||
set(MAC_OBJC_SOURCES
|
||||
os_mac/os_mac.m
|
||||
os_mac/os_mac_interface.m
|
||||
os_mac/os_mac_find.m)
|
||||
set(MAC_SOURCES
|
||||
os_mac/os_mac.h
|
||||
${MAC_OBJC_SOURCES})
|
||||
list(APPEND SOURCES ${MAC_SOURCES})
|
||||
# make sure we use the gcc for Objective-C files as well so that the
|
||||
# sysroot and deployment target arguments are correctly passed to the compiler
|
||||
set_source_files_properties(${MAC_OBJC_SOURCES} PROPERTIES LANGUAGE C)
|
||||
else()
|
||||
list(APPEND SOURCES io_nix.c)
|
||||
list(APPEND SOURCES os_nix.c)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
@@ -48,18 +58,20 @@ if(WIN32)
|
||||
elseif(LINUX)
|
||||
target_link_libraries(wiiuse m ${BLUEZ_LIBRARIES})
|
||||
elseif(APPLE)
|
||||
# link libraries
|
||||
find_library(IOBLUETOOTH_FRAMEWORK
|
||||
NAMES
|
||||
IOBluetooth)
|
||||
|
||||
find_library(COREFOUNDATION_FRAMEWORK
|
||||
NAMES
|
||||
CoreFoundation)
|
||||
|
||||
find_library(FOUNDATION_FRAMEWORK
|
||||
NAMES
|
||||
Foundation)
|
||||
target_link_libraries(wiiuse ${IOBLUETOOTH_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${FOUNDATION_FRAMEWORK})
|
||||
|
||||
# do not link Objective-C runtime with clang
|
||||
set_target_properties(wiiuse PROPERTIES XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME "NO")
|
||||
endif()
|
||||
|
||||
set_property(TARGET
|
||||
|
||||
@@ -77,8 +77,9 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte
|
||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||
|
||||
return 0;
|
||||
} else
|
||||
} else {
|
||||
data += 16;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,9 +101,9 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte
|
||||
/* handshake done */
|
||||
wm->exp.type = EXP_CLASSIC;
|
||||
|
||||
#ifdef WIIUSE_WIN32
|
||||
#ifdef WIIUSE_WIN32
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -40,14 +40,14 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup internal_classic Internal: Classic Controller */
|
||||
/** @{ */
|
||||
int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len);
|
||||
/** @defgroup internal_classic Internal: Classic Controller */
|
||||
/** @{ */
|
||||
int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len);
|
||||
|
||||
void classic_ctrl_disconnected(struct classic_ctrl_t* cc);
|
||||
void classic_ctrl_disconnected(struct classic_ctrl_t* cc);
|
||||
|
||||
void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg);
|
||||
/** @} */
|
||||
void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg);
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
/* this is wiiuse - used to distinguish from third party programs using wiiuse.h */
|
||||
#include <stdio.h>
|
||||
#include "os.h"
|
||||
#include "definitions_os.h"
|
||||
/** @addtogroup internal_general */
|
||||
/** @{ */
|
||||
|
||||
|
||||
51
src/definitions_os.h
Normal file
51
src/definitions_os.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Operating system related definitions.
|
||||
*
|
||||
* This file is an attempt to separate operating system
|
||||
* dependent functions and choose what should be used
|
||||
* at compile time.
|
||||
*/
|
||||
|
||||
#ifndef DEFINITIONS_OS_H_INCLUDED
|
||||
#define DEFINITIONS_OS_H_INCLUDED
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <float.h>
|
||||
/* windows with visual c */
|
||||
#define isnan(x) (_isnan(x))
|
||||
#define isinf(x) (!_finite(x))
|
||||
/* disable warnings I don't care about */
|
||||
/*#pragma warning(disable:4273) */ /* inconsistent dll linkage */
|
||||
#endif
|
||||
|
||||
#endif /* DEFINITIONS_OS_H_INCLUDED */
|
||||
@@ -77,12 +77,21 @@ void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct ori
|
||||
z = ((float)accel->z - (float)ac->cal_zero.z) / zg;
|
||||
|
||||
/* make sure x,y,z are between -1 and 1 for the tan functions */
|
||||
if (x < -1.0f) x = -1.0f;
|
||||
else if (x > 1.0f) x = 1.0f;
|
||||
if (y < -1.0f) y = -1.0f;
|
||||
else if (y > 1.0f) y = 1.0f;
|
||||
if (z < -1.0f) z = -1.0f;
|
||||
else if (z > 1.0f) z = 1.0f;
|
||||
if (x < -1.0f) {
|
||||
x = -1.0f;
|
||||
} else if (x > 1.0f) {
|
||||
x = 1.0f;
|
||||
}
|
||||
if (y < -1.0f) {
|
||||
y = -1.0f;
|
||||
} else if (y > 1.0f) {
|
||||
y = 1.0f;
|
||||
}
|
||||
if (z < -1.0f) {
|
||||
z = -1.0f;
|
||||
} else if (z > 1.0f) {
|
||||
z = 1.0f;
|
||||
}
|
||||
|
||||
/* if it is over 1g then it is probably accelerating and not reliable */
|
||||
if (abs(accel->x - ac->cal_zero.x) <= ac->cal_g.x) {
|
||||
@@ -180,39 +189,39 @@ void calc_joystick_state(struct joystick_t* js, float x, float y) {
|
||||
|
||||
void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) {
|
||||
switch (type) {
|
||||
case SMOOTH_ROLL:
|
||||
{
|
||||
/* it's possible last iteration was nan or inf, so set it to 0 if that happened */
|
||||
if (isnan(ac->st_roll) || isinf(ac->st_roll))
|
||||
ac->st_roll = 0.0f;
|
||||
case SMOOTH_ROLL: {
|
||||
/* it's possible last iteration was nan or inf, so set it to 0 if that happened */
|
||||
if (isnan(ac->st_roll) || isinf(ac->st_roll)) {
|
||||
ac->st_roll = 0.0f;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the sign changes (which will happen if going from -180 to 180)
|
||||
* or from (-1 to 1) then don't smooth, just use the new angle.
|
||||
*/
|
||||
if (((ac->st_roll < 0) && (orient->roll > 0)) || ((ac->st_roll > 0) && (orient->roll < 0))) {
|
||||
ac->st_roll = orient->roll;
|
||||
} else {
|
||||
orient->roll = ac->st_roll + (ac->st_alpha * (orient->a_roll - ac->st_roll));
|
||||
ac->st_roll = orient->roll;
|
||||
/*
|
||||
* If the sign changes (which will happen if going from -180 to 180)
|
||||
* or from (-1 to 1) then don't smooth, just use the new angle.
|
||||
*/
|
||||
if (((ac->st_roll < 0) && (orient->roll > 0)) || ((ac->st_roll > 0) && (orient->roll < 0))) {
|
||||
ac->st_roll = orient->roll;
|
||||
} else {
|
||||
orient->roll = ac->st_roll + (ac->st_alpha * (orient->a_roll - ac->st_roll));
|
||||
ac->st_roll = orient->roll;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
case SMOOTH_PITCH: {
|
||||
if (isnan(ac->st_pitch) || isinf(ac->st_pitch)) {
|
||||
ac->st_pitch = 0.0f;
|
||||
}
|
||||
|
||||
case SMOOTH_PITCH:
|
||||
{
|
||||
if (isnan(ac->st_pitch) || isinf(ac->st_pitch))
|
||||
ac->st_pitch = 0.0f;
|
||||
if (((ac->st_pitch < 0) && (orient->pitch > 0)) || ((ac->st_pitch > 0) && (orient->pitch < 0))) {
|
||||
ac->st_pitch = orient->pitch;
|
||||
} else {
|
||||
orient->pitch = ac->st_pitch + (ac->st_alpha * (orient->a_pitch - ac->st_pitch));
|
||||
ac->st_pitch = orient->pitch;
|
||||
}
|
||||
|
||||
if (((ac->st_pitch < 0) && (orient->pitch > 0)) || ((ac->st_pitch > 0) && (orient->pitch < 0))) {
|
||||
ac->st_pitch = orient->pitch;
|
||||
} else {
|
||||
orient->pitch = ac->st_pitch + (ac->st_alpha * (orient->a_pitch - ac->st_pitch));
|
||||
ac->st_pitch = orient->pitch;
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,14 +44,14 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup internal_dynamics Internal: Dynamics Functions */
|
||||
/** @{ */
|
||||
/** @defgroup internal_dynamics Internal: Dynamics Functions */
|
||||
/** @{ */
|
||||
|
||||
void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth);
|
||||
void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce);
|
||||
void calc_joystick_state(struct joystick_t* js, float x, float y);
|
||||
void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type);
|
||||
/** @} */
|
||||
void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth);
|
||||
void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce);
|
||||
void calc_joystick_state(struct joystick_t* js, float x, float y);
|
||||
void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type);
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
598
src/events.c
598
src/events.c
@@ -44,21 +44,13 @@
|
||||
#include "nunchuk.h" /* for nunchuk_disconnected, etc */
|
||||
#include "wiiboard.h" /* for wii_board_disconnected, etc */
|
||||
#include "motion_plus.h" /* for motion_plus_disconnected, etc */
|
||||
#include "io.h" /* for wiiuse_io_read on Windows, etc */
|
||||
|
||||
#ifndef WIIUSE_WIN32
|
||||
#include <sys/time.h> /* for timeval */
|
||||
#include <sys/select.h> /* for select, fd_set */
|
||||
#include <unistd.h> /* for read */
|
||||
#endif
|
||||
#include "os.h" /* for wiiuse_os_poll */
|
||||
|
||||
#include <errno.h> /* for errno */
|
||||
#include <stdio.h> /* for printf, perror */
|
||||
#include <stdlib.h> /* for free, malloc */
|
||||
#include <string.h> /* for memcpy, memset */
|
||||
|
||||
static void idle_cycle(struct wiimote_t* wm);
|
||||
static void clear_dirty_reads(struct wiimote_t* wm);
|
||||
static void event_data_read(struct wiimote_t* wm, byte* msg);
|
||||
static void event_data_write(struct wiimote_t *wm, byte *msg);
|
||||
static void event_status(struct wiimote_t* wm, byte* msg);
|
||||
@@ -80,141 +72,7 @@ static int state_changed(struct wiimote_t* wm);
|
||||
* the event variable will be set.
|
||||
*/
|
||||
int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
|
||||
int evnt = 0;
|
||||
|
||||
#ifdef WIIUSE_BLUEZ
|
||||
/*
|
||||
* *nix
|
||||
*/
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
int r;
|
||||
int i;
|
||||
int highest_fd = -1;
|
||||
|
||||
if (!wm) return 0;
|
||||
|
||||
/* block select() for 1/2000th of a second */
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 500;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
/* only poll it if it is connected */
|
||||
if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) {
|
||||
FD_SET(wm[i]->in_sock, &fds);
|
||||
|
||||
/* find the highest fd of the connected wiimotes */
|
||||
if (wm[i]->in_sock > highest_fd)
|
||||
highest_fd = wm[i]->in_sock;
|
||||
}
|
||||
|
||||
wm[i]->event = WIIUSE_NONE;
|
||||
}
|
||||
|
||||
if (highest_fd == -1)
|
||||
/* nothing to poll */
|
||||
return 0;
|
||||
|
||||
if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) {
|
||||
WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s).");
|
||||
perror("Error Details");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check each socket for an event */
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
/* if this wiimote is not connected, skip it */
|
||||
if (!WIIMOTE_IS_CONNECTED(wm[i]))
|
||||
continue;
|
||||
|
||||
if (FD_ISSET(wm[i]->in_sock, &fds)) {
|
||||
/* clear out the event buffer */
|
||||
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
|
||||
|
||||
/* clear out any old read requests */
|
||||
clear_dirty_reads(wm[i]);
|
||||
|
||||
/* read the pending message into the buffer */
|
||||
r = read(wm[i]->in_sock, wm[i]->event_buf, sizeof(wm[i]->event_buf));
|
||||
if (r == -1) {
|
||||
/* error reading data */
|
||||
WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid);
|
||||
perror("Error Details");
|
||||
|
||||
if (errno == ENOTCONN) {
|
||||
/* this can happen if the bluetooth dongle is disconnected */
|
||||
WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm[i]->unid);
|
||||
wiiuse_disconnect(wm[i]);
|
||||
wiiuse_disconnected(wm[i]);
|
||||
wm[i]->event = WIIUSE_UNEXPECTED_DISCONNECT;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
if (!r) {
|
||||
/* remote disconnect */
|
||||
wiiuse_disconnected(wm[i]);
|
||||
evnt = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* propagate the event */
|
||||
propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
|
||||
evnt += (wm[i]->event != WIIUSE_NONE);
|
||||
} else {
|
||||
idle_cycle(wm[i]);
|
||||
}
|
||||
}
|
||||
#elif defined(WIIUSE_WIN32)
|
||||
/*
|
||||
* Windows
|
||||
*/
|
||||
int i;
|
||||
|
||||
if (!wm) return 0;
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
wm[i]->event = WIIUSE_NONE;
|
||||
|
||||
if (wiiuse_io_read(wm[i])) {
|
||||
/* propagate the event */
|
||||
propagate_event(wm[i], wm[i]->event_buf[0], wm[i]->event_buf+1);
|
||||
evnt += (wm[i]->event != WIIUSE_NONE);
|
||||
|
||||
/* clear out the event buffer */
|
||||
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
|
||||
} else {
|
||||
idle_cycle(wm[i]);
|
||||
}
|
||||
}
|
||||
#elif defined(WIIUSE_MAC)
|
||||
/*
|
||||
* Mac
|
||||
*/
|
||||
int i;
|
||||
|
||||
if (!wm) return 0;
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
wm[i]->event = WIIUSE_NONE;
|
||||
|
||||
if (wiiuse_io_read(wm[i])) {
|
||||
/* propagate the event, messages should be read as in linux, starting from the second element */
|
||||
propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
|
||||
evnt += (wm[i]->event != WIIUSE_NONE);
|
||||
|
||||
/* clear out the event buffer */
|
||||
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
|
||||
} else {
|
||||
idle_cycle(wm[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return evnt;
|
||||
return wiiuse_os_poll(wm, wiimotes);
|
||||
}
|
||||
|
||||
int wiiuse_update(struct wiimote_t** wiimotes, int nwiimotes, wiiuse_update_cb callback) {
|
||||
@@ -241,7 +99,7 @@ int wiiuse_update(struct wiimote_t** wiimotes, int nwiimotes, wiiuse_update_cb c
|
||||
s.event = wiimotes[i]->event;
|
||||
s.state = wiimotes[i]->state;
|
||||
s.expansion = wiimotes[i]->exp;
|
||||
callback( &s );
|
||||
callback(&s);
|
||||
evnt++;
|
||||
break;
|
||||
}
|
||||
@@ -255,7 +113,7 @@ int wiiuse_update(struct wiimote_t** wiimotes, int nwiimotes, wiiuse_update_cb c
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
static void idle_cycle(struct wiimote_t* wm) {
|
||||
void idle_cycle(struct wiimote_t* wm) {
|
||||
/*
|
||||
* Smooth the angles.
|
||||
*
|
||||
@@ -282,7 +140,7 @@ static void idle_cycle(struct wiimote_t* wm) {
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
static void clear_dirty_reads(struct wiimote_t* wm) {
|
||||
void clear_dirty_reads(struct wiimote_t* wm) {
|
||||
struct read_req_t* req = wm->read_req;
|
||||
|
||||
while (req && req->dirty) {
|
||||
@@ -326,108 +184,98 @@ void propagate_event(struct wiimote_t* wm, byte event, byte* msg) {
|
||||
save_state(wm);
|
||||
|
||||
switch (event) {
|
||||
case WM_RPT_BTN:
|
||||
{
|
||||
/* button */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC:
|
||||
{
|
||||
/* button - motion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
case WM_RPT_BTN: {
|
||||
/* button */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC: {
|
||||
/* button - motion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
handle_wm_accel(wm, msg);
|
||||
handle_wm_accel(wm, msg);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_READ:
|
||||
{
|
||||
/* data read */
|
||||
event_data_read(wm, msg);
|
||||
break;
|
||||
}
|
||||
case WM_RPT_READ: {
|
||||
/* data read */
|
||||
event_data_read(wm, msg);
|
||||
|
||||
/* yeah buttons may be pressed, but this wasn't an "event" */
|
||||
return;
|
||||
}
|
||||
case WM_RPT_CTRL_STATUS:
|
||||
{
|
||||
/* controller status */
|
||||
event_status(wm, msg);
|
||||
/* yeah buttons may be pressed, but this wasn't an "event" */
|
||||
return;
|
||||
}
|
||||
case WM_RPT_CTRL_STATUS: {
|
||||
/* controller status */
|
||||
event_status(wm, msg);
|
||||
|
||||
/* don't execute the event callback */
|
||||
return;
|
||||
}
|
||||
case WM_RPT_BTN_EXP:
|
||||
{
|
||||
/* button - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
handle_expansion(wm, msg+2);
|
||||
/* don't execute the event callback */
|
||||
return;
|
||||
}
|
||||
case WM_RPT_BTN_EXP: {
|
||||
/* button - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
handle_expansion(wm, msg + 2);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC_EXP:
|
||||
{
|
||||
/* button - motion - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC_EXP: {
|
||||
/* button - motion - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
handle_wm_accel(wm, msg);
|
||||
handle_wm_accel(wm, msg);
|
||||
|
||||
handle_expansion(wm, msg+5);
|
||||
handle_expansion(wm, msg + 5);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC_IR:
|
||||
{
|
||||
/* button - motion - ir */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC_IR: {
|
||||
/* button - motion - ir */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
handle_wm_accel(wm, msg);
|
||||
handle_wm_accel(wm, msg);
|
||||
|
||||
/* ir */
|
||||
calculate_extended_ir(wm, msg+5);
|
||||
/* ir */
|
||||
calculate_extended_ir(wm, msg + 5);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_IR_EXP:
|
||||
{
|
||||
/* button - ir - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
handle_expansion(wm, msg+12);
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_IR_EXP: {
|
||||
/* button - ir - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
handle_expansion(wm, msg + 12);
|
||||
|
||||
/* ir */
|
||||
calculate_basic_ir(wm, msg+2);
|
||||
/* ir */
|
||||
calculate_basic_ir(wm, msg + 2);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC_IR_EXP:
|
||||
{
|
||||
/* button - motion - ir - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC_IR_EXP: {
|
||||
/* button - motion - ir - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
handle_wm_accel(wm, msg);
|
||||
handle_wm_accel(wm, msg);
|
||||
|
||||
handle_expansion(wm, msg+15);
|
||||
handle_expansion(wm, msg + 15);
|
||||
|
||||
/* ir */
|
||||
calculate_basic_ir(wm, msg+5);
|
||||
/* ir */
|
||||
calculate_basic_ir(wm, msg + 5);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_WRITE:
|
||||
{
|
||||
event_data_write(wm,msg);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
WIIUSE_WARNING("Unknown event, can not handle it [Code 0x%x].", event);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_RPT_WRITE: {
|
||||
event_data_write(wm, msg);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
WIIUSE_WARNING("Unknown event, can not handle it [Code 0x%x].", event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* was there an event? */
|
||||
if (state_changed(wm))
|
||||
if (state_changed(wm)) {
|
||||
wm->event = WIIUSE_EVENT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -476,8 +324,9 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
/* find the next non-dirty request */
|
||||
while (req && req->dirty)
|
||||
while (req && req->dirty) {
|
||||
req = req->next;
|
||||
}
|
||||
|
||||
/* if we don't have a request out then we didn't ask for this packet */
|
||||
if (!req) {
|
||||
@@ -487,12 +336,13 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
||||
|
||||
err = msg[2] & 0x0F;
|
||||
|
||||
if (err == 0x08)
|
||||
if (err == 0x08) {
|
||||
WIIUSE_WARNING("Unable to read data - address does not exist.");
|
||||
else if (err == 0x07)
|
||||
} else if (err == 0x07) {
|
||||
WIIUSE_WARNING("Unable to read data - address is for write-only registers.");
|
||||
else if (err)
|
||||
} else if (err) {
|
||||
WIIUSE_WARNING("Unable to read data - unknown error code %x.", err);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
/* this request errored out, so skip it and go to the next one */
|
||||
@@ -502,8 +352,9 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
||||
free(req);
|
||||
|
||||
/* if another request exists send it to the wiimote */
|
||||
if (wm->read_req)
|
||||
if (wm->read_req) {
|
||||
wiiuse_send_next_pending_read_request(wm);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -515,7 +366,9 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
||||
req->wait -= len;
|
||||
if (req->wait >= req->size)
|
||||
/* this should never happen */
|
||||
{
|
||||
req->wait = 0;
|
||||
}
|
||||
|
||||
WIIUSE_DEBUG("Received read packet:");
|
||||
WIIUSE_DEBUG(" Packet read offset: %i bytes", offset);
|
||||
@@ -527,15 +380,16 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
||||
/* reconstruct this part of the data */
|
||||
memcpy((req->buf + offset - req->addr), (msg + 5), len);
|
||||
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
int i = 0;
|
||||
printf("Read: ");
|
||||
for (; i < req->size - req->wait; ++i)
|
||||
for (; i < req->size - req->wait; ++i) {
|
||||
printf("%x ", req->buf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* if all data has been received, execute the read event callback or generate event */
|
||||
if (!req->wait) {
|
||||
@@ -559,25 +413,25 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
||||
}
|
||||
|
||||
/* if another request exists send it to the wiimote */
|
||||
if (wm->read_req)
|
||||
if (wm->read_req) {
|
||||
wiiuse_send_next_pending_read_request(wm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void event_data_write(struct wiimote_t *wm, byte *msg)
|
||||
{
|
||||
static void event_data_write(struct wiimote_t *wm, byte *msg) {
|
||||
|
||||
struct data_req_t* req = wm->data_req;
|
||||
|
||||
wiiuse_pressed_buttons(wm,msg);
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
/* if we don't have a request out then we didn't ask for this packet */
|
||||
if (!req) {
|
||||
WIIUSE_WARNING("Transmitting data packet when no request was made.");
|
||||
return;
|
||||
}
|
||||
if(!(req->state==REQ_SENT)) {
|
||||
if (!(req->state == REQ_SENT)) {
|
||||
WIIUSE_WARNING("Transmission is not necessary");
|
||||
/* delete this request */
|
||||
wm->data_req = req->next;
|
||||
@@ -588,23 +442,23 @@ static void event_data_write(struct wiimote_t *wm, byte *msg)
|
||||
|
||||
req->state = REQ_DONE;
|
||||
|
||||
if(req->cb) {
|
||||
if (req->cb) {
|
||||
/* this was a callback, so invoke it now */
|
||||
req->cb(wm,NULL,0);
|
||||
req->cb(wm, NULL, 0);
|
||||
/* delete this request */
|
||||
wm->data_req = req->next;
|
||||
free(req);
|
||||
} else {
|
||||
/*
|
||||
* This should generate an event.
|
||||
* We need to leave the event in the array so the client
|
||||
* can access it still. We'll flag is as being 'REQ_DONE'
|
||||
* and give the client one cycle to use it. Next event
|
||||
* we will remove it from the list.
|
||||
*/
|
||||
wm->event = WIIUSE_WRITE_DATA;
|
||||
/*
|
||||
* This should generate an event.
|
||||
* We need to leave the event in the array so the client
|
||||
* can access it still. We'll flag is as being 'REQ_DONE'
|
||||
* and give the client one cycle to use it. Next event
|
||||
* we will remove it from the list.
|
||||
*/
|
||||
wm->event = WIIUSE_WRITE_DATA;
|
||||
|
||||
}
|
||||
}
|
||||
/* if another request exists send it to the wiimote */
|
||||
if (wm->data_req) {
|
||||
wiiuse_send_next_pending_write_request(wm);
|
||||
@@ -627,8 +481,9 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
|
||||
struct data_req_t* req = wm->data_req;
|
||||
|
||||
/* initial handshake is not finished yet, ignore this */
|
||||
if(WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE))
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* An event occurred.
|
||||
@@ -640,28 +495,45 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
/* find what LEDs are lit */
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_1) led[0] = 1;
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_2) led[1] = 1;
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_3) led[2] = 1;
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_4) led[3] = 1;
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_1) {
|
||||
led[0] = 1;
|
||||
}
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_2) {
|
||||
led[1] = 1;
|
||||
}
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_3) {
|
||||
led[2] = 1;
|
||||
}
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_4) {
|
||||
led[3] = 1;
|
||||
}
|
||||
|
||||
/* probe for Motion+ */
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT)) {
|
||||
wiiuse_probe_motion_plus(wm);
|
||||
}
|
||||
|
||||
/* is an attachment connected to the expansion port? */
|
||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT)
|
||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT) {
|
||||
WIIUSE_DEBUG("Attachment detected!");
|
||||
attachment = 1;
|
||||
}
|
||||
|
||||
/* is the speaker enabled? */
|
||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) == WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED)
|
||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) == WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) {
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_SPEAKER);
|
||||
}
|
||||
|
||||
/* is IR sensing enabled? */
|
||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_IR_ENABLED) == WM_CTRL_STATUS_BYTE1_IR_ENABLED)
|
||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_IR_ENABLED) == WM_CTRL_STATUS_BYTE1_IR_ENABLED) {
|
||||
ir = 1;
|
||||
}
|
||||
|
||||
/* find the battery level and normalize between 0 and 1 */
|
||||
wm->battery_level = (msg[5] / (float)WM_MAX_BATTERY_CODE);
|
||||
|
||||
/* expansion port */
|
||||
if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||
if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP) && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP_HANDSHAKE)) {
|
||||
/* send the initialization code for the attachment */
|
||||
handshake_expansion(wm, NULL, 0);
|
||||
exp_changed = 1;
|
||||
@@ -671,20 +543,19 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
|
||||
exp_changed = 1;
|
||||
}
|
||||
|
||||
#ifdef WIIUSE_WIN32
|
||||
#ifdef WIIUSE_WIN32
|
||||
if (!attachment) {
|
||||
WIIUSE_DEBUG("Setting timeout to normal %i ms.", wm->normal_timeout);
|
||||
wm->timeout = wm->normal_timeout;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* From now on the remote will only send status packets.
|
||||
* We need to send a WIIMOTE_CMD_REPORT_TYPE packet to
|
||||
* reenable other incoming reports.
|
||||
*/
|
||||
if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
||||
{
|
||||
if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
/*
|
||||
* Since the expansion status changed IR needs to
|
||||
* be reset for the new IR report mode.
|
||||
@@ -697,13 +568,16 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
|
||||
}
|
||||
|
||||
/* handling new Tx for changed exp */
|
||||
if(!req) return;
|
||||
if(!(req->state==REQ_SENT)) return;
|
||||
if (!req) {
|
||||
return;
|
||||
}
|
||||
if (!(req->state == REQ_SENT)) {
|
||||
return;
|
||||
}
|
||||
wm->data_req = req->next;
|
||||
req->state = REQ_DONE;
|
||||
/* if(req->cb!=NULL) req->cb(wm,msg,6); */
|
||||
free(req);
|
||||
wiiuse_send_next_pending_write_request(wm);
|
||||
}
|
||||
|
||||
|
||||
@@ -752,15 +626,15 @@ static void handle_expansion(struct wiimote_t* wm, byte* msg) {
|
||||
* a handshake with the expansion.
|
||||
*/
|
||||
void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) {
|
||||
WIIUSE_DEBUG("handshake_expansion with state %d", wm->expansion_state);
|
||||
int id;
|
||||
byte val = 0;
|
||||
byte buf = 0x00;
|
||||
byte* handshake_buf;
|
||||
int gotIt = 0;
|
||||
WIIUSE_DEBUG("handshake_expansion with state %d", wm->expansion_state);
|
||||
|
||||
switch(wm->expansion_state) {
|
||||
/* These two initialization writes disable the encryption */
|
||||
switch (wm->expansion_state) {
|
||||
/* These two initialization writes disable the encryption */
|
||||
case 0:
|
||||
wm->expansion_state = 1;
|
||||
/* increase the timeout until the handshake completes */
|
||||
@@ -784,21 +658,23 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) {
|
||||
case 2:
|
||||
wm->expansion_state = 3;
|
||||
/* get the calibration data */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||
disable_expansion(wm);
|
||||
}
|
||||
handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
||||
/* tell the wiimote to send expansion data */
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP);
|
||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||
break;
|
||||
case 3:
|
||||
if(!data || !len) {
|
||||
if (!data || !len) {
|
||||
WIIUSE_DEBUG("no handshake data received from expansion");
|
||||
disable_expansion(wm);
|
||||
return;
|
||||
}
|
||||
wm->expansion_state = 0;
|
||||
id = from_big_endian_uint32_t(data + 220);
|
||||
switch(id) {
|
||||
switch (id) {
|
||||
case EXP_ID_CODE_NUNCHUK:
|
||||
if (nunchuk_handshake(wm, &wm->exp.nunchuk, data, len)) {
|
||||
wm->event = WIIUSE_NUNCHUK_INSERTED;
|
||||
@@ -828,12 +704,12 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) {
|
||||
gotIt = 1;
|
||||
break;
|
||||
|
||||
case EXP_ID_CODE_WII_BOARD:
|
||||
if(wii_board_handshake(wm, &wm->exp.wb, data, len)) {
|
||||
case EXP_ID_CODE_WII_BOARD:
|
||||
if (wii_board_handshake(wm, &wm->exp.wb, data, len)) {
|
||||
wm->event = WIIUSE_WII_BOARD_CTRL_INSERTED;
|
||||
gotIt = 1;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
WIIUSE_WARNING("Unknown expansion type. Code: 0x%x", id);
|
||||
@@ -841,8 +717,8 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) {
|
||||
}
|
||||
free(data);
|
||||
if (gotIt) {
|
||||
WIIMOTE_DISABLE_STATE(wm,WIIMOTE_STATE_EXP_HANDSHAKE);
|
||||
WIIMOTE_ENABLE_STATE(wm,WIIMOTE_STATE_EXP);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP);
|
||||
} else {
|
||||
WIIUSE_WARNING("Could not handshake with expansion id: 0x%x", id);
|
||||
}
|
||||
@@ -866,8 +742,9 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) {
|
||||
*/
|
||||
void disable_expansion(struct wiimote_t* wm) {
|
||||
WIIUSE_DEBUG("Disabling expansion");
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* tell the associated module the expansion was removed */
|
||||
switch (wm->exp.type) {
|
||||
@@ -954,31 +831,29 @@ static void save_state(struct wiimote_t* wm) {
|
||||
|
||||
case EXP_MOTION_PLUS:
|
||||
case EXP_MOTION_PLUS_CLASSIC:
|
||||
case EXP_MOTION_PLUS_NUNCHUK:
|
||||
{
|
||||
wm->lstate.drx = wm->exp.mp.raw_gyro.pitch;
|
||||
wm->lstate.dry = wm->exp.mp.raw_gyro.roll;
|
||||
wm->lstate.drz = wm->exp.mp.raw_gyro.yaw;
|
||||
case EXP_MOTION_PLUS_NUNCHUK: {
|
||||
wm->lstate.drx = wm->exp.mp.raw_gyro.pitch;
|
||||
wm->lstate.dry = wm->exp.mp.raw_gyro.roll;
|
||||
wm->lstate.drz = wm->exp.mp.raw_gyro.yaw;
|
||||
|
||||
if(wm->exp.type == EXP_MOTION_PLUS_CLASSIC)
|
||||
{
|
||||
wm->lstate.exp_ljs_ang = wm->exp.classic.ljs.ang;
|
||||
wm->lstate.exp_ljs_mag = wm->exp.classic.ljs.mag;
|
||||
wm->lstate.exp_rjs_ang = wm->exp.classic.rjs.ang;
|
||||
wm->lstate.exp_rjs_mag = wm->exp.classic.rjs.mag;
|
||||
wm->lstate.exp_r_shoulder = wm->exp.classic.r_shoulder;
|
||||
wm->lstate.exp_l_shoulder = wm->exp.classic.l_shoulder;
|
||||
wm->lstate.exp_btns = wm->exp.classic.btns;
|
||||
} else {
|
||||
wm->lstate.exp_ljs_ang = wm->exp.nunchuk.js.ang;
|
||||
wm->lstate.exp_ljs_mag = wm->exp.nunchuk.js.mag;
|
||||
wm->lstate.exp_btns = wm->exp.nunchuk.btns;
|
||||
wm->lstate.exp_accel = wm->exp.nunchuk.accel;
|
||||
if (wm->exp.type == EXP_MOTION_PLUS_CLASSIC) {
|
||||
wm->lstate.exp_ljs_ang = wm->exp.classic.ljs.ang;
|
||||
wm->lstate.exp_ljs_mag = wm->exp.classic.ljs.mag;
|
||||
wm->lstate.exp_rjs_ang = wm->exp.classic.rjs.ang;
|
||||
wm->lstate.exp_rjs_mag = wm->exp.classic.rjs.mag;
|
||||
wm->lstate.exp_r_shoulder = wm->exp.classic.r_shoulder;
|
||||
wm->lstate.exp_l_shoulder = wm->exp.classic.l_shoulder;
|
||||
wm->lstate.exp_btns = wm->exp.classic.btns;
|
||||
} else {
|
||||
wm->lstate.exp_ljs_ang = wm->exp.nunchuk.js.ang;
|
||||
wm->lstate.exp_ljs_mag = wm->exp.nunchuk.js.mag;
|
||||
wm->lstate.exp_btns = wm->exp.nunchuk.btns;
|
||||
wm->lstate.exp_accel = wm->exp.nunchuk.accel;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case EXP_NONE:
|
||||
break;
|
||||
}
|
||||
@@ -991,9 +866,9 @@ static void save_state(struct wiimote_t* wm) {
|
||||
* @return 1 if a significant change occurred, 0 if not.
|
||||
*/
|
||||
static int state_changed(struct wiimote_t* wm) {
|
||||
#define STATE_CHANGED(a, b) if (a != b) return 1
|
||||
#define STATE_CHANGED(a, b) if (a != b) return 1
|
||||
|
||||
#define CROSS_THRESH(last, now, thresh) \
|
||||
#define CROSS_THRESH(last, now, thresh) \
|
||||
do { \
|
||||
if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \
|
||||
if ((diff_f(last.roll, now.roll) >= thresh) || \
|
||||
@@ -1010,7 +885,7 @@ static int state_changed(struct wiimote_t* wm) {
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CROSS_THRESH_XYZ(last, now, thresh) \
|
||||
#define CROSS_THRESH_XYZ(last, now, thresh) \
|
||||
do { \
|
||||
if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \
|
||||
if ((diff_f(last.x, now.x) >= thresh) || \
|
||||
@@ -1045,54 +920,16 @@ static int state_changed(struct wiimote_t* wm) {
|
||||
|
||||
/* expansion */
|
||||
switch (wm->exp.type) {
|
||||
case EXP_NUNCHUK:
|
||||
{
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns);
|
||||
case EXP_NUNCHUK: {
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns);
|
||||
|
||||
CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold);
|
||||
CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold);
|
||||
break;
|
||||
}
|
||||
case EXP_CLASSIC:
|
||||
{
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_rjs_mag, wm->exp.classic.rjs.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.classic.r_shoulder);
|
||||
STATE_CHANGED(wm->lstate.exp_l_shoulder, wm->exp.classic.l_shoulder);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns);
|
||||
break;
|
||||
}
|
||||
case EXP_GUITAR_HERO_3:
|
||||
{
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.gh3.js.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.gh3.js.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.gh3.whammy_bar);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.gh3.btns);
|
||||
break;
|
||||
}
|
||||
case EXP_WII_BOARD:
|
||||
{
|
||||
STATE_CHANGED(wm->lstate.exp_wb_rtr,wm->exp.wb.tr);
|
||||
STATE_CHANGED(wm->lstate.exp_wb_rtl,wm->exp.wb.tl);
|
||||
STATE_CHANGED(wm->lstate.exp_wb_rbr,wm->exp.wb.br);
|
||||
STATE_CHANGED(wm->lstate.exp_wb_rbl,wm->exp.wb.bl);
|
||||
break;
|
||||
}
|
||||
|
||||
case EXP_MOTION_PLUS:
|
||||
case EXP_MOTION_PLUS_CLASSIC:
|
||||
case EXP_MOTION_PLUS_NUNCHUK:
|
||||
{
|
||||
STATE_CHANGED(wm->lstate.drx, wm->exp.mp.raw_gyro.pitch);
|
||||
STATE_CHANGED(wm->lstate.dry, wm->exp.mp.raw_gyro.roll);
|
||||
STATE_CHANGED(wm->lstate.drz, wm->exp.mp.raw_gyro.yaw);
|
||||
|
||||
if(wm->exp.type == EXP_MOTION_PLUS_CLASSIC)
|
||||
{
|
||||
CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold);
|
||||
CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold);
|
||||
break;
|
||||
}
|
||||
case EXP_CLASSIC: {
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang);
|
||||
@@ -1100,21 +937,52 @@ static int state_changed(struct wiimote_t* wm) {
|
||||
STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.classic.r_shoulder);
|
||||
STATE_CHANGED(wm->lstate.exp_l_shoulder, wm->exp.classic.l_shoulder);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns);
|
||||
} else {
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns);
|
||||
|
||||
CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold);
|
||||
CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold);
|
||||
break;
|
||||
}
|
||||
case EXP_GUITAR_HERO_3: {
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.gh3.js.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.gh3.js.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.gh3.whammy_bar);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.gh3.btns);
|
||||
break;
|
||||
}
|
||||
case EXP_WII_BOARD: {
|
||||
STATE_CHANGED(wm->lstate.exp_wb_rtr, wm->exp.wb.tr);
|
||||
STATE_CHANGED(wm->lstate.exp_wb_rtl, wm->exp.wb.tl);
|
||||
STATE_CHANGED(wm->lstate.exp_wb_rbr, wm->exp.wb.br);
|
||||
STATE_CHANGED(wm->lstate.exp_wb_rbl, wm->exp.wb.bl);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case EXP_NONE:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case EXP_MOTION_PLUS:
|
||||
case EXP_MOTION_PLUS_CLASSIC:
|
||||
case EXP_MOTION_PLUS_NUNCHUK: {
|
||||
STATE_CHANGED(wm->lstate.drx, wm->exp.mp.raw_gyro.pitch);
|
||||
STATE_CHANGED(wm->lstate.dry, wm->exp.mp.raw_gyro.roll);
|
||||
STATE_CHANGED(wm->lstate.drz, wm->exp.mp.raw_gyro.yaw);
|
||||
|
||||
if (wm->exp.type == EXP_MOTION_PLUS_CLASSIC) {
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_rjs_mag, wm->exp.classic.rjs.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.classic.r_shoulder);
|
||||
STATE_CHANGED(wm->lstate.exp_l_shoulder, wm->exp.classic.l_shoulder);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns);
|
||||
} else {
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns);
|
||||
|
||||
CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold);
|
||||
CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case EXP_NONE: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
STATE_CHANGED(wm->lstate.btns, wm->btns);
|
||||
|
||||
@@ -56,6 +56,9 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len);
|
||||
void disable_expansion(struct wiimote_t* wm);
|
||||
|
||||
void propagate_event(struct wiimote_t* wm, byte event, byte* msg);
|
||||
void idle_cycle(struct wiimote_t* wm);
|
||||
|
||||
void clear_dirty_reads(struct wiimote_t* wm);
|
||||
/** @} */
|
||||
|
||||
#endif /* EVENTS_H_INCLUDED */
|
||||
|
||||
@@ -86,8 +86,9 @@ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, b
|
||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||
|
||||
return 0;
|
||||
} else
|
||||
} else {
|
||||
data += 16;
|
||||
}
|
||||
}
|
||||
|
||||
/* joystick stuff */
|
||||
@@ -101,9 +102,9 @@ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, b
|
||||
/* handshake done */
|
||||
wm->exp.type = EXP_GUITAR_HERO_3;
|
||||
|
||||
#ifdef WIIUSE_WIN32
|
||||
#ifdef WIIUSE_WIN32
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -50,14 +50,14 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/** @defgroup internal_gh3 Internal: Guitar Hero 3 controller */
|
||||
/** @{ */
|
||||
int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len);
|
||||
/** @defgroup internal_gh3 Internal: Guitar Hero 3 controller */
|
||||
/** @{ */
|
||||
int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len);
|
||||
|
||||
void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3);
|
||||
void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3);
|
||||
|
||||
void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg);
|
||||
/** @} */
|
||||
void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg);
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
385
src/io.c
385
src/io.c
@@ -30,30 +30,163 @@
|
||||
* @file
|
||||
* @brief Handles device I/O (non-OS specific).
|
||||
*/
|
||||
|
||||
#include "io.h"
|
||||
#include "ir.h" /* for wiiuse_set_ir_mode */
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#include "os.h" /* for wiiuse_os_* */
|
||||
|
||||
#include <stdlib.h> /* for free, malloc */
|
||||
|
||||
|
||||
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm,byte *data,unsigned short len)
|
||||
{
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
||||
wiiuse_set_ir_mode(wm);
|
||||
|
||||
wm->handshake_state++;
|
||||
wiiuse_handshake(wm, NULL, 0);
|
||||
|
||||
/**
|
||||
* @brief Find a wiimote or wiimotes.
|
||||
*
|
||||
* @param wm An array of wiimote_t structures.
|
||||
* @param max_wiimotes The number of wiimote structures in \a wm.
|
||||
* @param timeout The number of seconds before the search times out.
|
||||
*
|
||||
* @return The number of wiimotes found.
|
||||
*
|
||||
* @see wiiuse_connect()
|
||||
* @see wiiuse_os_find()
|
||||
*
|
||||
* This function will only look for wiimote devices. \n
|
||||
* When a device is found the address in the structures will be set. \n
|
||||
* You can then call wiiuse_connect() to connect to the found \n
|
||||
* devices.
|
||||
*
|
||||
* This function only delegates to the platform-specific implementation
|
||||
* wiiuse_os_find.
|
||||
*
|
||||
* This function is declared in wiiuse.h
|
||||
*/
|
||||
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
return wiiuse_os_find(wm, max_wiimotes, timeout);
|
||||
}
|
||||
|
||||
static void wiiuse_disable_motion_plus1(struct wiimote_t *wm,byte *data,unsigned short len)
|
||||
{
|
||||
byte val = 0x00;
|
||||
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus2);
|
||||
/**
|
||||
* @brief Connect to a wiimote or wiimotes once an address is known.
|
||||
*
|
||||
* @param wm An array of wiimote_t structures.
|
||||
* @param wiimotes The number of wiimote structures in \a wm.
|
||||
*
|
||||
* @return The number of wiimotes that successfully connected.
|
||||
*
|
||||
* @see wiiuse_find()
|
||||
* @see wiiuse_disconnect()
|
||||
* @see wiiuse_os_connect()
|
||||
*
|
||||
* Connect to a number of wiimotes when the address is already set
|
||||
* in the wiimote_t structures. These addresses are normally set
|
||||
* by the wiiuse_find() function, but can also be set manually.
|
||||
*
|
||||
* This function only delegates to the platform-specific implementation
|
||||
* wiiuse_os_connect.
|
||||
*
|
||||
* This function is declared in wiiuse.h
|
||||
*/
|
||||
int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
|
||||
return wiiuse_os_connect(wm, wiimotes);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Disconnect a wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* @see wiiuse_connect()
|
||||
* @see wiiuse_os_disconnect()
|
||||
*
|
||||
* Note that this will not free the wiimote structure.
|
||||
*
|
||||
* This function only delegates to the platform-specific implementation
|
||||
* wiiuse_os_disconnect.
|
||||
*
|
||||
* This function is declared in wiiuse.h
|
||||
*/
|
||||
void wiiuse_disconnect(struct wiimote_t* wm) {
|
||||
wiiuse_os_disconnect(wm);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait until specified report arrives and return it
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param buffer Pre-allocated memory to store the received data
|
||||
* @param bufferLength size of buffer in bytes
|
||||
*
|
||||
* Synchronous/blocking, this function will not return until it receives the specified
|
||||
* report from the Wiimote.
|
||||
*
|
||||
*/
|
||||
void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength) {
|
||||
for (;;) {
|
||||
if (wiiuse_os_read(wm, buffer, bufferLength) > 0) {
|
||||
if (buffer[0] == report) {
|
||||
break;
|
||||
} else {
|
||||
WIIUSE_DEBUG("(id %i) dropping report 0x%x, waiting for 0x%x", wm->unid, buffer[0], report);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read memory/register data synchronously
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param memory If set to non-zero, reads EEPROM, otherwise registers
|
||||
* @param addr Address offset to read from
|
||||
* @param size How many bytes to read
|
||||
* @param data Pre-allocated memory to store the received data
|
||||
*
|
||||
* Synchronous/blocking read, this function will not return until it receives the specified
|
||||
* amount of data from the Wiimote.
|
||||
*
|
||||
*/
|
||||
void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data) {
|
||||
byte pkt[6];
|
||||
byte buf[MAX_PAYLOAD];
|
||||
unsigned n_full_reports;
|
||||
unsigned last_report;
|
||||
byte *output;
|
||||
unsigned int i;
|
||||
|
||||
/*
|
||||
* address in big endian first, the leading byte will
|
||||
* be overwritten (only 3 bytes are sent)
|
||||
*/
|
||||
to_big_endian_uint32_t(pkt, addr);
|
||||
|
||||
/* read from registers or memory */
|
||||
pkt[0] = (memory != 0) ? 0x00 : 0x04;
|
||||
|
||||
/* length in big endian */
|
||||
to_big_endian_uint16_t(pkt + 4, size);
|
||||
|
||||
/* send */
|
||||
wiiuse_send(wm, WM_CMD_READ_DATA, pkt, sizeof(pkt));
|
||||
|
||||
/* calculate how many 16B packets we have to get back */
|
||||
n_full_reports = size / 16;
|
||||
last_report = size % 16;
|
||||
output = data;
|
||||
|
||||
for (i = 0; i < n_full_reports; ++i) {
|
||||
wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD);
|
||||
memmove(output, buf + 6, 16);
|
||||
output += 16;
|
||||
}
|
||||
|
||||
/* read the last incomplete packet */
|
||||
if (last_report) {
|
||||
wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD);
|
||||
memmove(output, buf + 6, last_report);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get initialization data from the wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
@@ -66,80 +199,168 @@ static void wiiuse_disable_motion_plus1(struct wiimote_t *wm,byte *data,unsigned
|
||||
* The handshake will be concluded when the wiimote responds
|
||||
* with this data.
|
||||
*/
|
||||
|
||||
#ifdef WIIUSE_SYNC_HANDSHAKE
|
||||
|
||||
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
|
||||
if (!wm) return;
|
||||
/* send request to wiimote for accelerometer calibration */
|
||||
byte buf[MAX_PAYLOAD];
|
||||
|
||||
switch (wm->handshake_state) {
|
||||
case 0:
|
||||
{
|
||||
/* send request to wiimote for accelerometer calibration */
|
||||
byte* buf;
|
||||
/* step 0 - Reset wiimote */
|
||||
{
|
||||
//wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
|
||||
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP);
|
||||
WIIMOTE_DISABLE_FLAG(wm, WIIUSE_CONTINUOUS);
|
||||
|
||||
buf = (byte*)malloc(sizeof(byte) * 8);
|
||||
wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7);
|
||||
wm->handshake_state++;
|
||||
wiiuse_set_report_type(wm);
|
||||
wiiuse_millisleep(500);
|
||||
|
||||
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
|
||||
WIIUSE_DEBUG("Wiimote reset!\n");
|
||||
}
|
||||
|
||||
break;
|
||||
/* step 1 - calibration of accelerometers */
|
||||
{
|
||||
struct accel_t* accel = &wm->accel_calib;
|
||||
|
||||
wiiuse_read_data_sync(wm, 1, WM_MEM_OFFSET_CALIBRATION, 8, buf);
|
||||
|
||||
/* received read data */
|
||||
accel->cal_zero.x = buf[0];
|
||||
accel->cal_zero.y = buf[1];
|
||||
accel->cal_zero.z = buf[2];
|
||||
|
||||
accel->cal_g.x = buf[4] - accel->cal_zero.x;
|
||||
accel->cal_g.y = buf[5] - accel->cal_zero.y;
|
||||
accel->cal_g.z = buf[6] - accel->cal_zero.z;
|
||||
|
||||
WIIUSE_DEBUG("Calibrated wiimote acc\n");
|
||||
}
|
||||
|
||||
/* step 2 - re-enable IR and ask for status */
|
||||
{
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
|
||||
/* now enable IR if it was set before the handshake completed */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
WIIUSE_DEBUG("Handshake finished, enabling IR.");
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
wiiuse_set_ir(wm, 1);
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
struct read_req_t* req = wm->read_req;
|
||||
struct accel_t* accel = &wm->accel_calib;
|
||||
byte val;
|
||||
|
||||
/* received read data */
|
||||
accel->cal_zero.x = req->buf[0];
|
||||
accel->cal_zero.y = req->buf[1];
|
||||
accel->cal_zero.z = req->buf[2];
|
||||
|
||||
accel->cal_g.x = req->buf[4] - accel->cal_zero.x;
|
||||
accel->cal_g.y = req->buf[5] - accel->cal_zero.y;
|
||||
accel->cal_g.z = req->buf[6] - accel->cal_zero.z;
|
||||
|
||||
/* done with the buffer */
|
||||
free(req->buf);
|
||||
|
||||
/* handshake is done */
|
||||
WIIUSE_DEBUG("Handshake finished. Calibration: Idle: X=%x Y=%x Z=%x\t+1g: X=%x Y=%x Z=%x",
|
||||
accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z,
|
||||
accel->cal_g.x, accel->cal_g.y, accel->cal_g.z);
|
||||
|
||||
/* M+ off */
|
||||
val = 0x55;
|
||||
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus1);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
/* request the status of the wiimote to check for any expansion */
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
|
||||
wm->handshake_state++;
|
||||
|
||||
/* now enable IR if it was set before the handshake completed */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
WIIUSE_DEBUG("Handshake finished, enabling IR.");
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
wiiuse_set_ir(wm, 1);
|
||||
}
|
||||
|
||||
wm->event = WIIUSE_CONNECT;
|
||||
wiiuse_status(wm);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
WIIUSE_DEBUG("Asking for status ...\n");
|
||||
wm->event = WIIUSE_CONNECT;
|
||||
wiiuse_status(wm);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void wiiuse_disable_motion_plus1(struct wiimote_t *wm, byte *data, unsigned short len);
|
||||
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm, byte *data, unsigned short len);
|
||||
|
||||
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (wm->handshake_state) {
|
||||
case 0: {
|
||||
byte* buf;
|
||||
|
||||
/* continuous reporting off, report to buttons only */
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE);
|
||||
WIIMOTE_DISABLE_FLAG(wm, WIIUSE_CONTINUOUS);
|
||||
|
||||
wiiuse_set_report_type(wm);
|
||||
|
||||
/* send request to wiimote for accelerometer calibration */
|
||||
buf = (byte*)malloc(sizeof(byte) * 8);
|
||||
wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7);
|
||||
wm->handshake_state++;
|
||||
|
||||
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: {
|
||||
struct read_req_t* req = wm->read_req;
|
||||
struct accel_t* accel = &wm->accel_calib;
|
||||
byte val;
|
||||
|
||||
/* received read data */
|
||||
accel->cal_zero.x = req->buf[0];
|
||||
accel->cal_zero.y = req->buf[1];
|
||||
accel->cal_zero.z = req->buf[2];
|
||||
|
||||
accel->cal_g.x = req->buf[4] - accel->cal_zero.x;
|
||||
accel->cal_g.y = req->buf[5] - accel->cal_zero.y;
|
||||
accel->cal_g.z = req->buf[6] - accel->cal_zero.z;
|
||||
|
||||
/* done with the buffer */
|
||||
free(req->buf);
|
||||
|
||||
/* handshake is done */
|
||||
WIIUSE_DEBUG("Handshake finished. Calibration: Idle: X=%x Y=%x Z=%x\t+1g: X=%x Y=%x Z=%x",
|
||||
accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z,
|
||||
accel->cal_g.x, accel->cal_g.y, accel->cal_g.z);
|
||||
|
||||
/* M+ off */
|
||||
val = 0x55;
|
||||
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus1);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
/* request the status of the wiimote to check for any expansion */
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
|
||||
wm->handshake_state++;
|
||||
|
||||
/* now enable IR if it was set before the handshake completed */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
WIIUSE_DEBUG("Handshake finished, enabling IR.");
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
wiiuse_set_ir(wm, 1);
|
||||
}
|
||||
|
||||
wm->event = WIIUSE_CONNECT;
|
||||
wiiuse_status(wm);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void wiiuse_disable_motion_plus1(struct wiimote_t *wm, byte *data, unsigned short len) {
|
||||
byte val = 0x00;
|
||||
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus2);
|
||||
}
|
||||
|
||||
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm, byte *data, unsigned short len) {
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
||||
wiiuse_set_ir_mode(wm);
|
||||
|
||||
wm->handshake_state++;
|
||||
wiiuse_handshake(wm, NULL, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
26
src/io.h
26
src/io.h
@@ -31,12 +31,8 @@
|
||||
* @brief Handles device I/O.
|
||||
*/
|
||||
|
||||
#ifndef CONNECT_H_INCLUDED
|
||||
#define CONNECT_H_INCLUDED
|
||||
|
||||
#ifdef WIIUSE_BLUEZ
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#endif
|
||||
#ifndef IO_H_INCLUDED
|
||||
#define IO_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
@@ -44,20 +40,16 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup internal_io Internal: Device I/O */
|
||||
/** @{ */
|
||||
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len);
|
||||
|
||||
/** @defgroup internal_io Internal: Device IO */
|
||||
/** @{ */
|
||||
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len);
|
||||
|
||||
void wiiuse_init_platform_fields(struct wiimote_t* wm);
|
||||
void wiiuse_cleanup_platform_fields(struct wiimote_t* wm);
|
||||
|
||||
int wiiuse_io_read(struct wiimote_t* wm);
|
||||
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len);
|
||||
/** @} */
|
||||
void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength);
|
||||
void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data);
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONNECT_H_INCLUDED */
|
||||
#endif /* IO_H_INCLUDED */
|
||||
|
||||
107
src/io_mac.h
107
src/io_mac.h
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* io_mac.h
|
||||
*
|
||||
* This file is based on io_mac.h from WiiC, written By:
|
||||
* Gabriele Randelli
|
||||
* Email: < randelli (--AT--) dis [--DOT--] uniroma1 [--DOT--] it >
|
||||
*
|
||||
* Copyright 2010
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief I/O header file for MacOS.
|
||||
*/
|
||||
#ifndef IO_MAC_H
|
||||
#define IO_MAC_H
|
||||
|
||||
#import <stdio.h>
|
||||
#import <stdlib.h>
|
||||
#import <unistd.h>
|
||||
|
||||
#define BLUETOOTH_VERSION_USE_CURRENT
|
||||
|
||||
#import <arpa/inet.h> /* htons() */
|
||||
#import <IOBluetooth/IOBluetoothUtilities.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothDevice.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothHostController.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothL2CAPChannel.h>
|
||||
|
||||
#import "wiiuse_internal.h"
|
||||
#import "io.h"
|
||||
|
||||
@interface WiiSearch : NSObject
|
||||
{
|
||||
IOBluetoothDeviceInquiry* inquiry;
|
||||
BOOL isDiscovering;
|
||||
// Number of found wiimotes
|
||||
int foundWiimotes;
|
||||
// Maximum number of wiimotes to be searched
|
||||
int maxWiimotes;
|
||||
// The Wiimotes structure
|
||||
wiimote** wiimotes;
|
||||
}
|
||||
|
||||
- (BOOL) isDiscovering;
|
||||
- (void) setDiscovering:(BOOL) flag;
|
||||
- (void) setWiimoteStruct:(wiimote**) wiimote_struct;
|
||||
- (int) getFoundWiimotes;
|
||||
- (IOReturn) start:(unsigned int) timeout maxWiimotes:(unsigned int) wiimotesNum;
|
||||
- (IOReturn) stop;
|
||||
- (IOReturn) close;
|
||||
- (void) retrieveWiimoteInfo:(IOBluetoothDevice*) device;
|
||||
- (void) deviceInquiryStarted:(IOBluetoothDeviceInquiry*) sender;
|
||||
- (void) deviceInquiryDeviceFound:(IOBluetoothDeviceInquiry *) sender device:(IOBluetoothDevice *) device;
|
||||
- (void) deviceInquiryComplete:(IOBluetoothDeviceInquiry*) sender error:(IOReturn) error aborted:(BOOL) aborted;
|
||||
|
||||
@end
|
||||
|
||||
@interface WiiConnect : NSObject
|
||||
{
|
||||
// Buffer to store incoming data from the Wiimote
|
||||
NSData* receivedMsg;
|
||||
unsigned int msgLength;
|
||||
|
||||
// Reference to the relative wiimote struct (used only to complete handshaking)
|
||||
wiimote* _wm;
|
||||
BOOL isReading;
|
||||
BOOL timeout;
|
||||
BOOL disconnecting;
|
||||
}
|
||||
|
||||
- (IOBluetoothL2CAPChannel *) openL2CAPChannelWithPSM:(BluetoothL2CAPPSM) psm device:(IOBluetoothDevice*) device delegate:(id) delegate;
|
||||
- (IOReturn) connectToWiimote:(wiimote*) wm;
|
||||
- (void) l2capChannelData:(IOBluetoothL2CAPChannel*) channel data:(byte *) data length:(NSUInteger) length;
|
||||
- (byte*) getNextMsg;
|
||||
- (unsigned int) getMsgLength;
|
||||
- (void) deleteMsg;
|
||||
- (void) disconnected:(IOBluetoothUserNotification*) notification fromDevice:(IOBluetoothDevice*) device;
|
||||
- (BOOL) isReading;
|
||||
- (void) setReading:(BOOL) flag;
|
||||
- (BOOL) isTimeout;
|
||||
- (void) setTimeout:(BOOL) flag;
|
||||
- (void) startTimerThread;
|
||||
- (void) wakeUpMainThreadRunloop:(id)arg;
|
||||
- (BOOL) isDisconnecting;
|
||||
@end
|
||||
|
||||
#endif /* IO_MAC_H */
|
||||
826
src/io_mac.m
826
src/io_mac.m
@@ -1,826 +0,0 @@
|
||||
/*
|
||||
* io_mac.m
|
||||
*
|
||||
* This file is based on io_mac.m from WiiC, written By:
|
||||
* Gabriele Randelli
|
||||
* Email: < randelli (--AT--) dis [--DOT--] uniroma1 [--DOT--] it >
|
||||
*
|
||||
* Copyright 2010
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O for Mac.
|
||||
*/
|
||||
#ifdef __APPLE__
|
||||
|
||||
#import "io_mac.h"
|
||||
#import "events.h"
|
||||
|
||||
@implementation WiiSearch
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark WiiSearch
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
foundWiimotes = 0;
|
||||
isDiscovering = NO;
|
||||
if (self != nil) {
|
||||
BluetoothHCIPowerState powerState;
|
||||
IOBluetoothLocalDeviceGetPowerState(&powerState);
|
||||
/*
|
||||
* Calling IOBluetoothLocalDeviceAvailable has two advantages:
|
||||
* 1. it sets up a event source in the run loop (bug for C version of the bluetooth api)
|
||||
* 2. it checks for the availability of the BT hardware
|
||||
*/
|
||||
if (![IOBluetoothHostController defaultController] ||
|
||||
powerState == kBluetoothHCIPowerStateOFF)
|
||||
{
|
||||
WIIUSE_DEBUG("Bluetooth hardware not available.");
|
||||
[self release];
|
||||
self = nil;
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
inquiry = 0;
|
||||
WIIUSE_DEBUG("Wiimote Discovery released");
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (BOOL) isDiscovering
|
||||
{
|
||||
return isDiscovering;
|
||||
}
|
||||
|
||||
- (void) setDiscovering:(BOOL) flag
|
||||
{
|
||||
isDiscovering = flag;
|
||||
}
|
||||
|
||||
- (void) setWiimoteStruct:(wiimote**) wiimote_struct
|
||||
{
|
||||
wiimotes = wiimote_struct;
|
||||
}
|
||||
|
||||
- (int) getFoundWiimotes
|
||||
{
|
||||
return foundWiimotes;
|
||||
}
|
||||
|
||||
- (IOReturn) start:(unsigned int) timeout maxWiimotes:(unsigned int) wiimotesNum
|
||||
{
|
||||
if (![IOBluetoothHostController defaultController]) {
|
||||
WIIUSE_ERROR("Unable to find any bluetooth receiver on your host.");
|
||||
return kIOReturnNotAttached;
|
||||
}
|
||||
|
||||
// If we are currently discovering, we can't start a new discovery right now.
|
||||
if ([self isDiscovering]) {
|
||||
WIIUSE_INFO("Wiimote search is already in progress...");
|
||||
return kIOReturnSuccess;
|
||||
}
|
||||
|
||||
[self close];
|
||||
maxWiimotes = wiimotesNum;
|
||||
foundWiimotes = 0;
|
||||
|
||||
inquiry = [IOBluetoothDeviceInquiry inquiryWithDelegate:self];
|
||||
// We set the search timeout
|
||||
if(timeout == 0)
|
||||
[inquiry setInquiryLength:5];
|
||||
else if(timeout < 20)
|
||||
[inquiry setInquiryLength:timeout];
|
||||
else
|
||||
[inquiry setInquiryLength:20];
|
||||
[inquiry setSearchCriteria:kBluetoothServiceClassMajorAny majorDeviceClass:WM_DEV_MAJOR_CLASS minorDeviceClass:WM_DEV_MINOR_CLASS];
|
||||
[inquiry setUpdateNewDeviceNames:NO];
|
||||
|
||||
IOReturn status = [inquiry start];
|
||||
if (status == kIOReturnSuccess) {
|
||||
[inquiry retain];
|
||||
} else {
|
||||
[self close];
|
||||
WIIUSE_ERROR("Unable to search for bluetooth devices.");
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
- (IOReturn) stop
|
||||
{
|
||||
return [inquiry stop];
|
||||
}
|
||||
|
||||
- (IOReturn) close
|
||||
{
|
||||
IOReturn ret = kIOReturnSuccess;
|
||||
|
||||
ret = [inquiry stop];
|
||||
[inquiry release];
|
||||
inquiry = nil;
|
||||
|
||||
WIIUSE_DEBUG("Discovery closed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark IOBluetoothDeviceInquiry delegates
|
||||
//*************** HANDLERS FOR WIIUSE_FIND FOR MACOSX *******************/
|
||||
- (void) retrieveWiimoteInfo:(IOBluetoothDevice*) device
|
||||
{
|
||||
// We set the device reference (we must retain it to use it after the search)
|
||||
wiimotes[foundWiimotes]->device = [[device retain] getDeviceRef];
|
||||
wiimotes[foundWiimotes]->address = (CFStringRef)[[device getAddressString] retain];
|
||||
|
||||
// C String (common for Mac and Linux)
|
||||
CFStringGetCString(wiimotes[foundWiimotes]->address,wiimotes[foundWiimotes]->bdaddr_str,18,kCFStringEncodingMacRoman);
|
||||
|
||||
WIIMOTE_ENABLE_STATE(wiimotes[foundWiimotes], WIIMOTE_STATE_DEV_FOUND);
|
||||
WIIUSE_INFO("Found Wiimote (%s) [id %i].",CFStringGetCStringPtr(wiimotes[foundWiimotes]->address, kCFStringEncodingMacRoman),wiimotes[foundWiimotes]->unid);
|
||||
++foundWiimotes;
|
||||
}
|
||||
|
||||
- (void) deviceInquiryStarted:(IOBluetoothDeviceInquiry*) sender
|
||||
{
|
||||
[self setDiscovering:YES];
|
||||
}
|
||||
|
||||
- (void) deviceInquiryDeviceFound:(IOBluetoothDeviceInquiry *) sender device:(IOBluetoothDevice *) device
|
||||
{
|
||||
if(foundWiimotes < maxWiimotes)
|
||||
[self retrieveWiimoteInfo:device];
|
||||
else
|
||||
[inquiry stop];
|
||||
}
|
||||
|
||||
- (void) deviceInquiryComplete:(IOBluetoothDeviceInquiry*) sender error:(IOReturn) error aborted:(BOOL) aborted
|
||||
{
|
||||
// The inquiry has completed, we can now process what we have found
|
||||
[self setDiscovering:NO];
|
||||
|
||||
// We stop the search because of errors
|
||||
if ((error != kIOReturnSuccess) && !aborted) {
|
||||
foundWiimotes = 0;
|
||||
[self close];
|
||||
WIIUSE_ERROR("Search not completed, because of unexpected errors. This error can be due to a short search timeout.");
|
||||
return;
|
||||
}
|
||||
|
||||
foundWiimotes = [[inquiry foundDevices] count];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation WiiConnect
|
||||
#pragma mark -
|
||||
#pragma mark WiiConnect
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
receivedMsg = [[NSData alloc] init];
|
||||
msgLength = 0;
|
||||
_wm = 0;
|
||||
isReading = NO;
|
||||
timeout = NO;
|
||||
disconnecting = NO;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
WIIUSE_DEBUG("Wiimote released");
|
||||
if(receivedMsg)
|
||||
[receivedMsg release];
|
||||
receivedMsg = 0;
|
||||
_wm = 0;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (byte*) getNextMsg
|
||||
{
|
||||
if(!receivedMsg)
|
||||
return 0;
|
||||
|
||||
return (byte*)[receivedMsg bytes];
|
||||
}
|
||||
|
||||
- (void) deleteMsg
|
||||
{
|
||||
if(receivedMsg) {
|
||||
[receivedMsg release];
|
||||
msgLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) isDisconnecting
|
||||
{
|
||||
return disconnecting;
|
||||
}
|
||||
|
||||
- (BOOL) isReading
|
||||
{
|
||||
return isReading;
|
||||
}
|
||||
|
||||
- (void) setReading:(BOOL) flag
|
||||
{
|
||||
isReading = flag;
|
||||
}
|
||||
|
||||
- (BOOL) isTimeout
|
||||
{
|
||||
return timeout;
|
||||
}
|
||||
|
||||
- (void) setTimeout:(BOOL) flag
|
||||
{
|
||||
timeout = flag;
|
||||
}
|
||||
|
||||
- (void) startTimerThread
|
||||
{
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// Timer
|
||||
sleep(1);
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
- (void) wakeUpMainThreadRunloop:(id)arg
|
||||
{
|
||||
// This method is executed on main thread!
|
||||
// It doesn't need to do anything actually, just having it run will
|
||||
// make sure the main thread stops running the runloop
|
||||
}
|
||||
|
||||
|
||||
- (IOBluetoothL2CAPChannel*) openL2CAPChannelWithPSM:(BluetoothL2CAPPSM) psm device:(IOBluetoothDevice*) device delegate:(id) delegate
|
||||
{
|
||||
IOBluetoothL2CAPChannel* channel = nil;
|
||||
|
||||
if ([device openL2CAPChannelSync:&channel withPSM:psm delegate:delegate] != kIOReturnSuccess)
|
||||
channel = nil;
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
- (IOReturn) connectToWiimote:(wiimote*) wm
|
||||
{
|
||||
IOBluetoothDevice* device = [IOBluetoothDevice withDeviceRef:wm->device];
|
||||
IOBluetoothL2CAPChannel* outCh = nil;
|
||||
IOBluetoothL2CAPChannel* inCh = nil;
|
||||
|
||||
if(!device) {
|
||||
WIIUSE_ERROR("Non existent device or already connected.");
|
||||
return kIOReturnBadArgument;
|
||||
}
|
||||
|
||||
outCh = [self openL2CAPChannelWithPSM:WM_OUTPUT_CHANNEL device:device delegate:self];
|
||||
if (!outCh) {
|
||||
WIIUSE_ERROR("Unable to open L2CAP output channel (id %i).", wm->unid);
|
||||
[device closeConnection];
|
||||
return kIOReturnNotOpen;
|
||||
}
|
||||
wm->outputCh = [[outCh retain] getL2CAPChannelRef];
|
||||
usleep(20000);
|
||||
|
||||
inCh = [self openL2CAPChannelWithPSM:WM_INPUT_CHANNEL device:device delegate:self];
|
||||
if (!inCh) {
|
||||
WIIUSE_ERROR("Unable to open L2CAP input channel (id %i).", wm->unid);
|
||||
[device closeConnection];
|
||||
return kIOReturnNotOpen;
|
||||
}
|
||||
wm->inputCh = [[inCh retain] getL2CAPChannelRef];
|
||||
usleep(20000);
|
||||
|
||||
IOBluetoothUserNotification* disconnectNotification = [device registerForDisconnectNotification:self selector:@selector(disconnected:fromDevice:)];
|
||||
if(!disconnectNotification) {
|
||||
WIIUSE_ERROR("Unable to register disconnection handler (id %i).", wm->unid);
|
||||
[device closeConnection];
|
||||
return kIOReturnNotOpen;
|
||||
}
|
||||
|
||||
// We store the reference to its relative structure (Used for completing the handshake step)
|
||||
_wm = wm;
|
||||
|
||||
return kIOReturnSuccess;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark IOBluetoothL2CAPChannel delegates
|
||||
- (void) disconnected:(IOBluetoothUserNotification*) notification fromDevice:(IOBluetoothDevice*) device
|
||||
{
|
||||
[self deleteMsg];
|
||||
[self setReading:NO];
|
||||
disconnecting = YES;
|
||||
|
||||
// The wiimote_t struct must be re-initialized due to the disconnection
|
||||
wiiuse_disconnected(_wm) ;
|
||||
}
|
||||
|
||||
//*************** HANDLERS FOR WIIUSE_IO_READ FOR MACOSX *******************/
|
||||
- (void) l2capChannelData:(IOBluetoothL2CAPChannel*) channel data:(byte *) data length:(NSUInteger) length
|
||||
{
|
||||
// This is done in case the output channel woke up this handler
|
||||
if(!data) {
|
||||
[self setReading:NO];
|
||||
length = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called if we are receiving data before completing
|
||||
* the handshaking, hence before calling wiiuse_poll
|
||||
*/
|
||||
if(WIIMOTE_IS_SET(_wm, WIIMOTE_STATE_HANDSHAKE))
|
||||
propagate_event(_wm, data[1], data+2);
|
||||
|
||||
receivedMsg = [[NSData dataWithBytes:data length:length] retain];
|
||||
msgLength = length;
|
||||
|
||||
// This is done when a message is successfully received. Stop the main loop after reading
|
||||
[self setReading:NO];
|
||||
}
|
||||
|
||||
- (unsigned int) getMsgLength
|
||||
{
|
||||
return msgLength;
|
||||
}
|
||||
|
||||
- (void) l2capChannelReconfigured:(IOBluetoothL2CAPChannel*) l2capChannel
|
||||
{
|
||||
//NSLog(@"l2capChannelReconfigured");
|
||||
}
|
||||
|
||||
- (void) l2capChannelWriteComplete:(IOBluetoothL2CAPChannel*) l2capChannel refcon:(void*) refcon status:(IOReturn) error
|
||||
{
|
||||
//NSLog(@"l2capChannelWriteComplete");
|
||||
}
|
||||
|
||||
- (void) l2capChannelQueueSpaceAvailable:(IOBluetoothL2CAPChannel*) l2capChannel
|
||||
{
|
||||
//NSLog(@"l2capChannelQueueSpaceAvailable");
|
||||
}
|
||||
|
||||
- (void) l2capChannelOpenComplete:(IOBluetoothL2CAPChannel*) l2capChannel status:(IOReturn) error
|
||||
{
|
||||
//NSLog(@"l2capChannelOpenComplete (PSM:0x%x)", [l2capChannel getPSM]);
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Wiiuse
|
||||
/**
|
||||
* @brief Find a wiimote or wiimotes.
|
||||
*
|
||||
* @param wm An array of wiimote_t structures.
|
||||
* @param max_wiimotes The number of wiimote structures in \a wm.
|
||||
* @param timeout The number of seconds before the search times out.
|
||||
*
|
||||
* @return The number of wiimotes found.
|
||||
*
|
||||
* @see wiimote_connect()
|
||||
*
|
||||
* This function will only look for wiimote devices. \n
|
||||
* When a device is found the address in the structures will be set. \n
|
||||
* You can then call wiimote_connect() to connect to the found \n
|
||||
* devices.
|
||||
*
|
||||
* This function is defined in wiiuse.h
|
||||
*/
|
||||
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout)
|
||||
{
|
||||
int found_wiimotes = 0;
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
WiiSearch* search = [[WiiSearch alloc] init];
|
||||
[search setWiimoteStruct:wm];
|
||||
|
||||
if(timeout) { // Single search
|
||||
[search start:timeout maxWiimotes:max_wiimotes];
|
||||
|
||||
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
|
||||
while ([search isDiscovering] && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
|
||||
|
||||
found_wiimotes = [search getFoundWiimotes];
|
||||
}
|
||||
else { // Unlimited search
|
||||
found_wiimotes = 0;
|
||||
while(!found_wiimotes) {
|
||||
[search start:timeout maxWiimotes:max_wiimotes];
|
||||
|
||||
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
|
||||
while ([search isDiscovering] && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
|
||||
|
||||
found_wiimotes = [search getFoundWiimotes];
|
||||
}
|
||||
}
|
||||
|
||||
WIIUSE_INFO("Found %i Wiimote device(s).", found_wiimotes);
|
||||
|
||||
[search release];
|
||||
[pool drain];
|
||||
|
||||
return found_wiimotes;
|
||||
}
|
||||
|
||||
|
||||
//*************** HANDLERS FOR WIIUSE_DISCONNECT FOR MACOSX *******************/
|
||||
/**
|
||||
* @brief Disconnect a wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* @see wiic_connect()
|
||||
*
|
||||
* Note that this will not free the wiimote structure.
|
||||
*
|
||||
* This function is defined in wiiuse.h
|
||||
*/
|
||||
void wiiuse_disconnect(struct wiimote_t* wm)
|
||||
{
|
||||
IOReturn error;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return;
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// Input Channel
|
||||
if(wm->inputCh) {
|
||||
IOBluetoothL2CAPChannel* inCh = [IOBluetoothL2CAPChannel withL2CAPChannelRef:wm->inputCh];
|
||||
error = [inCh closeChannel];
|
||||
[inCh setDelegate:nil];
|
||||
if(error != kIOReturnSuccess)
|
||||
WIIUSE_ERROR("Unable to close input channel (id %i).", wm->unid);
|
||||
usleep(10000);
|
||||
[inCh release];
|
||||
inCh = nil;
|
||||
wm->inputCh = 0;
|
||||
}
|
||||
|
||||
// Output Channel
|
||||
if(wm->outputCh) {
|
||||
IOBluetoothL2CAPChannel* outCh = [IOBluetoothL2CAPChannel withL2CAPChannelRef:wm->outputCh];
|
||||
error = [outCh closeChannel];
|
||||
[outCh setDelegate:nil];
|
||||
if(error != kIOReturnSuccess)
|
||||
WIIUSE_ERROR("Unable to close output channel (id %i).", wm->unid);
|
||||
usleep(10000);
|
||||
[outCh release];
|
||||
outCh = nil;
|
||||
wm->outputCh = 0;
|
||||
}
|
||||
|
||||
// Device
|
||||
if(wm->device) {
|
||||
IOBluetoothDevice* device = [IOBluetoothDevice withDeviceRef:wm->device];
|
||||
error = [device closeConnection];
|
||||
|
||||
if(error != kIOReturnSuccess)
|
||||
WIIUSE_ERROR("Unable to close the device connection (id %i).", wm->unid);
|
||||
usleep(10000);
|
||||
[device release];
|
||||
device = nil;
|
||||
wm->device = 0;
|
||||
}
|
||||
|
||||
[pool drain];
|
||||
|
||||
wm->event = WIIUSE_NONE;
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Connect to a wiimote with a known address.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param address The address of the device to connect to.
|
||||
* If NULL, use the address in the struct set by wiic_find().
|
||||
*
|
||||
* @return 1 on success, 0 on failure
|
||||
* This function is defined in io_mac.h
|
||||
*/
|
||||
static int wiiuse_connect_single(struct wiimote_t* wm, char* address)
|
||||
{
|
||||
// Skip if already connected or device not found
|
||||
if(!wm || WIIMOTE_IS_CONNECTED(wm) || wm->device == 0) {
|
||||
WIIUSE_ERROR("Non existent device or already connected.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Convert the IP address
|
||||
// FIXME - see if it is possible
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
WiiConnect* connect = [[[WiiConnect alloc] init] autorelease];
|
||||
if([connect connectToWiimote:wm] == kIOReturnSuccess) {
|
||||
WIIUSE_INFO("Connected to wiimote [id %i].", wm->unid);
|
||||
// This is stored to retrieve incoming data
|
||||
wm->connectionHandler = (void*)([connect retain]);
|
||||
|
||||
// Do the handshake
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
wiiuse_handshake(wm, NULL, 0);
|
||||
wiiuse_set_report_type(wm);
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
else {
|
||||
[pool drain];
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Connect to a wiimote or wiimotes once an address is known.
|
||||
*
|
||||
* @param wm An array of wiimote_t structures.
|
||||
* @param wiimotes The number of wiimote structures in \a wm.
|
||||
*
|
||||
* @return The number of wiimotes that successfully connected.
|
||||
*
|
||||
* @see wiic_find()
|
||||
* @see wiic_connect_single()
|
||||
* @see wiic_disconnect()
|
||||
*
|
||||
* Connect to a number of wiimotes when the address is already set
|
||||
* in the wiimote_t structures. These addresses are normally set
|
||||
* by the wiic_find() function, but can also be set manually.
|
||||
* This function is defined in wiiuse.h
|
||||
*/
|
||||
int wiiuse_connect(struct wiimote_t** wm, int wiimotes)
|
||||
{
|
||||
int connected = 0;
|
||||
int i = 0;
|
||||
|
||||
for (; i < wiimotes; ++i) {
|
||||
if(!(wm[i])) {
|
||||
WIIUSE_ERROR("Trying to connect more Wiimotes than initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND))
|
||||
// If the device address is not set, skip it
|
||||
continue;
|
||||
|
||||
if (wiiuse_connect_single(wm[i], NULL))
|
||||
++connected;
|
||||
}
|
||||
|
||||
return connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Load Wii devices registered in the wiimotes.config file.
|
||||
*
|
||||
* @param wm An array of wiimote_t structures.
|
||||
*
|
||||
* @return The number of wiimotes successfully loaded.
|
||||
*
|
||||
* @see wiic_find()
|
||||
* @see wiic_connect()
|
||||
* @see wiic_connect_single()
|
||||
* @see wiic_disconnect()
|
||||
*
|
||||
* From version 0.53, it is possible to register the MAC address of your
|
||||
* Wii devices. This allows to automatically load them, without waiting for any
|
||||
* search timeout. To register a new device, go to: <HOME_DIR>/.wiic/ and
|
||||
* edit the file wiimotes.config, by adding the MAC address of the device
|
||||
* you want to register (one line per MAC address).
|
||||
* This function seems useful but it's not implemented in wiiuse
|
||||
* TODO: Erase or implement elsewhere
|
||||
*/
|
||||
int wiiuse_load(struct wiimote_t** wm)
|
||||
{
|
||||
int loaded = 0;
|
||||
int i = 0;
|
||||
char str[200];
|
||||
char configPath[100];
|
||||
char* tmp = 0;
|
||||
|
||||
// Retrieve the HOME environment variable
|
||||
tmp = getenv("HOME");
|
||||
strcpy(configPath,tmp);
|
||||
strncat(configPath,"/.wiic/wiimotes.config",22);
|
||||
|
||||
// Open the config file
|
||||
FILE* fd = 0;
|
||||
fd = fopen(configPath,"r");
|
||||
if(!fd)
|
||||
return loaded;
|
||||
|
||||
// Read line by line
|
||||
while(fgets(str,sizeof(str),fd) != NULL && loaded < 1) {
|
||||
int len = strlen(str)-1;
|
||||
if(str[len] == '\n')
|
||||
str[len] = 0;
|
||||
loaded++;
|
||||
}
|
||||
|
||||
// We initialize the device structure
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
for (; i < loaded; ++i) {
|
||||
NSString* string = [NSString stringWithCString:str encoding:[NSString defaultCStringEncoding]];
|
||||
BluetoothDeviceAddress deviceAddr;
|
||||
IOBluetoothNSStringToDeviceAddress(string, &deviceAddr);
|
||||
IOBluetoothDevice* device = [IOBluetoothDevice withAddress:&deviceAddr];
|
||||
wm[i]->device = [[device retain] getDeviceRef];
|
||||
wm[i]->address = (CFStringRef)[[device getAddressString] retain];
|
||||
WIIMOTE_ENABLE_STATE(wm[i], WIIMOTE_STATE_DEV_FOUND);
|
||||
WIIUSE_INFO("Loaded Wiimote (%s) [id %i].",CFStringGetCStringPtr(wm[i]->address, kCFStringEncodingMacRoman),wm[i]->unid);
|
||||
}
|
||||
[pool drain];
|
||||
|
||||
return loaded;
|
||||
}
|
||||
|
||||
// Defined in io.h
|
||||
int wiiuse_io_read(struct wiimote_t* wm)
|
||||
{
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
|
||||
return 0;
|
||||
|
||||
/* If this wiimote is not connected, skip it */
|
||||
if (!WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
WiiConnect* deviceHandler = 0;
|
||||
deviceHandler = (WiiConnect*)(wm->connectionHandler);
|
||||
|
||||
/* If this wiimote is disconnecting, skip it */
|
||||
if (!deviceHandler || [deviceHandler isDisconnecting]) {
|
||||
[pool drain];
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Run the main loop to get bt data
|
||||
[deviceHandler setReading:YES];
|
||||
[deviceHandler setTimeout:NO];
|
||||
|
||||
// We start the thread which manages the timeout to implement a non-blocking read
|
||||
[NSThread detachNewThreadSelector:@selector(startTimerThread) toTarget:deviceHandler withObject:nil];
|
||||
|
||||
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
|
||||
// Two possible events: we receive and incoming message or there is a timeout
|
||||
while([deviceHandler isReading] && ![deviceHandler isTimeout]) {
|
||||
NSAutoreleasePool *pool_loop = [[NSAutoreleasePool alloc] init]; // This is used for fast release of NSDate, otherwise it leaks
|
||||
[theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
|
||||
[pool_loop drain];
|
||||
}
|
||||
|
||||
// In this case we have no incoming data (TIMEOUT)
|
||||
if([deviceHandler isTimeout]) {
|
||||
[pool drain];
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!(wm->connectionHandler)) {
|
||||
WIIUSE_ERROR("Unable to find the connection handler (id %i).", wm->unid);
|
||||
[pool drain];
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Read next message
|
||||
byte* buffer = 0;
|
||||
unsigned int length = 0;
|
||||
if(![deviceHandler isDisconnecting]) {
|
||||
buffer = [deviceHandler getNextMsg];
|
||||
length = [deviceHandler getMsgLength];
|
||||
}
|
||||
|
||||
if(!buffer || !length) {
|
||||
[pool drain];
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Forward to WiiC
|
||||
if(length < sizeof(wm->event_buf))
|
||||
memcpy(wm->event_buf,buffer,length);
|
||||
else {
|
||||
WIIUSE_DEBUG("Received data are more than the buffer.... strange! (id %i)", wm->unid);
|
||||
memcpy(wm->event_buf,buffer,sizeof(wm->event_buf));
|
||||
}
|
||||
|
||||
// Release the consumed message
|
||||
[deviceHandler deleteMsg];
|
||||
|
||||
[pool drain];
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Defined in io.h
|
||||
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len)
|
||||
{
|
||||
unsigned int length = (unsigned int)len;
|
||||
|
||||
// Small check before writing
|
||||
if(!wm || !(wm->outputCh)) {
|
||||
WIIUSE_ERROR("Attempt to write over non-existent channel (id %i).", wm->unid);
|
||||
perror("Error Details");
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
IOBluetoothL2CAPChannel* channel = [IOBluetoothL2CAPChannel withL2CAPChannelRef:wm->outputCh];
|
||||
IOReturn error = [channel writeSync:buf length:length];
|
||||
|
||||
if (error != kIOReturnSuccess)
|
||||
{
|
||||
WIIUSE_ERROR("Unable to write over the output channel (id %i).", wm->unid);
|
||||
WIIUSE_INFO("Attempting to reopen the output channel (id %i).", wm->unid);
|
||||
|
||||
IOReturn error = [channel closeChannel];
|
||||
if (error != kIOReturnSuccess)
|
||||
WIIUSE_ERROR("Unable to close the output channel (id %i).", wm->unid);
|
||||
[channel setDelegate:nil];
|
||||
usleep(10000);
|
||||
[channel release];
|
||||
wm->outputCh = 0;
|
||||
|
||||
WiiConnect* connect = (WiiConnect*)(wm->connectionHandler);
|
||||
|
||||
IOBluetoothDevice* device = [IOBluetoothDevice withDeviceRef:wm->device];
|
||||
channel = [connect openL2CAPChannelWithPSM:WM_OUTPUT_CHANNEL device:device delegate:connect];
|
||||
if (!channel) {
|
||||
WIIUSE_ERROR("Unable to open L2CAP output channel (id %i).", wm->unid);
|
||||
[device closeConnection];
|
||||
return kIOReturnNotOpen;
|
||||
}
|
||||
wm->outputCh = [[channel retain] getL2CAPChannelRef];
|
||||
usleep(20000);
|
||||
|
||||
WIIUSE_INFO("Attempting to write again through the output channel (id %i).", wm->unid);
|
||||
error = [channel writeSync:buf length:length];
|
||||
if (error != kIOReturnSuccess)
|
||||
{
|
||||
WIIUSE_ERROR("Unable to write again over the output channel (id %i).", wm->unid);
|
||||
}
|
||||
}
|
||||
|
||||
usleep(10000);
|
||||
|
||||
[pool drain];
|
||||
|
||||
return (error == kIOReturnSuccess ? len : 0);
|
||||
}
|
||||
|
||||
void wiiuse_init_platform_fields(struct wiimote_t* wm)
|
||||
{
|
||||
wm->device = nil;
|
||||
wm->address = nil;
|
||||
wm->inputCh = nil;
|
||||
wm->outputCh = 0;
|
||||
wm->disconnectionRef = nil;
|
||||
wm->connectionHandler = NULL;
|
||||
memset (wm->bdaddr_str,'\0',18);
|
||||
}
|
||||
|
||||
void wiiuse_cleanup_platform_fields(struct wiimote_t* wm)
|
||||
{
|
||||
/* TODO isn't this already done in wiiuse_disconnect ? */
|
||||
wm->device = nil;
|
||||
wm->address = nil;
|
||||
wm->inputCh = nil;
|
||||
wm->outputCh = 0;
|
||||
wm->disconnectionRef = nil;
|
||||
wm->connectionHandler = NULL;
|
||||
memset (wm->bdaddr_str,'\0',18);
|
||||
}
|
||||
|
||||
#endif
|
||||
389
src/ir.c
389
src/ir.c
@@ -57,16 +57,22 @@ static const byte WM_IR_BLOCK2_LEVEL4[] = "\x35\x03";
|
||||
static const byte WM_IR_BLOCK1_LEVEL5[] = "\x07\x00\x00\x71\x01\x00\x72\x00\x20";
|
||||
static const byte WM_IR_BLOCK2_LEVEL5[] = "\x1f\x03";
|
||||
|
||||
void wiiuse_set_ir_mode(struct wiimote_t *wm)
|
||||
{
|
||||
void wiiuse_set_ir_mode(struct wiimote_t *wm) {
|
||||
byte buf = 0x00;
|
||||
|
||||
if(!wm) return;
|
||||
if(!WIIMOTE_IS_SET(wm,WIIMOTE_STATE_IR)) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP)) buf = WM_IR_TYPE_BASIC;
|
||||
else buf = WM_IR_TYPE_EXTENDED;
|
||||
wiiuse_write_data(wm,WM_REG_IR_MODENUM, &buf, 1);
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||
buf = WM_IR_TYPE_BASIC;
|
||||
} else {
|
||||
buf = WM_IR_TYPE_EXTENDED;
|
||||
}
|
||||
wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1);
|
||||
}
|
||||
/**
|
||||
* @brief Set if the wiimote should track IR targets.
|
||||
@@ -80,8 +86,9 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
|
||||
const byte* block2 = NULL;
|
||||
int ir_level;
|
||||
|
||||
if (!wm)
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for the handshake to finish first.
|
||||
@@ -90,7 +97,7 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
|
||||
* again to actually enable IR.
|
||||
*/
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE)) {
|
||||
if(status) {
|
||||
if (status) {
|
||||
WIIUSE_DEBUG("Tried to enable IR, will wait until handshake finishes.");
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
} /* else ignoring request to turn off, since it's turned off by default */
|
||||
@@ -108,13 +115,15 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
|
||||
|
||||
if (status) {
|
||||
/* if already enabled then stop */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
return;
|
||||
}
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
} else {
|
||||
/* if already disabled then stop */
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
return;
|
||||
}
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
}
|
||||
|
||||
@@ -141,10 +150,11 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (byte*)block2, 2);
|
||||
|
||||
/* set the IR mode */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||
buf = WM_IR_TYPE_BASIC;
|
||||
else
|
||||
} else {
|
||||
buf = WM_IR_TYPE_EXTENDED;
|
||||
}
|
||||
wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1);
|
||||
|
||||
wiiuse_millisleep(50);
|
||||
@@ -201,10 +211,12 @@ static int get_ir_sens(struct wiimote_t* wm, const byte** block1, const byte** b
|
||||
* @param status 1 to enable, 0 to disable.
|
||||
*/
|
||||
void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y) {
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
wm->ir.vres[0] = (x-1);
|
||||
wm->ir.vres[1] = (y-1);
|
||||
wm->ir.vres[0] = (x - 1);
|
||||
wm->ir.vres[1] = (y - 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +226,9 @@ void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y) {
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) {
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
wm->ir.pos = pos;
|
||||
|
||||
@@ -223,20 +237,22 @@ void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) {
|
||||
case WIIUSE_IR_ABOVE:
|
||||
wm->ir.offset[0] = 0;
|
||||
|
||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9)
|
||||
wm->ir.offset[1] = WM_ASPECT_16_9_Y/2 - 70;
|
||||
else if (wm->ir.aspect == WIIUSE_ASPECT_4_3)
|
||||
wm->ir.offset[1] = WM_ASPECT_4_3_Y/2 - 100;
|
||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9) {
|
||||
wm->ir.offset[1] = WM_ASPECT_16_9_Y / 2 - 70;
|
||||
} else if (wm->ir.aspect == WIIUSE_ASPECT_4_3) {
|
||||
wm->ir.offset[1] = WM_ASPECT_4_3_Y / 2 - 100;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
case WIIUSE_IR_BELOW:
|
||||
wm->ir.offset[0] = 0;
|
||||
|
||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9)
|
||||
wm->ir.offset[1] = -WM_ASPECT_16_9_Y/2 + 100;
|
||||
else if (wm->ir.aspect == WIIUSE_ASPECT_4_3)
|
||||
wm->ir.offset[1] = -WM_ASPECT_4_3_Y/2 + 70;
|
||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9) {
|
||||
wm->ir.offset[1] = -WM_ASPECT_16_9_Y / 2 + 100;
|
||||
} else if (wm->ir.aspect == WIIUSE_ASPECT_4_3) {
|
||||
wm->ir.offset[1] = -WM_ASPECT_4_3_Y / 2 + 70;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -253,7 +269,9 @@ void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) {
|
||||
* @param aspect Either WIIUSE_ASPECT_16_9 or WIIUSE_ASPECT_4_3
|
||||
*/
|
||||
void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect) {
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
wm->ir.aspect = aspect;
|
||||
|
||||
@@ -283,16 +301,22 @@ void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level) {
|
||||
const byte* block1 = NULL;
|
||||
const byte* block2 = NULL;
|
||||
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (level > 5) level = 5;
|
||||
if (level < 1) level = 1;
|
||||
if (level > 5) {
|
||||
level = 5;
|
||||
}
|
||||
if (level < 1) {
|
||||
level = 1;
|
||||
}
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, (WIIMOTE_STATE_IR_SENS_LVL1 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL2 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL3 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL4 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL5));
|
||||
WIIMOTE_STATE_IR_SENS_LVL2 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL3 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL4 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL5));
|
||||
|
||||
switch (level) {
|
||||
case 1:
|
||||
@@ -348,9 +372,9 @@ void calculate_basic_ir(struct wiimote_t* wm, byte* data) {
|
||||
|
||||
/* set each IR spot to visible if spot is in range */
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].ry == 1023)
|
||||
if (dot[i].ry == 1023) {
|
||||
dot[i].visible = 0;
|
||||
else {
|
||||
} else {
|
||||
dot[i].visible = 1;
|
||||
dot[i].size = 0; /* since we don't know the size, set it as 0 */
|
||||
}
|
||||
@@ -371,16 +395,17 @@ void calculate_extended_ir(struct wiimote_t* wm, byte* data) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
dot[i].rx = 1023 - (data[3*i] | ((data[(3*i)+2] & 0x30) << 4));
|
||||
dot[i].ry = data[(3*i)+1] | ((data[(3*i)+2] & 0xC0) << 2);
|
||||
dot[i].rx = 1023 - (data[3 * i] | ((data[(3 * i) + 2] & 0x30) << 4));
|
||||
dot[i].ry = data[(3 * i) + 1] | ((data[(3 * i) + 2] & 0xC0) << 2);
|
||||
|
||||
dot[i].size = data[(3*i)+2] & 0x0F;
|
||||
dot[i].size = data[(3 * i) + 2] & 0x0F;
|
||||
|
||||
/* if in range set to visible */
|
||||
if (dot[i].ry == 1023)
|
||||
if (dot[i].ry == 1023) {
|
||||
dot[i].visible = 0;
|
||||
else
|
||||
} else {
|
||||
dot[i].visible = 1;
|
||||
}
|
||||
}
|
||||
|
||||
interpret_ir_data(wm);
|
||||
@@ -398,147 +423,150 @@ static void interpret_ir_data(struct wiimote_t* wm) {
|
||||
float roll = 0.0f;
|
||||
int last_num_dots = wm->ir.num_dots;
|
||||
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC))
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC)) {
|
||||
roll = wm->orient.roll;
|
||||
}
|
||||
|
||||
/* count visible dots */
|
||||
wm->ir.num_dots = 0;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].visible)
|
||||
if (dot[i].visible) {
|
||||
wm->ir.num_dots++;
|
||||
}
|
||||
}
|
||||
|
||||
switch (wm->ir.num_dots) {
|
||||
case 0:
|
||||
{
|
||||
wm->ir.state = 0;
|
||||
case 0: {
|
||||
wm->ir.state = 0;
|
||||
|
||||
/* reset the dot ordering */
|
||||
for (i = 0; i < 4; ++i)
|
||||
dot[i].order = 0;
|
||||
|
||||
wm->ir.x = 0;
|
||||
wm->ir.y = 0;
|
||||
wm->ir.z = 0.0f;
|
||||
|
||||
return;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
fix_rotated_ir_dots(wm->ir.dot, roll);
|
||||
|
||||
if (wm->ir.state < 2) {
|
||||
/*
|
||||
* Only 1 known dot, so use just that.
|
||||
*/
|
||||
/* reset the dot ordering */
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].visible) {
|
||||
wm->ir.x = dot[i].x;
|
||||
wm->ir.y = dot[i].y;
|
||||
|
||||
wm->ir.ax = wm->ir.x;
|
||||
wm->ir.ay = wm->ir.y;
|
||||
|
||||
/* can't calculate yaw because we don't have the distance */
|
||||
/* wm->orient.yaw = calc_yaw(&wm->ir); */
|
||||
|
||||
ir_convert_to_vres(&wm->ir.x, &wm->ir.y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
break;
|
||||
}
|
||||
dot[i].order = 0;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Only see 1 dot but know theres 2.
|
||||
* Try to estimate where the other one
|
||||
* should be and use that.
|
||||
*/
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].visible) {
|
||||
int ox = 0;
|
||||
int x, y;
|
||||
|
||||
if (dot[i].order == 1)
|
||||
/* visible is the left dot - estimate where the right is */
|
||||
ox = (int32_t)(dot[i].x + wm->ir.distance);
|
||||
else if (dot[i].order == 2)
|
||||
/* visible is the right dot - estimate where the left is */
|
||||
ox = (int32_t)(dot[i].x - wm->ir.distance);
|
||||
|
||||
x = ((signed int)dot[i].x + ox) / 2;
|
||||
y = dot[i].y;
|
||||
|
||||
wm->ir.ax = x;
|
||||
wm->ir.ay = y;
|
||||
wm->orient.yaw = calc_yaw(&wm->ir);
|
||||
|
||||
if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) {
|
||||
ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
wm->ir.x = x;
|
||||
wm->ir.y = y;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
{
|
||||
/*
|
||||
* Two (or more) dots known and seen.
|
||||
* Average them together to estimate the true location.
|
||||
*/
|
||||
int x, y;
|
||||
wm->ir.state = 2;
|
||||
|
||||
fix_rotated_ir_dots(wm->ir.dot, roll);
|
||||
|
||||
/* if there is at least 1 new dot, reorder them all */
|
||||
if (wm->ir.num_dots > last_num_dots) {
|
||||
reorder_ir_dots(dot);
|
||||
wm->ir.x = 0;
|
||||
wm->ir.y = 0;
|
||||
wm->ir.z = 0.0f;
|
||||
|
||||
return;
|
||||
}
|
||||
case 1: {
|
||||
fix_rotated_ir_dots(wm->ir.dot, roll);
|
||||
|
||||
wm->ir.distance = ir_distance(dot);
|
||||
wm->ir.z = 1023 - wm->ir.distance;
|
||||
if (wm->ir.state < 2) {
|
||||
/*
|
||||
* Only 1 known dot, so use just that.
|
||||
*/
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].visible) {
|
||||
wm->ir.x = dot[i].x;
|
||||
wm->ir.y = dot[i].y;
|
||||
|
||||
get_ir_dot_avg(wm->ir.dot, &x, &y);
|
||||
wm->ir.ax = wm->ir.x;
|
||||
wm->ir.ay = wm->ir.y;
|
||||
|
||||
wm->ir.ax = x;
|
||||
wm->ir.ay = y;
|
||||
wm->orient.yaw = calc_yaw(&wm->ir);
|
||||
/* can't calculate yaw because we don't have the distance */
|
||||
/* wm->orient.yaw = calc_yaw(&wm->ir); */
|
||||
|
||||
if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) {
|
||||
ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
wm->ir.x = x;
|
||||
wm->ir.y = y;
|
||||
ir_convert_to_vres(&wm->ir.x, &wm->ir.y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Only see 1 dot but know theres 2.
|
||||
* Try to estimate where the other one
|
||||
* should be and use that.
|
||||
*/
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].visible) {
|
||||
int ox = 0;
|
||||
int x, y;
|
||||
|
||||
if (dot[i].order == 1)
|
||||
/* visible is the left dot - estimate where the right is */
|
||||
{
|
||||
ox = (int32_t)(dot[i].x + wm->ir.distance);
|
||||
} else if (dot[i].order == 2)
|
||||
/* visible is the right dot - estimate where the left is */
|
||||
{
|
||||
ox = (int32_t)(dot[i].x - wm->ir.distance);
|
||||
}
|
||||
|
||||
x = ((signed int)dot[i].x + ox) / 2;
|
||||
y = dot[i].y;
|
||||
|
||||
wm->ir.ax = x;
|
||||
wm->ir.ay = y;
|
||||
wm->orient.yaw = calc_yaw(&wm->ir);
|
||||
|
||||
if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) {
|
||||
ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
wm->ir.x = x;
|
||||
wm->ir.y = y;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
case 4: {
|
||||
/*
|
||||
* Two (or more) dots known and seen.
|
||||
* Average them together to estimate the true location.
|
||||
*/
|
||||
int x, y;
|
||||
wm->ir.state = 2;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
fix_rotated_ir_dots(wm->ir.dot, roll);
|
||||
|
||||
/* if there is at least 1 new dot, reorder them all */
|
||||
if (wm->ir.num_dots > last_num_dots) {
|
||||
reorder_ir_dots(dot);
|
||||
wm->ir.x = 0;
|
||||
wm->ir.y = 0;
|
||||
}
|
||||
|
||||
wm->ir.distance = ir_distance(dot);
|
||||
wm->ir.z = 1023 - wm->ir.distance;
|
||||
|
||||
get_ir_dot_avg(wm->ir.dot, &x, &y);
|
||||
|
||||
wm->ir.ax = x;
|
||||
wm->ir.ay = y;
|
||||
wm->orient.yaw = calc_yaw(&wm->ir);
|
||||
|
||||
if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) {
|
||||
ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
wm->ir.x = x;
|
||||
wm->ir.y = y;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
int ir_level;
|
||||
WIIUSE_GET_IR_SENSITIVITY(wm, &ir_level);
|
||||
WIIUSE_DEBUG("IR sensitivity: %i", ir_level);
|
||||
WIIUSE_DEBUG("IR visible dots: %i", wm->ir.num_dots);
|
||||
for (i = 0; i < 4; ++i)
|
||||
if (dot[i].visible)
|
||||
WIIUSE_DEBUG("IR[%i][order %i] (%.3i, %.3i) -> (%.3i, %.3i)", i, dot[i].order, dot[i].rx, dot[i].ry, dot[i].x, dot[i].y);
|
||||
WIIUSE_DEBUG("IR[absolute]: (%i, %i)", wm->ir.x, wm->ir.y);
|
||||
int ir_level;
|
||||
WIIUSE_GET_IR_SENSITIVITY(wm, &ir_level);
|
||||
WIIUSE_DEBUG("IR sensitivity: %i", ir_level);
|
||||
WIIUSE_DEBUG("IR visible dots: %i", wm->ir.num_dots);
|
||||
for (i = 0; i < 4; ++i)
|
||||
if (dot[i].visible) {
|
||||
WIIUSE_DEBUG("IR[%i][order %i] (%.3i, %.3i) -> (%.3i, %.3i)", i, dot[i].order, dot[i].rx, dot[i].ry, dot[i].x, dot[i].y);
|
||||
}
|
||||
WIIUSE_DEBUG("IR[absolute]: (%i, %i)", wm->ir.x, wm->ir.y);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -579,17 +607,18 @@ static void fix_rotated_ir_dots(struct ir_dot_t* dot, float ang) {
|
||||
*/
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (!dot[i].visible)
|
||||
if (!dot[i].visible) {
|
||||
continue;
|
||||
}
|
||||
|
||||
x = dot[i].rx - (1024/2);
|
||||
y = dot[i].ry - (768/2);
|
||||
x = dot[i].rx - (1024 / 2);
|
||||
y = dot[i].ry - (768 / 2);
|
||||
|
||||
dot[i].x = (uint32_t)((c * x) + (-s * y));
|
||||
dot[i].y = (uint32_t)((s * x) + (c * y));
|
||||
|
||||
dot[i].x += (1024/2);
|
||||
dot[i].y += (768/2);
|
||||
dot[i].x += (1024 / 2);
|
||||
dot[i].y += (768 / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,19 +658,22 @@ static void reorder_ir_dots(struct ir_dot_t* dot) {
|
||||
int i, j, order;
|
||||
|
||||
/* reset the dot ordering */
|
||||
for (i = 0; i < 4; ++i)
|
||||
for (i = 0; i < 4; ++i) {
|
||||
dot[i].order = 0;
|
||||
}
|
||||
|
||||
for (order = 1; order < 5; ++order) {
|
||||
i = 0;
|
||||
|
||||
for (; !dot[i].visible || dot[i].order; ++i)
|
||||
if (i >= 3)
|
||||
return;
|
||||
if (i >= 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (j = 0; j < 4; ++j) {
|
||||
if (dot[j].visible && !dot[j].order && (dot[j].x < dot[i].x))
|
||||
if (dot[j].visible && !dot[j].order && (dot[j].x < dot[i].x)) {
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
|
||||
dot[i].order = order;
|
||||
@@ -659,21 +691,25 @@ static float ir_distance(struct ir_dot_t* dot) {
|
||||
int xd, yd;
|
||||
|
||||
for (i1 = 0; i1 < 4; ++i1)
|
||||
if (dot[i1].visible)
|
||||
if (dot[i1].visible) {
|
||||
break;
|
||||
if (i1 == 4)
|
||||
}
|
||||
if (i1 == 4) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
for (i2 = i1+1; i2 < 4; ++i2)
|
||||
if (dot[i2].visible)
|
||||
for (i2 = i1 + 1; i2 < 4; ++i2)
|
||||
if (dot[i2].visible) {
|
||||
break;
|
||||
if (i2 == 4)
|
||||
}
|
||||
if (i2 == 4) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
xd = dot[i2].x - dot[i1].x;
|
||||
yd = dot[i2].y - dot[i1].y;
|
||||
|
||||
return sqrtf(xd*xd + yd*yd);
|
||||
return sqrtf(xd * xd + yd * yd);
|
||||
}
|
||||
|
||||
|
||||
@@ -707,10 +743,9 @@ static int ir_correct_for_bounds(int* x, int* y, enum aspect_t aspect, int offse
|
||||
y0 = ((768 - ys) / 2) + offset_y;
|
||||
|
||||
if ((*x >= x0)
|
||||
&& (*x <= (x0 + xs))
|
||||
&& (*y >= y0)
|
||||
&& (*y <= (y0 + ys)))
|
||||
{
|
||||
&& (*x <= (x0 + xs))
|
||||
&& (*y >= y0)
|
||||
&& (*y <= (y0 + ys))) {
|
||||
*x -= offset_x;
|
||||
*y -= offset_y;
|
||||
|
||||
@@ -735,8 +770,8 @@ static void ir_convert_to_vres(int* x, int* y, enum aspect_t aspect, int vx, int
|
||||
ys = WM_ASPECT_4_3_Y;
|
||||
}
|
||||
|
||||
*x -= ((1024-xs)/2);
|
||||
*y -= ((768-ys)/2);
|
||||
*x -= ((1024 - xs) / 2);
|
||||
*y -= ((768 - ys) / 2);
|
||||
|
||||
*x = (int)((*x / (float)xs) * vx);
|
||||
*y = (int)((*y / (float)ys) * vy);
|
||||
@@ -754,5 +789,5 @@ float calc_yaw(struct ir_t* ir) {
|
||||
x = (float)(ir->ax - 512);
|
||||
x = x * (ir->z / 1024.0f);
|
||||
|
||||
return RAD_TO_DEGREE( atanf(x / ir->z) );
|
||||
return RAD_TO_DEGREE(atanf(x / ir->z));
|
||||
}
|
||||
|
||||
14
src/ir.h
14
src/ir.h
@@ -44,13 +44,13 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/** @defgroup internal_ir Internal: IR Sensor */
|
||||
/** @{ */
|
||||
void wiiuse_set_ir_mode(struct wiimote_t *wm);
|
||||
void calculate_basic_ir(struct wiimote_t* wm, byte* data);
|
||||
void calculate_extended_ir(struct wiimote_t* wm, byte* data);
|
||||
float calc_yaw(struct ir_t* ir);
|
||||
/** @} */
|
||||
/** @defgroup internal_ir Internal: IR Sensor */
|
||||
/** @{ */
|
||||
void wiiuse_set_ir_mode(struct wiimote_t *wm);
|
||||
void calculate_basic_ir(struct wiimote_t* wm, byte* data);
|
||||
void calculate_extended_ir(struct wiimote_t* wm, byte* data);
|
||||
float calc_yaw(struct ir_t* ir);
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "motion_plus.h"
|
||||
|
||||
#include "io.h" /* for wiiuse_read */
|
||||
#include "events.h" /* for disable_expansion */
|
||||
#include "ir.h" /* for wiiuse_set_ir_mode */
|
||||
#include "nunchuk.h" /* for nunchuk_pressed_buttons */
|
||||
@@ -42,30 +43,83 @@ static void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp);
|
||||
static void calculate_gyro_rates(struct motion_plus_t* mp);
|
||||
|
||||
|
||||
void wiiuse_motion_plus_handshake(struct wiimote_t *wm,byte *data,unsigned short len)
|
||||
{
|
||||
uint32_t val;
|
||||
if(data == NULL)
|
||||
{
|
||||
wiiuse_read_data_cb(wm, wiiuse_motion_plus_handshake, wm->motion_plus_id, WM_EXP_ID, 6);
|
||||
void wiiuse_probe_motion_plus(struct wiimote_t *wm) {
|
||||
byte buf[MAX_PAYLOAD];
|
||||
unsigned id;
|
||||
|
||||
wiiuse_read_data_sync(wm, 0, WM_EXP_MOTION_PLUS_IDENT, 6, buf);
|
||||
|
||||
/* check error code */
|
||||
if (buf[4] & 0x0f) {
|
||||
WIIUSE_DEBUG("No Motion+ available, stopping probe.");
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* decode the id */
|
||||
id = from_big_endian_uint32_t(buf + 2);
|
||||
|
||||
if (id != EXP_ID_CODE_INACTIVE_MOTION_PLUS &&
|
||||
id != EXP_ID_CODE_NLA_MOTION_PLUS &&
|
||||
id != EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK &&
|
||||
id != EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC) {
|
||||
/* we have read something weird */
|
||||
WIIUSE_DEBUG("Motion+ ID doesn't match, probably not connected.");
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT);
|
||||
return;
|
||||
}
|
||||
|
||||
WIIUSE_DEBUG("Detected inactive Motion+!");
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT);
|
||||
|
||||
/* init M+ */
|
||||
buf[0] = 0x55;
|
||||
wiiuse_write_data(wm, WM_EXP_MOTION_PLUS_INIT, buf, 1);
|
||||
|
||||
/* Init whatever is hanging on the pass-through port */
|
||||
buf[0] = 0x55;
|
||||
wiiuse_write_data(wm, WM_EXP_MEM_ENABLE1, buf, 1);
|
||||
|
||||
buf[0] = 0x00;
|
||||
wiiuse_write_data(wm, WM_EXP_MEM_ENABLE2, buf, 1);
|
||||
|
||||
/* Init gyroscope data */
|
||||
wm->exp.mp.cal_gyro.roll = 0;
|
||||
wm->exp.mp.cal_gyro.pitch = 0;
|
||||
wm->exp.mp.cal_gyro.yaw = 0;
|
||||
wm->exp.mp.orient.roll = 0.0;
|
||||
wm->exp.mp.orient.pitch = 0.0;
|
||||
wm->exp.mp.orient.yaw = 0.0;
|
||||
wm->exp.mp.raw_gyro_threshold = 10;
|
||||
|
||||
wm->exp.mp.nc = &(wm->exp.nunchuk);
|
||||
wm->exp.mp.classic = &(wm->exp.classic);
|
||||
wm->exp.nunchuk.flags = &wm->flags;
|
||||
|
||||
wm->exp.mp.ext = 0;
|
||||
|
||||
wiiuse_set_ir_mode(wm);
|
||||
wiiuse_set_report_type(wm);
|
||||
}
|
||||
|
||||
void wiiuse_motion_plus_handshake(struct wiimote_t *wm, byte *data, unsigned short len) {
|
||||
uint32_t val;
|
||||
if (data == NULL) {
|
||||
wiiuse_read_data_cb(wm, wiiuse_motion_plus_handshake, wm->motion_plus_id, WM_EXP_ID, 6);
|
||||
} else {
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP); /* tell wiimote to include exp. data in reports */
|
||||
|
||||
val = from_big_endian_uint32_t(data + 2);
|
||||
|
||||
if(val == EXP_ID_CODE_MOTION_PLUS ||
|
||||
val == EXP_ID_CODE_MOTION_PLUS_NUNCHUK ||
|
||||
val == EXP_ID_CODE_MOTION_PLUS_CLASSIC)
|
||||
{
|
||||
if (val == EXP_ID_CODE_MOTION_PLUS ||
|
||||
val == EXP_ID_CODE_MOTION_PLUS_NUNCHUK ||
|
||||
val == EXP_ID_CODE_MOTION_PLUS_CLASSIC) {
|
||||
/* handshake done */
|
||||
wm->event = WIIUSE_MOTION_PLUS_ACTIVATED;
|
||||
|
||||
switch(val)
|
||||
{
|
||||
switch (val) {
|
||||
case EXP_ID_CODE_MOTION_PLUS:
|
||||
wm->exp.type = EXP_MOTION_PLUS;
|
||||
break;
|
||||
@@ -108,16 +162,14 @@ void wiiuse_motion_plus_handshake(struct wiimote_t *wm,byte *data,unsigned short
|
||||
}
|
||||
}
|
||||
|
||||
static void wiiuse_set_motion_plus_clear2(struct wiimote_t *wm,byte *data,unsigned short len)
|
||||
{
|
||||
static void wiiuse_set_motion_plus_clear2(struct wiimote_t *wm, byte *data, unsigned short len) {
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
||||
wiiuse_set_ir_mode(wm);
|
||||
wiiuse_status(wm);
|
||||
}
|
||||
|
||||
static void wiiuse_set_motion_plus_clear1(struct wiimote_t *wm,byte *data,unsigned short len)
|
||||
{
|
||||
static void wiiuse_set_motion_plus_clear1(struct wiimote_t *wm, byte *data, unsigned short len) {
|
||||
byte val = 0x00;
|
||||
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_set_motion_plus_clear2);
|
||||
}
|
||||
@@ -125,36 +177,35 @@ static void wiiuse_set_motion_plus_clear1(struct wiimote_t *wm,byte *data,unsign
|
||||
/**
|
||||
* @brief Enable/disable Motion+ expansion
|
||||
*
|
||||
* @param wm Pointer to the wiimote with Motion+
|
||||
* @param wm Pointer to the wiimote with Motion+
|
||||
* @param status 0 - off, 1 - on, standalone, 2 - nunchuk pass-through
|
||||
*
|
||||
*/
|
||||
void wiiuse_set_motion_plus(struct wiimote_t *wm, int status)
|
||||
{
|
||||
void wiiuse_set_motion_plus(struct wiimote_t *wm, int status) {
|
||||
byte val;
|
||||
|
||||
if(status && !WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP_HANDSHAKE))
|
||||
{
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT) ||
|
||||
WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP_HANDSHAKE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
||||
val = (status == 1) ? 0x04 : 0x05;
|
||||
wiiuse_write_data_cb(wm, WM_EXP_MOTION_PLUS_ENABLE, &val, 1, wiiuse_motion_plus_handshake);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
disable_expansion(wm);
|
||||
val = 0x55;
|
||||
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_set_motion_plus_clear1);
|
||||
}
|
||||
}
|
||||
|
||||
void motion_plus_disconnected(struct motion_plus_t* mp)
|
||||
{
|
||||
void motion_plus_disconnected(struct motion_plus_t* mp) {
|
||||
WIIUSE_DEBUG("Motion plus disconnected");
|
||||
memset(mp, 0, sizeof(struct motion_plus_t));
|
||||
}
|
||||
|
||||
void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
||||
{
|
||||
void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg) {
|
||||
/*
|
||||
* Pass-through modes interleave data from the gyro
|
||||
* with the expansion data. This extracts the tag
|
||||
@@ -163,8 +214,7 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
||||
int isMPFrame = (1 << 1) & msg[5];
|
||||
mp->ext = msg[4] & 0x1; /* extension attached to pass-through port? */
|
||||
|
||||
if (mp->ext == 0 || isMPFrame) /* reading gyro frame */
|
||||
{
|
||||
if (mp->ext == 0 || isMPFrame) { /* reading gyro frame */
|
||||
/* Check if the gyroscope is in fast or slow mode (0 if rotating fast, 1 if slow or still) */
|
||||
mp->acc_mode = ((msg[4] & 0x2) << 1) | ((msg[3] & 0x1) << 1) | ((msg[3] & 0x2) >> 1);
|
||||
|
||||
@@ -174,15 +224,14 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
||||
|
||||
/* First calibration */
|
||||
if ((mp->raw_gyro.roll > 5000) &&
|
||||
(mp->raw_gyro.pitch > 5000) &&
|
||||
(mp->raw_gyro.yaw > 5000) &&
|
||||
(mp->raw_gyro.roll < 0x3fff) &&
|
||||
(mp->raw_gyro.pitch < 0x3fff) &&
|
||||
(mp->raw_gyro.yaw < 0x3fff) &&
|
||||
!(mp->cal_gyro.roll) &&
|
||||
!(mp->cal_gyro.pitch) &&
|
||||
!(mp->cal_gyro.yaw))
|
||||
{
|
||||
(mp->raw_gyro.pitch > 5000) &&
|
||||
(mp->raw_gyro.yaw > 5000) &&
|
||||
(mp->raw_gyro.roll < 0x3fff) &&
|
||||
(mp->raw_gyro.pitch < 0x3fff) &&
|
||||
(mp->raw_gyro.yaw < 0x3fff) &&
|
||||
!(mp->cal_gyro.roll) &&
|
||||
!(mp->cal_gyro.pitch) &&
|
||||
!(mp->cal_gyro.yaw)) {
|
||||
wiiuse_calibrate_motion_plus(mp);
|
||||
}
|
||||
|
||||
@@ -190,11 +239,9 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
||||
calculate_gyro_rates(mp);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
else {
|
||||
/* expansion frame */
|
||||
if (exp_type == EXP_MOTION_PLUS_NUNCHUK)
|
||||
{
|
||||
if (exp_type == EXP_MOTION_PLUS_NUNCHUK) {
|
||||
/* ok, this is nunchuck, re-encode it as regular nunchuck packet */
|
||||
|
||||
/* get button states */
|
||||
@@ -209,23 +256,21 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
||||
mp->nc->accel.z = (msg[4] & 0xFE) | ((msg[5] >> 5) & 0x04);
|
||||
|
||||
calculate_orientation(&(mp->nc->accel_calib),
|
||||
&(mp->nc->accel),
|
||||
&(mp->nc->orient),
|
||||
NUNCHUK_IS_FLAG_SET(mp->nc, WIIUSE_SMOOTHING));
|
||||
&(mp->nc->accel),
|
||||
&(mp->nc->orient),
|
||||
NUNCHUK_IS_FLAG_SET(mp->nc, WIIUSE_SMOOTHING));
|
||||
|
||||
calculate_gforce(&(mp->nc->accel_calib),
|
||||
&(mp->nc->accel),
|
||||
&(mp->nc->gforce));
|
||||
&(mp->nc->accel),
|
||||
&(mp->nc->gforce));
|
||||
|
||||
}
|
||||
|
||||
else if (exp_type == EXP_MOTION_PLUS_CLASSIC)
|
||||
{
|
||||
else if (exp_type == EXP_MOTION_PLUS_CLASSIC) {
|
||||
WIIUSE_ERROR("Classic controller pass-through is not implemented!\n");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
else {
|
||||
WIIUSE_ERROR("Unsupported mode passed to motion_plus_event() !\n");
|
||||
}
|
||||
}
|
||||
@@ -239,8 +284,7 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
||||
* This should be called only after receiving the first values
|
||||
* from the Motion Plus.
|
||||
*/
|
||||
void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp)
|
||||
{
|
||||
void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp) {
|
||||
mp->cal_gyro.roll = mp->raw_gyro.roll;
|
||||
mp->cal_gyro.pitch = mp->raw_gyro.pitch;
|
||||
mp->cal_gyro.yaw = mp->raw_gyro.yaw;
|
||||
@@ -249,8 +293,7 @@ void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp)
|
||||
mp->orient.yaw = 0.0;
|
||||
}
|
||||
|
||||
static void calculate_gyro_rates(struct motion_plus_t* mp)
|
||||
{
|
||||
static void calculate_gyro_rates(struct motion_plus_t* mp) {
|
||||
short int tmp_r, tmp_p, tmp_y;
|
||||
float tmp_roll, tmp_pitch, tmp_yaw;
|
||||
|
||||
@@ -260,28 +303,34 @@ static void calculate_gyro_rates(struct motion_plus_t* mp)
|
||||
tmp_y = mp->raw_gyro.yaw - mp->cal_gyro.yaw;
|
||||
|
||||
/* We convert to degree/sec according to fast/slow mode */
|
||||
if (mp->acc_mode & 0x04)
|
||||
if (mp->acc_mode & 0x04) {
|
||||
tmp_roll = (float)tmp_r / 20.0f;
|
||||
else
|
||||
} else {
|
||||
tmp_roll = (float)tmp_r / 4.0f;
|
||||
}
|
||||
|
||||
if (mp->acc_mode & 0x02)
|
||||
if (mp->acc_mode & 0x02) {
|
||||
tmp_pitch = (float)tmp_p / 20.0f;
|
||||
else
|
||||
} else {
|
||||
tmp_pitch = (float)tmp_p / 4.0f;
|
||||
}
|
||||
|
||||
if (mp->acc_mode & 0x01)
|
||||
if (mp->acc_mode & 0x01) {
|
||||
tmp_yaw = (float)tmp_y / 20.0f;
|
||||
else
|
||||
} else {
|
||||
tmp_yaw = (float)tmp_y / 4.0f;
|
||||
}
|
||||
|
||||
/* Simple filtering */
|
||||
if (fabs(tmp_roll) < 0.5f)
|
||||
if (fabs(tmp_roll) < 0.5f) {
|
||||
tmp_roll = 0.0f;
|
||||
if (fabs(tmp_pitch) < 0.5f)
|
||||
}
|
||||
if (fabs(tmp_pitch) < 0.5f) {
|
||||
tmp_pitch = 0.0f;
|
||||
if (fabs(tmp_yaw) < 0.5f)
|
||||
}
|
||||
if (fabs(tmp_yaw) < 0.5f) {
|
||||
tmp_yaw = 0.0f;
|
||||
}
|
||||
|
||||
mp->angle_rate_gyro.roll = tmp_roll;
|
||||
mp->angle_rate_gyro.pitch = tmp_pitch;
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
* @brief Motion plus extension
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
* @brief Motion plus extension
|
||||
*/
|
||||
|
||||
#ifndef MOTION_PLUS_H_INCLUDED
|
||||
#define MOTION_PLUS_H_INCLUDED
|
||||
@@ -41,15 +41,17 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup internal_mp Internal: MotionPlus */
|
||||
/** @{ */
|
||||
void motion_plus_disconnected(struct motion_plus_t* mp);
|
||||
/** @defgroup internal_mp Internal: MotionPlus */
|
||||
/** @{ */
|
||||
void motion_plus_disconnected(struct motion_plus_t* mp);
|
||||
|
||||
void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg);
|
||||
void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg);
|
||||
|
||||
void wiiuse_motion_plus_handshake(struct wiimote_t *wm, byte *data,unsigned short len);
|
||||
void wiiuse_motion_plus_handshake(struct wiimote_t *wm, byte *data, unsigned short len);
|
||||
|
||||
/** @} */
|
||||
void wiiuse_probe_motion_plus(struct wiimote_t *wm);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -77,8 +77,9 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
|
||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||
|
||||
return 0;
|
||||
} else
|
||||
} else {
|
||||
data += 16;
|
||||
}
|
||||
}
|
||||
|
||||
nc->accel_calib.cal_zero.x = data[0];
|
||||
@@ -94,8 +95,8 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
|
||||
nc->js.min.y = data[12];
|
||||
nc->js.center.y = data[13];
|
||||
WIIUSE_DEBUG("Nunchuk calibration X: min %x, max %x, center %x Y: min %x, max %x, center %x",
|
||||
nc->js.min.x, nc->js.max.x, nc->js.center.x,
|
||||
nc->js.min.y, nc->js.max.y, nc->js.center.y);
|
||||
nc->js.min.x, nc->js.max.x, nc->js.center.x,
|
||||
nc->js.min.y, nc->js.max.y, nc->js.center.y);
|
||||
|
||||
/* default the thresholds to the same as the wiimote */
|
||||
nc->orient_threshold = wm->orient_threshold;
|
||||
@@ -104,9 +105,9 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
|
||||
/* handshake done */
|
||||
wm->exp.type = EXP_NUNCHUK;
|
||||
|
||||
#ifdef WIIUSE_WIN32
|
||||
#ifdef WIIUSE_WIN32
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -177,7 +178,9 @@ void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now) {
|
||||
* See wiiuse_set_orient_threshold() for details.
|
||||
*/
|
||||
void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold) {
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
wm->exp.nunchuk.orient_threshold = threshold;
|
||||
}
|
||||
@@ -192,7 +195,9 @@ void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold)
|
||||
* See wiiuse_set_orient_threshold() for details.
|
||||
*/
|
||||
void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold) {
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
wm->exp.nunchuk.accel_threshold = threshold;
|
||||
}
|
||||
|
||||
@@ -41,16 +41,16 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/** @defgroup internal_nunchuk Internal: Nunchuk */
|
||||
/** @{ */
|
||||
int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len);
|
||||
/** @defgroup internal_nunchuk Internal: Nunchuk */
|
||||
/** @{ */
|
||||
int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len);
|
||||
|
||||
void nunchuk_disconnected(struct nunchuk_t* nc);
|
||||
void nunchuk_disconnected(struct nunchuk_t* nc);
|
||||
|
||||
void nunchuk_event(struct nunchuk_t* nc, byte* msg);
|
||||
void nunchuk_event(struct nunchuk_t* nc, byte* msg);
|
||||
|
||||
void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now);
|
||||
/** @} */
|
||||
void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now);
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
45
src/os.h
45
src/os.h
@@ -26,26 +26,39 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Operating system related definitions.
|
||||
*
|
||||
* This file is an attempt to separate operating system
|
||||
* dependent functions and choose what should be used
|
||||
* at compile time.
|
||||
* @brief Handles device I/O.
|
||||
*/
|
||||
|
||||
#ifndef OS_H_INCLUDED
|
||||
#define OS_H_INCLUDED
|
||||
#ifndef PLATFORM_H_INCLUDED
|
||||
#define PLATFORM_H_INCLUDED
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <float.h>
|
||||
/* windows with visual c */
|
||||
#define isnan(x) (_isnan(x))
|
||||
#define isinf(x) (!_finite(x))
|
||||
/* disable warnings I don't care about */
|
||||
/*#pragma warning(disable:4273) */ /* inconsistent dll linkage */
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#endif /* OS_H_INCLUDED */
|
||||
|
||||
/** @defgroup internal_io Internal: Platform-specific Device I/O */
|
||||
/** @{ */
|
||||
void wiiuse_init_platform_fields(struct wiimote_t* wm);
|
||||
void wiiuse_cleanup_platform_fields(struct wiimote_t* wm);
|
||||
|
||||
int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
|
||||
|
||||
int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes);
|
||||
void wiiuse_os_disconnect(struct wiimote_t* wm);
|
||||
|
||||
int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes);
|
||||
/* buf[0] will be the report type, buf+1 the rest of the report */
|
||||
int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len);
|
||||
int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len);
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PLATFORM_H_INCLUDED */
|
||||
|
||||
92
src/os_mac/os_mac.h
Normal file
92
src/os_mac/os_mac.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O for Mac OS X.
|
||||
*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
|
||||
#define BLUETOOTH_VERSION_USE_CURRENT
|
||||
|
||||
#import <IOBluetooth/objc/IOBluetoothDevice.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothL2CAPChannel.h>
|
||||
|
||||
#import "../wiiuse_internal.h"
|
||||
|
||||
|
||||
#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
|
||||
#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 1
|
||||
#else
|
||||
#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 0
|
||||
#endif
|
||||
|
||||
|
||||
@interface WiiuseWiimote : NSObject<IOBluetoothL2CAPChannelDelegate> {
|
||||
wiimote* wm; // reference to the C wiimote struct
|
||||
|
||||
IOBluetoothDevice* device;
|
||||
IOBluetoothL2CAPChannel* controlChannel;
|
||||
IOBluetoothL2CAPChannel* interruptChannel;
|
||||
|
||||
IOBluetoothUserNotification* disconnectNotification;
|
||||
|
||||
NSMutableArray* receivedData; // a queue of NSObject<WiiuseReceivedMessage>*
|
||||
NSLock* receivedDataLock;
|
||||
}
|
||||
|
||||
- (id) initWithPtr: (wiimote*) wm device: (IOBluetoothDevice*) device;
|
||||
|
||||
- (IOReturn) connect;
|
||||
- (void) disconnect;
|
||||
|
||||
- (int) readBuffer: (byte*) buffer length: (NSUInteger) bufferLength;
|
||||
- (int) writeReport: (byte) report_type buffer: (byte*) buffer length: (NSUInteger) length;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@protocol WiiuseReceivedMessage <NSObject>
|
||||
- (int) applyToStruct: (wiimote*) wm buffer: (byte*) buffer length: (NSUInteger) bufferLength; // <0: not copied, 0: copied empty, >0: copied
|
||||
@end
|
||||
|
||||
@interface WiiuseReceivedData : NSObject<WiiuseReceivedMessage> {
|
||||
NSData* data;
|
||||
}
|
||||
- (id) initWithBytes: (void*) bytes length: (NSUInteger) length;
|
||||
- (id) initWithData: (NSData*) data;
|
||||
@end
|
||||
|
||||
@interface WiiuseDisconnectionMessage : NSObject<WiiuseReceivedMessage> {
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
#endif // __APPLE__
|
||||
351
src/os_mac/os_mac.m
Normal file
351
src/os_mac/os_mac.m
Normal file
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O for Mac OS X.
|
||||
*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#import "os_mac.h"
|
||||
|
||||
#import "../events.h"
|
||||
|
||||
#import <IOBluetooth/IOBluetoothUtilities.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothDevice.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothHostController.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothL2CAPChannel.h>
|
||||
|
||||
|
||||
@implementation WiiuseWiimote
|
||||
|
||||
#pragma mark init, dealloc
|
||||
|
||||
- (id) initWithPtr: (wiimote*) wm_ device:(IOBluetoothDevice *)device_ {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
wm = wm_;
|
||||
|
||||
device = [device_ retain];
|
||||
controlChannel = nil;
|
||||
interruptChannel = nil;
|
||||
|
||||
disconnectNotification = nil;
|
||||
|
||||
receivedData = [[NSMutableArray alloc] initWithCapacity: 2];
|
||||
receivedDataLock = [[NSLock alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc {
|
||||
wm = NULL;
|
||||
|
||||
[interruptChannel release];
|
||||
[controlChannel release];
|
||||
[device release];
|
||||
|
||||
[disconnectNotification unregister];
|
||||
[disconnectNotification release];
|
||||
|
||||
[receivedData release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark connect, disconnect
|
||||
|
||||
- (BOOL) connectChannel: (IOBluetoothL2CAPChannel**) pChannel PSM: (BluetoothL2CAPPSM) psm {
|
||||
if ([device openL2CAPChannelSync:pChannel withPSM:psm delegate:self] != kIOReturnSuccess) {
|
||||
WIIUSE_ERROR("Unable to open L2CAP channel [id %i].", wm->unid);
|
||||
*pChannel = nil;
|
||||
return NO;
|
||||
} else {
|
||||
[*pChannel retain];
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (IOReturn) connect {
|
||||
if(!device) {
|
||||
WIIUSE_ERROR("Missing device.");
|
||||
return kIOReturnBadArgument;
|
||||
}
|
||||
|
||||
// open channels
|
||||
if(![self connectChannel:&controlChannel PSM:kBluetoothL2CAPPSMHIDControl]) {
|
||||
[self disconnect];
|
||||
return kIOReturnNotOpen;
|
||||
} else if(![self connectChannel:&interruptChannel PSM:kBluetoothL2CAPPSMHIDInterrupt]) {
|
||||
[self disconnect];
|
||||
return kIOReturnNotOpen;
|
||||
}
|
||||
|
||||
// register for device disconnection
|
||||
disconnectNotification = [device registerForDisconnectNotification:self selector:@selector(disconnected:fromDevice:)];
|
||||
if(!disconnectNotification) {
|
||||
WIIUSE_ERROR("Unable to register disconnection handler [id %i].", wm->unid);
|
||||
[self disconnect];
|
||||
return kIOReturnNotOpen;
|
||||
}
|
||||
|
||||
return kIOReturnSuccess;
|
||||
}
|
||||
|
||||
- (void) disconnectChannel: (IOBluetoothL2CAPChannel**) pChannel {
|
||||
if(!pChannel) return;
|
||||
|
||||
if([*pChannel closeChannel] != kIOReturnSuccess)
|
||||
WIIUSE_ERROR("Unable to close channel [id %i].", wm ? wm->unid : -1);
|
||||
[*pChannel release];
|
||||
*pChannel = nil;
|
||||
}
|
||||
|
||||
- (void) disconnect {
|
||||
// channels
|
||||
[self disconnectChannel:&interruptChannel];
|
||||
[self disconnectChannel:&controlChannel];
|
||||
|
||||
// device
|
||||
if([device closeConnection] != kIOReturnSuccess)
|
||||
WIIUSE_ERROR("Unable to close the device connection [id %i].", wm ? wm->unid : -1);
|
||||
[device release];
|
||||
device = nil;
|
||||
}
|
||||
|
||||
- (void) disconnected:(IOBluetoothUserNotification*) notification fromDevice:(IOBluetoothDevice*) device {
|
||||
|
||||
WiiuseDisconnectionMessage* message = [[WiiuseDisconnectionMessage alloc] init];
|
||||
[receivedDataLock lock];
|
||||
[receivedData addObject:message];
|
||||
[receivedDataLock unlock];
|
||||
[message release];
|
||||
}
|
||||
|
||||
#pragma mark read, write
|
||||
|
||||
// <0: nothing received, else: length of data received (can be 0 in case of disconnection message)
|
||||
- (int) checkForAvailableDataForBuffer: (byte*) buffer length: (NSUInteger) bufferLength {
|
||||
int result = -1;
|
||||
|
||||
[receivedDataLock lock];
|
||||
if([receivedData count]) {
|
||||
// look at first item in queue
|
||||
NSObject<WiiuseReceivedMessage>* firstMessage = [receivedData objectAtIndex:0];
|
||||
result = [firstMessage applyToStruct:wm buffer: buffer length: bufferLength];
|
||||
if(result >= 0)
|
||||
[receivedData removeObjectAtIndex:0];
|
||||
}
|
||||
[receivedDataLock unlock];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void) waitForIncomingData: (NSTimeInterval) duration {
|
||||
NSDate* timeoutDate = [NSDate dateWithTimeIntervalSinceNow: duration];
|
||||
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
|
||||
while (true) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // This is used for fast release of NSDate, otherwise it leaks
|
||||
if(![theRL runMode:NSDefaultRunLoopMode beforeDate:timeoutDate]) {
|
||||
WIIUSE_ERROR("Could not start run loop while waiting for read [id %i].", wm->unid);
|
||||
break;
|
||||
}
|
||||
[pool drain];
|
||||
|
||||
[receivedDataLock lock];
|
||||
NSUInteger count = [receivedData count];
|
||||
[receivedDataLock unlock];
|
||||
if(count) {
|
||||
// received some data, stop waiting
|
||||
break;
|
||||
}
|
||||
|
||||
if([timeoutDate isLessThanOrEqualTo:[NSDate date]]) {
|
||||
// timeout
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// result = length of data copied to event buffer
|
||||
- (int) readBuffer:(byte *)buffer length:(NSUInteger)bufferLength {
|
||||
// is there already some data to read?
|
||||
int result = [self checkForAvailableDataForBuffer: buffer length: bufferLength];
|
||||
if(result < 0) {
|
||||
// wait a short amount of time, until data becomes available or a timeout is reached
|
||||
[self waitForIncomingData:1];
|
||||
|
||||
// check again
|
||||
result = [self checkForAvailableDataForBuffer: buffer length: bufferLength];
|
||||
}
|
||||
|
||||
return result >= 0 ? result : 0;
|
||||
}
|
||||
|
||||
- (int) writeReport: (byte) report_type buffer: (byte*) buffer length: (NSUInteger) length {
|
||||
if(interruptChannel == nil) {
|
||||
WIIUSE_ERROR("Attempted to write to nil interrupt channel [id %i].", wm->unid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
byte write_buffer[MAX_PAYLOAD];
|
||||
write_buffer[0] = WM_SET_DATA | WM_BT_OUTPUT;
|
||||
write_buffer[1] = report_type;
|
||||
memcpy(write_buffer+2, buffer, length);
|
||||
|
||||
IOReturn error = [interruptChannel writeSync:write_buffer length:length+2];
|
||||
if (error != kIOReturnSuccess) {
|
||||
WIIUSE_ERROR("Error writing to interrupt channel [id %i].", wm->unid);
|
||||
|
||||
WIIUSE_DEBUG("Attempting to reopen the interrupt channel [id %i].", wm->unid);
|
||||
[self disconnectChannel:&interruptChannel];
|
||||
[self connectChannel:&interruptChannel PSM:kBluetoothL2CAPPSMHIDInterrupt];
|
||||
if(!interruptChannel) {
|
||||
WIIUSE_ERROR("Error reopening the interrupt channel [id %i].", wm->unid);
|
||||
[self disconnect];
|
||||
} else {
|
||||
WIIUSE_DEBUG("Attempting to write again to the interrupt channel [id %i].", wm->unid);
|
||||
error = [interruptChannel writeSync:write_buffer length:length+2];
|
||||
if (error != kIOReturnSuccess)
|
||||
WIIUSE_ERROR("Unable to write again to the interrupt channel [id %i].", wm->unid);
|
||||
}
|
||||
}
|
||||
|
||||
return (error == kIOReturnSuccess) ? length : 0;
|
||||
}
|
||||
|
||||
#pragma mark IOBluetoothL2CAPChannelDelegate
|
||||
|
||||
- (void) l2capChannelData:(IOBluetoothL2CAPChannel*)channel data:(void*)data_ length:(NSUInteger)length {
|
||||
|
||||
byte* data = (byte*) data_;
|
||||
|
||||
// This is done in case the control channel woke up this handler
|
||||
#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE
|
||||
BluetoothL2CAPPSM psm = channel.PSM;
|
||||
#else
|
||||
BluetoothL2CAPPSM psm = [channel getPSM];
|
||||
#endif
|
||||
if(!data || (psm == kBluetoothL2CAPPSMHIDControl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// copy the data into the buffer
|
||||
// on Mac, we ignore the first byte
|
||||
WiiuseReceivedData* newData = [[WiiuseReceivedData alloc] initWithBytes: data+1 length: length-1];
|
||||
[receivedDataLock lock];
|
||||
[receivedData addObject: newData];
|
||||
[receivedDataLock unlock];
|
||||
[newData release];
|
||||
}
|
||||
|
||||
#if !WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE
|
||||
// the following delegate methods were required on 10.6. They are here to get rid of 10.6 compiler warnings.
|
||||
- (void)l2capChannelOpenComplete:(IOBluetoothL2CAPChannel*)l2capChannel status:(IOReturn)error {
|
||||
/* no-op */
|
||||
}
|
||||
- (void)l2capChannelClosed:(IOBluetoothL2CAPChannel*)l2capChannel {
|
||||
/* no-op */
|
||||
}
|
||||
- (void)l2capChannelReconfigured:(IOBluetoothL2CAPChannel*)l2capChannel {
|
||||
/* no-op */
|
||||
}
|
||||
- (void)l2capChannelWriteComplete:(IOBluetoothL2CAPChannel*)l2capChannel refcon:(void*)refcon status:(IOReturn)error {
|
||||
/* no-op */
|
||||
}
|
||||
- (void)l2capChannelQueueSpaceAvailable:(IOBluetoothL2CAPChannel*)l2capChannel {
|
||||
/* no-op */
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark WiiuseReceivedMessage
|
||||
|
||||
@implementation WiiuseReceivedData
|
||||
|
||||
- (id) initWithData:(NSData *)data_ {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
data = [data_ retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (id) initWithBytes: (void*) bytes length: (NSUInteger) length {
|
||||
NSData* data_ = [[NSData alloc] initWithBytes:bytes length:length];
|
||||
id result = [self initWithData: data_];
|
||||
[data_ release];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void) dealloc {
|
||||
[data release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (int) applyToStruct:(wiimote *)wm buffer:(byte *)buffer length:(NSUInteger)bufferLength {
|
||||
byte* bytes = (byte*) [data bytes];
|
||||
NSUInteger length = [data length];
|
||||
if(length > bufferLength) {
|
||||
WIIUSE_WARNING("Received data was longer than event buffer. Dropping excess bytes.");
|
||||
length = bufferLength;
|
||||
}
|
||||
|
||||
// log the received data
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, bytes[0]);
|
||||
int x;
|
||||
for (x = 1; x < length; ++x)
|
||||
printf("%.2x ", bytes[x]);
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
// copy to struct
|
||||
memcpy(buffer, bytes, length);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation WiiuseDisconnectionMessage
|
||||
|
||||
- (int) applyToStruct:(wiimote *)wm buffer:(byte *)buffer length:(NSUInteger)bufferLength {
|
||||
wiiuse_disconnected(wm);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#endif // __APPLE__
|
||||
240
src/os_mac/os_mac_find.m
Normal file
240
src/os_mac/os_mac_find.m
Normal file
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O for Mac OS X.
|
||||
*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#import "os_mac.h"
|
||||
|
||||
#import "../io.h"
|
||||
#import "../events.h"
|
||||
#import "../os.h"
|
||||
|
||||
#import <IOBluetooth/IOBluetoothUtilities.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothDevice.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothHostController.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>
|
||||
#if !WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE
|
||||
#import <IOBluetooth/IOBluetoothUserLib.h> // IOBluetoothLocalDeviceGetPowerState
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark WiiuseDeviceInquiry
|
||||
|
||||
#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE
|
||||
@interface WiiuseDeviceInquiry : NSObject<IOBluetoothDeviceInquiryDelegate> {
|
||||
#else
|
||||
@interface WiiuseDeviceInquiry : NSObject {
|
||||
#endif
|
||||
wiimote** wiimotes;
|
||||
NSUInteger maxDevices;
|
||||
int timeout;
|
||||
|
||||
BOOL _running;
|
||||
NSUInteger _foundDevices;
|
||||
BOOL _inquiryComplete;
|
||||
}
|
||||
|
||||
- (id) initWithMemory:(wiimote**)wiimotes maxDevices:(int)maxDevices timeout:(int)timeout;
|
||||
- (int) run;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WiiuseDeviceInquiry
|
||||
|
||||
- (id) initWithMemory:(wiimote**)wiimotes_ maxDevices:(int)maxDevices_ timeout:(int)timeout_ {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
|
||||
BluetoothHCIPowerState powerState = kBluetoothHCIPowerStateUnintialized;
|
||||
#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE
|
||||
if([IOBluetoothHostController defaultController])
|
||||
powerState = [IOBluetoothHostController defaultController].powerState;
|
||||
#else
|
||||
// yes it is deprecated. no, there is no alternative (on 10.6).
|
||||
IOBluetoothLocalDeviceGetPowerState(&powerState);
|
||||
#endif
|
||||
if (![IOBluetoothHostController defaultController] ||
|
||||
powerState != kBluetoothHCIPowerStateON)
|
||||
{
|
||||
WIIUSE_DEBUG("Bluetooth hardware not available.");
|
||||
[self release];
|
||||
self = nil;
|
||||
} else {
|
||||
wiimotes = wiimotes_;
|
||||
maxDevices = maxDevices_;
|
||||
timeout = timeout_;
|
||||
_running = NO;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
// creates and starts inquiry. the returned object is in the current autorelease pool.
|
||||
- (IOBluetoothDeviceInquiry*) start {
|
||||
|
||||
// reset state variables
|
||||
_foundDevices = 0;
|
||||
_inquiryComplete = NO;
|
||||
|
||||
// create inquiry
|
||||
IOBluetoothDeviceInquiry* inquiry = [IOBluetoothDeviceInquiry inquiryWithDelegate: self];
|
||||
|
||||
// refine search & set timeout
|
||||
[inquiry setSearchCriteria:kBluetoothServiceClassMajorAny
|
||||
majorDeviceClass:WM_DEV_MAJOR_CLASS
|
||||
minorDeviceClass:WM_DEV_MINOR_CLASS];
|
||||
[inquiry setUpdateNewDeviceNames: NO];
|
||||
if(timeout > 0)
|
||||
[inquiry setInquiryLength:timeout];
|
||||
|
||||
// start inquiry
|
||||
IOReturn status = [inquiry start];
|
||||
if (status != kIOReturnSuccess) {
|
||||
WIIUSE_ERROR("Unable to start bluetooth device inquiry.");
|
||||
if(![inquiry stop]) {
|
||||
WIIUSE_ERROR("Unable to stop bluetooth device inquiry.");
|
||||
} else {
|
||||
WIIUSE_DEBUG("Bluetooth device inquiry stopped.");
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
return inquiry;
|
||||
}
|
||||
|
||||
- (void) wait {
|
||||
// wait for the inquiry to complete
|
||||
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
|
||||
while(!_inquiryComplete &&
|
||||
[runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
||||
- (NSUInteger) collectResultsOf: (IOBluetoothDeviceInquiry*) inquiry {
|
||||
// stop the inquiry
|
||||
if(![inquiry stop])
|
||||
WIIUSE_ERROR("Unable to stop bluetooth device inquiry.");
|
||||
|
||||
// read found device information
|
||||
NSArray* devices = [inquiry foundDevices];
|
||||
NSUInteger i;
|
||||
for(i = 0; i < [devices count]; i++) {
|
||||
IOBluetoothDevice* device = [devices objectAtIndex:i];
|
||||
|
||||
// save the device in the wiimote structure
|
||||
wiimotes[i]->objc_wm = (void*) [[WiiuseWiimote alloc] initWithPtr:wiimotes[i] device: device];
|
||||
|
||||
// mark as found
|
||||
WIIMOTE_ENABLE_STATE(wiimotes[i], WIIMOTE_STATE_DEV_FOUND);
|
||||
NSString* address = IOBluetoothNSStringFromDeviceAddress([device getAddress]);
|
||||
const char* address_str = [address cStringUsingEncoding:NSMacOSRomanStringEncoding];
|
||||
WIIUSE_INFO("Found Wiimote (%s) [id %i]", address_str, wiimotes[i]->unid);
|
||||
}
|
||||
|
||||
return [devices count];
|
||||
}
|
||||
|
||||
- (int) run {
|
||||
int result = -1;
|
||||
|
||||
if(maxDevices == 0) {
|
||||
result = 0;
|
||||
} else if(!_running) {
|
||||
_running = YES;
|
||||
|
||||
if (![IOBluetoothHostController defaultController]) {
|
||||
WIIUSE_ERROR("Unable to find any bluetooth receiver on your host.");
|
||||
} else {
|
||||
IOBluetoothDeviceInquiry* inquiry = [self start];
|
||||
if(inquiry) {
|
||||
[self wait];
|
||||
result = [self collectResultsOf: inquiry];
|
||||
WIIUSE_INFO("Found %i Wiimote device(s).", result);
|
||||
}
|
||||
}
|
||||
|
||||
_running = NO;
|
||||
} else { // if(_running)
|
||||
WIIUSE_ERROR("Device inquiry already running - won't start it again.");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma mark IOBluetoothDeviceInquiryDelegate
|
||||
|
||||
- (void) deviceInquiryDeviceFound:(IOBluetoothDeviceInquiry *) inquiry device:(IOBluetoothDevice *) device {
|
||||
|
||||
WIIUSE_DEBUG("Found a wiimote");
|
||||
|
||||
_foundDevices++;
|
||||
if(_foundDevices >= maxDevices) {
|
||||
// reached maximum number of devices
|
||||
_inquiryComplete = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) deviceInquiryComplete:(IOBluetoothDeviceInquiry*) inquiry error:(IOReturn) error aborted:(BOOL) aborted
|
||||
{
|
||||
WIIUSE_DEBUG("Inquiry complete, error=%i, aborted=%s", error, aborted ? "YES" : "NO");
|
||||
|
||||
// mark completion
|
||||
_inquiryComplete = YES;
|
||||
|
||||
// print error message if we stop due to an error
|
||||
if ((error != kIOReturnSuccess) && !aborted) {
|
||||
WIIUSE_ERROR("Bluetooth device inquiry not completed due to unexpected errors. Try increasing the timeout.");
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark public interface
|
||||
|
||||
int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
int result;
|
||||
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
WiiuseDeviceInquiry* inquiry = [[WiiuseDeviceInquiry alloc] initWithMemory:wm maxDevices:max_wiimotes timeout:timeout];
|
||||
result = [inquiry run];
|
||||
[inquiry release];
|
||||
|
||||
[pool drain];
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // __APPLE__
|
||||
222
src/os_mac/os_mac_interface.m
Normal file
222
src/os_mac/os_mac_interface.m
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief C function interface to os_mac.
|
||||
*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#import "os_mac.h"
|
||||
|
||||
#import "../io.h"
|
||||
#import "../events.h"
|
||||
#import "../os.h"
|
||||
|
||||
#import <IOBluetooth/IOBluetoothUtilities.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothDevice.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothHostController.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>
|
||||
#import <IOBluetooth/objc/IOBluetoothL2CAPChannel.h>
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark find
|
||||
|
||||
// See os_mac_find.m
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark connect, disconnect
|
||||
|
||||
/**
|
||||
* @brief Connect to a wiimote with a known address.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* @see wiimote_os_connect()
|
||||
* @see wiimote_os_find()
|
||||
*
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
static short wiiuse_os_connect_single(struct wiimote_t* wm) {
|
||||
// Skip if already connected or device not found
|
||||
if(!wm) {
|
||||
WIIUSE_ERROR("No Wiimote given.");
|
||||
return 0;
|
||||
} else if(wm && (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_DEV_FOUND) || wm->objc_wm == NULL)) {
|
||||
WIIUSE_ERROR("Tried to connect Wiimote without an address.");
|
||||
return 0;
|
||||
} else if(WIIMOTE_IS_CONNECTED(wm)) {
|
||||
WIIUSE_WARNING("Wiimote [id %i] is already connected.", wm->unid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
WIIUSE_DEBUG("Connecting to Wiimote [id %i].", wm->unid);
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
short result = 0;
|
||||
|
||||
// connect
|
||||
WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm;
|
||||
if([objc_wm connect] == kIOReturnSuccess) {
|
||||
WIIUSE_INFO("Connected to Wiimote [id %i].", wm->unid);
|
||||
|
||||
// save the connect structure to retrieve data later on
|
||||
wm->objc_wm = (void*)objc_wm;
|
||||
|
||||
// save the connection status
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
|
||||
// Do the handshake
|
||||
wiiuse_handshake(wm, NULL, 0);
|
||||
wiiuse_set_report_type(wm);
|
||||
|
||||
result = 1;
|
||||
}
|
||||
|
||||
[pool drain];
|
||||
return result;
|
||||
}
|
||||
|
||||
int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) {
|
||||
int connected = 0;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
if(wm[i] == NULL) {
|
||||
WIIUSE_ERROR("Trying to connect to non-initialized Wiimote.");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND) || !wm[i]->objc_wm) {
|
||||
// If the device is not found, skip it
|
||||
continue;
|
||||
}
|
||||
|
||||
if (wiiuse_os_connect_single(wm[i]))
|
||||
++connected;
|
||||
}
|
||||
|
||||
return connected;
|
||||
}
|
||||
|
||||
void wiiuse_os_disconnect(struct wiimote_t* wm) {
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm) || !wm->objc_wm)
|
||||
return;
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
[((WiiuseWiimote*)wm->objc_wm) disconnect];
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark poll, read, write
|
||||
|
||||
int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
||||
int i;
|
||||
byte read_buffer[MAX_PAYLOAD];
|
||||
int evnt = 0;
|
||||
|
||||
if (!wm) return 0;
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
wm[i]->event = WIIUSE_NONE;
|
||||
|
||||
/* clear out the buffer */
|
||||
memset(read_buffer, 0, sizeof(read_buffer));
|
||||
/* read */
|
||||
if (wiiuse_os_read(wm[i], read_buffer, sizeof(read_buffer))) {
|
||||
/* propagate the event */
|
||||
propagate_event(wm[i], read_buffer[0], read_buffer+1);
|
||||
} else {
|
||||
/* send out any waiting writes */
|
||||
wiiuse_send_next_pending_write_request(wm[i]);
|
||||
idle_cycle(wm[i]);
|
||||
}
|
||||
|
||||
evnt += (wm[i]->event != WIIUSE_NONE);
|
||||
}
|
||||
|
||||
return evnt;
|
||||
}
|
||||
|
||||
int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) {
|
||||
if(!wm || !wm->objc_wm) return 0;
|
||||
if(!WIIMOTE_IS_CONNECTED(wm)) {
|
||||
WIIUSE_ERROR("Attempting to read from unconnected Wiimote");
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm;
|
||||
int result = [objc_wm readBuffer: buf length: len];
|
||||
|
||||
[pool drain];
|
||||
return result;
|
||||
}
|
||||
|
||||
int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len) {
|
||||
if(!wm || !wm->objc_wm) return 0;
|
||||
if(!WIIMOTE_IS_CONNECTED(wm)) {
|
||||
WIIUSE_ERROR("Attempting to write to unconnected Wiimote");
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm;
|
||||
int result = [objc_wm writeReport: report_type buffer: buf length: (NSUInteger)len];
|
||||
|
||||
[pool drain];
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark platform fields
|
||||
|
||||
void wiiuse_init_platform_fields(struct wiimote_t* wm) {
|
||||
wm->objc_wm = NULL;
|
||||
}
|
||||
|
||||
void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) {
|
||||
if(!wm) return;
|
||||
WiiuseWiimote* objc_wm = (WiiuseWiimote*) wm->objc_wm;
|
||||
|
||||
// disconnect
|
||||
// Note: this should already have happened, because this function
|
||||
// is called once the device is disconnected. This is just paranoia.
|
||||
[objc_wm disconnect];
|
||||
|
||||
// release WiiuseWiimote object
|
||||
[objc_wm release];
|
||||
wm->objc_wm = NULL;
|
||||
}
|
||||
|
||||
#endif // __APPLE__
|
||||
@@ -32,6 +32,8 @@
|
||||
*/
|
||||
|
||||
#include "io.h"
|
||||
#include "events.h"
|
||||
#include "os.h"
|
||||
|
||||
#ifdef WIIUSE_BLUEZ
|
||||
|
||||
@@ -44,28 +46,13 @@
|
||||
#include <stdio.h> /* for perror */
|
||||
#include <string.h> /* for memset */
|
||||
#include <sys/socket.h> /* for connect, socket */
|
||||
#include <sys/time.h> /* for struct timeval */
|
||||
#include <unistd.h> /* for close, write */
|
||||
#include <errno.h>
|
||||
|
||||
static int wiiuse_connect_single(struct wiimote_t* wm, char* address);
|
||||
static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address);
|
||||
|
||||
/**
|
||||
* @brief Find a wiimote or wiimotes.
|
||||
*
|
||||
* @param wm An array of wiimote_t structures.
|
||||
* @param max_wiimotes The number of wiimote structures in \a wm.
|
||||
* @param timeout The number of seconds before the search times out.
|
||||
*
|
||||
* @return The number of wiimotes found.
|
||||
*
|
||||
* @see wiimote_connect()
|
||||
*
|
||||
* This function will only look for wiimote devices. \n
|
||||
* When a device is found the address in the structures will be set. \n
|
||||
* You can then call wiimote_connect() to connect to the found \n
|
||||
* devices.
|
||||
*/
|
||||
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
int device_id;
|
||||
int device_sock;
|
||||
inquiry_info scan_info_arr[128];
|
||||
@@ -113,9 +100,8 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
/* display discovered devices */
|
||||
for (i = 0; (i < found_devices) && (found_wiimotes < max_wiimotes); ++i) {
|
||||
if ((scan_info[i].dev_class[0] == WM_DEV_CLASS_0) &&
|
||||
(scan_info[i].dev_class[1] == WM_DEV_CLASS_1) &&
|
||||
(scan_info[i].dev_class[2] == WM_DEV_CLASS_2))
|
||||
{
|
||||
(scan_info[i].dev_class[1] == WM_DEV_CLASS_1) &&
|
||||
(scan_info[i].dev_class[2] == WM_DEV_CLASS_2)) {
|
||||
/* found a device */
|
||||
ba2str(&scan_info[i].bdaddr, wm[found_wiimotes]->bdaddr_str);
|
||||
|
||||
@@ -133,32 +119,23 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Connect to a wiimote or wiimotes once an address is known.
|
||||
*
|
||||
* @param wm An array of wiimote_t structures.
|
||||
* @param wiimotes The number of wiimote structures in \a wm.
|
||||
*
|
||||
* @return The number of wiimotes that successfully connected.
|
||||
*
|
||||
* @see wiiuse_find()
|
||||
* @see wiiuse_connect_single()
|
||||
* @see wiiuse_disconnect()
|
||||
*
|
||||
* Connect to a number of wiimotes when the address is already set
|
||||
* in the wiimote_t structures. These addresses are normally set
|
||||
* by the wiiuse_find() function, but can also be set manually.
|
||||
* @see wiiuse_connect()
|
||||
* @see wiiuse_os_connect_single()
|
||||
*/
|
||||
int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
|
||||
int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) {
|
||||
int connected = 0;
|
||||
int i = 0;
|
||||
|
||||
for (; i < wiimotes; ++i) {
|
||||
if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND))
|
||||
/* if the device address is not set, skip it */
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (wiiuse_connect_single(wm[i], NULL))
|
||||
if (wiiuse_os_connect_single(wm[i], NULL)) {
|
||||
++connected;
|
||||
}
|
||||
}
|
||||
|
||||
return connected;
|
||||
@@ -170,24 +147,25 @@ int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param address The address of the device to connect to.
|
||||
* If NULL, use the address in the struct set by wiiuse_find().
|
||||
* If NULL, use the address in the struct set by wiiuse_os_find().
|
||||
*
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
static int wiiuse_connect_single(struct wiimote_t* wm, char* address) {
|
||||
static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address) {
|
||||
struct sockaddr_l2 addr;
|
||||
memset(&addr, 0, sizeof (addr));
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
addr.l2_family = AF_BLUETOOTH;
|
||||
bdaddr_t *bdaddr = &wm->bdaddr;
|
||||
if (address)
|
||||
/* use provided address */
|
||||
str2ba(address, &addr.l2_bdaddr);
|
||||
else
|
||||
{
|
||||
str2ba(address, &addr.l2_bdaddr);
|
||||
} else {
|
||||
/** @todo this line doesn't make sense
|
||||
bacmp(bdaddr, BDADDR_ANY);*/
|
||||
/* use address of device discovered */
|
||||
@@ -199,8 +177,9 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address) {
|
||||
* OUTPUT CHANNEL
|
||||
*/
|
||||
wm->out_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
|
||||
if (wm->out_sock == -1)
|
||||
if (wm->out_sock == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
addr.l2_psm = htobs(WM_OUTPUT_CHANNEL);
|
||||
|
||||
@@ -241,19 +220,10 @@ static int wiiuse_connect_single(struct wiimote_t* wm, char* address) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disconnect a wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* @see wiiuse_connect()
|
||||
*
|
||||
* Note that this will not free the wiimote structure.
|
||||
*/
|
||||
void wiiuse_disconnect(struct wiimote_t* wm) {
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
||||
void wiiuse_os_disconnect(struct wiimote_t* wm) {
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return;
|
||||
}
|
||||
|
||||
close(wm->out_sock);
|
||||
close(wm->in_sock);
|
||||
@@ -267,14 +237,138 @@ void wiiuse_disconnect(struct wiimote_t* wm) {
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_io_read(struct wiimote_t* wm) {
|
||||
/* not used */
|
||||
return 0;
|
||||
int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
||||
int evnt;
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
int r;
|
||||
int i;
|
||||
byte read_buffer[MAX_PAYLOAD];
|
||||
int highest_fd = -1;
|
||||
|
||||
evnt = 0;
|
||||
if (!wm) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* block select() for 1/2000th of a second */
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 500;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
/* only poll it if it is connected */
|
||||
if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) {
|
||||
FD_SET(wm[i]->in_sock, &fds);
|
||||
|
||||
/* find the highest fd of the connected wiimotes */
|
||||
if (wm[i]->in_sock > highest_fd) {
|
||||
highest_fd = wm[i]->in_sock;
|
||||
}
|
||||
}
|
||||
|
||||
wm[i]->event = WIIUSE_NONE;
|
||||
}
|
||||
|
||||
if (highest_fd == -1)
|
||||
/* nothing to poll */
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) {
|
||||
WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s).");
|
||||
perror("Error Details");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check each socket for an event */
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
/* if this wiimote is not connected, skip it */
|
||||
if (!WIIMOTE_IS_CONNECTED(wm[i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FD_ISSET(wm[i]->in_sock, &fds)) {
|
||||
/* clear out the event buffer */
|
||||
memset(read_buffer, 0, sizeof(read_buffer));
|
||||
|
||||
/* clear out any old read data */
|
||||
clear_dirty_reads(wm[i]);
|
||||
|
||||
/* read the pending message into the buffer */
|
||||
r = wiiuse_os_read(wm[i], read_buffer, sizeof(read_buffer));
|
||||
if (r > 0) {
|
||||
/* propagate the event */
|
||||
propagate_event(wm[i], read_buffer[0], read_buffer + 1);
|
||||
evnt += (wm[i]->event != WIIUSE_NONE);
|
||||
}
|
||||
} else {
|
||||
/* send out any waiting writes */
|
||||
wiiuse_send_next_pending_write_request(wm[i]);
|
||||
idle_cycle(wm[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return evnt;
|
||||
}
|
||||
|
||||
int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) {
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
|
||||
return write(wm->out_sock, buf, len);
|
||||
rc = read(wm->in_sock, buf, len);
|
||||
|
||||
if (rc == -1) {
|
||||
/* error reading data */
|
||||
WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid);
|
||||
perror("Error Details");
|
||||
|
||||
if (errno == ENOTCONN) {
|
||||
/* this can happen if the bluetooth dongle is disconnected */
|
||||
WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm->unid);
|
||||
wiiuse_os_disconnect(wm);
|
||||
wiiuse_disconnected(wm);
|
||||
}
|
||||
} else if (rc == 0) {
|
||||
/* remote disconnect */
|
||||
wiiuse_disconnected(wm);
|
||||
} else {
|
||||
/* read successful */
|
||||
/* on *nix we ignore the first byte */
|
||||
memmove(buf, buf + 1, len - 1);
|
||||
|
||||
/* log the received data */
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
int i;
|
||||
printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, buf[0]);
|
||||
for (i = 1; i < rc; i++) {
|
||||
printf("%.2x ", buf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len) {
|
||||
int rc;
|
||||
byte write_buffer[MAX_PAYLOAD];
|
||||
|
||||
write_buffer[0] = WM_SET_REPORT | WM_BT_OUTPUT;
|
||||
write_buffer[1] = report_type;
|
||||
memcpy(write_buffer + 2, buf, len);
|
||||
rc = write(wm->out_sock, write_buffer, len + 2);
|
||||
|
||||
if (rc < 0) {
|
||||
wiiuse_disconnected(wm);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void wiiuse_init_platform_fields(struct wiimote_t* wm) {
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
|
||||
#include "io.h"
|
||||
#include "events.h"
|
||||
#include "os.h"
|
||||
|
||||
#ifdef WIIUSE_WIN32
|
||||
#include <stdlib.h>
|
||||
@@ -52,7 +54,7 @@ extern "C" {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
GUID device_id;
|
||||
HANDLE dev;
|
||||
HDEVINFO device_info;
|
||||
@@ -82,8 +84,9 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
}
|
||||
|
||||
/* query the next hid device info */
|
||||
if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data))
|
||||
if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data)) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* get the size of the data block required */
|
||||
i = SetupDiGetDeviceInterfaceDetail(device_info, &device_data, NULL, 0, &len, NULL);
|
||||
@@ -91,16 +94,18 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
||||
|
||||
/* query the data for this device */
|
||||
if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL))
|
||||
if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* open the device */
|
||||
dev = CreateFile(detail_data->DevicePath,
|
||||
(GENERIC_READ | GENERIC_WRITE),
|
||||
(FILE_SHARE_READ | FILE_SHARE_WRITE),
|
||||
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||
if (dev == INVALID_HANDLE_VALUE)
|
||||
(GENERIC_READ | GENERIC_WRITE),
|
||||
(FILE_SHARE_READ | FILE_SHARE_WRITE),
|
||||
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||
if (dev == INVALID_HANDLE_VALUE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* get device attributes */
|
||||
attr.Size = sizeof(attr);
|
||||
@@ -129,16 +134,18 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
WIIUSE_INFO("Connected to wiimote [id %i].", wm[found]->unid);
|
||||
|
||||
++found;
|
||||
if (found >= max_wiimotes)
|
||||
if (found >= max_wiimotes) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* not a wiimote */
|
||||
CloseHandle(dev);
|
||||
}
|
||||
}
|
||||
|
||||
if (detail_data)
|
||||
if (detail_data) {
|
||||
free(detail_data);
|
||||
}
|
||||
|
||||
SetupDiDestroyDeviceInfoList(device_info);
|
||||
|
||||
@@ -146,24 +153,27 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
|
||||
int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) {
|
||||
int connected = 0;
|
||||
int i = 0;
|
||||
|
||||
for (; i < wiimotes; ++i) {
|
||||
if (!wm[i])
|
||||
if (!wm[i]) {
|
||||
continue;
|
||||
if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED))
|
||||
}
|
||||
if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) {
|
||||
++connected;
|
||||
}
|
||||
}
|
||||
|
||||
return connected;
|
||||
}
|
||||
|
||||
|
||||
void wiiuse_disconnect(struct wiimote_t* wm) {
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
||||
void wiiuse_os_disconnect(struct wiimote_t* wm) {
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CloseHandle(wm->dev_handle);
|
||||
wm->dev_handle = 0;
|
||||
@@ -177,13 +187,43 @@ void wiiuse_disconnect(struct wiimote_t* wm) {
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_io_read(struct wiimote_t* wm) {
|
||||
int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
||||
int i;
|
||||
byte read_buffer[MAX_PAYLOAD];
|
||||
int evnt = 0;
|
||||
|
||||
if (!wm) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
wm[i]->event = WIIUSE_NONE;
|
||||
|
||||
/* clear out the buffer */
|
||||
memset(read_buffer, 0, sizeof(read_buffer));
|
||||
/* read */
|
||||
if (wiiuse_os_read(wm[i], read_buffer, sizeof(read_buffer))) {
|
||||
/* propagate the event */
|
||||
propagate_event(wm[i], read_buffer[0], read_buffer + 1);
|
||||
evnt += (wm[i]->event != WIIUSE_NONE);
|
||||
} else {
|
||||
/* send out any waiting writes */
|
||||
wiiuse_send_next_pending_write_request(wm[i]);
|
||||
idle_cycle(wm[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return evnt;
|
||||
}
|
||||
|
||||
int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) {
|
||||
DWORD b, r;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ReadFile(wm->dev_handle, wm->event_buf, sizeof(wm->event_buf), &b, &wm->hid_overlap)) {
|
||||
if (!ReadFile(wm->dev_handle, buf, len, &b, &wm->hid_overlap)) {
|
||||
/* partial read */
|
||||
b = GetLastError();
|
||||
|
||||
@@ -197,8 +237,9 @@ int wiiuse_io_read(struct wiimote_t* wm) {
|
||||
if (r == WAIT_TIMEOUT) {
|
||||
/* timeout - cancel and continue */
|
||||
|
||||
if (*wm->event_buf)
|
||||
if (*buf) {
|
||||
WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout);
|
||||
}
|
||||
|
||||
CancelIo(wm->dev_handle);
|
||||
ResetEvent(wm->hid_overlap.hEvent);
|
||||
@@ -208,8 +249,21 @@ int wiiuse_io_read(struct wiimote_t* wm) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0))
|
||||
if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* log the received data */
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
DWORD i;
|
||||
printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, buf[0]);
|
||||
for (i = 1; i < b; i++) {
|
||||
printf("%.2x ", buf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ResetEvent(wm->hid_overlap.hEvent);
|
||||
@@ -217,37 +271,41 @@ int wiiuse_io_read(struct wiimote_t* wm) {
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
|
||||
int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len) {
|
||||
DWORD bytes;
|
||||
int i;
|
||||
byte write_buffer[MAX_PAYLOAD];
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
write_buffer[0] = report_type;
|
||||
memcpy(write_buffer + 1, buf, len);
|
||||
|
||||
switch (wm->stack) {
|
||||
case WIIUSE_STACK_UNKNOWN:
|
||||
{
|
||||
/* try to auto-detect the stack type */
|
||||
if (i = WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap)) {
|
||||
/* bluesoleil will always return 1 here, even if it's not connected */
|
||||
wm->stack = WIIUSE_STACK_BLUESOLEIL;
|
||||
return i;
|
||||
}
|
||||
case WIIUSE_STACK_UNKNOWN: {
|
||||
/* try to auto-detect the stack type */
|
||||
if (i = WriteFile(wm->dev_handle, write_buffer, 22, &bytes, &wm->hid_overlap)) {
|
||||
/* bluesoleil will always return 1 here, even if it's not connected */
|
||||
wm->stack = WIIUSE_STACK_BLUESOLEIL;
|
||||
return i;
|
||||
}
|
||||
|
||||
if (i = HidD_SetOutputReport(wm->dev_handle, buf, len)) {
|
||||
wm->stack = WIIUSE_STACK_MS;
|
||||
return i;
|
||||
}
|
||||
if (i = HidD_SetOutputReport(wm->dev_handle, write_buffer, len + 1)) {
|
||||
wm->stack = WIIUSE_STACK_MS;
|
||||
return i;
|
||||
}
|
||||
|
||||
WIIUSE_ERROR("Unable to determine bluetooth stack type.");
|
||||
return 0;
|
||||
}
|
||||
WIIUSE_ERROR("Unable to determine bluetooth stack type.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WIIUSE_STACK_MS:
|
||||
return HidD_SetOutputReport(wm->dev_handle, buf, len);
|
||||
return HidD_SetOutputReport(wm->dev_handle, write_buffer, len + 1);
|
||||
|
||||
case WIIUSE_STACK_BLUESOLEIL:
|
||||
return WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap);
|
||||
return WriteFile(wm->dev_handle, write_buffer, 22, &bytes, &wm->hid_overlap);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -53,14 +53,13 @@ int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
int i;
|
||||
printf("DECRYPTED DATA WIIBOARD\n");
|
||||
for (i = 0; i < len; ++i)
|
||||
{
|
||||
if(i%16==0)
|
||||
{
|
||||
if(i!=0)
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (i % 16 == 0) {
|
||||
if (i != 0) {
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("%X: ",0x4a40000+32+i);
|
||||
printf("%X: ", 0x4a40000 + 32 + i);
|
||||
}
|
||||
printf("%02X ", data[i]);
|
||||
}
|
||||
@@ -87,9 +86,9 @@ int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data
|
||||
wm->event = WIIUSE_WII_BOARD_CTRL_INSERTED;
|
||||
wm->exp.type = EXP_WII_BOARD;
|
||||
|
||||
#ifdef WIIUSE_WIN32
|
||||
#ifdef WIIUSE_WIN32
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -109,9 +108,9 @@ static float do_interpolate(uint16_t raw, uint16_t cal[3]) {
|
||||
if (raw < cal[0]) {
|
||||
return 0.0f;
|
||||
} else if (raw < cal[1]) {
|
||||
return ((float)(raw-cal[0]) * WIIBOARD_MIDDLE_CALIB)/(float)(cal[1] - cal[0]);
|
||||
return ((float)(raw - cal[0]) * WIIBOARD_MIDDLE_CALIB) / (float)(cal[1] - cal[0]);
|
||||
} else if (raw < cal[2]) {
|
||||
return ((float)(raw-cal[1]) * WIIBOARD_MIDDLE_CALIB)/(float)(cal[2] - cal[1]) + WIIBOARD_MIDDLE_CALIB;
|
||||
return ((float)(raw - cal[1]) * WIIBOARD_MIDDLE_CALIB) / (float)(cal[2] - cal[1]) + WIIBOARD_MIDDLE_CALIB;
|
||||
} else {
|
||||
return WIIBOARD_MIDDLE_CALIB * 2.0f;
|
||||
}
|
||||
@@ -143,6 +142,5 @@ void wii_board_event(struct wii_board_t* wb, byte* msg) {
|
||||
/**
|
||||
@todo not implemented!
|
||||
*/
|
||||
void wiiuse_set_wii_board_calib(struct wiimote_t *wm)
|
||||
{
|
||||
void wiiuse_set_wii_board_calib(struct wiimote_t *wm) {
|
||||
}
|
||||
|
||||
@@ -40,14 +40,14 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup internal_wiiboard Internal: Wii Balance Board */
|
||||
/** @{ */
|
||||
int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data, uint16_t len);
|
||||
/** @defgroup internal_wiiboard Internal: Wii Balance Board */
|
||||
/** @{ */
|
||||
int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data, uint16_t len);
|
||||
|
||||
void wii_board_disconnected(struct wii_board_t* wb);
|
||||
void wii_board_disconnected(struct wii_board_t* wb);
|
||||
|
||||
void wii_board_event(struct wii_board_t* wb, byte* msg);
|
||||
/** @} */
|
||||
void wii_board_event(struct wii_board_t* wb, byte* msg);
|
||||
/** @} */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
269
src/wiiuse.c
269
src/wiiuse.c
@@ -37,6 +37,7 @@
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
#include "io.h" /* for wiiuse_handshake, etc */
|
||||
#include "os.h" /* for wiiuse_os_* */
|
||||
|
||||
#include <stdio.h> /* for printf, FILE */
|
||||
#include <stdlib.h> /* for malloc, free */
|
||||
@@ -66,8 +67,7 @@ FILE* logtarget[4];
|
||||
*
|
||||
* The default <code>FILE*</code> for all loglevels is <code>stderr</code>
|
||||
*/
|
||||
void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logfile)
|
||||
{
|
||||
void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logfile) {
|
||||
logtarget[(int)loglevel] = logfile;
|
||||
}
|
||||
|
||||
@@ -77,13 +77,15 @@ void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logfile)
|
||||
void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes) {
|
||||
int i = 0;
|
||||
|
||||
if (!wm)
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
WIIUSE_INFO("wiiuse clean up...");
|
||||
|
||||
for (; i < wiimotes; ++i) {
|
||||
wiiuse_disconnect(wm[i]);
|
||||
wiiuse_cleanup_platform_fields(wm[i]);
|
||||
free(wm[i]);
|
||||
}
|
||||
|
||||
@@ -118,9 +120,9 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
|
||||
* to call this function again it won't be intrusive.
|
||||
*/
|
||||
if (!g_banner) {
|
||||
printf( "wiiuse v" WIIUSE_VERSION " loaded.\n"
|
||||
" Fork at http://github.com/rpavlik/wiiuse\n"
|
||||
" Original By: Michael Laforest <thepara[at]gmail{dot}com> http://wiiuse.net\n");
|
||||
printf("wiiuse v" WIIUSE_VERSION " loaded.\n"
|
||||
" Fork at http://github.com/rpavlik/wiiuse\n"
|
||||
" Original By: Michael Laforest <thepara[at]gmail{dot}com> http://wiiuse.net\n");
|
||||
g_banner = 1;
|
||||
}
|
||||
|
||||
@@ -129,8 +131,9 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
|
||||
logtarget[2] = stderr;
|
||||
logtarget[3] = stderr;
|
||||
|
||||
if (!wiimotes)
|
||||
if (!wiimotes) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wm = malloc(sizeof(struct wiimote_t*) * wiimotes);
|
||||
|
||||
@@ -138,7 +141,7 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
|
||||
wm[i] = malloc(sizeof(struct wiimote_t));
|
||||
memset(wm[i], 0, sizeof(struct wiimote_t));
|
||||
|
||||
wm[i]->unid = i+1;
|
||||
wm[i]->unid = i + 1;
|
||||
wiiuse_init_platform_fields(wm[i]);
|
||||
|
||||
wm[i]->state = WIIMOTE_INIT_STATES;
|
||||
@@ -168,7 +171,9 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
void wiiuse_disconnected(struct wiimote_t* wm) {
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
WIIUSE_INFO("Wiimote disconnected [id %i].", wm->unid);
|
||||
|
||||
@@ -176,16 +181,15 @@ void wiiuse_disconnected(struct wiimote_t* wm) {
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
|
||||
/* reset a bunch of stuff */
|
||||
wiiuse_cleanup_platform_fields(wm);
|
||||
|
||||
wm->leds = 0;
|
||||
wm->state = WIIMOTE_INIT_STATES;
|
||||
wm->read_req = NULL;
|
||||
#ifndef WIIUSE_SYNC_HANDSHAKE
|
||||
wm->handshake_state = 0;
|
||||
#endif
|
||||
wm->btns = 0;
|
||||
wm->btns_held = 0;
|
||||
wm->btns_released = 0;
|
||||
memset(wm->event_buf, 0, sizeof(wm->event_buf));
|
||||
|
||||
wm->event = WIIUSE_DISCONNECT;
|
||||
}
|
||||
@@ -200,8 +204,9 @@ void wiiuse_disconnected(struct wiimote_t* wm) {
|
||||
void wiiuse_rumble(struct wiimote_t* wm, int status) {
|
||||
byte buf;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* make sure to keep the current lit leds */
|
||||
buf = wm->leds;
|
||||
@@ -217,8 +222,9 @@ void wiiuse_rumble(struct wiimote_t* wm, int status) {
|
||||
}
|
||||
|
||||
/* preserve IR state */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
buf |= 0x04;
|
||||
}
|
||||
|
||||
wiiuse_send(wm, WM_CMD_RUMBLE, &buf, 1);
|
||||
}
|
||||
@@ -230,7 +236,9 @@ void wiiuse_rumble(struct wiimote_t* wm, int status) {
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
void wiiuse_toggle_rumble(struct wiimote_t* wm) {
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
wiiuse_rumble(wm, !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE));
|
||||
}
|
||||
@@ -247,15 +255,17 @@ void wiiuse_toggle_rumble(struct wiimote_t* wm) {
|
||||
void wiiuse_set_leds(struct wiimote_t* wm, int leds) {
|
||||
byte buf;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* remove the lower 4 bits because they control rumble */
|
||||
wm->leds = (leds & 0xF0);
|
||||
|
||||
/* make sure if the rumble is on that we keep it on */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) {
|
||||
wm->leds |= 0x01;
|
||||
}
|
||||
|
||||
buf = wm->leds;
|
||||
|
||||
@@ -274,10 +284,11 @@ void wiiuse_set_leds(struct wiimote_t* wm, int leds) {
|
||||
* by default.
|
||||
*/
|
||||
void wiiuse_motion_sensing(struct wiimote_t* wm, int status) {
|
||||
if (status)
|
||||
if (status) {
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_ACC);
|
||||
else
|
||||
} else {
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC);
|
||||
}
|
||||
|
||||
wiiuse_set_report_type(wm);
|
||||
}
|
||||
@@ -299,34 +310,46 @@ int wiiuse_set_report_type(struct wiimote_t* wm) {
|
||||
byte buf[2];
|
||||
int motion, exp, ir;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
buf[0] = (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_CONTINUOUS) ? 0x04 : 0x00); /* set to 0x04 for continuous reporting */
|
||||
buf[1] = 0x00;
|
||||
|
||||
/* if rumble is enabled, make sure we keep it */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) {
|
||||
buf[0] |= 0x01;
|
||||
}
|
||||
|
||||
motion = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC);
|
||||
exp = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP);
|
||||
ir = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR);
|
||||
|
||||
if (motion && ir && exp) buf[1] = WM_RPT_BTN_ACC_IR_EXP;
|
||||
else if (motion && exp) buf[1] = WM_RPT_BTN_ACC_EXP;
|
||||
else if (motion && ir) buf[1] = WM_RPT_BTN_ACC_IR;
|
||||
else if (ir && exp) buf[1] = WM_RPT_BTN_IR_EXP;
|
||||
else if (ir) buf[1] = WM_RPT_BTN_ACC_IR;
|
||||
else if (exp) buf[1] = WM_RPT_BTN_EXP;
|
||||
else if (motion) buf[1] = WM_RPT_BTN_ACC;
|
||||
else buf[1] = WM_RPT_BTN;
|
||||
if (motion && ir && exp) {
|
||||
buf[1] = WM_RPT_BTN_ACC_IR_EXP;
|
||||
} else if (motion && exp) {
|
||||
buf[1] = WM_RPT_BTN_ACC_EXP;
|
||||
} else if (motion && ir) {
|
||||
buf[1] = WM_RPT_BTN_ACC_IR;
|
||||
} else if (ir && exp) {
|
||||
buf[1] = WM_RPT_BTN_IR_EXP;
|
||||
} else if (ir) {
|
||||
buf[1] = WM_RPT_BTN_ACC_IR;
|
||||
} else if (exp) {
|
||||
buf[1] = WM_RPT_BTN_EXP;
|
||||
} else if (motion) {
|
||||
buf[1] = WM_RPT_BTN_ACC;
|
||||
} else {
|
||||
buf[1] = WM_RPT_BTN;
|
||||
}
|
||||
|
||||
WIIUSE_DEBUG("Setting report type: 0x%x", buf[1]);
|
||||
|
||||
exp = wiiuse_send(wm, WM_CMD_REPORT_TYPE, buf, 2);
|
||||
if (exp <= 0)
|
||||
if (exp <= 0) {
|
||||
return exp;
|
||||
}
|
||||
|
||||
return buf[1];
|
||||
}
|
||||
@@ -352,15 +375,18 @@ int wiiuse_set_report_type(struct wiimote_t* wm) {
|
||||
int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int addr, uint16_t len) {
|
||||
struct read_req_t* req;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return 0;
|
||||
if (!buffer || !len)
|
||||
}
|
||||
if (!buffer || !len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* make this request structure */
|
||||
req = (struct read_req_t*)malloc(sizeof(struct read_req_t));
|
||||
if (req == NULL)
|
||||
if (req == NULL) {
|
||||
return 0;
|
||||
}
|
||||
req->cb = read_cb;
|
||||
req->buf = buffer;
|
||||
req->addr = addr;
|
||||
@@ -380,7 +406,9 @@ int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buff
|
||||
wiiuse_send_next_pending_read_request(wm);
|
||||
} else {
|
||||
struct read_req_t* nptr = wm->read_req;
|
||||
for (; nptr->next; nptr = nptr->next);
|
||||
for (; nptr->next; nptr = nptr->next) {
|
||||
;
|
||||
}
|
||||
nptr->next = req;
|
||||
|
||||
WIIUSE_DEBUG("Added pending data read request.");
|
||||
@@ -424,16 +452,21 @@ void wiiuse_send_next_pending_read_request(struct wiimote_t* wm) {
|
||||
byte buf[6];
|
||||
struct read_req_t* req;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return;
|
||||
if (!wm->read_req) return;
|
||||
}
|
||||
if (!wm->read_req) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* skip over dirty ones since they have already been read */
|
||||
req = wm->read_req;
|
||||
while (req && req->dirty)
|
||||
while (req && req->dirty) {
|
||||
req = req->next;
|
||||
if (!req)
|
||||
}
|
||||
if (!req) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* the offset is in big endian */
|
||||
to_big_endian_uint32_t(buf, req->addr);
|
||||
@@ -456,8 +489,9 @@ void wiiuse_send_next_pending_read_request(struct wiimote_t* wm) {
|
||||
void wiiuse_status(struct wiimote_t* wm) {
|
||||
byte buf = 0;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return;
|
||||
}
|
||||
|
||||
WIIUSE_DEBUG("Requested wiimote status.");
|
||||
|
||||
@@ -476,14 +510,17 @@ void wiiuse_status(struct wiimote_t* wm) {
|
||||
*/
|
||||
struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid) {
|
||||
int i = 0;
|
||||
if (!wm)
|
||||
if (!wm) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (; i < wiimotes; ++i) {
|
||||
if (!wm[i])
|
||||
if (!wm[i]) {
|
||||
continue;
|
||||
if (wm[i]->unid == unid)
|
||||
}
|
||||
if (wm[i]->unid == unid) {
|
||||
return wm[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -502,22 +539,25 @@ int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, const byte* data,
|
||||
byte buf[21] = {0}; /* the payload is always 23 */
|
||||
|
||||
byte * bufPtr = buf;
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return 0;
|
||||
if (!data || !len)
|
||||
}
|
||||
if (!data || !len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
WIIUSE_DEBUG("Writing %i bytes to memory location 0x%x...", len, addr);
|
||||
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
int i = 0;
|
||||
printf("Write data is: ");
|
||||
for (; i < len; ++i)
|
||||
for (; i < len; ++i) {
|
||||
printf("%x ", data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* the offset is in big endian */
|
||||
buffer_big_endian_uint32_t(&bufPtr, (uint32_t)addr);
|
||||
@@ -548,17 +588,20 @@ int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, const byte* data,
|
||||
* to a pending list and be sent out when the previous
|
||||
* finishes.
|
||||
*/
|
||||
int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte *data, byte len, wiiuse_write_cb write_cb)
|
||||
{
|
||||
int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte *data, byte len, wiiuse_write_cb write_cb) {
|
||||
struct data_req_t* req;
|
||||
|
||||
if(!wm || !WIIMOTE_IS_CONNECTED(wm)) return 0;
|
||||
if( !data || !len ) return 0;
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return 0;
|
||||
}
|
||||
if (!data || !len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
req = (struct data_req_t*)malloc(sizeof(struct data_req_t));
|
||||
req->cb = write_cb;
|
||||
req->len = len;
|
||||
memcpy(req->data,data,req->len);
|
||||
memcpy(req->data, data, req->len);
|
||||
req->state = REQ_READY;
|
||||
req->addr = addr;/* BIG_ENDIAN_LONG(addr); */
|
||||
req->next = NULL;
|
||||
@@ -573,8 +616,10 @@ int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte *data, by
|
||||
wiiuse_send_next_pending_write_request(wm);
|
||||
} else {
|
||||
struct data_req_t* nptr = wm->data_req;
|
||||
WIIUSE_DEBUG("chaud2fois");
|
||||
for (; nptr->next; nptr = nptr->next);
|
||||
WIIUSE_DEBUG("chaud2fois");
|
||||
for (; nptr->next; nptr = nptr->next) {
|
||||
;
|
||||
}
|
||||
nptr->next = req;
|
||||
|
||||
WIIUSE_DEBUG("Added pending data write request.");
|
||||
@@ -595,14 +640,19 @@ WIIUSE_DEBUG("chaud2fois");
|
||||
void wiiuse_send_next_pending_write_request(struct wiimote_t* wm) {
|
||||
struct data_req_t* req;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||
return;
|
||||
}
|
||||
req = wm->data_req;
|
||||
if (!req)
|
||||
if (!req) {
|
||||
return;
|
||||
if (!req->data || !req->len)
|
||||
}
|
||||
if (!req->data || !req->len) {
|
||||
return;
|
||||
if(req->state!=REQ_READY) return;
|
||||
}
|
||||
if (req->state != REQ_READY) {
|
||||
return;
|
||||
}
|
||||
|
||||
wiiuse_write_data(wm, req->addr, req->data, req->len);
|
||||
|
||||
@@ -615,65 +665,38 @@ void wiiuse_send_next_pending_write_request(struct wiimote_t* wm) {
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param report_type The report type to send (WIIMOTE_CMD_LED, WIIMOTE_CMD_RUMBLE, etc). Found in wiiuse.h
|
||||
* @param msg The payload.
|
||||
* @param msg The payload. Might be changed by the callee.
|
||||
* @param len Length of the payload in bytes.
|
||||
*
|
||||
* This function should replace any write()s directly to the wiimote device.
|
||||
*/
|
||||
int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
|
||||
byte buf[32]; /* no payload is better than this */
|
||||
int rumble = 0;
|
||||
|
||||
#ifdef WIIUSE_WIN32
|
||||
buf[0] = report_type;
|
||||
#else
|
||||
buf[0] = WM_SET_REPORT | WM_BT_OUTPUT;
|
||||
buf[1] = report_type;
|
||||
#endif
|
||||
|
||||
switch (report_type) {
|
||||
case WM_CMD_LED:
|
||||
case WM_CMD_RUMBLE:
|
||||
case WM_CMD_CTRL_STATUS:
|
||||
{
|
||||
/* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
|
||||
rumble = 1;
|
||||
break;
|
||||
}
|
||||
case WM_CMD_CTRL_STATUS: {
|
||||
/* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) {
|
||||
msg[0] |= 0x01;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef WIIUSE_WIN32
|
||||
memcpy(buf+2, msg, len);
|
||||
if (rumble)
|
||||
buf[2] |= 0x01;
|
||||
#else
|
||||
memcpy(buf+1, msg, len);
|
||||
if (rumble)
|
||||
buf[1] |= 0x01;
|
||||
#endif
|
||||
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
int x = 2;
|
||||
printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
|
||||
#ifndef WIIUSE_WIN32
|
||||
for (; x < len+2; ++x)
|
||||
#else
|
||||
for (; x < len+1; ++x)
|
||||
#endif
|
||||
printf("%.2x ", buf[x]);
|
||||
int x;
|
||||
printf("[DEBUG] (id %i) SEND: (%.2x) %.2x ", wm->unid, report_type, msg[0]);
|
||||
for (x = 1; x < len; ++x) {
|
||||
printf("%.2x ", msg[x]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef WIIUSE_WIN32
|
||||
return wiiuse_io_write(wm, buf, len+2);
|
||||
#else
|
||||
return wiiuse_io_write(wm, buf, len+1);
|
||||
#endif
|
||||
return wiiuse_os_write(wm, report_type, msg, len);
|
||||
}
|
||||
|
||||
|
||||
@@ -690,7 +713,9 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
|
||||
* Flags are defined in wiiuse.h.
|
||||
*/
|
||||
int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable) {
|
||||
if (!wm) return 0;
|
||||
if (!wm) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* remove mutually exclusive flags */
|
||||
enable &= ~disable;
|
||||
@@ -719,15 +744,18 @@ int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable) {
|
||||
float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha) {
|
||||
float old;
|
||||
|
||||
if (!wm) return 0.0f;
|
||||
if (!wm) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
old = wm->accel_calib.st_alpha;
|
||||
|
||||
wm->accel_calib.st_alpha = alpha;
|
||||
|
||||
/* if there is a nunchuk set that too */
|
||||
if (wm->exp.type == EXP_NUNCHUK)
|
||||
if (wm->exp.type == EXP_NUNCHUK) {
|
||||
wm->exp.nunchuk.accel_calib.st_alpha = alpha;
|
||||
}
|
||||
|
||||
return old;
|
||||
}
|
||||
@@ -741,14 +769,17 @@ float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha) {
|
||||
* @param type The type of bluetooth stack to use.
|
||||
*/
|
||||
void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type) {
|
||||
#ifdef WIIUSE_WIN32
|
||||
#ifdef WIIUSE_WIN32
|
||||
int i;
|
||||
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < wiimotes; ++i)
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
wm[i]->stack = type;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -763,7 +794,9 @@ void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt
|
||||
* the angle has to change by a full degree to generate an event.
|
||||
*/
|
||||
void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold) {
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
wm->orient_threshold = threshold;
|
||||
}
|
||||
@@ -776,7 +809,9 @@ void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold) {
|
||||
* @param threshold The decimal place that should be considered a significant change.
|
||||
*/
|
||||
void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) {
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
wm->accel_threshold = threshold;
|
||||
}
|
||||
@@ -788,9 +823,13 @@ void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) {
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
void wiiuse_resync(struct wiimote_t* wm) {
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef WIIUSE_SYNC_HANDSHAKE
|
||||
wm->handshake_state = 0;
|
||||
#endif
|
||||
wiiuse_handshake(wm, NULL, 0);
|
||||
}
|
||||
|
||||
@@ -804,14 +843,16 @@ void wiiuse_resync(struct wiimote_t* wm) {
|
||||
* @param exp_timeout The timeout in millisecondsd to wait for an expansion handshake.
|
||||
*/
|
||||
void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout) {
|
||||
#ifdef WIIUSE_WIN32
|
||||
#ifdef WIIUSE_WIN32
|
||||
int i;
|
||||
|
||||
if (!wm) return;
|
||||
if (!wm) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
wm[i]->normal_timeout = normal_timeout;
|
||||
wm[i]->exp_timeout = exp_timeout;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
213
src/wiiuse.h
213
src/wiiuse.h
@@ -99,11 +99,6 @@
|
||||
/* nix */
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#endif
|
||||
#ifdef WIIUSE_MAC
|
||||
/* mac */
|
||||
#include <CoreFoundation/CoreFoundation.h> /*CFRunLoops and CFNumberRef in Bluetooth classes*/
|
||||
#include <IOBluetooth/IOBluetoothUserLib.h> /*IOBluetoothDeviceRef and IOBluetoothL2CAPChannelRef*/
|
||||
#endif
|
||||
|
||||
#ifndef WCONST
|
||||
#define WCONST const
|
||||
@@ -124,6 +119,33 @@
|
||||
/** @defgroup publicapi External API */
|
||||
/** @{ */
|
||||
|
||||
/** @name Wiimote state flags and macros */
|
||||
/** @{ */
|
||||
#define WIIMOTE_STATE_DEV_FOUND 0x0001
|
||||
#define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_CONNECTED 0x0008
|
||||
#define WIIMOTE_STATE_RUMBLE 0x0010
|
||||
#define WIIMOTE_STATE_ACC 0x0020
|
||||
#define WIIMOTE_STATE_EXP 0x0040
|
||||
#define WIIMOTE_STATE_IR 0x0080
|
||||
#define WIIMOTE_STATE_SPEAKER 0x0100
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL1 0x0200
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL2 0x0400
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL3 0x0800
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL4 0x1000
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL5 0x2000
|
||||
#define WIIMOTE_STATE_EXP_HANDSHAKE 0x10000 /* actual M+ connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_EXP_EXTERN 0x20000 /* actual M+ connection exists but handshake failed */
|
||||
#define WIIMOTE_STATE_EXP_FAILED 0x40000 /* actual M+ connection exists but handshake failed */
|
||||
#define WIIMOTE_STATE_MPLUS_PRESENT 0x80000 /* Motion+ is connected */
|
||||
|
||||
#define WIIMOTE_ID(wm) (wm->unid)
|
||||
|
||||
#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
|
||||
#define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
|
||||
/** @} */
|
||||
|
||||
/** @name LED bit masks */
|
||||
/** @{ */
|
||||
#define WIIMOTE_LED_NONE 0x00
|
||||
@@ -285,12 +307,6 @@ typedef enum ir_position_t {
|
||||
#define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
|
||||
/** @} */
|
||||
|
||||
/*
|
||||
* Largest known payload is 21 bytes.
|
||||
* Add 2 for the prefix and round up to a power of 2.
|
||||
*/
|
||||
#define MAX_PAYLOAD 32
|
||||
|
||||
/*
|
||||
* This is left over from an old hack, but it may actually
|
||||
* be a useful feature to keep so it wasn't removed.
|
||||
@@ -300,6 +316,9 @@ typedef enum ir_position_t {
|
||||
#define WIIMOTE_EXP_TIMEOUT 10
|
||||
#endif
|
||||
|
||||
#define WIIUSE_SYNC_HANDSHAKE
|
||||
|
||||
|
||||
typedef unsigned char byte;
|
||||
typedef char sbyte;
|
||||
|
||||
@@ -344,7 +363,7 @@ struct read_req_t {
|
||||
* @brief Roll/Pitch/Yaw short angles.
|
||||
*/
|
||||
typedef struct ang3s_t {
|
||||
int16_t roll, pitch, yaw;
|
||||
int16_t roll, pitch, yaw;
|
||||
} ang3s_t;
|
||||
|
||||
/**
|
||||
@@ -352,7 +371,7 @@ typedef struct ang3s_t {
|
||||
* @brief Roll/Pitch/Yaw float angles.
|
||||
*/
|
||||
typedef struct ang3f_t {
|
||||
float roll, pitch, yaw;
|
||||
float roll, pitch, yaw;
|
||||
} ang3f_t;
|
||||
|
||||
/**
|
||||
@@ -547,9 +566,8 @@ typedef struct guitar_hero_3_t {
|
||||
/**
|
||||
* @brief Motion Plus expansion device
|
||||
*/
|
||||
typedef struct motion_plus_t
|
||||
{
|
||||
byte ext; /**< is there a device on the pass-through port? */
|
||||
typedef struct motion_plus_t {
|
||||
byte ext; /**< is there a device on the pass-through port? */
|
||||
|
||||
struct ang3s_t raw_gyro; /**< current raw gyroscope data */
|
||||
struct ang3s_t cal_gyro; /**< calibration raw gyroscope data */
|
||||
@@ -558,7 +576,7 @@ typedef struct motion_plus_t
|
||||
byte acc_mode; /**< Fast/slow rotation mode for roll, pitch and yaw (0 if rotating fast, 1 if slow or still) */
|
||||
int raw_gyro_threshold; /**< threshold for gyroscopes to generate an event */
|
||||
|
||||
struct nunchuk_t *nc; /**< pointers to nunchuk & classic in pass-through-mode */
|
||||
struct nunchuk_t *nc; /**< pointers to nunchuk & classic in pass-through-mode */
|
||||
struct classic_ctrl_t *classic;
|
||||
} motion_plus_t;
|
||||
|
||||
@@ -699,45 +717,34 @@ typedef enum WIIUSE_EVENT_TYPE {
|
||||
typedef struct wiimote_t {
|
||||
WCONST int unid; /**< user specified id */
|
||||
|
||||
#ifdef WIIUSE_BLUEZ
|
||||
#ifdef WIIUSE_BLUEZ
|
||||
/** @name Linux-specific (BlueZ) members */
|
||||
/** @{ */
|
||||
WCONST bdaddr_t bdaddr; /**< bt address */
|
||||
WCONST int out_sock; /**< output socket */
|
||||
WCONST int in_sock; /**< input socket */
|
||||
WCONST char bdaddr_str[18]; /**< readable bt address */
|
||||
WCONST bdaddr_t bdaddr; /**< bt address */
|
||||
WCONST int out_sock; /**< output socket */
|
||||
WCONST int in_sock; /**< input socket */
|
||||
/** @} */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WIIUSE_WIN32
|
||||
#ifdef WIIUSE_WIN32
|
||||
/** @name Windows-specific members */
|
||||
/** @{ */
|
||||
WCONST HANDLE dev_handle; /**< HID handle */
|
||||
WCONST OVERLAPPED hid_overlap; /**< overlap handle */
|
||||
WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */
|
||||
WCONST int timeout; /**< read timeout */
|
||||
WCONST byte normal_timeout; /**< normal timeout */
|
||||
WCONST byte exp_timeout; /**< timeout for expansion handshake */
|
||||
WCONST HANDLE dev_handle; /**< HID handle */
|
||||
WCONST OVERLAPPED hid_overlap; /**< overlap handle */
|
||||
WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */
|
||||
WCONST int timeout; /**< read timeout */
|
||||
WCONST byte normal_timeout; /**< normal timeout */
|
||||
WCONST byte exp_timeout; /**< timeout for expansion handshake */
|
||||
/** @} */
|
||||
#endif
|
||||
|
||||
#ifdef WIIUSE_MAC
|
||||
/** @name Mac OS X-specific members */
|
||||
/** @{ */
|
||||
WCONST IOBluetoothDeviceRef device; /** Device reference object */
|
||||
WCONST CFStringRef address; /** MacOS-like device address string */
|
||||
WCONST IOBluetoothL2CAPChannelRef inputCh; /** Input L2CAP channel */
|
||||
WCONST IOBluetoothL2CAPChannelRef outputCh; /** Output L2CAP channel */
|
||||
WCONST IOBluetoothUserNotificationRef disconnectionRef; /** Disconnection Notification Reference **/
|
||||
WCONST void* connectionHandler; /** Wiimote connection handler for MACOSX **/
|
||||
/** @} */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(WIIUSE_BLUEZ) || defined(WIIUSE_MAC)
|
||||
/** @name Linux (BlueZ) and Mac OS X shared members */
|
||||
#ifdef WIIUSE_MAC
|
||||
/** @name Mac OS X-specific members */
|
||||
/** @{ */
|
||||
WCONST char bdaddr_str[18]; /**< readable bt address */
|
||||
WCONST void* objc_wm; /** WiiuseWiimote* as opaque pointer */
|
||||
/** @} */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
WCONST int state; /**< various state flags */
|
||||
WCONST byte leds; /**< currently lit leds */
|
||||
@@ -745,8 +752,10 @@ typedef struct wiimote_t {
|
||||
|
||||
WCONST int flags; /**< options flag */
|
||||
|
||||
#ifndef WIIUSE_SYNC_HANDSHAKE
|
||||
WCONST byte handshake_state; /**< the state of the connection handshake */
|
||||
WCONST byte expansion_state; /**< the state of the expansion handshake */
|
||||
#endif
|
||||
WCONST byte expansion_state; /**< the state of the expansion handshake */
|
||||
WCONST struct data_req_t* data_req; /**< list of data read requests */
|
||||
|
||||
WCONST struct read_req_t* read_req; /**< list of data read requests */
|
||||
@@ -769,7 +778,6 @@ typedef struct wiimote_t {
|
||||
WCONST struct wiimote_state_t lstate; /**< last saved state */
|
||||
|
||||
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occurred */
|
||||
WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */
|
||||
WCONST byte motion_plus_id[6];
|
||||
} wiimote;
|
||||
|
||||
@@ -808,8 +816,7 @@ typedef void (*wiiuse_update_cb)(struct wiimote_callback_data_t* wm);
|
||||
*/
|
||||
typedef void (*wiiuse_write_cb)(struct wiimote_t* wm, unsigned char* data, unsigned short len);
|
||||
|
||||
typedef enum data_req_s
|
||||
{
|
||||
typedef enum data_req_s {
|
||||
REQ_READY = 0,
|
||||
REQ_SENT,
|
||||
REQ_DONE
|
||||
@@ -868,69 +875,69 @@ typedef enum wiiuse_loglevel {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* wiiuse.c */
|
||||
WIIUSE_EXPORT extern const char* wiiuse_version();
|
||||
/* wiiuse.c */
|
||||
WIIUSE_EXPORT extern const char* wiiuse_version();
|
||||
|
||||
/** @brief Define indicating the presence of the feature allowing you to
|
||||
* redirect output for one or more logging levels within the library.
|
||||
*/
|
||||
/** @brief Define indicating the presence of the feature allowing you to
|
||||
* redirect output for one or more logging levels within the library.
|
||||
*/
|
||||
#define WIIUSE_HAS_OUTPUT_REDIRECTION
|
||||
WIIUSE_EXPORT extern void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logtarget);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logtarget);
|
||||
|
||||
WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds);
|
||||
WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, uint16_t len);
|
||||
WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, const byte* data, byte len);
|
||||
WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid);
|
||||
WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable);
|
||||
WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds);
|
||||
WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, uint16_t len);
|
||||
WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, const byte* data, byte len);
|
||||
WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid);
|
||||
WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable);
|
||||
WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
|
||||
/* connect.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
|
||||
WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm);
|
||||
/* io.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
|
||||
WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm);
|
||||
|
||||
/* events.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes);
|
||||
/* events.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes);
|
||||
|
||||
/**
|
||||
* @brief Poll Wiimotes, and call the provided callback with information
|
||||
* on each Wiimote that had an event.
|
||||
*
|
||||
* Alternative to calling wiiuse_poll yourself, and provides the same
|
||||
* information struct on all platforms.
|
||||
*
|
||||
* @return Number of wiimotes that had an event.
|
||||
*/
|
||||
WIIUSE_EXPORT extern int wiiuse_update(struct wiimote_t** wm, int wiimotes, wiiuse_update_cb callback);
|
||||
/**
|
||||
* @brief Poll Wiimotes, and call the provided callback with information
|
||||
* on each Wiimote that had an event.
|
||||
*
|
||||
* Alternative to calling wiiuse_poll yourself, and provides the same
|
||||
* information struct on all platforms.
|
||||
*
|
||||
* @return Number of wiimotes that had an event.
|
||||
*/
|
||||
WIIUSE_EXPORT extern int wiiuse_update(struct wiimote_t** wm, int wiimotes, wiiuse_update_cb callback);
|
||||
|
||||
/* ir.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level);
|
||||
/* ir.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level);
|
||||
|
||||
/* nunchuk.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
/* nunchuk.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
|
||||
/* wiiboard.c */
|
||||
/* this function not currently implemented... */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_wii_board_calib(struct wiimote_t *wm);
|
||||
/* wiiboard.c */
|
||||
/* this function not currently implemented... */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_wii_board_calib(struct wiimote_t *wm);
|
||||
|
||||
WIIUSE_EXPORT extern void wiiuse_set_motion_plus(struct wiimote_t *wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_motion_plus(struct wiimote_t *wm, int status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@
|
||||
#define WM_INPUT_CHANNEL 0x13
|
||||
|
||||
#define WM_SET_REPORT 0x50
|
||||
#define WM_SET_DATA 0xA0
|
||||
|
||||
/* commands */
|
||||
#define WM_CMD_LED 0x11
|
||||
@@ -142,12 +143,12 @@
|
||||
* not store them in such a way, rather it uses
|
||||
* the concept of major service, major class,
|
||||
* and minor class, that are respectivelly
|
||||
* 11bit, 5bit, and 6bit long. Hence, the
|
||||
* 11bit, 5bit, and 6bit long. Hence, the
|
||||
* numbers are different.
|
||||
* The Wiimote CoD Bluetooth division is the following:
|
||||
* 00000000001 00101 000001 00 (major service - major class - minor class - format type)
|
||||
* This can also be seen in the WiiC Linux way:
|
||||
* 00000000 00100101 00000100
|
||||
* 00000000 00100101 00000100
|
||||
*/
|
||||
#ifdef WIIUSE_MAC
|
||||
#define WM_DEV_MINOR_CLASS 0x01
|
||||
@@ -172,6 +173,7 @@
|
||||
#define WM_EXP_MEM_ENABLE1 0x04A400F0
|
||||
#define WM_EXP_MEM_ENABLE2 0x04A400FB
|
||||
#define WM_EXP_MEM_CALIBR 0x04A40020
|
||||
#define WM_EXP_MOTION_PLUS_IDENT 0x04A600FA
|
||||
#define WM_EXP_MOTION_PLUS_ENABLE 0x04A600FE
|
||||
#define WM_EXP_MOTION_PLUS_INIT 0x04A600F0
|
||||
#define WM_REG_IR 0x04B00030
|
||||
@@ -209,10 +211,16 @@
|
||||
#define EXP_ID_CODE_WII_BOARD 0xA4200402
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER 0xA4200101
|
||||
#define EXP_ID_CODE_GUITAR 0xA4200103
|
||||
#define EXP_ID_CODE_MOTION_PLUS 0xa4200405
|
||||
#define EXP_ID_CODE_MOTION_PLUS 0xA4200405
|
||||
#define EXP_ID_CODE_MOTION_PLUS_NUNCHUK 0xA4200505 /** Motion Plus ID in Nunchuck passthrough mode */
|
||||
#define EXP_ID_CODE_MOTION_PLUS_CLASSIC 0xA4200705 /** Motion Plus ID in Classic control. passthrough */
|
||||
|
||||
/* decrypted M+ codes at 0x04A600FA */
|
||||
#define EXP_ID_CODE_INACTIVE_MOTION_PLUS 0xA6200005 /** Inactive Motion Plus ID */
|
||||
#define EXP_ID_CODE_NLA_MOTION_PLUS 0xA6200405 /** No longer active Motion Plus ID */
|
||||
#define EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK 0xA6200505 /** No longer active Motion Plus ID in Nunchuck passthrough mode */
|
||||
#define EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC 0xA6200705 /** No longer active Motion Plus ID in Classic control. passthrough */
|
||||
|
||||
#define EXP_HANDSHAKE_LEN 224
|
||||
|
||||
/********************
|
||||
@@ -221,31 +229,9 @@
|
||||
*
|
||||
********************/
|
||||
|
||||
/* wiimote state flags - (some duplicated in wiiuse.h)*/
|
||||
#define WIIMOTE_STATE_DEV_FOUND 0x0001
|
||||
#define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_CONNECTED 0x0008
|
||||
#define WIIMOTE_STATE_RUMBLE 0x0010
|
||||
#define WIIMOTE_STATE_ACC 0x0020
|
||||
#define WIIMOTE_STATE_EXP 0x0040
|
||||
#define WIIMOTE_STATE_IR 0x0080
|
||||
#define WIIMOTE_STATE_SPEAKER 0x0100
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL1 0x0200
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL2 0x0400
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL3 0x0800
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL4 0x1000
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL5 0x2000
|
||||
#define WIIMOTE_STATE_EXP_HANDSHAKE 0x10000 /* actual M+ connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_EXP_EXTERN 0x20000 /* actual M+ connection exists but handshake failed */
|
||||
#define WIIMOTE_STATE_EXP_FAILED 0x40000 /* actual M+ connection exists but handshake failed */
|
||||
|
||||
|
||||
|
||||
#define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3)
|
||||
|
||||
/* macro to manage states */
|
||||
#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
|
||||
#define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s))
|
||||
#define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s))
|
||||
#define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
|
||||
@@ -257,9 +243,11 @@
|
||||
|
||||
#define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s))
|
||||
|
||||
/* misc macros */
|
||||
#define WIIMOTE_ID(wm) (wm->unid)
|
||||
#define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
|
||||
/*
|
||||
* Largest known payload is 21 bytes.
|
||||
* Add 1 (Win32) or 2 (Mac, *nix) for the prefix and round up to a power of 2.
|
||||
*/
|
||||
#define MAX_PAYLOAD 32
|
||||
|
||||
/*
|
||||
* Smooth tilt calculations are computed with the
|
||||
@@ -292,121 +280,121 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* not part of the api */
|
||||
/* not part of the api */
|
||||
|
||||
/** @brief Cross-platform call to sleep for at least the specified number
|
||||
* of milliseconds.
|
||||
*
|
||||
* Use instead of Sleep(), usleep(), or similar functions.
|
||||
* Defined in util.c
|
||||
*/
|
||||
void wiiuse_millisleep(int durationMilliseconds);
|
||||
/** @brief Cross-platform call to sleep for at least the specified number
|
||||
* of milliseconds.
|
||||
*
|
||||
* Use instead of Sleep(), usleep(), or similar functions.
|
||||
* Defined in util.c
|
||||
*/
|
||||
void wiiuse_millisleep(int durationMilliseconds);
|
||||
|
||||
int wiiuse_set_report_type(struct wiimote_t* wm);
|
||||
void wiiuse_send_next_pending_read_request(struct wiimote_t* wm);
|
||||
void wiiuse_send_next_pending_write_request(struct wiimote_t* wm);
|
||||
int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len);
|
||||
int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int offset, uint16_t len);
|
||||
int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte* data, byte len, wiiuse_write_cb write_cb);
|
||||
int wiiuse_set_report_type(struct wiimote_t* wm);
|
||||
void wiiuse_send_next_pending_read_request(struct wiimote_t* wm);
|
||||
void wiiuse_send_next_pending_write_request(struct wiimote_t* wm);
|
||||
int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len);
|
||||
int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int offset, uint16_t len);
|
||||
int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte* data, byte len, wiiuse_write_cb write_cb);
|
||||
|
||||
|
||||
#ifdef WIIUSE_DOXYGEN_PARSING
|
||||
/** @addtogroup betosystem Big-endian buffer to system-byte-order value
|
||||
@{ */
|
||||
/** @addtogroup betosystem Big-endian buffer to system-byte-order value
|
||||
@{ */
|
||||
|
||||
/** @brief Given a buffer buf, copy and return a value of type uint8_t.
|
||||
*/
|
||||
uint8_t from_big_endian_uint8_t(byte * buf);
|
||||
/** @brief Given a buffer buf, copy out a uint16_t, convert it from big-endian
|
||||
to system byte order, and return it.
|
||||
/** @brief Given a buffer buf, copy and return a value of type uint8_t.
|
||||
*/
|
||||
uint8_t from_big_endian_uint8_t(byte * buf);
|
||||
/** @brief Given a buffer buf, copy out a uint16_t, convert it from big-endian
|
||||
to system byte order, and return it.
|
||||
|
||||
@note Requires that at least 2 bytes be available in buf, but does not
|
||||
check this - it is your responsibility.
|
||||
*/
|
||||
uint16_t from_big_endian_uint16_t(byte * buf);
|
||||
@note Requires that at least 2 bytes be available in buf, but does not
|
||||
check this - it is your responsibility.
|
||||
*/
|
||||
uint16_t from_big_endian_uint16_t(byte * buf);
|
||||
|
||||
/** @brief Given a buffer buf, copy out a uint32_t, convert it from big-endian
|
||||
to system byte order, and return it.
|
||||
/** @brief Given a buffer buf, copy out a uint32_t, convert it from big-endian
|
||||
to system byte order, and return it.
|
||||
|
||||
@note Requires that at least 4 bytes be available in buf, but does not
|
||||
check this - it is your responsibility.
|
||||
*/
|
||||
uint32_t from_big_endian_uint32_t(byte * buf);
|
||||
/** @} */
|
||||
@note Requires that at least 4 bytes be available in buf, but does not
|
||||
check this - it is your responsibility.
|
||||
*/
|
||||
uint32_t from_big_endian_uint32_t(byte * buf);
|
||||
/** @} */
|
||||
|
||||
/** @addtogroup systemtobe System-byte-order value to big-endian buffer
|
||||
@{
|
||||
*/
|
||||
/** @addtogroup systemtobe System-byte-order value to big-endian buffer
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief Copies the value val into the buffer buf.
|
||||
@note Requires that at least 1 byte is available in buf, but does not
|
||||
check this - it is your responsibility.
|
||||
*/
|
||||
void to_big_endian_uint8_t(byte * buf, uint8_t val);
|
||||
/** @brief Copies the value val into the buffer buf.
|
||||
@note Requires that at least 1 byte is available in buf, but does not
|
||||
check this - it is your responsibility.
|
||||
*/
|
||||
void to_big_endian_uint8_t(byte * buf, uint8_t val);
|
||||
|
||||
/** @brief Converts the value val from system byte order to big endian,
|
||||
and copies it into the given buffer starting at buf.
|
||||
/** @brief Converts the value val from system byte order to big endian,
|
||||
and copies it into the given buffer starting at buf.
|
||||
|
||||
@note Requires that at least 2 bytes be available in buf, but does not
|
||||
check this - it is your responsibility.
|
||||
*/
|
||||
void to_big_endian_uint16_t(byte * buf, uint16_t val);
|
||||
@note Requires that at least 2 bytes be available in buf, but does not
|
||||
check this - it is your responsibility.
|
||||
*/
|
||||
void to_big_endian_uint16_t(byte * buf, uint16_t val);
|
||||
|
||||
/** @brief Converts the value val from system byte order to big endian,
|
||||
and copies it into the given buffer starting at buf.
|
||||
/** @brief Converts the value val from system byte order to big endian,
|
||||
and copies it into the given buffer starting at buf.
|
||||
|
||||
@note Requires that at least 4 bytes be available in buf, but does not
|
||||
check this - it is your responsibility.
|
||||
*/
|
||||
void to_big_endian_uint32_t(byte * buf, uint32_t val);
|
||||
/** @}
|
||||
*/
|
||||
@note Requires that at least 4 bytes be available in buf, but does not
|
||||
check this - it is your responsibility.
|
||||
*/
|
||||
void to_big_endian_uint32_t(byte * buf, uint32_t val);
|
||||
/** @}
|
||||
*/
|
||||
|
||||
/** @addtogroup bufferfunc Buffering functions
|
||||
@brief These wrap around from/to_big_endian_TYPE, but take a byte** so that
|
||||
they can advance the input/output pointer appropriately.
|
||||
@{
|
||||
*/
|
||||
/** @brief Converts the value val from system byte order to big endian,
|
||||
copies it into the given buffer starting at *buf, and advances buf by
|
||||
sizeof(uint16_t).
|
||||
*/
|
||||
void buffer_big_endian_uint16_t(byte ** buf, uint16_t val);
|
||||
/** @addtogroup bufferfunc Buffering functions
|
||||
@brief These wrap around from/to_big_endian_TYPE, but take a byte** so that
|
||||
they can advance the input/output pointer appropriately.
|
||||
@{
|
||||
*/
|
||||
/** @brief Converts the value val from system byte order to big endian,
|
||||
copies it into the given buffer starting at *buf, and advances buf by
|
||||
sizeof(uint16_t).
|
||||
*/
|
||||
void buffer_big_endian_uint16_t(byte ** buf, uint16_t val);
|
||||
|
||||
/** @brief Given the address of a buffer pointer buf, copy out a uint16_t
|
||||
from *buf, convert it from big-endian to system byte order, advance
|
||||
buf by sizeof(uint16_t), and return the value retrieved.
|
||||
*/
|
||||
uint16_t unbuffer_big_endian_uint16_t(byte ** buf);
|
||||
/** @brief Given the address of a buffer pointer buf, copy out a uint16_t
|
||||
from *buf, convert it from big-endian to system byte order, advance
|
||||
buf by sizeof(uint16_t), and return the value retrieved.
|
||||
*/
|
||||
uint16_t unbuffer_big_endian_uint16_t(byte ** buf);
|
||||
|
||||
/** @sa buffer_big_endian_uint16_t()
|
||||
*/
|
||||
void buffer_big_endian_uint8_t(byte ** buf, uint8_t val);
|
||||
/** @sa buffer_big_endian_uint16_t()
|
||||
*/
|
||||
void buffer_big_endian_uint8_t(byte ** buf, uint8_t val);
|
||||
|
||||
/** @sa unbuffer_big_endian_uint8_t
|
||||
*/
|
||||
uint8_t unbuffer_big_endian_uint8_t(byte ** buf);
|
||||
/** @sa unbuffer_big_endian_uint8_t
|
||||
*/
|
||||
uint8_t unbuffer_big_endian_uint8_t(byte ** buf);
|
||||
|
||||
/** @sa buffer_big_endian_uint16_t
|
||||
*/
|
||||
void buffer_big_endian_uint32_t(byte ** buf, uint32_t val);
|
||||
/** @sa buffer_big_endian_uint16_t
|
||||
*/
|
||||
void buffer_big_endian_uint32_t(byte ** buf, uint32_t val);
|
||||
|
||||
/** @sa unbuffer_big_endian_uint32_t
|
||||
*/
|
||||
uint8_t unbuffer_big_endian_uint32_t(byte ** buf)
|
||||
/** @sa unbuffer_big_endian_uint32_t
|
||||
*/
|
||||
uint8_t unbuffer_big_endian_uint32_t(byte ** buf)
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
#else /* this else is true when not in doxygen */
|
||||
|
||||
INLINE_UTIL void to_big_endian_uint8_t(byte * buf, uint8_t val) {
|
||||
memcpy(buf, &val, 1);
|
||||
}
|
||||
INLINE_UTIL void to_big_endian_uint8_t(byte * buf, uint8_t val) {
|
||||
memcpy(buf, &val, 1);
|
||||
}
|
||||
|
||||
INLINE_UTIL uint8_t from_big_endian_uint8_t(byte * buf) {
|
||||
uint8_t beVal;
|
||||
memcpy(&beVal, buf, 1);
|
||||
return beVal;
|
||||
}
|
||||
INLINE_UTIL uint8_t from_big_endian_uint8_t(byte * buf) {
|
||||
uint8_t beVal;
|
||||
memcpy(&beVal, buf, 1);
|
||||
return beVal;
|
||||
}
|
||||
|
||||
#define WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(_TYPE, _TOBE, _FROMBE) \
|
||||
INLINE_UTIL void to_big_endian_##_TYPE(byte * buf, _TYPE val) { \
|
||||
@@ -419,8 +407,8 @@ INLINE_UTIL _TYPE from_big_endian_##_TYPE(byte * buf) { \
|
||||
return _FROMBE(beVal); \
|
||||
}
|
||||
|
||||
WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint16_t, htons, ntohs)
|
||||
WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint32_t, htonl, ntohl)
|
||||
WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint16_t, htons, ntohs)
|
||||
WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint32_t, htonl, ntohl)
|
||||
|
||||
#undef WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS
|
||||
|
||||
@@ -435,9 +423,9 @@ INLINE_UTIL _TYPE unbuffer_big_endian_##_TYPE (byte ** buf) { \
|
||||
return from_big_endian_##_TYPE(current); \
|
||||
}
|
||||
|
||||
WIIUSE_DECLARE_BUFFERING_OPS(uint8_t)
|
||||
WIIUSE_DECLARE_BUFFERING_OPS(uint16_t)
|
||||
WIIUSE_DECLARE_BUFFERING_OPS(uint32_t)
|
||||
WIIUSE_DECLARE_BUFFERING_OPS(uint8_t)
|
||||
WIIUSE_DECLARE_BUFFERING_OPS(uint16_t)
|
||||
WIIUSE_DECLARE_BUFFERING_OPS(uint32_t)
|
||||
|
||||
#undef WIIUSE_DECLARE_BUFFERING_OPS
|
||||
|
||||
|
||||
Reference in New Issue
Block a user