Skip to content
Permalink
Browse files

WiimoteReal: reimplement using HIDAPI

Using the HIDAPI library has the advantage that we get Wiimote and
DolphinBar support on all platforms with only one IO implementation.
  • Loading branch information...
Tilka committed Jan 10, 2015
1 parent 1c26d41 commit ca0c2efe7ab19c85449d52dd1bf4beec8603bbfe
@@ -2,6 +2,7 @@
# General setup
#
cmake_minimum_required(VERSION 2.8.8)
project(dolphin-emu)

option(USE_EGL "Enables EGL OpenGL Interface" OFF)
option(TRY_X11 "Enables X11 Support" ON)
@@ -13,6 +14,9 @@ option(ENABLE_LTO "Enables Link Time Optimization" OFF)
option(ENABLE_GENERIC "Enables generic build that should run on any little-endian host" OFF)
if(APPLE)
option(OSX_USE_DEFAULT_SEARCH_PATH "Don't prioritize system library paths" OFF)
option(SKIP_POSTPROCESS_BUNDLE "Skip postprocessing bundle for redistributability" OFF)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
option(INSTALL_UDEV_RULES "Install udev rules for hidraw/usb devices" OFF)
endif()

option(ENCODE_FRAMEDUMPS "Encode framedumps in AVI format" ON)
@@ -21,9 +25,6 @@ option(FASTLOG "Enable all logs" OFF)
option(OPROFILING "Enable profiling" OFF)
option(GDBSTUB "Enable gdb stub for remote debugging." OFF)

if(APPLE)
option(SKIP_POSTPROCESS_BUNDLE "Skip postprocessing bundle for redistributability" OFF)
endif()
########################################
# Optional Targets
# TODO: Add DSPSpy
@@ -45,7 +46,6 @@ if (APPLE)
endif()
endif()
endif()
project(dolphin-emu)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMakeTests)
set(DOLPHIN_IS_STABLE FALSE)
# Libraries to link
@@ -292,7 +292,6 @@ if(APPLE)
find_library(COREFUND_LIBRARY CoreFoundation)
find_library(CORESERV_LIBRARY CoreServices)
find_library(FOUNDATION_LIBRARY foundation)
find_library(IOB_LIBRARY IOBluetooth)
find_library(IOK_LIBRARY IOKit)
find_library(QUICKTIME_LIBRARY QuickTime)
find_library(WEBKIT_LIBRARY WebKit)
@@ -379,15 +378,6 @@ if(NOT ANDROID)
message("ao NOT found, disabling ao sound backend")
endif(AO_FOUND)

check_lib(BLUEZ bluez QUIET)
if(BLUEZ_FOUND)
add_definitions(-DHAVE_BLUEZ=1)
message("bluez found, enabling bluetooth support")
else()
add_definitions(-DHAVE_BLUEZ=0)
message("bluez NOT found, disabling bluetooth support")
endif(BLUEZ_FOUND)

check_lib(PULSEAUDIO libpulse QUIET)
if(PULSEAUDIO_FOUND)
add_definitions(-DHAVE_PULSEAUDIO=1)
@@ -595,10 +585,19 @@ endif()

include(FindLibUSB OPTIONAL)
if(LIBUSB_FOUND)
message("Using shared LibUSB")
message("Using shared libusb")
add_definitions(-D__LIBUSB__)
include_directories(${LIBUSB_INCLUDE_DIR})
endif(LIBUSB_FOUND)
list(APPEND LIBS ${LIBUSB_LIBRARIES})
elseif(ANDROID)
message("Using static libusb from Externals")
add_subdirectory(Externals/libusb/libusb)
include_directories(Externals/libusb/libusb)
list(APPEND LIBS usb-1.0)
else()
message(FATAL_ERROR "libusb is required. Either extend the CMakeLists.txt file to support your OS"
" or just install libusb as a shared library.")
endif()

set(SFML_REQD_VERSION 2.1)
if(NOT APPLE AND NOT ANDROID)
@@ -665,6 +664,32 @@ else()
mark_as_advanced(ICONV_INCLUDE_DIR ICONV_LIBRARIES)
endif()

include(FindHIDAPI OPTIONAL)
find_package(HIDAPI)
if(HIDAPI_FOUND)
message("Using shared ${HIDAPI_LIBRARIES} ${HIDAPI_VERSION}")
include_directories(${HIDAPI_INCLUDE_DIRS})
list(APPEND LIBS ${HIDAPI_LIBRARIES})
else()
include_directories(Externals/hidapi/hidapi)
if(APPLE)
message("Using static hidapi from Externals")
add_subdirectory(Externals/hidapi/mac)
list(APPEND LIBS hidapi)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT ANDROID)
message("Using static hidapi-hidraw from Externals")
add_subdirectory(Externals/hidapi/linux)
list(APPEND LIBS hidapi-hidraw udev)
else()
message("Using static hidapi-libusb from Externals")
add_subdirectory(Externals/hidapi/libusb)
list(APPEND LIBS hidapi-libusb)
endif()
endif()
if(INSTALL_UDEV_RULES)
install(FILES Installer/90-wiimote.rules /etc/udev/rules.d/)
endif()

if(ENABLE_QT)
find_package(Qt5Widgets REQUIRED)
message("Found Qt version ${Qt5Core_VERSION}, enabling the Qt backend")
@@ -0,0 +1,9 @@
find_path(HIDAPI_INCLUDE_DIR NAMES hidapi.h PATH_SUFFIXES hidapi)
find_library(HIDAPI_LIBRARY NAMES hidapi hidapi-hidraw hidapi-libusb)
set(HIDAPI_LIBRARIES ${HIDAPI_LIBRARY})
set(HIDAPI_INCLUDE_DIRS ${HIDAPI_INCLUDE_DIR})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HIDAPI DEFAULT_MSG HIDAPI_LIBRARY HIDAPI_INCLUDE_DIR)

mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_LIBRARY)
@@ -0,0 +1 @@
add_library(hidapi-libusb hid.c)
@@ -0,0 +1 @@
add_library(hidapi-hidraw hid.c)
@@ -0,0 +1 @@
add_library(hidapi hid.c)
@@ -0,0 +1,17 @@
# This file is only used for Android (because I'm lazy).
# We don't use CMake on Windows and just require libusb to be installed everywhere else.

set(SRCS
core.c
descriptor.c
hotplug.c
io.c
strerror.c
sync.c
)

include_directories(BEFORE ../android)

add_subdirectory(os)
add_library(usb-1.0 STATIC ${SRCS})
target_link_libraries(usb-1.0 usb-os)
@@ -0,0 +1,7 @@
include_directories(..)
add_library(usb-os STATIC
linux_netlink.c
linux_usbfs.c
poll_posix.c
threads_posix.c
)
@@ -27,7 +27,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -38,7 +37,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
@@ -0,0 +1,8 @@
# This is how you can match Wiimotes (and Wiimote-emulating devices like the DolphinBar) in udev.
# If you are a package maintainer you'll probably want to restrict permissions to a group: GROUP="plugdev", MODE="0660".

# Wiimote or DolphinBar
SUBSYSTEMS=="hid", ATTRS{idVendor}=="057e", ATTRS{idProduct}=="0306", MODE="0666"

# newer Wiimotes (RVL-CNT-01-TR)
SUBSYSTEMS=="hid", ATTRS{idVendor}=="057e", ATTRS{idProduct}=="0330", MODE="0666"
@@ -116,6 +116,7 @@ set(SRCS ActionReplay.cpp
HW/SI_DeviceGBA.cpp
HW/SI_DeviceGCController.cpp
HW/SI_DeviceGCSteeringWheel.cpp
HW/SI_GCAdapter.cpp
HW/Sram.cpp
HW/StreamADPCM.cpp
HW/SystemTimers.cpp
@@ -132,6 +133,7 @@ set(SRCS ActionReplay.cpp
HW/WiimoteEmu/EmuSubroutines.cpp
HW/WiimoteEmu/Encryption.cpp
HW/WiimoteEmu/Speaker.cpp
HW/WiimoteReal/IOhidapi.cpp
HW/WiimoteReal/WiimoteReal.cpp
HW/WiiSaveCrypted.cpp
IPC_HLE/ICMPLin.cpp
@@ -140,6 +142,7 @@ set(SRCS ActionReplay.cpp
IPC_HLE/WII_IPC_HLE_Device_es.cpp
IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp
IPC_HLE/WII_IPC_HLE_Device_fs.cpp
IPC_HLE/WII_IPC_HLE_Device_hid.cpp
IPC_HLE/WII_Socket.cpp
IPC_HLE/WII_IPC_HLE_Device_net.cpp
IPC_HLE/WII_IPC_HLE_Device_net_ssl.cpp
@@ -245,29 +248,15 @@ set(LIBS
z
)

if(LIBUSB_FOUND)
# Using shared LibUSB
set(LIBS ${LIBS} ${LIBUSB_LIBRARIES})
set(SRCS ${SRCS} IPC_HLE/WII_IPC_HLE_Device_hid.cpp
HW/SI_GCAdapter.cpp)
endif(LIBUSB_FOUND)

set(LIBS ${LIBS} ${POLARSSL_LIBRARY})

if(WIN32)
set(SRCS ${SRCS} HW/BBA-TAP/TAP_Win32.cpp HW/WiimoteReal/IOWin.cpp)
set(SRCS ${SRCS} HW/BBA-TAP/TAP_Win32.cpp)
elseif(APPLE)
set(SRCS ${SRCS} HW/BBA-TAP/TAP_Apple.cpp HW/WiimoteReal/IOdarwin.mm)
set(LIBS ${LIBS}
${IOB_LIBRARY})
set(SRCS ${SRCS} HW/BBA-TAP/TAP_Apple.cpp)
elseif(UNIX)
set(SRCS ${SRCS} HW/BBA-TAP/TAP_Unix.cpp)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND BLUEZ_FOUND)
set(SRCS ${SRCS} HW/WiimoteReal/IONix.cpp)
set(LIBS ${LIBS} bluetooth)
else()
set(SRCS ${SRCS} HW/WiimoteReal/IODummy.cpp)
endif()
endif()

if(PORTAUDIO_FOUND)
@@ -169,7 +169,7 @@
<ClCompile Include="HW\WiimoteEmu\Encryption.cpp" />
<ClCompile Include="HW\WiimoteEmu\Speaker.cpp" />
<ClCompile Include="HW\WiimoteEmu\WiimoteEmu.cpp" />
<ClCompile Include="HW\WiimoteReal\IOWin.cpp" />
<ClCompile Include="HW\WiimoteReal\IOhidapi.cpp" />
<ClCompile Include="HW\WiimoteReal\WiimoteReal.cpp" />
<ClCompile Include="HW\WII_IPC.cpp" />
<ClCompile Include="HW\WiiSaveCrypted.cpp" />
@@ -470,6 +470,9 @@
<ProjectReference Include="$(CoreDir)VideoCommon\VideoCommon.vcxproj">
<Project>{3de9ee35-3e91-4f27-a014-2866ad8c3fe3}</Project>
</ProjectReference>
<ProjectReference Include="$(ExternalsDir)hidapi\hidapi.vcxproj">
<Project>{549d32d8-1640-46f9-9d78-bae6eb0d723d}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
@@ -484,7 +484,7 @@
<ClCompile Include="HW\WiimoteEmu\WiimoteEmu.cpp">
<Filter>HW %28Flipper/Hollywood%29\Wiimote\Emu</Filter>
</ClCompile>
<ClCompile Include="HW\WiimoteReal\IOWin.cpp">
<ClCompile Include="HW\WiimoteReal\IOhidapi.cpp">
<Filter>HW %28Flipper/Hollywood%29\Wiimote\Real</Filter>
</ClCompile>
<ClCompile Include="HW\WiimoteReal\WiimoteReal.cpp">

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit ca0c2ef

Please sign in to comment.
You can’t perform that action at this time.