From 6f00eb9bf8d8d0e686ba692b1b799bc20245460c Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Sun, 5 May 2024 22:40:30 -0700 Subject: [PATCH] swtich: improved disconnect timer. Prevents possible crash. or at least logic is more clear. --- AUTHORS.md | 2 +- docs/supported_gamepads.md | 26 ++++++++++++------- examples/posix/src/my_platform.c | 2 +- .../include/controller/uni_controller_list.h | 7 ++++- .../bluepad32/parser/uni_hid_parser_switch.c | 18 +++++-------- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 5b8acafa..159103ac 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -75,5 +75,5 @@ [datafrog_switch_controller]: https://www.aliexpress.us/item/3256805448827549.html -[gamesir_t3s_controller]: https://www.amazon.com/gp/product/B0B5Z3S54J +[gamesir_t3s_controller]: https://www.gamesir.hk/products/gamesir-t3s-multi-platform-game-controller diff --git a/docs/supported_gamepads.md b/docs/supported_gamepads.md index 00d1935c..b19097a9 100644 --- a/docs/supported_gamepads.md +++ b/docs/supported_gamepads.md @@ -457,21 +457,29 @@ Supported "extra features": [fire_tv_remote]: https://lh3.googleusercontent.com/qnSdv7NM5et0vDhMQsRp7oMniqcjYxGKN9QJY0_gRWT6NXFrdWBf94JKNvP77abBZoykaSQOJBtXUnGW-Z1yF-MWn3q3t2Nt_TUVVV7a2HsPFjRc_DIuLh8tPiQNsEZSWDsb0z6Ys3k=-no -## Generic HID controllers +## Misc controllers -![Generic][generic_gamepad] +Collection of misc controllers. Only the emulation modes that are known to be working are enumerated. -In general, any Bluetooth Classic (not BLE) controller that supports HID is supported, or should be easy to support it. +| Model | Protocol | Emulation | Rumble | Lightbar | Player LEDs | Gyro / Accelerometer | +|-----------------------------------------|----------|------------------|------------------|------------------|------------------|----------------------| +| [DATA FROG PS4][datafrog_ps4] | BR/EDR | DualShock 4 | :material-check: | :material-check: | | :material-check: | +| [DATA FROG Switch][datafrog_switch] | BR/EDR | Switch | :material-check: | | :material-check: | :material-check: | +| | BR/EDR | Xbox | :material-check: | | | :material-check: | +| [Gamesir T3s][gamesir_t3s] | BR/EDR | Switch | :material-check: | | | | +| [HS-SW510][hs_sw510] | BR/EDR | Switch | :material-check: | | :material-check: | | +| | BR/EDR | Android | | | | | +| [Terios T3 / ShanWan BM-769][terios_t3] | BLE | Android (iPhone) | | | | | -BLE controllers are supported, but this is an experimental feature as of Bluepad32 v3.6 +[datafrog_ps4]: https://www.aliexpress.us/item/3256806233659084.html -There many *generic* Bluetooth controllers that sometimes are offered as gifts in conferences. Usually these *generic* -Bluetooth controllers have different connection modes. Use the HID one. +[datafrog_switch]: https://www.aliexpress.us/item/3256805448827549.html -- Select Button + X + Right trigger to enter into Gamepad mode -- Select Button + X + Left trigger to enter in iCade mode. +[gamesir_t3s]: https://www.gamesir.hk/products/gamesir-t3s-multi-platform-game-controller -[generic_gamepad]: https://lh3.googleusercontent.com/JG0sQGQ4lmFIITl_nincUDdPi-mlYPol-RSQrnoxsYZf1_cc16A4WMod_ttuLJoIQigvcZ_ZF6NiA7p54bBQP-Eu52b28mbjfVCwsMjuu_LCQB9Lj0k9e5UkW_PkRM12IB0HrW8ah0k=-no +[hs_sw510]: https://new.tvc-mall.com/details/hs-sw510-wireless-controller-for-nintendo-switch-bluetooth-multi-platform-gamepad-joystick-with-turbo-function-black-white-sku681600362b.html + +[terios_t3]: https://www.aliexpress.us/item/2251832602044731.html ## Bluetooth gamepads and their protocol diff --git a/examples/posix/src/my_platform.c b/examples/posix/src/my_platform.c index 4561e750..2f0f9588 100644 --- a/examples/posix/src/my_platform.c +++ b/examples/posix/src/my_platform.c @@ -118,7 +118,7 @@ static uni_error_t posix_on_device_discovered(bd_addr_t addr, const char* name, // As an example, if you want to filter out keyboards, do: if (((cod & UNI_BT_COD_MINOR_MASK) & UNI_BT_COD_MINOR_KEYBOARD) == UNI_BT_COD_MINOR_KEYBOARD) { logi("Ignoring keyboard\n"); - return UNI_ERROR_IGNORE_DEVICE; +// return UNI_ERROR_IGNORE_DEVICE; } return UNI_ERROR_SUCCESS; diff --git a/src/components/bluepad32/include/controller/uni_controller_list.h b/src/components/bluepad32/include/controller/uni_controller_list.h index 3ea8928b..53c21dad 100644 --- a/src/components/bluepad32/include/controller/uni_controller_list.h +++ b/src/components/bluepad32/include/controller/uni_controller_list.h @@ -624,7 +624,7 @@ static const uni_controller_description_t arrControllers[] = { { MAKE_CONTROLLER_ID(0x18d1, 0x9400), k_eControllerType_AndroidController, NULL}, // Stadia BLE mode // Smart TV remotes - { MAKE_CONTROLLER_ID(0x1949, 0x0401), k_eControllerType_SmartTVRemoteController, NULL}, // Amazon Fire TV remote Controlelr 1st gen + { MAKE_CONTROLLER_ID(0x1949, 0x0401), k_eControllerType_SmartTVRemoteController, NULL}, // Amazon Fire TV remote Controller 1st gen // 8BitDo controllers { MAKE_CONTROLLER_ID(0x2820, 0x0009), k_eControllerType_8BitdoController, NULL}, // 8BitDo NES30 Gamepro @@ -657,6 +657,11 @@ static const uni_controller_description_t arrControllers[] = { // Atari Modern VCS Controllers { MAKE_CONTROLLER_ID( 0x3250, 0x1001 ), k_eControllerType_AtariJoystick, NULL }, // Atari Wireless Classic Joystick + // Note on: MAKE_CONTROLLER_ID( 0x1949, 0x0402 ). Reported by: + // - Gamesir T3s in Android mode, says it is an Xbox 360 Controller for Windows + // - Amazon Fire 1st gen + // - Generic controller in Android mode + // Bluepad32 addons to here. }; diff --git a/src/components/bluepad32/parser/uni_hid_parser_switch.c b/src/components/bluepad32/parser/uni_hid_parser_switch.c index 93666845..d4afdef8 100644 --- a/src/components/bluepad32/parser/uni_hid_parser_switch.c +++ b/src/components/bluepad32/parser/uni_hid_parser_switch.c @@ -416,21 +416,14 @@ static void process_fsm(struct uni_hid_device_s* d) { switch_instance_t* ins = get_switch_instance(d); logd("Switch: fsm next state = %d\n", ins->state + 1); - // Disable previous timer, except for the first state which has no timer - if (ins->state != STATE_SETUP) - btstack_run_loop_remove_timer(&ins->setup_timer); - - // But re-schedule it for the next step - if (ins->state != STATE_READY) { - btstack_run_loop_set_timer_context(&ins->setup_timer, d); - btstack_run_loop_set_timer_handler(&ins->setup_timer, &switch_setup_timeout_callback); - btstack_run_loop_set_timer(&ins->setup_timer, SWITCH_SETUP_TIMEOUT_MS); - btstack_run_loop_add_timer(&ins->setup_timer); - } - switch (ins->state) { case STATE_SETUP: logd("STATE_SETUP\n"); + btstack_run_loop_set_timer_context(&ins->setup_timer, d); + btstack_run_loop_set_timer_handler(&ins->setup_timer, &switch_setup_timeout_callback); + btstack_run_loop_set_timer(&ins->setup_timer, SWITCH_SETUP_TIMEOUT_MS); + btstack_run_loop_add_timer(&ins->setup_timer); + fsm_request_device_info(d); break; case STATE_REQ_DEV_INFO: @@ -467,6 +460,7 @@ static void process_fsm(struct uni_hid_device_s* d) { break; case STATE_READY: logd("STATE_READY\n"); + btstack_run_loop_remove_timer(&ins->setup_timer); break; default: loge("Switch: unexpected state: 0x%02x\n", ins->mode);