ricardoquesada / bluepad32

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

[Bug]: `uni_hid_device_get_idx_for_instance()` reports index 0 for all devices #62

Closed juan518munoz closed 5 months ago

juan518munoz commented 5 months ago

What happened?

Running example program, inside static void my_platform_on_controller_data(uni_hid_device_t* d, uni_controller_t* ctl) I've set a variable to get the index of each connected gamepad, all report to zero.

static void my_platform_on_controller_data(uni_hid_device_t* d, uni_controller_t* ctl) {
    int id = uni_hid_device_get_idx_for_instance(d);
    logi("id %d ", idx);
    ...

Bluepad32 Version

Latest

Bluepad32 version custom

Develop branch

Bluepad32 Platform

Other

Platform version

Pico W

Controller

Joycons, Xbox Series controller

ESP32 chip

None, Raspberry Pi pico W

OS

Linux

Relevant log output

(0x20006644) dpad=0x00, x= -54, y=  79, rx=   0, ry=   0, brake=   0, throttle=   0, buttons=0x0000, misc=0x00, gyro= 176000, -39000, 120000 accel=    535,  -3105,  -2859, batte5
id: 0
(0x20006644) dpad=0x00, x= -54, y=  78, rx=   0, ry=   0, brake=   0, throttle=   0, buttons=0x0000, misc=0x00, gyro=-417000,-112000, -48000 accel=    611,  -3131,  -2622, batte5
id: 0
(0x200039bc) dpad=0x02, x= -15, y= -23, rx=  -4, ry=   7, brake=   0, throttle=   0, buttons=0x0000, misc=0x00, gyro=      0,      0,      0 accel=      0,      0,      0, batte0
id: 0
(0x200039bc) dpad=0x00, x= -15, y= -23, rx=  -4, ry=   7, brake=   0, throttle=   0, buttons=0x0000, misc=0x00, gyro=      0,      0,      0 accel=      0,      0,      0, batte0
id: 0

Relevant sketch

ricardoquesada commented 5 months ago

your sketch is incomplete... how are you printing idx ?

ricardoquesada commented 5 months ago

also, you should check return value... if it idx < 0 it is an error

juan518munoz commented 5 months ago

Sorry, I was working with two code editors side by side and passed the wrong one, it's now updated.

I never got a -1 signaling an error.

ricardoquesada commented 5 months ago

again, your sketch is incomplete. I strongly suggest that you paste a complete sketch... something that compiles and reproduce the error. don't just copy & paste parts of it.

for example, I don't know what get_connected_device_idx() is.

juan518munoz commented 5 months ago

Sent the wrong snipped again, sorry, It was late and instead of focusing on what I was doing, I wanted to get it done. I've updated the sketch. Please let me know if something else is needed.

ricardoquesada commented 5 months ago

thanks. ouch... that was a nasty bug.

fixed.