libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.52k stars 1.77k forks source link

8BidDo SN30 Pro is charging, but connection_state is set to wireless (Windows) #10862

Open AntTheAlchemist opened 1 week ago

AntTheAlchemist commented 1 week ago
    SDL_PowerState state;
    int charging = (packet->controllerState.ucBatteryAndConnection & 0x10);
    int level = (packet->controllerState.ucBatteryAndConnection & 0xE0) >> 4;
    int percent = (int)SDL_roundf((level / 8.0f) * 100.0f);

    if (packet->controllerState.ucBatteryAndConnection & 0x01) {
        joystick->connection_state = SDL_JOYSTICK_CONNECTION_WIRED;
    } else {
        joystick->connection_state = SDL_JOYSTICK_CONNECTION_WIRELESS;
    }

Is the above code in SDL_hidapi_switch.c correct? The charging state is being determined correctly, when connected, but the connection_state is wireless. Surely, if it's charging, it's wired? Is 0x01 correct? can 0x11 be used?

slouken commented 1 week ago

Yeah, we should probably sanity check this based on USB/Bluetooth and charging state. It is possible for the controller to be charging on a wire and still be talking over Bluetooth, so we'd have to take that into account.