Skip to content

Commit

Permalink
swtich: improved disconnect timer.
Browse files Browse the repository at this point in the history
Prevents possible crash. or at least logic is more clear.
  • Loading branch information
ricardoquesada committed May 6, 2024
1 parent 5b8788a commit 6f00eb9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

26 changes: 17 additions & 9 deletions docs/supported_gamepads.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/posix/src/my_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
};

Expand Down
18 changes: 6 additions & 12 deletions src/components/bluepad32/parser/uni_hid_parser_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6f00eb9

Please sign in to comment.