From: Dan Streetman <ddstreet@ieee.org>
To: linux-input@vger.kernel.org,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Vojtech Pavlik <vojtech@suse.cz>
Subject: Utility file to add to input-utils
Date: Fri, 23 Jan 2009 13:41:16 -0500 [thread overview]
Message-ID: <3fad22b40901231041v2c2a4822p6c81d27afaeaf2a@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 302 bytes --]
Dmitry and/or Vojtech, are either of you the right person to send a
new input utility to?
The attached file is a simple utility program that allows a user to
set the absolute value parameters (min, max, fuzz, and flat values)
for an absolute-value axis. Can you add this to the input utils?
Thanks.
[-- Attachment #2: absset.c --]
[-- Type: text/x-csrc, Size: 4953 bytes --]
/*
* absset.c
* Sets Absolute limits/values
* Copyright 2009 Dan Streetman <ddstreet@ieee.org>
*/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <fcntl.h>
#include <linux/input.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <errno.h>
char *progname;
void print_usage()
{
printf("Usage: %s [param...] <axis> <device>\n", progname);
printf("Modifies the parameters of an absolute-value axis.\n");
printf("\n");
printf("Params:\n");
printf(" -v --value=VALUE Set the current value.\n");
printf(" -m --min=MIN Set the minimum value.\n");
printf(" -M --max=MAX Set the maximum value.\n");
printf(" -f --fuzz=FUZZ Set the fuzz value.\n");
printf(" -F --flat=FLAT Set the flat value.\n");
printf("\n");
printf("Axis setting:\n");
printf(" -a --axis=N Change the values of axis number N.\n");
printf(" -x Change the X axis values, same as '-a 0'.\n");
printf(" -y Change the Y axis values, same as '-a 1'.\n");
printf(" -z Change the Z axis values, same as '-a 2'.\n");
}
int set_axis(char *arg, int *axisSet)
{
if (*axisSet) {
fprintf(stderr, "Cannot set more than 1 axis\n\n");
print_usage();
exit(1);
}
*axisSet = 1;
return strtol(arg, NULL, 0);
}
int main(int argc, char** argv)
{
int fd = 0;
char *device_file_name;
int retval = 0;
int opt;
char *shortopts = "hv:m:M:f:F:a:xyz";
struct option longopts[] = {
{ "value", 1, NULL, 'v' },
{ "min", 1, NULL, 'm' },
{ "max", 1, NULL, 'M' },
{ "fuzz", 1, NULL, 'f' },
{ "flat", 1, NULL, 'F' },
{ "axis", 1, NULL, 'a' },
{ 0, 0, 0, 0 }
};
__s32 value=0, min=0, max=0, fuzz=0, flat=0, axis=0;
int valueSet=0, minSet=0, maxSet=0, fuzzSet=0, flatSet=0, axisSet=0;
struct input_absinfo *ia = NULL;
progname = argv[0];
while ((opt = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch (opt) {
case 'v': value = strtol(optarg, NULL, 0); valueSet = 1; break;
case 'm': min = strtol(optarg, NULL, 0); minSet = 1; break;
case 'M': max = strtol(optarg, NULL, 0); maxSet = 1; break;
case 'f': fuzz = strtol(optarg, NULL, 0); fuzzSet = 1; break;
case 'F': flat = strtol(optarg, NULL, 0); flatSet = 1; break;
case 'a': axis = set_axis(optarg, &axisSet); break;
case 'x': axis = set_axis("0", &axisSet); break;
case 'y': axis = set_axis("1", &axisSet); break;
case 'z': axis = set_axis("2", &axisSet); break;
case 'h': /* fall through */
default:
print_usage();
exit(1);
}
}
if (optind >= argc) {
fprintf(stderr, "No device node specified.\n\n");
print_usage();
exit(1);
}
device_file_name = argv[optind];
if (!valueSet && !minSet && !maxSet && !fuzzSet && !flatSet && !axisSet) {
fprintf(stderr, "No param specified. You must specify at least one param.\n\n");
print_usage();
exit(1);
}
if (!axisSet) {
fprintf(stderr, "No axis specified.\n\n");
print_usage();
exit(1);
}
/* Open device */
fd = open(device_file_name, O_RDWR);
if (fd == -1) {
retval = -errno;
fprintf(stderr, "Error opening device %s : %s\n", device_file_name, strerror(-retval));
goto end;
}
if (!(ia = malloc(sizeof(*ia)))) {
fprintf(stderr, "Out of memory!\n");
retval = -ENOMEM;
goto end;
}
if (!valueSet || !minSet || !maxSet || !fuzzSet || !flatSet || !axisSet) {
if (ioctl(fd, EVIOCGABS(axis), ia) == -1) {
retval = -errno;
fprintf(stderr, "Error getting current axis %d values : %s\n", axis, strerror(-retval));
goto end;
}
}
if (valueSet)
ia->value = value;
if (minSet)
ia->minimum = min;
if (maxSet)
ia->maximum = max;
if (fuzzSet)
ia->fuzz = fuzz;
if (flatSet)
ia->flat = flat;
if (ioctl(fd, EVIOCSABS(axis), ia) == -1) {
fprintf(stderr, "Error setting axis %d values : %s\n", axis, strerror(errno));
retval = -1;
} else {
char *axisstr = "";
switch (axis) {
case 0: axisstr = " (X)"; break;
case 1: axisstr = " (Y)"; break;
case 2: axisstr = " (Z)"; break;
}
printf("Set axis %d%s parameters:\n\tvalue: %d\n\tminimum: %d\n\tmaximum: %d\n\tfuzz: %d\n\tflat: %d\n",
axis, axisstr, ia->value, ia->minimum, ia->maximum, ia->fuzz, ia->flat);
}
end:
if (fd)
close(fd);
if (ia)
free(ia);
exit(retval);
}
reply other threads:[~2009-01-23 18:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3fad22b40901231041v2c2a4822p6c81d27afaeaf2a@mail.gmail.com \
--to=ddstreet@ieee.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=vojtech@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).