reworking the kluge
This commit is contained in:
@@ -17,8 +17,12 @@ alsaseq.o: alsaseq.c alsaseq.h Makefile
|
||||
serial.o: serial.c serial.h Makefile
|
||||
gcc ${OPTS} -c $<
|
||||
|
||||
joyutils.o: joyutils.c joyutils.h Makefile
|
||||
gcc ${OPTS} -c $<
|
||||
|
||||
ncursefuncs.o: ncursefuncs.c ncursefuncs.h Makefile
|
||||
gcc ${OPTS} -c $<
|
||||
|
||||
libpocosc.a: senders.o alsaseq.o serial.o ncursefuncs.o
|
||||
libpocosc.a: senders.o alsaseq.o serial.o ncursefuncs.o \
|
||||
joyutils.o
|
||||
ar r $@ $?
|
||||
|
||||
64
functions/joyutils.c
Normal file
64
functions/joyutils.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* joystick utility functions
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <linux/joystick.h>
|
||||
|
||||
#include "joyutils.h"
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
static char *type2txt(unsigned char type)
|
||||
{
|
||||
static char temp[100];
|
||||
|
||||
if (!(type & JS_EVENT_INIT)) {
|
||||
switch(type) {
|
||||
case JS_EVENT_BUTTON: return "button";
|
||||
case JS_EVENT_AXIS: return "axis";
|
||||
}
|
||||
}
|
||||
else {
|
||||
sprintf(temp, "init %d", type & 0x7f);
|
||||
return temp;
|
||||
}
|
||||
return "???";
|
||||
}
|
||||
void dump_my_joystick(char *joy_device)
|
||||
{
|
||||
int joy_fd, foo;
|
||||
struct js_event js;
|
||||
int flag = 0;
|
||||
unsigned long debut;
|
||||
|
||||
if( ( joy_fd = open(joy_device , O_RDONLY)) == -1 ) {
|
||||
fprintf(stderr, "%s: couldn't open %s\n", __func__, joy_device);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
foo = read(joy_fd, &js, sizeof(struct js_event));
|
||||
if ( ! flag ) {
|
||||
debut = js.time;
|
||||
flag = 1;
|
||||
}
|
||||
|
||||
if (8 != foo) {
|
||||
fprintf(stderr, "%s: err reading joy\n", __func__);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("%8lu %4d / %-8s %2d %7d\n",
|
||||
js.time-debut,
|
||||
js.type, type2txt(js.type),
|
||||
js.number, js.value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
6
functions/joyutils.h
Normal file
6
functions/joyutils.h
Normal file
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
* joystick utility functions
|
||||
*/
|
||||
|
||||
|
||||
void dump_my_joystick(char *joy_device);
|
||||
Reference in New Issue
Block a user