Compare commits

...

2 Commits

Author SHA1 Message Date
tth
03bdd5ab88 adding 'joystick->osc' soft 2019-08-02 18:04:22 +02:00
tth
78173e9aa4 correcting a cut'n'past 2019-08-02 15:16:44 +02:00
4 changed files with 160 additions and 1 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ MANIFEST
tarball
osc2cursor
osc-joy
doc/*.toc
doc/*.log

View File

@ -9,4 +9,7 @@ OPTS = -Wall -g -DDEBUG_LEVEL=1
osc2cursor: osc2cursor.c ${DEPS} functions/libpocosc.a
gcc ${OPTS} $< functions/libpocosc.a -llo -lcurses -o $@
osc-joy: osc-joy.c ${DEPS} functions/libpocosc.a
gcc ${OPTS} $< functions/libpocosc.a -llo -o $@
# ----------------------------------------------------

View File

@ -15,7 +15,7 @@
\makeindex
% -------------------------------------------------------------------
\title{Floating images processing}
\title{Gadgets for Open Sound Control}
\author{tTh}
\begin{document}
@ -31,6 +31,18 @@ De quoi parle-t-on exactement ?
% -------------------------------------------------------------------
\subsection{osc-joy}
\begin{verbatim}
* joystick -> osc Aug 2 2019 *
-r remote host (localhost)
-p remote UDP port (9000)
-j joystick device (/dev/input/js0)
-v increase verbosity
-o offset added to button number
-I change text id ("suck my stick")
\end{verbatim}
\pagebreak
\tableofcontents
\printindex

143
osc-joy.c Normal file
View File

@ -0,0 +1,143 @@
/*
* Pour compiler :
* gcc -Wall osc-joy.c -llo -o osc-joy
*
* Options :
* -j joydevice default /dev/input/js0
* -h destination (or IP addr) default localhost
* -p destport default is 9000
* -o nnn offset for button number
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/joystick.h>
#include <lo/lo.h>
#include "functions/senders.h"
/* default values, can be changed on command line */
#define REMOTE_HOST "localhost" /* just loling */
#define REMOTE_PORT "9000"
#define JOY_DEVICE "/dev/input/js0"
#define MY_TEXT_ID "suck my stick"
/* ----------------------------------------------------------------- */
int verbosity = 0;
int button_offset = 0;
char *my_id = MY_TEXT_ID;
/* ----------------------------------------------------------------- */
static void help(int k)
{
puts("\t * joystick -> osc "__DATE__" *");
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");
puts("\t-I\tchange text id (\""MY_TEXT_ID"\")");
exit(0);
}
/* ----------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo, joy_fd;
struct js_event js;
int x_pos, y_pos, flag;
char joy_name[128];
int opt;
char *remote_host = REMOTE_HOST;
char *remote_port = REMOTE_PORT;
char *joy_device = JOY_DEVICE;
/* parsing command line options */
while ((opt = getopt(argc, argv, "hp:r:vj:o:I:")) != -1) {
switch (opt) {
case 'h': help(0); break;
case 'r': remote_host = optarg; break;
case 'p': remote_port = optarg; break;
case 'j': joy_device = optarg; break;
case 'v': verbosity++; break;
case 'o': button_offset = atoi(optarg);
break;
case 'I': my_id = optarg; break;
default: exit(1); break;
}
}
if (verbosity) {
fprintf(stderr, "%s is sending to %s:%s\n", argv[0],
remote_host, remote_port);
fprintf(stderr, " the stick '%s'is on %s\n", my_id, joy_device);
}
lo_address t = lo_address_new(remote_host, remote_port);
if( ( joy_fd = open(joy_device , O_RDONLY)) == -1 ) {
fprintf(stderr, "Couldn't open %s\n", JOY_DEVICE);
exit(1);
}
if (verbosity) {
if (ioctl(joy_fd, JSIOCGNAME(sizeof(joy_name)), joy_name) < 0)
strncpy(joy_name, "Unknown", sizeof(joy_name));
fprintf(stderr, "Name: %s\n", joy_name);
}
send_data_id(t, my_id);
x_pos = y_pos = 0;
for (;;) {
foo = read(joy_fd, &js, sizeof(struct js_event));
if (8 != foo) {
fprintf(stderr, "err reading joy\n");
exit(1);
}
/* calibration datas ignored */
if (js.type > 128) continue;
if (verbosity>1) {
fprintf(stderr, "%10u %2d %2d %7d\n",
js.time, js.type, js.number, js.value);
}
if (2==js.type) { /* oscillating stick */
flag = 0;
switch (js.number)
{
case 0:
x_pos = js.value;
flag = 1;
break;
case 1:
y_pos = js.value;
flag = 1;
break;
}
if (flag) {
foo = send_data_xy(t, x_pos, y_pos);
flag = 0;
}
}
if (1==js.type) { /* it's a button */
foo = send_data_button(t, js.number+button_offset,
js.value);
}
}
return 0;
}
/* ----------------------------------------------------------------- */