Skip to content

Commit

Permalink
Fix reconnect bug where SDL would never find another controller
Browse files Browse the repository at this point in the history
Install fix and upgrade
  • Loading branch information
Electronicks committed Mar 19, 2021
1 parent 80f9ee2 commit d868ca5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
4 changes: 3 additions & 1 deletion JoyShockMapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if (WINDOWS)
if(SDL)
target_sources (
${BINARY_NAME} PRIVATE
src/SDLWrapper.cpp include/JoyShockLibrary.h
src/SDL2Wrapper.cpp include/JoyShockLibrary.h
)
endif()

Expand Down Expand Up @@ -155,6 +155,7 @@ if(SDL)

install (
TARGETS ${BINARY_NAME} SDL2
RUNTIME DESTINATION ${PACKAGE_DIR}
)
else()
# JoyShockLibrary
Expand All @@ -172,6 +173,7 @@ else()

install (
TARGETS ${BINARY_NAME} JoyShockLibrary
RUNTIME DESTINATION ${PACKAGE_DIR}
)
endif()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ int JslConnectDevices()
SDL_Thread *controller_polling_thread = SDL_CreateThread(&SdlInstance::pollDevices, "Poll Devices", nullptr);
SDL_DetachThread(controller_polling_thread);
}
SDL_GameControllerUpdate(); // Refresh driver listing
return SDL_NumJoysticks();
}

Expand Down Expand Up @@ -187,20 +188,24 @@ IMU_STATE JslGetIMUState(int deviceId)
if (SdlInstance::_inst->_controllerMap[deviceId]->_has_gyro)
{
array<float, 3> gyro;
SDL_GameControllerGetSensorData(SdlInstance::_inst->_controllerMap[deviceId]->_sdlController, SDL_SENSOR_GYRO, &gyro[0], 3);
constexpr float toDegPerSec = 180.f / M_PI;
imuState.gyroX = gyro[0] * toDegPerSec;
imuState.gyroY = gyro[1] * toDegPerSec;
imuState.gyroZ = gyro[2] * toDegPerSec;
if (SDL_GameControllerGetSensorData(SdlInstance::_inst->_controllerMap[deviceId]->_sdlController, SDL_SENSOR_GYRO, &gyro[0], 3) == 0)
{
constexpr float toDegPerSec = 180.f / M_PI;
imuState.gyroX = gyro[0] * toDegPerSec;
imuState.gyroY = gyro[1] * toDegPerSec;
imuState.gyroZ = gyro[2] * toDegPerSec;
}
}
if (SdlInstance::_inst->_controllerMap[deviceId]->_has_accel)
{
array<float, 3> accel;
SDL_GameControllerGetSensorData(SdlInstance::_inst->_controllerMap[deviceId]->_sdlController, SDL_SENSOR_ACCEL, &accel[0], 3);
constexpr float toGs = 1.f / 9.8f;
imuState.accelX = accel[0] * toGs;
imuState.accelY = accel[1] * toGs;
imuState.accelZ = accel[2] * toGs;
if (SDL_GameControllerGetSensorData(SdlInstance::_inst->_controllerMap[deviceId]->_sdlController, SDL_SENSOR_ACCEL, &accel[0], 3) == 0)
{
constexpr float toGs = 1.f / 9.8f;
imuState.accelX = accel[0] * toGs;
imuState.accelY = accel[1] * toGs;
imuState.accelZ = accel[2] * toGs;
}
}
return imuState;
}
Expand Down
22 changes: 14 additions & 8 deletions cmake/WindowsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,44 +43,50 @@
add_library (Platform::Dependencies ALIAS platform_dependencies)

set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/${CONFIG}/install")

if(SDL)
set(PACKAGE_DIR "${PROJECT_NAME}_${CMAKE_GENERATOR_PLATFORM}_SDL2")
else()
set(PACKAGE_DIR "${PROJECT_NAME}_${CMAKE_GENERATOR_PLATFORM}")
endif()

install (
DIRECTORY ${PROJECT_SOURCE_DIR}/dist/GyroConfigs
DESTINATION bin
DESTINATION ${PACKAGE_DIR}
)

install (
DIRECTORY ${PROJECT_SOURCE_DIR}/dist/AutoLoad
DESTINATION bin
DESTINATION ${PACKAGE_DIR}
)

install (
FILES ${PROJECT_SOURCE_DIR}/dist/OnReset.txt
DESTINATION bin
DESTINATION ${PACKAGE_DIR}
)

install (
FILES ${PROJECT_SOURCE_DIR}/dist/OnStartup.txt
DESTINATION bin
DESTINATION ${PACKAGE_DIR}
)

install (
FILES ${PROJECT_SOURCE_DIR}/CHANGELOG.md
DESTINATION bin
DESTINATION ${PACKAGE_DIR}
)

install (
FILES ${PROJECT_SOURCE_DIR}/LICENSE.md
DESTINATION bin
DESTINATION ${PACKAGE_DIR}
)

install (
FILES ${PROJECT_SOURCE_DIR}/README.md
DESTINATION bin
DESTINATION ${PACKAGE_DIR}
)

install (
FILES ${PROJECT_SOURCE_DIR}/README_中文.md
DESTINATION bin
DESTINATION ${PACKAGE_DIR}
)
endif ()
14 changes: 7 additions & 7 deletions dist/OnStartup.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Edit this file to your preference automatic settings
# Edit this file to your prefered settings on startup

GyroConfigs/Desktop.txt # Load a basic configuration to navigate the OS
GyroConfigs/Desktop.txt # Load a configuration to navigate the OS

# Uncomment the following three lines to calibrate all your devices at startup
RESTART_GYRO_CALIBRATION
SLEEP 2
FINISH_GYRO_CALIBRATION
#RESTART_GYRO_CALIBRATION
#SLEEP 2 # wait two seconds
#FINISH_GYRO_CALIBRATION

AUTOLOAD = OFF # Uncomment to disable AUTOLOAD on startup
#AUTOLOAD = OFF # Uncomment to disable AUTOLOAD on startup

HIDE_MINIMIZED = ON # Uncomment to remove JSM from the taskbar when minimized.
#HIDE_MINIMIZED = ON # Uncomment to remove JSM from the taskbar when minimized.

0 comments on commit d868ca5

Please sign in to comment.