Skip to content

Commit e236a48

Browse files
8BitDoslouken
authored andcommitted
8BitDo
Add adaptation ULTIMATE2_WIRELESS V1.02
1 parent 4de3967 commit e236a48

File tree

1 file changed

+41
-29
lines changed

1 file changed

+41
-29
lines changed

src/joystick/hidapi/SDL_hidapi_8bitdo.c

+41-29
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typedef struct
5252
bool rumble_type;
5353
bool rgb_supported;
5454
bool player_led_supported;
55+
bool powerstate_supported;
5556
Uint8 serial[6];
5657
Uint16 version;
5758
Uint16 version_beta;
@@ -105,8 +106,8 @@ static void HIDAPI_Driver8BitDo_UnregisterHints(SDL_HintCallback callback, void
105106
static bool HIDAPI_Driver8BitDo_IsEnabled(void)
106107
{
107108
// 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);
110111
}
111112

112113
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
117118
static bool HIDAPI_Driver8BitDo_InitDevice(SDL_HIDAPI_Device *device)
118119
{
119120
SDL_Driver8BitDo_Context *ctx;
120-
121+
Uint8 data[USB_PACKET_LENGTH];
122+
int size;
121123
ctx = (SDL_Driver8BitDo_Context *)SDL_calloc(1, sizeof(*ctx));
122124
if (!ctx) {
123125
return false;
@@ -129,7 +131,15 @@ static bool HIDAPI_Driver8BitDo_InitDevice(SDL_HIDAPI_Device *device)
129131
ctx->sensors_supported = true;
130132
ctx->rumble_supported = true;
131133
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+
}
133143
}
134144

135145
return HIDAPI_JoystickConnected(device, NULL);
@@ -316,33 +326,35 @@ static void HIDAPI_Driver8BitDo_HandleStatePacket(SDL_Joystick *joystick, SDL_Dr
316326
}
317327
#undef READ_TRIGGER_AXIS
318328

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);
343356
}
344357

345-
SDL_SendJoystickPowerInfo(joystick, state, percent);
346358

347359
if (ctx->sensors_supported) {
348360
Uint64 sensor_timestamp;

0 commit comments

Comments
 (0)