# Gamepad identification using the Python bindings for libSDL3.

import sdl3
import ctypes

sdl3.SDL_Init(sdl3.SDL_INIT_GAMEPAD)

print("SDL version:", sdl3.SDL_GetVersion())
print("SDL revision", sdl3.SDL_GetRevision())

if not sdl3.SDL_HasGamepad():
    print("no gamepad found.")

else:
    count = ctypes.c_int()
    pads = sdl3.SDL_GetGamepads(count)
    print("number of gamepads:", count.value)
    first_id = pads[0]
    print("first joystick ID:", first_id)
    controller = sdl3.SDL_OpenGamepad(first_id)
    print("connected:",  sdl3.SDL_GamepadConnected(controller))
    print("name:",       sdl3.SDL_GetGamepadName(controller))
    print("product:",    sdl3.SDL_GetGamepadProduct(controller))
    print("type:",       sdl3.SDL_GetGamepadType(controller))
    print("vendor:",     sdl3.SDL_GetGamepadVendor(controller))

sdl3.SDL_Quit()
