mirror of https://github.com/encounter/SDL.git
SDL: let through a SetLED command every 5sec to deall with situations where the controller loses power when a computer is suspended
CR: SamL
This commit is contained in:
parent
c59d4dcd38
commit
2a20cc0f1d
|
@ -416,6 +416,7 @@ SDL_JoystickOpen(int device_index)
|
||||||
joystick->instance_id = instance_id;
|
joystick->instance_id = instance_id;
|
||||||
joystick->attached = SDL_TRUE;
|
joystick->attached = SDL_TRUE;
|
||||||
joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
|
joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
|
||||||
|
joystick->led_expiration = SDL_GetTicks();
|
||||||
|
|
||||||
if (driver->Open(joystick, device_index) < 0) {
|
if (driver->Open(joystick, device_index) < 0) {
|
||||||
SDL_free(joystick);
|
SDL_free(joystick);
|
||||||
|
@ -954,6 +955,7 @@ int
|
||||||
SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
SDL_bool isfreshvalue;
|
||||||
|
|
||||||
if (!SDL_PrivateJoystickValid(joystick)) {
|
if (!SDL_PrivateJoystickValid(joystick)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -961,13 +963,17 @@ SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||||
|
|
||||||
SDL_LockJoysticks();
|
SDL_LockJoysticks();
|
||||||
|
|
||||||
if (red == joystick->led_red &&
|
isfreshvalue = red != joystick->led_red ||
|
||||||
green == joystick->led_green &&
|
green != joystick->led_green ||
|
||||||
blue == joystick->led_blue) {
|
blue != joystick->led_blue;
|
||||||
|
|
||||||
|
if ( isfreshvalue || SDL_TICKS_PASSED( SDL_GetTicks(), joystick->led_expiration ) ) {
|
||||||
|
result = joystick->driver->SetLED(joystick, red, green, blue);
|
||||||
|
joystick->led_expiration = SDL_GetTicks() + SDL_LED_MIN_REPEAT_MS;
|
||||||
|
}
|
||||||
|
else {
|
||||||
/* Avoid spamming the driver */
|
/* Avoid spamming the driver */
|
||||||
result = 0;
|
result = 0;
|
||||||
} else {
|
|
||||||
result = joystick->driver->SetLED(joystick, red, green, blue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the LED value regardless of success, so we don't spam the driver */
|
/* Save the LED value regardless of success, so we don't spam the driver */
|
||||||
|
|
|
@ -99,6 +99,7 @@ struct _SDL_Joystick
|
||||||
Uint8 led_red;
|
Uint8 led_red;
|
||||||
Uint8 led_green;
|
Uint8 led_green;
|
||||||
Uint8 led_blue;
|
Uint8 led_blue;
|
||||||
|
Uint32 led_expiration;
|
||||||
|
|
||||||
SDL_bool attached;
|
SDL_bool attached;
|
||||||
SDL_bool is_game_controller;
|
SDL_bool is_game_controller;
|
||||||
|
@ -189,6 +190,8 @@ typedef struct _SDL_JoystickDriver
|
||||||
/* Windows and Mac OSX has a limit of MAX_DWORD / 1000, Linux kernel has a limit of 0xFFFF */
|
/* Windows and Mac OSX has a limit of MAX_DWORD / 1000, Linux kernel has a limit of 0xFFFF */
|
||||||
#define SDL_MAX_RUMBLE_DURATION_MS 0xFFFF
|
#define SDL_MAX_RUMBLE_DURATION_MS 0xFFFF
|
||||||
|
|
||||||
|
#define SDL_LED_MIN_REPEAT_MS 5000
|
||||||
|
|
||||||
/* The available joystick drivers */
|
/* The available joystick drivers */
|
||||||
extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver;
|
extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver;
|
||||||
extern SDL_JoystickDriver SDL_BSD_JoystickDriver;
|
extern SDL_JoystickDriver SDL_BSD_JoystickDriver;
|
||||||
|
|
Loading…
Reference in New Issue