(self)
return batt_type, level
Get battery type & charge level
Get battery type & charge level
Get battery type & charge level
def get_battery_information(self):
        "Get battery type & charge level"
        BATTERY_DEVTYPE_GAMEPAD = 0x00
        BATTERY_DEVTYPE_HEADSET = 0x01
        # Set up function argument types and return type
        XInputGetBatteryInformation = xinput.XInputGetBatteryInformation
        XInputGetBatteryInformation.argtypes = [ctypes.c_uint, ctypes.c_ubyte, ctypes.POINTER(XINPUT_BATTERY_INFORMATION)]
        XInputGetBatteryInformation.restype = ctypes.c_uint

        battery = XINPUT_BATTERY_INFORMATION(0,0)
        XInputGetBatteryInformation(self.device_number, BATTERY_DEVTYPE_GAMEPAD, ctypes.byref(battery))

        #define BATTERY_TYPE_DISCONNECTED       0x00
        #define BATTERY_TYPE_WIRED              0x01
        #define BATTERY_TYPE_ALKALINE           0x02
        #define BATTERY_TYPE_NIMH               0x03
        #define BATTERY_TYPE_UNKNOWN            0xFF
        #define BATTERY_LEVEL_EMPTY             0x00
        #define BATTERY_LEVEL_LOW               0x01
        #define BATTERY_LEVEL_MEDIUM            0x02
        #define BATTERY_LEVEL_FULL              0x03
        batt_type = "Unknown" if battery.BatteryType == 0xFF else ["Disconnected", "Wired", "Alkaline", "Nimh"][battery.BatteryType]
        level = ["Empty", "Low", "Medium", "Full"][battery.BatteryLevel]
        return batt_type, level
def get_battery_information ( self ) : BATTERY_DEVTYPE_GAMEPAD = 0x00 BATTERY_DEVTYPE_HEADSET = 0x01 # Set up function argument types and return type XInputGetBatteryInformation = xinput . XInputGetBatteryInformation XInputGetBatteryInformation . argtypes = [ ctypes . c_uint , ctypes . c_ubyte , ctypes . POINTER ( XINPUT_BATTERY_INFORMATION ) ] XInputGetBatteryInformation . restype = ctypes . c_uint battery = XINPUT_BATTERY_INFORMATION ( 0 , 0 ) XInputGetBatteryInformation ( self . device_number , BATTERY_DEVTYPE_GAMEPAD , ctypes . byref ( battery ) ) #define BATTERY_TYPE_DISCONNECTED       0x00 #define BATTERY_TYPE_WIRED              0x01 #define BATTERY_TYPE_ALKALINE           0x02 #define BATTERY_TYPE_NIMH               0x03 #define BATTERY_TYPE_UNKNOWN            0xFF #define BATTERY_LEVEL_EMPTY             0x00 #define BATTERY_LEVEL_LOW               0x01 #define BATTERY_LEVEL_MEDIUM            0x02 #define BATTERY_LEVEL_FULL              0x03 batt_type = "Unknown" if battery . BatteryType == 0xFF else [ "Disconnected" , "Wired" , "Alkaline" , "Nimh" ] [ battery . BatteryType ] level = [ "Empty" , "Low" , "Medium" , "Full" ] [ battery . BatteryLevel ] return batt_type , level