@@ -52,6 +52,7 @@ typedef struct
52
52
bool rumble_type ;
53
53
bool rgb_supported ;
54
54
bool player_led_supported ;
55
+ bool powerstate_supported ;
55
56
Uint8 serial [6 ];
56
57
Uint16 version ;
57
58
Uint16 version_beta ;
@@ -105,8 +106,8 @@ static void HIDAPI_Driver8BitDo_UnregisterHints(SDL_HintCallback callback, void
105
106
static bool HIDAPI_Driver8BitDo_IsEnabled (void )
106
107
{
107
108
// We'll default this off for now, since we don't have a way to tell whether the controller is running firmware v1.03 and don't have a fallback for controllers running firmware v1.02 (the out-of-box firmware)
108
- // return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_8BITDO, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
109
- return SDL_GetHintBoolean (SDL_HINT_JOYSTICK_HIDAPI_8BITDO , false);
109
+ return SDL_GetHintBoolean (SDL_HINT_JOYSTICK_HIDAPI_8BITDO , SDL_GetHintBoolean (SDL_HINT_JOYSTICK_HIDAPI , SDL_HIDAPI_DEFAULT ));
110
+ // return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_8BITDO, false);
110
111
}
111
112
112
113
static bool HIDAPI_Driver8BitDo_IsSupportedDevice (SDL_HIDAPI_Device * device , const char * name , SDL_GamepadType type , Uint16 vendor_id , Uint16 product_id , Uint16 version , int interface_number , int interface_class , int interface_subclass , int interface_protocol )
@@ -117,7 +118,8 @@ static bool HIDAPI_Driver8BitDo_IsSupportedDevice(SDL_HIDAPI_Device *device, con
117
118
static bool HIDAPI_Driver8BitDo_InitDevice (SDL_HIDAPI_Device * device )
118
119
{
119
120
SDL_Driver8BitDo_Context * ctx ;
120
-
121
+ Uint8 data [USB_PACKET_LENGTH ];
122
+ int size ;
121
123
ctx = (SDL_Driver8BitDo_Context * )SDL_calloc (1 , sizeof (* ctx ));
122
124
if (!ctx ) {
123
125
return false;
@@ -129,7 +131,15 @@ static bool HIDAPI_Driver8BitDo_InitDevice(SDL_HIDAPI_Device *device)
129
131
ctx -> sensors_supported = true;
130
132
ctx -> rumble_supported = true;
131
133
ctx -> rumble_type = 0 ;
132
- ctx -> rgb_supported = true;
134
+ ctx -> powerstate_supported = true;
135
+
136
+ size = SDL_hid_read_timeout (device -> dev , data , sizeof (data ), 80 );
137
+ //ULTIMATE2_WIRELESS V1.02
138
+ if (size < 30 ) {
139
+ ctx -> powerstate_supported = false;
140
+ ctx -> rumble_supported = false;
141
+ ctx -> sensors_supported = false;
142
+ }
133
143
}
134
144
135
145
return HIDAPI_JoystickConnected (device , NULL );
@@ -316,33 +326,35 @@ static void HIDAPI_Driver8BitDo_HandleStatePacket(SDL_Joystick *joystick, SDL_Dr
316
326
}
317
327
#undef READ_TRIGGER_AXIS
318
328
319
- SDL_PowerState state ;
320
- int percent ;
321
- Uint8 status = data [14 ] >> 7 ;
322
- Uint8 level = (data [14 ] & 0x7f );
323
- if (level == 100 ) {
324
- status = 2 ;
325
- }
326
- switch (status ) {
327
- case 0 :
328
- state = SDL_POWERSTATE_ON_BATTERY ;
329
- percent = level ;
330
- break ;
331
- case 1 :
332
- state = SDL_POWERSTATE_CHARGING ;
333
- percent = level ;
334
- break ;
335
- case 2 :
336
- state = SDL_POWERSTATE_CHARGED ;
337
- percent = 100 ;
338
- break ;
339
- default :
340
- state = SDL_POWERSTATE_UNKNOWN ;
341
- percent = 0 ;
342
- break ;
329
+ if (ctx -> powerstate_supported ) {
330
+ SDL_PowerState state ;
331
+ int percent ;
332
+ Uint8 status = data [14 ] >> 7 ;
333
+ Uint8 level = (data [14 ] & 0x7f );
334
+ if (level == 100 ) {
335
+ status = 2 ;
336
+ }
337
+ switch (status ) {
338
+ case 0 :
339
+ state = SDL_POWERSTATE_ON_BATTERY ;
340
+ percent = level ;
341
+ break ;
342
+ case 1 :
343
+ state = SDL_POWERSTATE_CHARGING ;
344
+ percent = level ;
345
+ break ;
346
+ case 2 :
347
+ state = SDL_POWERSTATE_CHARGED ;
348
+ percent = 100 ;
349
+ break ;
350
+ default :
351
+ state = SDL_POWERSTATE_UNKNOWN ;
352
+ percent = 0 ;
353
+ break ;
354
+ }
355
+ SDL_SendJoystickPowerInfo (joystick , state , percent );
343
356
}
344
357
345
- SDL_SendJoystickPowerInfo (joystick , state , percent );
346
358
347
359
if (ctx -> sensors_supported ) {
348
360
Uint64 sensor_timestamp ;
0 commit comments