summaryrefslogtreecommitdiff
path: root/x11-toolkits/plib
diff options
context:
space:
mode:
authorJean-Yves Lefort <jylefort@FreeBSD.org>2005-12-07 10:07:28 +0000
committerJean-Yves Lefort <jylefort@FreeBSD.org>2005-12-07 10:07:28 +0000
commit9bc41d5dde53895fc0d9bf2c741222364d3c13d2 (patch)
tree9ed7a891675b414c7217bbe4c4509058a01c9b5c /x11-toolkits/plib
parent- Add SHA256 checksum (diff)
- PC joystick fixes:
- support joysticks having only one axis - filter out bogus values - warn if the calibration files cannot be read - provide a calibration utility - Makefile cleanup
Notes
Notes: svn path=/head/; revision=150576
Diffstat (limited to 'x11-toolkits/plib')
-rw-r--r--x11-toolkits/plib/Makefile14
-rw-r--r--x11-toolkits/plib/files/jsBSDCal.c199
-rw-r--r--x11-toolkits/plib/files/patch-src_js_jsBSD.cxx48
-rw-r--r--x11-toolkits/plib/pkg-plist1
4 files changed, 257 insertions, 5 deletions
diff --git a/x11-toolkits/plib/Makefile b/x11-toolkits/plib/Makefile
index 789a4d9dbdc4..55eba88d0200 100644
--- a/x11-toolkits/plib/Makefile
+++ b/x11-toolkits/plib/Makefile
@@ -7,6 +7,7 @@
PORTNAME= plib
PORTVERSION= 1.8.4
+PORTREVISION= 1
CATEGORIES= x11-toolkits
MASTER_SITES= http://plib.sourceforge.net/dist/
@@ -17,10 +18,13 @@ USE_X_PREFIX= yes
USE_GL= yes
USE_GMAKE= yes
GNU_CONFIGURE= yes
-CONFIGURE_ENV= CC="${CC}" CFLAGS="${CFLAGS}" \
- CXX="${CXX}" CXXFLAGS="${CXXFLAGS} -fPIC" \
- CPPFLAGS="${PTHREAD_CFLAGS}" \
- LDFLAGS="${PTHREAD_LIBS}"
-CONFIGURE_ARGS= --with-GL=${X11BASE} --with-x
+CONFIGURE_ENV= CPPFLAGS="-I${X11BASE}/include ${PTHREAD_CFLAGS}" \
+ LDFLAGS="-L${X11BASE}/lib ${PTHREAD_LIBS}"
+
+post-build:
+ ${CC} ${CFLAGS} -o ${WRKDIR}/plib-jscal ${FILESDIR}/jsBSDCal.c
+
+post-install:
+ ${INSTALL_PROGRAM} ${WRKDIR}/plib-jscal ${PREFIX}/bin
.include <bsd.port.mk>
diff --git a/x11-toolkits/plib/files/jsBSDCal.c b/x11-toolkits/plib/files/jsBSDCal.c
new file mode 100644
index 000000000000..b09aed60fc79
--- /dev/null
+++ b/x11-toolkits/plib/files/jsBSDCal.c
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2005 Jean-Yves Lefort <jylefort@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <sys/joystick.h>
+
+#define N_ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+typedef struct
+{
+ int min;
+ int center;
+ int max;
+} Axis;
+
+typedef struct
+{
+ int n;
+ int fd;
+ Axis axes[2];
+} Joystick;
+
+static Joystick joysticks[2];
+
+static void
+get_position (Joystick *joy, int *x, int *y)
+{
+ int b1 = -1;
+ int b2 = -1;
+
+ *x = 0;
+ *y = 0;
+
+ while (1)
+ {
+ struct joystick data;
+
+ if (read(joy->fd, &data, sizeof(data)) == sizeof(data))
+ {
+ if ((data.b1 && b1 == 0) || (data.b2 && b2 == 0))
+ break;
+
+ b1 = data.b1;
+ b2 = data.b2;
+
+ if (data.x > -1000000000)
+ *x = data.x;
+ if (data.y > -1000000000)
+ *y = data.y;
+ }
+
+ printf("\rCurrent position: (%10i,%10i)", *x, *y);
+ fflush(stdout);
+
+ usleep(50000);
+ }
+
+ printf("\n");
+}
+
+static void
+handle_axis_reversal (Axis *axis)
+{
+ if (axis->min > axis->max)
+ {
+ int tmp;
+
+ tmp = axis->min;
+ axis->min = axis->max;
+ axis->max = tmp;
+ }
+}
+
+static void
+calibrate_joystick (Joystick *joy)
+{
+ int n = joy->n + 1;
+
+ printf("Move joystick %i to the lower left corner and press any button.\n", n);
+ get_position(joy, &joy->axes[0].min, &joy->axes[1].min);
+
+ printf("Center joystick %i and press any button.\n", n);
+ get_position(joy, &joy->axes[0].center, &joy->axes[1].center);
+
+ printf("Move joystick %i to the upper right corner and press any button.\n", n);
+ get_position(joy, &joy->axes[0].max, &joy->axes[1].max);
+
+ handle_axis_reversal(&joy->axes[0]);
+ handle_axis_reversal(&joy->axes[1]);
+}
+
+int
+main (int argc, char **argv)
+{
+ int joy_count = 0;
+ Joystick *joy;
+ int n;
+ char *home;
+
+ home = getenv("HOME");
+ if (! home)
+ {
+ fprintf(stderr, "$HOME environment variable not set.\n");
+ exit(1);
+ }
+
+ for (joy = &joysticks[0], n = 0; n < N_ELEMENTS(joysticks); joy++, n++)
+ {
+ char devname[PATH_MAX];
+
+ joy->n = n;
+
+ snprintf(devname, sizeof(devname), "/dev/joy%i", n);
+ joy->fd = open(devname, O_RDONLY);
+
+ if (joy->fd < 0)
+ printf("Cannot open joystick %s: %s\n", devname, strerror(errno));
+ else
+ {
+ joy_count++;
+ calibrate_joystick(joy);
+ close(joy->fd);
+ }
+ }
+
+ if (joy_count == 0)
+ {
+ fprintf(stderr, "No joystick was found.\n");
+ exit(1);
+ }
+
+ for (joy = &joysticks[0], n = 0; n < N_ELEMENTS(joysticks); joy++, n++)
+ if (joy->fd >= 0)
+ {
+ FILE *f;
+ char filename[PATH_MAX];
+
+ snprintf(filename, sizeof(filename), "%s/.joy%irc", home, joy->n);
+ f = fopen(filename, "w");
+
+ if (! f)
+ {
+ fprintf(stderr, "Unable to open %s for writing: %s.\n", filename, strerror(errno));
+ exit(1);
+ }
+
+ if (fprintf(f, "16 %i %i %i %i %i %i",
+ joy->axes[0].min, joy->axes[0].center, joy->axes[0].max,
+ joy->axes[1].min, joy->axes[1].center, joy->axes[1].max) < 0)
+ {
+ fprintf(stderr, "Unable to write %s: %s.\n", filename, strerror(errno));
+ exit(1);
+ }
+
+ if (fclose(f) != 0)
+ {
+ fprintf(stderr, "Unable to close %s: %s.\n", filename, strerror(errno));
+ exit(1);
+ }
+
+ printf("Wrote %s.\n", filename);
+ }
+
+ return 0;
+}
diff --git a/x11-toolkits/plib/files/patch-src_js_jsBSD.cxx b/x11-toolkits/plib/files/patch-src_js_jsBSD.cxx
new file mode 100644
index 000000000000..12bfa1f86e75
--- /dev/null
+++ b/x11-toolkits/plib/files/patch-src_js_jsBSD.cxx
@@ -0,0 +1,48 @@
+--- src/js/jsBSD.cxx.orig Wed Jan 12 02:22:26 2005
++++ src/js/jsBSD.cxx Wed Dec 7 10:35:27 2005
+@@ -44,6 +44,8 @@
+ #define HAVE_USB_JS 1
+ #endif
+
++#include <string.h>
++#include <errno.h>
+ #include <sys/ioctl.h>
+ #if defined(__FreeBSD__)
+ # include <sys/joystick.h>
+@@ -312,7 +314,7 @@
+ int buttons [ _JS_MAX_AXES ] ;
+
+ rawRead ( buttons, axes ) ;
+- error = axes[0] < -1000000000.0f ;
++ error = axes[0] < -1000000000.0f && axes[1] < -1000000000.0f ;
+ if ( error )
+ return ;
+
+@@ -321,7 +323,11 @@
+ joyfile = fopen ( joyfname, "r" ) ;
+ error = ( joyfile == NULL ) ;
+ if ( error )
++ {
++ ulSetError ( UL_WARNING, "unable to open calibration file %s (%s), joystick %i disabled (you can generate the calibration file with the plib-jscal utility)",
++ joyfname, strerror ( errno ), id + 1 );
+ return ;
++ }
+
+ noargs = fscanf ( joyfile, "%d%f%f%f%f%f%f", &in_no_axes,
+ &min [ 0 ], &center [ 0 ], &max [ 0 ],
+@@ -445,8 +451,13 @@
+
+ if ( axes != NULL )
+ {
+- axes[0] = (float) os->ajs.x ;
+- axes[1] = (float) os->ajs.y ;
++ if ( os->ajs.x >= -1000000000 )
++ os->cache_axes[0] = os->ajs.x;
++ if ( os->ajs.y >= -1000000000 )
++ os->cache_axes[1] = os->ajs.y;
++
++ axes[0] = os->cache_axes[0];
++ axes[1] = os->cache_axes[1];
+ }
+
+ return;
diff --git a/x11-toolkits/plib/pkg-plist b/x11-toolkits/plib/pkg-plist
index c89488c2024c..fa68c25af8ac 100644
--- a/x11-toolkits/plib/pkg-plist
+++ b/x11-toolkits/plib/pkg-plist
@@ -1,3 +1,4 @@
+bin/plib-jscal
include/plib/fnt.h
include/plib/js.h
include/plib/net.h