ricardoquesada / bluepad32

Bluetooth gamepad, mouse and keyboard support for ESP32 and PicoW
https://bluepad32.readthedocs.io/
Other
503 stars 53 forks source link

Add safe platform hook method #102

Closed mitchellcairns closed 1 month ago

mitchellcairns commented 1 month ago

This request adds a few bits of functionality

1) uni_run_platform_hook_safe(void) This is a safe way to call and execute a function on the bluetooth core. The functionality is provided by the custom platform

2) safe_platform_hook attribute to uni_platform This is a user-defined method that gets executed when uni_run_platform_hook_safe is called

Why? There's no good way to safely execute custom code on the bluetooth core right now. Things like changing rumble state in real time is a bit convoluted, and requires hooking in to the gamepad update status, which, if the analog sticks haven't moved, rumble just stays on (as an example of an edge case). This allows working around such behavior, but also allows expanding on functionality in other perhaps unthought of manners.

ricardoquesada commented 1 month ago

I'm not convinced that we should add a "play rumble" this way.

I think users should do btstack_run_loop_execute_on_main_thread() as described here:

https://bluepad32.readthedocs.io/en/latest/programmers_guide_raw/#multithreading

(and from the Discord discussion it seems that you sort of agree with that). If you are Ok, I'll close this pull-request. Thanks

mitchellcairns commented 1 month ago

No problem, thank you!