diff --git a/Makefile b/Makefile index 80db751..a13f993 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ # umpf... OPTS = -Wall -g -DDEBUG_LEVEL=1 +DEPS = Makefile + +all: osc-joy osc2cursor text2osc # ---------------------------------------------------- diff --git a/functions/Makefile b/functions/Makefile index 41be22a..6925e13 100644 --- a/functions/Makefile +++ b/functions/Makefile @@ -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 $@ $? diff --git a/functions/joyutils.c b/functions/joyutils.c new file mode 100644 index 0000000..000435b --- /dev/null +++ b/functions/joyutils.c @@ -0,0 +1,64 @@ +/* + * joystick utility functions + */ +#include +#include +#include +#include + +#include + +#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); + + } + +} +/* ----------------------------------------------------------------- */ + +/* ----------------------------------------------------------------- */ diff --git a/functions/joyutils.h b/functions/joyutils.h new file mode 100644 index 0000000..db5e1f6 --- /dev/null +++ b/functions/joyutils.h @@ -0,0 +1,6 @@ +/* + * joystick utility functions + */ + + +void dump_my_joystick(char *joy_device); diff --git a/osc-joy.c b/osc-joy.c index b67d10b..3362ed0 100644 --- a/osc-joy.c +++ b/osc-joy.c @@ -21,6 +21,7 @@ #include #include "functions/senders.h" +#include "functions/joyutils.h" /* default values, can be changed on command line */ @@ -39,11 +40,12 @@ char *my_id = MY_TEXT_ID; static void help(int k) { puts("\t * joystick -> osc "__DATE__" *"); +puts("\t-D\tdump joystick datas"); puts("\t-r\tremote host ("REMOTE_HOST")"); puts("\t-p\tremote UDP port ("REMOTE_PORT")"); puts("\t-j\tjoystick device ("JOY_DEVICE")"); puts("\t-v\tincrease verbosity"); -puts("\t-o\toffset added to button number"); +printf("\t-o\toffset added to button number (%d)\n", button_offset); puts("\t-I\tchange text id (\""MY_TEXT_ID"\")"); exit(0); } @@ -58,10 +60,12 @@ int opt; char *remote_host = REMOTE_HOST; char *remote_port = REMOTE_PORT; char *joy_device = JOY_DEVICE; +int do_dump = 0; /* parsing command line options */ -while ((opt = getopt(argc, argv, "hp:r:vj:o:I:")) != -1) { +while ((opt = getopt(argc, argv, "Dhp:r:vj:o:I:")) != -1) { switch (opt) { + case 'D': do_dump = 1; break; case 'h': help(0); break; case 'r': remote_host = optarg; break; case 'p': remote_port = optarg; break; @@ -74,6 +78,11 @@ while ((opt = getopt(argc, argv, "hp:r:vj:o:I:")) != -1) { } } +if (do_dump) { + fprintf(stderr, "dumping data from '%s'\n", joy_device); + dump_my_joystick(joy_device); + } + if (verbosity) { fprintf(stderr, "%s is sending to %s:%s\n", argv[0], remote_host, remote_port); diff --git a/tools/destinations.liste b/tools/destinations.liste new file mode 100644 index 0000000..1b4a254 --- /dev/null +++ b/tools/destinations.liste @@ -0,0 +1,2 @@ +localhost:9001 +localhost:9002 diff --git a/tools/relay.py b/tools/relay.py new file mode 100755 index 0000000..1d9c341 --- /dev/null +++ b/tools/relay.py @@ -0,0 +1,60 @@ +#!/usr/bin/python + +import socket, sys, getopt + +# --- default values + +RX_UDP_IP = "" # pour ecouter sur toutes les interfaces +RX_UDP_PORT = 5005 # entree du relais + +# --- + +rx_port = RX_UDP_PORT +verbose = 0 + +# --- parse command line arguments + +options = "hvp:c:" +arguments = sys.argv[1:] +opts, args = getopt.getopt(arguments, options) + +for o, a in opts: + print ' ', o, ' --> ', a + if "-v" == o: verbose += 1 + elif "-p" == o: rx_port = int(a) + +print "listening port : ", rx_port + +# --- + +cibles = [ ]; +for ligne in open("destinations.liste"): + a, p = ligne.replace('\n', '').split(":") + # print a, p + if p: cibles.append((a, int(p))) + +for cible in cibles: + print " -> ", cible + + +# point d'entree, d'ecoute +sock_rx = socket.socket(socket.AF_INET, # Internet + socket.SOCK_DGRAM) # UDP +sock_rx.bind((RX_UDP_IP, rx_port)) + +# point de sortie vers les autres +sock_tx = socket.socket(socket.AF_INET, # Internet + socket.SOCK_DGRAM) # UDP + +while True: + data, addr = sock_rx.recvfrom(1024) # buffer size is 1024 bytes + if verbose: + print "got:", addr, " ", len(data) + for cible in cibles: + # print cible + sock_tx.sendto(data, cible) + +# hop, ce truc doit fonctionner ! + + +