Skip to content

Instantly share code, notes, and snippets.

@Spacefreak18
Last active September 9, 2022 14:53
Show Gist options
  • Save Spacefreak18/50e27015bdfeb1c9a4da7d3e1b03dff5 to your computer and use it in GitHub Desktop.
Save Spacefreak18/50e27015bdfeb1c9a4da7d3e1b03dff5 to your computer and use it in GitHub Desktop.
SDL Linux Infinite Haptic Effect Length
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index a9be7e0d3..a50fce6b1 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -766,6 +766,8 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
/* Replay */
dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ?
0 : CLAMP(constant->length);
+ dest->replay.length = (constant->length == -1) ?
+ USHRT_MAX : constant->length;
dest->replay.delay = CLAMP(constant->delay);
/* Trigger */
@@ -773,6 +775,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
dest->trigger.interval = CLAMP(constant->interval);
/* Constant */
+
+ constant->level = (constant->level == -1) ?
+ SHRT_MAX : constant->level;
dest->u.constant.level = constant->level;
/* Envelope */
@@ -801,6 +806,8 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
/* Replay */
dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ?
0 : CLAMP(periodic->length);
+ dest->replay.length = (periodic->length == -1) ?
+ USHRT_MAX : periodic->length;
dest->replay.delay = CLAMP(periodic->delay);
/* Trigger */
@@ -821,6 +828,9 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
dest->u.periodic.waveform = FF_SAW_DOWN;
dest->u.periodic.period = CLAMP(periodic->period);
dest->u.periodic.magnitude = periodic->magnitude;
+
+ periodic->offset = (periodic->offset == -1) ?
+ SHRT_MAX : periodic->offset;
dest->u.periodic.offset = periodic->offset;
/* Linux phase is defined in interval "[0x0000, 0x10000[", corresponds with "[0deg, 360deg[" phase shift. */
dest->u.periodic.phase = ((Uint32)periodic->phase * 0x10000U) / 36000;
@@ -855,6 +865,8 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
/* Replay */
dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ?
0 : CLAMP(condition->length);
+ dest->replay.length = (condition->length == -1) ?
+ USHRT_MAX : condition->length;
dest->replay.delay = CLAMP(condition->delay);
/* Trigger */
@@ -877,6 +889,18 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
dest->u.condition[1].deadband = condition->deadband[1];
dest->u.condition[1].center = condition->center[1];
+ dest->u.condition[0].right_coeff = (condition->right_coeff[0] == -1) ?
+ SHRT_MAX : condition->right_coeff[0];
+ dest->u.condition[0].left_coeff = (condition->left_coeff[0] == -1) ?
+ SHRT_MAX : condition->left_coeff[0];
+ dest->u.condition[0].center = (condition->center[0] == -1) ?
+ SHRT_MAX : condition->center[0];
+ dest->u.condition[1].right_coeff = (condition->right_coeff[1] == -1) ?
+ SHRT_MAX : condition->right_coeff[1];
+ dest->u.condition[1].left_coeff = (condition->left_coeff[1] == -1) ?
+ SHRT_MAX : condition->left_coeff[1];
+ dest->u.condition[1].center = (condition->center[1] == -1) ?
+ SHRT_MAX : condition->center[1];
/*
* There is no envelope in the linux force feedback api for conditions.
*/
@@ -894,6 +918,8 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
/* Replay */
dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ?
0 : CLAMP(ramp->length);
+ dest->replay.length = (ramp->length == -1) ?
+ USHRT_MAX : ramp->length;
dest->replay.delay = CLAMP(ramp->delay);
/* Trigger */
@@ -922,6 +948,8 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
/* Replay */
dest->replay.length = (leftright->length == SDL_HAPTIC_INFINITY) ?
0 : CLAMP(leftright->length);
+ dest->replay.length = (leftright->length == -1) ?
+ USHRT_MAX : leftright->length;
/* Trigger */
dest->trigger.button = 0;
@@ -941,7 +969,6 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
return 0;
}
-
/*
* Creates a new haptic effect.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment