Browse Source

first step done ?

master
tth 3 months ago
parent
commit
dea4232d8e
9 changed files with 318 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +24
    -0
      Gaby/Makefile
  3. +13
    -0
      Gaby/audiodrive.c
  4. +8
    -0
      Gaby/burps.sh
  5. +103
    -0
      Gaby/gabylaser.c
  6. +52
    -0
      Gaby/receive-osc.c
  7. +12
    -0
      Gaby/receive-osc.h
  8. +93
    -0
      Gaby/transmit.c
  9. +11
    -0
      Gaby/transmit.h

+ 2
- 0
.gitignore View File

@ -22,6 +22,8 @@ tools/wait-for-joystick
tools/*.o
Gaby/*.[oa]
Gaby/gabylaser
Gaby/DUMP*
specific/joy2laser
specific/asyncburp


+ 24
- 0
Gaby/Makefile View File

@ -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 $@
# ------------------------------------------------------

+ 13
- 0
Gaby/audiodrive.c View File

@ -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 <stdio.h>
/* ---------------------------------------------------------------- */

+ 8
- 0
Gaby/burps.sh View File

@ -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

+ 103
- 0
Gaby/gabylaser.c View File

@ -0,0 +1,103 @@
/*
* LE LASER DE GABY
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <getopt.h>
#include <lo/lo.h>
#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;
}
/* ---------------------------------------------------------------- */

+ 52
- 0
Gaby/receive-osc.c View File

@ -0,0 +1,52 @@
/*
* LE LASER DE GABY
*
* +--------------------------------------------------+
* | reception des trames osc depuis le grand monde |
* +--------------------------------------------------+
*/
#include <stdio.h>
#include <lo/lo.h>
#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;
}
/* ---------------------------------------------------------------- */

+ 12
- 0
Gaby/receive-osc.h View File

@ -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);

+ 93
- 0
Gaby/transmit.c View File

@ -1,6 +1,99 @@
/*
* LE LASER DE GABY
*
* +---------------------------------------------+
* | transmission des commandes vers l'arduino |
* +---------------------------------------------+
$ oscsend localhost 9001 /joystick/xy ii 32000 -2210
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#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;
}
/* ---------------------------------------------------------------- */

+ 11
- 0
Gaby/transmit.h View File

@ -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);

Loading…
Cancel
Save