Browse Source

reworking the kluge

tth 5 months ago
parent
commit
cff083a21d
7 changed files with 151 additions and 3 deletions
  1. 3
    0
      Makefile
  2. 5
    1
      functions/Makefile
  3. 64
    0
      functions/joyutils.c
  4. 6
    0
      functions/joyutils.h
  5. 11
    2
      osc-joy.c
  6. 2
    0
      tools/destinations.liste
  7. 60
    0
      tools/relay.py

+ 3
- 0
Makefile View File

@@ -3,6 +3,9 @@
3 3
 # umpf...
4 4
 
5 5
 OPTS = -Wall -g -DDEBUG_LEVEL=1
6
+DEPS = Makefile
7
+
8
+all:	osc-joy osc2cursor text2osc
6 9
 
7 10
 # ----------------------------------------------------
8 11
 

+ 5
- 1
functions/Makefile View File

@@ -17,8 +17,12 @@ alsaseq.o:	alsaseq.c alsaseq.h Makefile
17 17
 serial.o:	serial.c serial.h Makefile
18 18
 	gcc ${OPTS} -c $<
19 19
 
20
+joyutils.o:	joyutils.c joyutils.h Makefile
21
+	gcc ${OPTS} -c $<
22
+
20 23
 ncursefuncs.o:	ncursefuncs.c ncursefuncs.h Makefile
21 24
 	gcc ${OPTS} -c $<
22 25
 
23
-libpocosc.a:	senders.o alsaseq.o serial.o ncursefuncs.o
26
+libpocosc.a:	senders.o alsaseq.o serial.o ncursefuncs.o	\
27
+		joyutils.o
24 28
 	ar r $@ $?

+ 64
- 0
functions/joyutils.c View File

@@ -0,0 +1,64 @@
1
+/*
2
+ *		joystick utility functions
3
+ */
4
+#include  <stdio.h>
5
+#include  <stdlib.h>
6
+#include  <unistd.h>
7
+#include  <fcntl.h>
8
+
9
+#include  <linux/joystick.h>
10
+
11
+#include  "joyutils.h"
12
+
13
+/* ----------------------------------------------------------------- */
14
+static char *type2txt(unsigned char type)
15
+{
16
+static char	temp[100];
17
+
18
+if (!(type & JS_EVENT_INIT)) {
19
+	switch(type) {
20
+		case JS_EVENT_BUTTON:		return "button";
21
+		case JS_EVENT_AXIS:		return "axis";
22
+		}
23
+	}
24
+else	{
25
+	sprintf(temp, "init %d", type & 0x7f);
26
+	return temp;
27
+	}
28
+return "???";
29
+}
30
+void dump_my_joystick(char *joy_device)
31
+{
32
+int			joy_fd, foo;
33
+struct js_event 	js;
34
+int			flag = 0;
35
+unsigned long		debut;
36
+
37
+if( ( joy_fd = open(joy_device , O_RDONLY)) == -1 ) {
38
+	fprintf(stderr, "%s: couldn't open %s\n", __func__, joy_device);
39
+	exit(1);
40
+	}
41
+
42
+for (;;) {
43
+	foo = read(joy_fd, &js, sizeof(struct js_event));
44
+	if ( ! flag ) {
45
+		debut = js.time;
46
+		flag = 1;
47
+		}
48
+
49
+	if (8 != foo) {
50
+		fprintf(stderr, "%s: err reading joy\n", __func__);
51
+		exit(1);
52
+		}
53
+
54
+	printf("%8lu      %4d / %-8s         %2d      %7d\n",
55
+			js.time-debut,
56
+			js.type, type2txt(js.type),
57
+			js.number, js.value);
58
+
59
+	}
60
+
61
+}
62
+/* ----------------------------------------------------------------- */
63
+
64
+/* ----------------------------------------------------------------- */

+ 6
- 0
functions/joyutils.h View File

@@ -0,0 +1,6 @@
1
+/*
2
+ *		joystick utility functions
3
+ */
4
+
5
+
6
+void dump_my_joystick(char *joy_device);

+ 11
- 2
osc-joy.c View File

@@ -21,6 +21,7 @@
21 21
 #include <lo/lo.h>
22 22
 
23 23
 #include  "functions/senders.h"
24
+#include  "functions/joyutils.h"
24 25
 
25 26
 /*   default values, can be changed on command line */
26 27
 
@@ -39,11 +40,12 @@ char		*my_id = MY_TEXT_ID;
39 40
 static void help(int k)
40 41
 {
41 42
 puts("\t * joystick -> osc       "__DATE__" *");
43
+puts("\t-D\tdump joystick datas");
42 44
 puts("\t-r\tremote host ("REMOTE_HOST")");
43 45
 puts("\t-p\tremote UDP port ("REMOTE_PORT")");
44 46
 puts("\t-j\tjoystick device ("JOY_DEVICE")");
45 47
 puts("\t-v\tincrease verbosity");
46
-puts("\t-o\toffset added to button number");
48
+printf("\t-o\toffset added to button number (%d)\n", button_offset);
47 49
 puts("\t-I\tchange text id (\""MY_TEXT_ID"\")");
48 50
 exit(0);
49 51
 }
@@ -58,10 +60,12 @@ int		opt;
58 60
 char		*remote_host = REMOTE_HOST;
59 61
 char		*remote_port = REMOTE_PORT;
60 62
 char		*joy_device = JOY_DEVICE;
63
+int		do_dump = 0;
61 64
 
62 65
 /* parsing command line options */
63
-while ((opt = getopt(argc, argv, "hp:r:vj:o:I:")) != -1) {
66
+while ((opt = getopt(argc, argv, "Dhp:r:vj:o:I:")) != -1) {
64 67
 	switch (opt) {
68
+		case 'D':	do_dump = 1;		break;
65 69
 		case 'h':	help(0);		break;
66 70
 		case 'r':	remote_host = optarg;	break;
67 71
 		case 'p':	remote_port = optarg;	break;
@@ -74,6 +78,11 @@ while ((opt = getopt(argc, argv, "hp:r:vj:o:I:")) != -1) {
74 78
 		}
75 79
 	}
76 80
 
81
+if (do_dump)	{
82
+	fprintf(stderr, "dumping data from '%s'\n", joy_device);
83
+	dump_my_joystick(joy_device);
84
+	}
85
+
77 86
 if (verbosity) {
78 87
 	fprintf(stderr, "%s is sending to %s:%s\n", argv[0],
79 88
 			remote_host, remote_port);

+ 2
- 0
tools/destinations.liste View File

@@ -0,0 +1,2 @@
1
+localhost:9001
2
+localhost:9002

+ 60
- 0
tools/relay.py View File

@@ -0,0 +1,60 @@
1
+#!/usr/bin/python
2
+
3
+import socket, sys, getopt
4
+
5
+# --- default values
6
+
7
+RX_UDP_IP = ""			# pour ecouter sur toutes les interfaces
8
+RX_UDP_PORT = 5005		# entree du relais
9
+
10
+# ---
11
+
12
+rx_port = RX_UDP_PORT
13
+verbose = 0
14
+
15
+# --- parse command line arguments
16
+
17
+options = "hvp:c:"
18
+arguments = sys.argv[1:]
19
+opts, args = getopt.getopt(arguments, options)
20
+
21
+for o, a in opts:
22
+    print '    ', o, ' --> ', a
23
+    if		"-v" == o:	verbose += 1
24
+    elif	"-p" == o:	rx_port = int(a)
25
+
26
+print "listening port    : ", rx_port
27
+
28
+# ---
29
+
30
+cibles = [ ];
31
+for ligne in open("destinations.liste"):
32
+    a, p = ligne.replace('\n', '').split(":")
33
+    # print a, p
34
+    if p:	cibles.append((a, int(p)))
35
+
36
+for cible in cibles:
37
+    print "   -> ", cible
38
+    
39
+
40
+#   point d'entree, d'ecoute
41
+sock_rx = socket.socket(socket.AF_INET, # Internet
42
+                     socket.SOCK_DGRAM) # UDP
43
+sock_rx.bind((RX_UDP_IP, rx_port))
44
+
45
+#   point de sortie vers les autres
46
+sock_tx = socket.socket(socket.AF_INET, # Internet
47
+                     socket.SOCK_DGRAM) # UDP
48
+
49
+while True:
50
+    data, addr = sock_rx.recvfrom(1024) # buffer size is 1024 bytes
51
+    if verbose:
52
+        print "got:", addr, " ", len(data)
53
+    for cible in cibles:
54
+        # print cible
55
+        sock_tx.sendto(data, cible)
56
+	
57
+# hop, ce truc doit fonctionner !
58
+
59
+
60
+

Loading…
Cancel
Save