Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duration fix #35

Merged
merged 3 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions bin/ffbwrap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

OPTIONS=$(getopt --long 'logger:,update-fix,direction-fix,features-hack,force-inversion,ignore-set-gain,offset-fix,throttling,throttling-time:' -n "$0" -- "" "$@")
OPTIONS=$(getopt --long 'logger:,update-fix,direction-fix,duration-fix,features-hack,force-inversion,ignore-set-gain,offset-fix,throttling,throttling-time:' -n "$0" -- "" "$@")

if [ $? -ne 0 ]; then
exit 1
Expand Down Expand Up @@ -60,6 +60,11 @@ while true; do
shift
continue
;;
'--duration-fix')
FFBTOOLS_DURATION_FIX=1
shift
continue
;;
'--features-hack')
FFBTOOLS_FEATURES_HACK=1
shift
Expand Down Expand Up @@ -114,12 +119,12 @@ COMMAND="$1"
shift

if [ -z "${FFBTOOLS_DEV_MAJOR}" -o -z "${FFBTOOLS_DEV_MINOR}" -o -z "${COMMAND}" ]; then
echo "Usage: $0 [--logger=logfile] [--update-fix] [--direction-fix] [--features-hack] [--force-inversion] [--ignore-set-gain] [--offset-fix] [--throttling] [--throttling-time=N] <device> -- <command>"
echo "Usage: $0 [--logger=logfile] [--update-fix] [--direction-fix] [--duration-fix] [--features-hack] [--force-inversion] [--ignore-set-gain] [--offset-fix] [--throttling] [--throttling-time=N] <device> -- <command>"
exit 1
fi

FFBTOOLS_DEVICE_NAME="$(eval $(udevadm info -q property -x "${DEVICE_FILE}") && echo "${ID_VENDOR} ${ID_MODEL//_/ }")"

export LD_PRELOAD FFBTOOLS_DEVICE_NAME FFBTOOLS_DEV_MAJOR FFBTOOLS_DEV_MINOR FFBTOOLS_LOGGER FFBTOOLS_LOG_FILE FFBTOOLS_UPDATE_FIX FFBTOOLS_DIRECTION_FIX FFBTOOLS_FEATURES_HACK FFBTOOLS_FORCE_INVERSION FFBTOOLS_IGNORE_SET_GAIN FFBTOOLS_OFFSET_FIX FFBTOOLS_THROTTLING
export LD_PRELOAD FFBTOOLS_DEVICE_NAME FFBTOOLS_DEV_MAJOR FFBTOOLS_DEV_MINOR FFBTOOLS_LOGGER FFBTOOLS_LOG_FILE FFBTOOLS_UPDATE_FIX FFBTOOLS_DIRECTION_FIX FFBTOOLS_DURATION_FIX FFBTOOLS_FEATURES_HACK FFBTOOLS_FORCE_INVERSION FFBTOOLS_IGNORE_SET_GAIN FFBTOOLS_OFFSET_FIX FFBTOOLS_THROTTLING

"${COMMAND}" "$@"
3 changes: 3 additions & 0 deletions docs/ffbwrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ One or more of the following options can be used:
a vertical component are ignored so this fix sets an horizontal direction to
all effects.

`--duration-fix`: Apply a fix to set the duration 0 to 0xFFFF for devices that
do not interpret 0 as an infinite effect..

`--features-hack`: Reports all effect types as supported. The effect types not
supported by the device will later fail but it allows to log all the effects
the application can generate.
Expand Down
20 changes: 17 additions & 3 deletions src/ffbwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static unsigned int dev_minor = 0;
static int enable_logger = 0;
static int enable_update_fix = 0;
static int enable_direction_fix = 0;
static int enable_duration_fix = 0;
static int enable_features_hack = 0;
static int enable_force_inversion = 0;
static int ignore_set_gain = 0;
Expand Down Expand Up @@ -180,6 +181,11 @@ static void ffbt_init()
enable_direction_fix = 1;
}

const char *str_duration_fix = getenv("FFBTOOLS_DURATION_FIX");
if (str_duration_fix != NULL && strcmp(str_duration_fix, "1") == 0) {
enable_duration_fix = 1;
}

const char *str_features_hack = getenv("FFBTOOLS_FEATURES_HACK");
if (str_features_hack != NULL && strcmp(str_features_hack, "1") == 0) {
enable_features_hack = 1;
Expand Down Expand Up @@ -227,11 +233,11 @@ static void ffbt_init()

if (enable_logger && ftell(log_file) == 0) {
report("# DEVICE_NAME=%s, UPDATE_FIX=%d, "
"DIRECTION_FIX=%d, FEATURES_HACK=%d, "
"DIRECTION_FIX=%d, DURATION_FIX=%d, FEATURES_HACK=%d, "
"FORCE_INVERSION=%d, IGNORE_SET_GAIN=%d, OFFSET_FIX=%d, "
"THROTTLING=%s",
getenv("FFBTOOLS_DEVICE_NAME"), enable_update_fix,
enable_direction_fix, enable_features_hack,
enable_direction_fix, enable_duration_fix, enable_features_hack,
enable_force_inversion, ignore_set_gain, enable_offset_fix,
str_throttling == NULL ? "0" : str_throttling);
}
Expand Down Expand Up @@ -378,13 +384,21 @@ int ioctl(int fd, unsigned long request, char *argp)
effect->u.condition[0].center);
}

int modified = enable_direction_fix | enable_force_inversion;
int modified = enable_direction_fix | enable_force_inversion | enable_duration_fix;

report("%s> UPLOAD id:%d dir:%d length:%d delay:%d type:%s %s",
modified ? "#" : "", effect->id,
effect->direction, effect->replay.length,
effect->replay.delay, type, effect_params);

if (enable_duration_fix && effect->replay.length == 0) {
effect->replay.length = 0xFFFF;
report("> UPLOAD id:%d dir:%d type:%s length:%d delay:%d %s "
"# duration fix", effect->id, effect->direction, type,
effect->replay.length, effect->replay.delay,
effect_params);
}

if (enable_direction_fix && (effect->direction == 0 || effect->direction == 0x8000)) {
effect->direction -= 0x4000;
report("> UPLOAD id:%d dir:%d type:%s length:%d delay:%d %s "
Expand Down