diff --git a/.gitignore b/.gitignore index d39a694..e671407 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,8 @@ tools/wait-for-joystick tools/*.o Gaby/*.[oa] +Gaby/gabylaser +Gaby/DUMP* specific/joy2laser specific/asyncburp diff --git a/Gaby/Makefile b/Gaby/Makefile index 8be0cec..fdb1938 100644 --- a/Gaby/Makefile +++ b/Gaby/Makefile @@ -4,3 +4,27 @@ # Piloter le laser de Gaby # ------------------------------------------------------ +DEPS = Makefile transmit.h receive-osc.h + +receive-osc.o: receive-osc.c $(DEPS) + gcc -Wall -c $< + +transmit.o: transmit.c $(DEPS) + gcc -Wall -c $< + +audiodrive.o: audiodrive.c $(DEPS) + gcc -Wall -c $< + +# ------------------------------------------------------ + +gabylaser.o: gabylaser.c $(DEPS) + gcc -Wall -c $< + +OBJS = receive-osc.o transmit.o + +gabylaser: gabylaser.o $(DEPS) $(OBJS) + gcc -Wall $< $(OBJS) -llo -o $@ + +# ------------------------------------------------------ + + diff --git a/Gaby/audiodrive.c b/Gaby/audiodrive.c new file mode 100644 index 0000000..d3054f9 --- /dev/null +++ b/Gaby/audiodrive.c @@ -0,0 +1,13 @@ +/* + * LE LASER DE GABY + * + * +--------------------------------------------------+ + * | pilotage du bouzin par la sortie audio (wtf?) | + * +--------------------------------------------------+ + */ + +/**** note de l'auteur : on devrait essayer de faire ça en chuck ***/ + +#include + +/* ---------------------------------------------------------------- */ diff --git a/Gaby/burps.sh b/Gaby/burps.sh new file mode 100755 index 0000000..097797f --- /dev/null +++ b/Gaby/burps.sh @@ -0,0 +1,8 @@ +#!/bin/bash + + +for x in $(seq -32000 133 32000) +do + echo $x + oscsend localhost 9001 /joystick/xy ii $x -9999 +done diff --git a/Gaby/gabylaser.c b/Gaby/gabylaser.c new file mode 100644 index 0000000..fa6b703 --- /dev/null +++ b/Gaby/gabylaser.c @@ -0,0 +1,103 @@ +/* + * LE LASER DE GABY + */ + + +#include +#include +#include +#include + +#include + +#include + +#include "transmit.h" +#include "receive-osc.h" + +int verbosity; + +/* ---------------------------------------------------------------- */ +static void error(int num, const char *msg, const char *path) +{ +fprintf(stderr, "liblo server error %d in path %s : %s\n", num, path, msg); +exit(1); +} +/* ---------------------------------------------------------------- */ +int init_rx_osc(char *port) +{ +lo_server_thread st; + +st = lo_server_thread_new(port, error); + +lo_server_thread_add_method(st, "/joystick/xy", "ii", xy_handler, NULL); +lo_server_thread_add_method(st, "/joystick/b", "ii", button_handler, NULL); + +lo_server_thread_start(st); + +fprintf(stderr, "%s [done]\n", __func__); + +return 0; +} +/* ---------------------------------------------------------------- */ +static void print_lo_version(char *bla) +{ +#define SZ 100 +char str[SZ]; +char extra[SZ]; + +lo_version(str, SZ, 0, 0, extra, SZ, 0, 0, 0); + +fprintf(stderr, "%s: liblo v%s %s\n", bla, str, extra); +} +/* ---------------------------------------------------------------- */ +int help(int k) +{ +fprintf(stderr, "help = %d\n", k); +return 1; +} +/* ---------------------------------------------------------------- */ +int main(int argc, char *argv[]) +{ +char *local_port = "9001"; +int bauds = 0; +int foo, opt; + +fprintf(stderr, "GabyLaser - compiled %s %s\n", __DATE__, __TIME__); + +while ((opt = getopt(argc, argv, "hp:vE:C:")) != -1) { + switch (opt) { + case 'h': if (help(0)) exit(1); break; + case 'p': local_port = optarg; break; + case 'v': verbosity++; break; + } + } + +if (verbosity) print_lo_version(argv[0]); + +foo = init_rx_osc(local_port); +if (foo) { + fprintf(stderr, "init rx osc -> %d\n", foo); + exit(1); + } + +foo = init_transmit("./DUMP", bauds); +if (foo < 0) { + fprintf(stderr, "init transmit -> %d\n", foo); + exit(1); + } + +/* + * infinite loop is infinite + */ + +for (;;) { + if (verbosity) + fprintf(stderr, "t = %ld\n", time(NULL)); + sleep(100); + } + + +return 0; +} +/* ---------------------------------------------------------------- */ diff --git a/Gaby/receive-osc.c b/Gaby/receive-osc.c new file mode 100644 index 0000000..20f5c7a --- /dev/null +++ b/Gaby/receive-osc.c @@ -0,0 +1,52 @@ +/* + * LE LASER DE GABY + * + * +--------------------------------------------------+ + * | reception des trames osc depuis le grand monde | + * +--------------------------------------------------+ + */ + +#include + +#include + +#include "receive-osc.h" +#include "transmit.h" + +/* ---------------------------------------------------------------- */ + +static int old_x, old_y; + +int xy_handler(const char *path, const char *types, lo_arg ** argv, + int argc, void *data, void *user_data) +{ +int val_x, val_y; +int foo; + +// fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, path, types); + +val_x = argv[0]->i; val_y = argv[1]->i; + +fprintf(stderr, "osc -> %7d %7d\n", val_x, val_y); + +if (old_x != val_x) { + foo = send_position('X', val_x); + old_x = val_x; + } +if (old_y != val_y) { + foo = send_position('Y', val_y); + old_y = val_y; + } + +return -1; +} +/* ---------------------------------------------------------------- */ +int button_handler(const char *path, const char *types, lo_arg ** argv, + int argc, void *data, void *user_data) +{ + +fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, path, types); + +return -1; +} +/* ---------------------------------------------------------------- */ diff --git a/Gaby/receive-osc.h b/Gaby/receive-osc.h new file mode 100644 index 0000000..82ec8e0 --- /dev/null +++ b/Gaby/receive-osc.h @@ -0,0 +1,12 @@ + + + + + +int xy_handler(const char *path, const char *types, lo_arg ** argv, + int argc, void *data, void *user_data); + + +int button_handler(const char *path, const char *types, lo_arg ** argv, + int argc, void *data, void *user_data); + diff --git a/Gaby/transmit.c b/Gaby/transmit.c index 66546d8..3694de4 100644 --- a/Gaby/transmit.c +++ b/Gaby/transmit.c @@ -1,6 +1,99 @@ /* + * LE LASER DE GABY + * * +---------------------------------------------+ * | transmission des commandes vers l'arduino | * +---------------------------------------------+ + + $ oscsend localhost 9001 /joystick/xy ii 32000 -2210 + + */ +#include +#include +#include +#include +#include +#include + +#include + +#include "../functions/serial.h" +#include "transmit.h" + +/* ---------------------------------------------------------------- */ + +static int fdtx = -1; + +/* ---------------------------------------------------------------- */ +/* + * parametres : + * fname: a file for dumping data or a serial device + * bauds: speed of serial port, 0 for a file dump + * + */ +int init_transmit(char *fname, int bauds) +{ +int fd; +int baudsymb; + +fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, bauds); + +if (0 == bauds) { + /* open as a dump file */ + fd = open(fname, O_CREAT|O_WRONLY|O_TRUNC, S_IRWXU); + if (fd < 0) { + perror(fname); + exit(1); + } + } +else { + + /* open as as a serial out to Arduino */ + + fprintf(stderr, "bauds are %d, exiting\n", bauds); + exit(1); + + /* XXX */ + + } + +fdtx = fd; +fprintf(stderr, "%s: fd is %d\n", __func__, fdtx); + +return fd; +} +/* ---------------------------------------------------------------- */ +/* + * ici on présupoose que la valeur est un "short int" + * donc 2^16 valeurs -32768 32767 + */ +int send_position(char xy, int value) +{ +char message[100]; +char val8; +int foo; + +if (fdtx < 0) { + fprintf(stderr, "%s: fdtx not initialized !\n", __func__); + exit(1); + } + +if (xy != 'X' && xy != 'Y') { + fprintf(stderr, "%s: invalid xy tag '%c'\n", __func__, xy); + return -1; + } + +val8 = (char)(value / 256); /* -> signed byte */ +sprintf(message, "%c%02x", xy, (unsigned char)val8); +fprintf(stderr, " %c %8d %8d %s\n", xy, value, val8, message); +foo = write(fdtx, message, 3); +if (3 != foo) { + perror("write ?"); + return -1; + } +return 0; +} + +/* ---------------------------------------------------------------- */ diff --git a/Gaby/transmit.h b/Gaby/transmit.h new file mode 100644 index 0000000..39e70cb --- /dev/null +++ b/Gaby/transmit.h @@ -0,0 +1,11 @@ +/* + * LE LASER DE GABY + * + * +---------------------------------------------+ + * | transmission des commandes vers l'arduino | + * +---------------------------------------------+ + */ + +int init_transmit(char *fname, int k); +int send_position(char xy, int value); +