From 9c3bcf8e8aed6189a6d957e709fe1e50b304e189 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 11 Nov 2021 17:31:14 -0800
Subject: [PATCH] Added SDL_hid_ble_scan() for pairing Steam Controllers on iOS
and tvOS
---
include/SDL_hidapi.h | 9 +++++++++
src/dynapi/SDL_dynapi_overrides.h | 1 +
src/dynapi/SDL_dynapi_procs.h | 1 +
src/hidapi/SDL_hidapi.c | 7 +++++++
src/hidapi/hidapi/hidapi.h | 4 ++++
src/hidapi/ios/hid.m | 2 +-
6 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/include/SDL_hidapi.h b/include/SDL_hidapi.h
index 6c3bc978b9..6fdfbd40b3 100644
--- a/include/SDL_hidapi.h
+++ b/include/SDL_hidapi.h
@@ -431,6 +431,15 @@ extern DECLSPEC int SDLCALL SDL_hid_get_serial_number_string(SDL_hid_device *dev
*/
extern DECLSPEC int SDLCALL SDL_hid_get_indexed_string(SDL_hid_device *dev, int string_index, wchar_t *string, size_t maxlen);
+/**
+ * Start or stop a BLE scan on iOS and tvOS to pair Steam Controllers
+ *
+ * \param active SDL_TRUE to start the scan, SDL_FALSE to stop the scan
+ *
+ * \since This function is available since SDL 2.0.18.
+ */
+extern DECLSPEC void SDLCALL SDL_hid_ble_scan(SDL_bool active);
+
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 7faab8deca..62364c3291 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -853,3 +853,4 @@
#define SDL_JoystickHasRumbleTriggers SDL_JoystickHasRumbleTriggers_REAL
#define SDL_GameControllerHasRumble SDL_GameControllerHasRumble_REAL
#define SDL_GameControllerHasRumbleTriggers SDL_GameControllerHasRumbleTriggers_REAL
+#define SDL_hid_ble_scan SDL_hid_ble_scan_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 28bf27dbcd..00fae10f5c 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -922,3 +922,4 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickHasRumble,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickHasRumbleTriggers,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasRumble,(SDL_GameController *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasRumbleTriggers,(SDL_GameController *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_hid_ble_scan,(SDL_bool a),(a),)
diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c
index e7dfd1a3e0..28003b40fa 100644
--- a/src/hidapi/SDL_hidapi.c
+++ b/src/hidapi/SDL_hidapi.c
@@ -1492,6 +1492,13 @@ int SDL_hid_get_indexed_string(SDL_hid_device *device, int string_index, wchar_t
return result;
}
+void SDL_hid_ble_scan(SDL_bool active)
+{
+#if __IPHONEOS__ || __TVOS__
+ hid_ble_scan(active);
+#endif
+}
+
#ifdef HAVE_ENABLE_GAMECUBE_ADAPTORS
/* This is needed to enable input for Nyko and EVORETRO GameCube adaptors */
void SDL_EnableGameCubeAdaptors(void)
diff --git a/src/hidapi/hidapi/hidapi.h b/src/hidapi/hidapi/hidapi.h
index 3743c4ea9f..3fddfa885e 100644
--- a/src/hidapi/hidapi/hidapi.h
+++ b/src/hidapi/hidapi/hidapi.h
@@ -406,6 +406,10 @@ namespace NAMESPACE {
*/
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev);
+#if __IPHONEOS__ || __TVOS__
+ HID_API_EXPORT void HID_API_CALL hid_ble_scan(int active);
+#endif
+
#if defined(__cplusplus) && !defined(NAMESPACE)
}
#endif
diff --git a/src/hidapi/ios/hid.m b/src/hidapi/ios/hid.m
index d8abfd3745..e193a727cc 100644
--- a/src/hidapi/ios/hid.m
+++ b/src/hidapi/ios/hid.m
@@ -743,7 +743,7 @@ int HID_API_EXPORT HID_API_CALL hid_exit(void)
return 0;
}
-void HID_API_EXPORT HID_API_CALL hid_ble_scan( bool bStart )
+void HID_API_EXPORT HID_API_CALL hid_ble_scan( int bStart )
{
HIDBLEManager *bleManager = HIDBLEManager.sharedInstance;
if ( bStart )