Compare commits

...

22 Commits

Author SHA1 Message Date
tTh
494f9ebf01 cosmetic 2024-03-31 21:46:50 +02:00
tTh
e19f6b311b cosmetic again 2024-03-31 21:35:08 +02:00
tTh
593eeeddc9 cosmetic 2024-03-31 21:25:19 +02:00
tTh
7879c84020 add z & w joystick values to sender 2024-03-31 21:12:40 +02:00
tTh
16917ad551 add mandary dependencies 2024-03-31 21:08:13 +02:00
tTh
31087627ac better err msg 2024-03-30 14:42:05 +01:00
tTh
00920841d2 commit before morning nap 2023-03-17 10:33:53 +01:00
tTh
f804d2c7ab some tuning... 2023-01-13 15:36:31 +01:00
tTh
655a528192 bla 2022-10-30 22:42:30 +01:00
tth
b55f9f3575 oups... 2022-01-08 03:52:48 +01:00
tth
85c1846a0b 2020+2 a new hope ? 2022-01-08 03:34:05 +01:00
tth
95046aa71d more debug msg 2021-07-23 23:30:52 +02:00
tth
6a1fc34031 fine tuning 2021-07-23 20:41:39 +02:00
tth
7c91072873 osc+chuck=wip 2021-07-23 14:13:56 +02:00
tth
2e9b344922 typo 2021-07-23 12:15:18 +02:00
tth
11cd7dbf5e dessiner avec chuck, premier pas 2021-07-22 18:34:34 +02:00
tth
2a8c892e33 ok 2021-07-20 22:24:05 +02:00
tth
3301315367 oups, need more tests 2021-07-20 12:04:47 +02:00
tth
030472e7d9 + send_button 2021-07-20 11:24:27 +02:00
tth
47e6f7a690 a new idea is floating 2021-07-20 11:20:03 +02:00
tth
dea4232d8e first step done ? 2021-07-09 12:46:18 +02:00
tth
5b6359ce9e changes to an unused function 2021-07-09 08:43:14 +02:00
36 changed files with 784 additions and 102 deletions

2
.gitignore vendored
View File

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

View File

@@ -4,3 +4,27 @@
# Piloter le laser de Gaby # 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
Gaby/audiodrive.c Normal file
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
Gaby/burps.sh Executable file
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

102
Gaby/gabylaser.c Normal file
View File

@@ -0,0 +1,102 @@
/*
* 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:v")) != -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;
}
/* ---------------------------------------------------------------- */

56
Gaby/receive-osc.c Normal file
View File

@@ -0,0 +1,56 @@
/*
* 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)
{
int foo;
fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, path, types);
foo = send_button(argv[0]->i, argv[1]->i);
return -1;
}
/* ---------------------------------------------------------------- */

12
Gaby/receive-osc.h Normal file
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);

View File

@@ -1,6 +1,126 @@
/* /*
* LE LASER DE GABY
*
* +---------------------------------------------+ * +---------------------------------------------+
* | transmission des commandes vers l'arduino | * | 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;
}
/* ---------------------------------------------------------------- */
/*
* comment gerer le up/down des boutons ?
*/
int send_button(int number, int state)
{
char message[100];
if (fdtx < 0) {
fprintf(stderr, "%s: fdtx not initialized !\n", __func__);
exit(1);
}
if (number<0 || number>16) {
return -1;
}
sprintf(message, "T%01x%1x", number, state);
fprintf(stderr, "%s ----> '%s'\n", __func__, message);
foo = write(fdtx, message, 3);
if (3 != foo) {
perror("write ?");
return -1;
}
return 0;
}
/* ---------------------------------------------------------------- */

13
Gaby/transmit.h Normal file
View File

@@ -0,0 +1,13 @@
/*
* LE LASER DE GABY
*
* +---------------------------------------------+
* | transmission des commandes vers l'arduino |
* +---------------------------------------------+
*/
int init_transmit(char *fname, int k);
int send_position(char xy, int value);
int send_button(int number, int state);

View File

@@ -2,10 +2,11 @@
# umpf... # umpf...
OPTS = -Wall -g -DDEBUG_LEVEL=1 OPTS = -Wall -g -DDEBUG_LEVEL=0
DEPS = Makefile DEPS = Makefile functions/senders.h functions/joyutils.h \
functions/ncursefuncs.h
all: osc-joy osc2cursor text2osc all: osc-joy osc2cursor text2osc showbuttons
# -------------------------------------------------------------- # --------------------------------------------------------------

View File

@@ -1,6 +1,10 @@
# Gadgets autour du protocole OSC # Gadgets autour du protocole OSC
Oui, je sais, tout ça n'est pas vraiment clair. Oui, je sais, tout ça n'est pas vraiment clair. Mais je me soigne.
Première étape : consulter le
[site d'OSC](https://opensoundcontrol.stanford.edu/) pour comprendre comment
ça fonctionne.
## prérequis ## prérequis
@@ -10,6 +14,7 @@ bibliothèques de support :
``` ```
apt install liblo-tools liblo-dev apt install liblo-tools liblo-dev
apt install libasound2-dev apt install libasound2-dev
apt install ncurses-dev
``` ```
Plus le module Perl `Net::OpenSoundControl` à chercher dans le CPAN. Plus le module Perl `Net::OpenSoundControl` à chercher dans le CPAN.
@@ -21,14 +26,15 @@ cd functions
make make
``` ```
Et ensuite `make` dans le répertoire de base... Et ensuite `make` dans le répertoire de base, je pense que c'est
assez simple, et parfois ça marche...
# Les programmes # Les programmes
## osc-joy ## osc-joy
Lecture d'une manette de jeu USB et envoi des x/y et des boutons Lecture d'une manette de jeu USB et envoi des coordonnées x/y/z/w
vers un écouteur OSC. et des boutons vers un écouteur OSC.
L'option `-o NN` rajoute NN au numéro de bouton. L'option `-o NN` rajoute NN au numéro de bouton.
Voir les [générateurs](generators/) pour les détails. Voir les [générateurs](generators/) pour les détails.
@@ -41,15 +47,10 @@ Une appli ncurses trop choupie :)
Pour faire __beep__ vers Chuck... Pour faire __beep__ vers Chuck...
# Le reste ## showbuttons
Presque fini depuis quelques mois/années.
## Loth Project
Voir README.md
## Teamlaser
Voir asyncburp.c

16
chuck/README.md Normal file
View File

@@ -0,0 +1,16 @@
# trucs en ChucK
Attention, il faut parfois utiliser l'option `--silent`
pour lancer Chuck sans connexion audio.
## dessiner.ck
Faire des courbes de Lissajous...
## pouet.ck
## midi2osc.ck
## zwouik.ck

View File

@@ -1,4 +1,46 @@
# /*
# dessiner par OSC avec le laser de Gaby * dessiner par OSC
# * (avec le laser de Gaby ?)
*
* nouveau Rural Art System 2021 - TerreBlanque
*
*/
9000 => int OSCPort;
32760.0 => float Amplitude;
OscOut xmit;
float dx, dy;
xmit.dest("localhost", OSCPort);
clear_the_screen();
for (0 => int foo; foo<25800; foo++) {
<<< foo >>>;
Amplitude * Math.sin(foo * 0.3001) => dx;
Amplitude * Math.cos(foo * 0.4999) => dy;
xmit.start("/joystick/xy");
Std.ftoi(dx) => xmit.add;
Std.ftoi(dy) => xmit.add;
xmit.send();
0.025::second => now;
}
// ----------------------------------------------------
fun void clear_the_screen()
{
xmit.start("/joystick/b");
50 => xmit.add; 1 => xmit.add;
xmit.send();
xmit.start("/joystick/b");
50 => xmit.add; 0 => xmit.add;
xmit.send();
}
// ----------------------------------------------------

43
chuck/midi2osc.ck Normal file
View File

@@ -0,0 +1,43 @@
/*
* recevoir des notes on/off par le MIDI
* et envoyer des boutons de joy par OSC
*
* nouveau Rural Art System 2021 - TerreBlanque
*/
MidiIn input;
MidiMsg msg;
OscOut xmit;
1 => int port; // please explain
9000 => int OSCPort;
if (!input.open(port)) {
<<< "erreur open" >>>;
me.exit();
}
// print out device that was opened
<<< "MIDI device:", input.num(), " -> ", input.name() >>>;
xmit.dest("localhost", OSCPort);
// infinite loop
while (1) {
input => now;
while ( input.recv(msg) ) {
<<< msg.data1, msg.data2, msg.data3 >>>;
xmit.start("/joystick/b");
}
}

View File

@@ -1,4 +1,5 @@
/* faire pouet avec chuck osc et un joystick /*
faire pouet avec chuck osc et un joystick
----------------------------------------- -----------------------------------------
reception des boutons reception des boutons
*/ */
@@ -9,7 +10,7 @@ SqrOsc sl => Envelope envl => dac.left;
SawOsc sr => Envelope envr => dac.right; SawOsc sr => Envelope envr => dac.right;
0.5 => sl.gain => sr.gain; 0.5 => sl.gain => sr.gain;
0.01 => envl.time; 0.06 => envr.time; 0.22 => envl.time; 0.22 => envr.time;
OscIn oscin; OscMsg msg; OscIn oscin; OscMsg msg;
@@ -33,7 +34,7 @@ while( true ) {
else { else {
1 => envl.keyOff => envr.keyOff; 1 => envl.keyOff => envr.keyOff;
} }
// 0.2::second => now; 0.1::second => now;
} }
} }

View File

@@ -4,20 +4,21 @@
*/ */
7777 => int InPort; 7777 => int InPort;
15.55 => float divisor;
SqrOsc sl => dac.left; SqrOsc sl => dac.left;
SawOsc sr => dac.right; SawOsc sr => dac.right;
0.0 => sl.gain => sr.gain; 0.0 => sl.gain => sr.gain;
OscIn oscin; OscIn oscin;
OscMsg msg; OscMsg msg;
InPort => oscin.port; InPort => oscin.port;
oscin.addAddress( "/joystick/xy, ii" ); oscin.addAddress( "/joystick/xy, ii" );
int x, y; int x, y;
55 => int base; 55 => int base;
0.5 => sl.gain => sr.gain;
<<< "listening on port", InPort >>>; <<< "listening on port", InPort >>>;
while( true ) { while( true ) {
@@ -26,8 +27,16 @@ while( true ) {
msg.getInt(0) => x; msg.getInt(0) => x;
msg.getInt(1) => y; msg.getInt(1) => y;
<<< "got (via ", InPort,") ", x, y >>>; <<< "got (via ", InPort,") ", x, y >>>;
x/12.0 => sl.freq;
y/12.0 => sr.freq;
} }
} }
/* made in doubledragon2 by tTh */ /* made in doubledragon2 by tTh */
/* --------------------------------------------------------
conversion coordonnées vers frequence */

View File

@@ -24,7 +24,10 @@
\section{Open Sound Control} \section{Open Sound Control}
De quoi parle-t-on exactement ? De quoi parle-t-on exactement ?
\vspace{1em} \vspace{5em}
OSC est un protocole réseau basé sur UDP\index{UDP}.
% ------------------------------------------------------------------- % -------------------------------------------------------------------
\section{Example} \section{Example}

4
functions/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
mkbigchars
t

BIN
functions/8x8thin Normal file

Binary file not shown.

View File

@@ -6,7 +6,7 @@
all: libpocosc.a all: libpocosc.a
OPTS = -Wall -g -DDEBUG_LEVEL=1 OPTS = -Wall -g -DDEBUG_LEVEL=0
senders.o: senders.c senders.h Makefile senders.o: senders.c senders.h Makefile
gcc ${OPTS} -c $< gcc ${OPTS} -c $<
@@ -23,6 +23,26 @@ joyutils.o: joyutils.c joyutils.h Makefile
ncursefuncs.o: ncursefuncs.c ncursefuncs.h Makefile ncursefuncs.o: ncursefuncs.c ncursefuncs.h Makefile
gcc ${OPTS} -c $< 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 joyutils.o bigchars.o
ar r $@ $? ar r $@ $?
#
mkbigchars: mkbigchars.c Makefile
gcc ${OPTS} $< -o $@
chars8x8.def: mkbigchars Makefile
./mkbigchars 8x8thin $@
bigchars.o: bigchars.c chars8x8.def ncursefuncs.h Makefile
gcc ${OPTS} -c $<
# programmes de test
t: t.c Makefile libpocosc.a ncursefuncs.h
gcc $(OPTS) $< libpocosc.a -o $@

44
functions/bigchars.c Normal file
View File

@@ -0,0 +1,44 @@
/*
! ncurses widgets for poc-osc
!
! nnnnn n nnnn
! n n n n n
! nnnnn n n
! n n n n nnn
! n n n n n
! nnnnn n nnnn
!
!
! nnnn n n nn nnnnn nnnn
! n n n n n n n n n
! n nnnnnn n n n n nnnn
! n n n nnnnnn nnnnn n
! n n n n n n n n n n
! nnnn n n n n n n nnnn
!
*/
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include <signal.h>
#include <locale.h>
#include "ncursefuncs.h"
/* XXX */
#include "chars8x8.def"
extern int verbosity; /* to be declared public near main() */
/* ----------------------------------------------------------------- */
/* ----------------------------------------------------------------- */
int essai_bigchars(char *texte, int stand)
{
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, texte, stand);
return -1;
}
/* ----------------------------------------------------------------- */

View File

@@ -28,6 +28,7 @@ else {
} }
return "???"; return "???";
} }
/* ----------------------------------------------------------------- */
void dump_my_joystick(char *joy_device) void dump_my_joystick(char *joy_device)
{ {
int joy_fd, foo; int joy_fd, foo;
@@ -47,23 +48,19 @@ fprintf(stderr, "Name: \"%s\"\n", joy_name);
for (;;) { for (;;) {
foo = read(joy_fd, &js, sizeof(struct js_event)); foo = read(joy_fd, &js, sizeof(struct js_event));
if ( ! flag ) {
debut = js.time;
flag = 1;
}
if (8 != foo) { if (8 != foo) {
fprintf(stderr, "%s: err reading joy\n", __func__); fprintf(stderr, "%s: err reading joy\n", __func__);
exit(1); exit(1);
} }
if ( ! flag ) {
printf("%8lu %4d / %-8s %2d %7d\n", debut = js.time;
flag = 1;
}
printf("%8lu %4d %-8s %3d %7d\n",
js.time-debut, js.time-debut,
js.type, type2txt(js.type), js.type, type2txt(js.type),
js.number, js.value); js.number, js.value);
} }
} }
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */

77
functions/mkbigchars.c Normal file
View File

@@ -0,0 +1,77 @@
/*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
/* ----------------------------------------------------------------- */
int make_bigfont_def(char *input, char *deffile)
{
FILE *fp;
int fd, idx, foo;
unsigned char buffer[2048];
fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, input, deffile);
/*
* load the binary font datas
*/
fd = open(input, O_RDONLY, 0);
if (-1 == fd) {
perror(input);
exit(1);
}
foo = read(fd, buffer, 2048);
if (2048 != foo) {
fprintf(stderr, "%s: read %d bytes, 2048 expected\n", __func__, foo);
close(fd);
return 1;
}
close(fd);
/*
* write the definition file as a .h c-file
*/
fp = fopen(deffile, "w");
if (NULL == fp) {
perror(deffile);
exit(1);
}
fprintf(fp, "/*\n * ! ! ! GENERATED FILE ! ! !\n*/\n");
for (idx=0; idx-256; idx++) {
fprintf(fp, "/*\n *\t***\t%3d 0x%02x\n */\n", idx, idx);
fprintf(fp, "\n");
}
fprintf(fp, "/* yolo? */\n");
fclose(fp);
return 0;
}
/* ----------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
if (3 != argc) {
fprintf(stderr, "ERR: %s need two filenames\n", argv[0]);
exit(1);
}
foo = make_bigfont_def(argv[1], argv[2]);
if (foo) {
fprintf(stderr, "got %d from font converter.\n", foo);
exit(1);
}
return 0;
}
/* ----------------------------------------------------------------- */

View File

@@ -49,7 +49,7 @@ char ligne[81];
int foo; int foo;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, "--> %s ( '%s' %d )\n", __func__, title, unused); fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, title, unused);
#endif #endif
if (verbosity) { if (verbosity) {
@@ -68,10 +68,10 @@ return 0; /* this is not a magic number */
int blast_error_message(char *txt, int violence, int unused) int blast_error_message(char *txt, int violence, int unused)
{ {
int line, foo; int line, foo;
char buff[60]; char buff[80];
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, "--> %s ( '%s' %d %d )\n", __func__, fprintf(stderr, ">>> %s ( '%s' %d %d )\n", __func__,
txt, violence, unused); txt, violence, unused);
#endif #endif
@@ -82,26 +82,42 @@ if (verbosity > 3) {
} }
standout(); standout();
// setup our part of screen
// clear our part of screen
for (foo=0; foo<COLS; foo++) { for (foo=0; foo<COLS; foo++) {
mvaddch(line, foo, '_'); mvaddch(line, foo, '|');
} }
mvaddstr(line, 0, "SYS$MSG_| ");
mvaddstr(line, 0, "SYS$MSG_ "); mvaddstr(line, 10, txt);
mvaddstr(line, 9, txt);
standend(); standend();
refresh();
return 0; return 0;
} }
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
int erase_error_message(int ascii)
{
int foo;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%c' )\n", __func__, ascii);
#endif
standout();
// clear our part of screen
for (foo=0; foo<COLS; foo++) {
mvaddch(LINES-1, foo, ascii);
}
standend(); refresh();
return 0;
}
/* ----------------------------------------------------------------- */
/* warning: only use the bit 0 of the 'state' arg */ /* warning: only use the bit 0 of the 'state' arg */
int draw_a_button(WINDOW *w, int lig, int col, char *txt, int state) int draw_a_button(WINDOW *w, int lig, int col, char *txt, int state)
{ {
#if DEBUG_LEVEL > 1 #if DEBUG_LEVEL > 1
fprintf(stderr, "--> %s ( %3d %3d '%s' %d )\n", __func__, fprintf(stderr, ">>> %s ( %3d %3d '%s' %d )\n", __func__,
lig, col, txt, state); lig, col, txt, state);
#endif #endif

View File

@@ -9,6 +9,13 @@ void endcurses(int p);
int draw_main_screen(char *title, int unused); int draw_main_screen(char *title, int unused);
int blast_error_message(char *txt, int violence, int unused); int blast_error_message(char *txt, int violence, int unused);
int erase_error_message(int ascii);
/* warning: only use the bit 0 of the 'state' arg */ /* warning: only use the bit 0 of the 'state' arg */
int draw_a_button(WINDOW *w, int lig, int col, char *txt, int state); int draw_a_button(WINDOW *w, int lig, int col, char *txt, int state);
/*
* bigchars.c
*/
int essai_bigchars(char *texte, int stand);

View File

@@ -22,6 +22,19 @@ if (verbosity > 2) {
return foo; return foo;
} }
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
/* function added Sun Mar 31 18:51:46 UTC 2024 */
int send_data_zw(lo_address dst, int w, int z)
{
int foo;
if (verbosity) fprintf(stderr, "sending w z %7d %7d\n", w, z);
foo = lo_send(dst, "/joystick/wz", "ii", w, z);
if (verbosity > 2) {
fprintf(stderr, "lo_send -> %d\n", foo);
}
return foo;
}
/* ----------------------------------------------------------------- */
int send_data_button(lo_address dst, int n, int v) int send_data_button(lo_address dst, int n, int v)
{ {
int foo; int foo;

View File

@@ -5,6 +5,7 @@
/* ------------------------------------------------------- */ /* ------------------------------------------------------- */
int send_data_xy(lo_address dst, int x, int y); int send_data_xy(lo_address dst, int x, int y);
int send_data_zw(lo_address dst, int w, int z);
int send_data_button(lo_address dst, int n, int v); int send_data_button(lo_address dst, int n, int v);
int send_data_id(lo_address dst, char *s); int send_data_id(lo_address dst, char *s);

View File

@@ -41,22 +41,10 @@ return fd;
this will disconnect the line. this will disconnect the line.
*/ */
int bauds_str_to_B(char *strb, int unused) int bauds_to_B(int bauds)
{ {
long value;
#if DEBUG_LEVEL switch (bauds) {
fprintf(stderr, "--> %s ( '%s' 0x%x )\n", __func__, strb, unused);
#endif
if (1 != sscanf(strb, "%ld", &value)) {
return B0;
}
#if DEBUG_LEVEL
fprintf(stderr, " computed baudrate = %ld\n", value);
#endif
switch (value) {
case 50: return B50; case 50: return B50;
case 75: return B75; case 75: return B75;
case 110: return B110; case 110: return B110;

View File

@@ -4,4 +4,5 @@
*/ */
int open_serial(char *dev, int bauds, int unused); int open_serial(char *dev, int bauds, int unused);
int bauds_str_to_B(char *strb, int unused);
int bauds_to_B(int bauds);

21
functions/t.c Normal file
View File

@@ -0,0 +1,21 @@
/*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "ncursefuncs.h"
/* ----------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
foo = essai_bigchars("foo", 0);
fprintf(stderr, " essai bigchars -> %d\n", foo);
return 0;
}
/* ----------------------------------------------------------------- */

View File

@@ -21,7 +21,7 @@ cpan[3]> install Net::OpenSoundControl
Et voilà... Et voilà...
## moresinus.pl ## moresinus.pl
Options : `-d host:port` et `-v` Options : `-d host:port` et `-v`

View File

@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
{ {
int foo, joy_fd; int foo, joy_fd;
struct js_event js; struct js_event js;
int x_pos, y_pos, flag; int x_pos, y_pos, z_pos, w_pos, what;
char joy_name[128]; char joy_name[128];
int opt; int opt;
char *remote_host = REMOTE_HOST; char *remote_host = REMOTE_HOST;
@@ -84,34 +84,36 @@ if (do_dump) {
} }
if (verbosity) { if (verbosity) {
fprintf(stderr, "%s is sending to %s:%s\n", argv[0], fprintf(stderr, " %s is sending to %s:%s\n", argv[0],
remote_host, remote_port); remote_host, remote_port);
fprintf(stderr, " the stick '%s'is on %s\n", my_id, joy_device); fprintf(stderr, " the stick '%s' is on %s\n", my_id, joy_device);
} }
lo_address t = lo_address_new(remote_host, remote_port); lo_address t = lo_address_new(remote_host, remote_port);
/*
* XXX no error check ? wtf ?
*/
if( ( joy_fd = open(joy_device , O_RDONLY)) == -1 ) { if( ( joy_fd = open(joy_device , O_RDONLY)) == -1 ) {
fprintf(stderr, "Couldn't open %s\n", joy_device); fprintf(stderr, "%s: Couldn't open %s\n", argv[0], joy_device);
exit(1); exit(1);
} }
if (verbosity) { if (verbosity) {
if (ioctl(joy_fd, JSIOCGNAME(sizeof(joy_name)), joy_name) < 0) if (ioctl(joy_fd, JSIOCGNAME(sizeof(joy_name)), joy_name) < 0)
strncpy(joy_name, "Unknown", sizeof(joy_name)); strncpy(joy_name, "Unknown", sizeof(joy_name));
fprintf(stderr, "Name: %s\n", joy_name); fprintf(stderr, " Name: %s\n", joy_name);
} }
send_data_id(t, my_id); send_data_id(t, my_id);
x_pos = y_pos = 0; x_pos = y_pos = z_pos = w_pos = 0;
for (;;) { for (;;) {
foo = read(joy_fd, &js, sizeof(struct js_event)); foo = read(joy_fd, &js, sizeof(struct js_event));
if (8 != foo) { if (8 != foo) {
fprintf(stderr, "err reading joy\n"); fprintf(stderr, "err reading joy\n");
exit(1); exit(1);
} }
/* calibration datas ignored */ /* calibration datas ignored */
if (js.type > 128) continue; if (js.type > 128) continue;
@@ -119,24 +121,37 @@ for (;;) {
fprintf(stderr, "%10u %2d %2d %7d\n", fprintf(stderr, "%10u %2d %2d %7d\n",
js.time, js.type, js.number, js.value); js.time, js.type, js.number, js.value);
} }
if (2==js.type) { /* oscillating stick */ if (2==js.type) { /* oscillating stick */
flag = 0; what = 0;
switch (js.number) switch (js.number) {
{
case 0: case 0:
x_pos = js.value; x_pos = js.value;
flag = 1; what = 1;
break; break;
case 1: case 1:
y_pos = js.value; y_pos = js.value;
flag = 1; what = 1;
break;
case 2:
z_pos = js.value;
what = 2;
break;
case 3:
w_pos = js.value;
what = 2;
break; break;
} }
/* now, send the datas */
if (flag) { // fprintf(stderr, "\t\twhat = %d\n", what);
switch (what) {
case 1:
foo = send_data_xy(t, x_pos, y_pos); foo = send_data_xy(t, x_pos, y_pos);
flag = 0; what = 0;
break;
case 2:
foo = send_data_zw(t, z_pos, w_pos);
what = 0;
break;
} }
} }
@@ -144,7 +159,6 @@ for (;;) {
foo = send_data_button(t, js.number+button_offset, foo = send_data_button(t, js.number+button_offset,
js.value); js.value);
} }
} }
return 0; return 0;

View File

@@ -46,6 +46,8 @@ printf(stderr, "%s : %s %s %d\n", __func__, path, types, argc);
if (verbosity) { if (verbosity) {
sprintf(ligne, "%s %s %s %d\n", __func__, path, types, argc); sprintf(ligne, "%s %s %s %d\n", __func__, path, types, argc);
mvaddstr(2, 2, ligne); mvaddstr(2, 2, ligne);
sprintf(ligne, "button : %6d %6d", argv[0]->i, argv[1]->i);
mvaddstr(3, 2, ligne);
refresh(); refresh();
} }
@@ -54,6 +56,8 @@ if (-1 == erase_button) return 0;
if ( (argv[0]->i == erase_button) && if ( (argv[0]->i == erase_button) &&
(argv[1]->i == 0) ) { (argv[1]->i == 0) ) {
must_erase = 1; must_erase = 1;
mvaddstr(3, 2, "KILL ! KILL !");
refresh();
} }
return 0; return 0;
@@ -116,7 +120,7 @@ if (verbosity) {
} }
/* erase the old spot */ /* erase the old spot */
if (old_l) mvaddch(old_l, old_c, current_char); if (old_l || old_c) mvaddch(old_l, old_c, current_char);
standout(); standout();
mvaddch(cur_l, cur_c, '#'); mvaddch(cur_l, cur_c, '#');
@@ -169,9 +173,9 @@ fprintf(stderr, "erase %d\n", erase_button);
st = lo_server_thread_new(local_port, error); st = lo_server_thread_new(local_port, error);
foo = initcurses(); foo = initcurses();
sprintf(ligne, ":%s ", local_port); sprintf(ligne, ":%s e=%d ", local_port, erase_button);
foo = draw_main_screen(ligne, 0); foo = draw_main_screen(ligne, 0);
if (verbosity) fprintf(stderr, "dms %d\n", foo); // if (verbosity) fprintf(stderr, "dms %d\n", foo);
lo_server_thread_add_method(st, "/joystick/xy", "ii", xy_handler, NULL); 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_add_method(st, "/joystick/b", "ii", button_handler, NULL);

View File

@@ -67,13 +67,15 @@ int display_a_value(int lig, short value, char letter)
char buffer[80], symbol; char buffer[80], symbol;
int width, seuil, foo; int width, seuil, foo;
width = 60;
sprintf(buffer, "%6d [", value); sprintf(buffer, "%6d [", value);
mvaddstr(lig, 4, buffer); mvaddstr(lig, 4, buffer);
mvaddch(lig, width+12, ']');
if (value < 0) symbol = '-'; if (value < 0) symbol = '-';
else symbol = '+'; else symbol = '+';
width = 60;
seuil = (abs((int)value) * width) / 32767; seuil = (abs((int)value) * width) / 32767;
#if DEBUG_LEVEL > 1 #if DEBUG_LEVEL > 1
@@ -141,8 +143,7 @@ int do_animation(int cycles, int speed)
(void)initcurses(); (void)initcurses();
animation(cycles, speed); animation(cycles, speed);
sleep(2); sleep(2); exit(0);
exit(0);
return 0; return 0;
} }
@@ -230,8 +231,8 @@ return 0;
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
static void help(int k) static void help(int k)
{ {
puts("\t * showbuttons " __DATE__ " *"); puts("\t*** showbuttons " __DATE__ " ***");
puts("\t-a\tshow animation"); puts("\t-a\tshow animation and exit");
puts("\t-p\tlocal udp port ("LOCAL_PORT")"); puts("\t-p\tlocal udp port ("LOCAL_PORT")");
puts("\t-v\tenhance my verbosity"); puts("\t-v\tenhance my verbosity");
exit(0); exit(0);
@@ -273,7 +274,7 @@ if (foo) {
/* set up the pretty screen user interface */ /* set up the pretty screen user interface */
foo = initcurses(); foo = initcurses();
sprintf(ligne, ":%s ", local_port); sprintf(ligne, "showbuttons port=%s ", local_port);
foo = draw_main_screen(ligne, 0); foo = draw_main_screen(ligne, 0);
if (foo) { if (foo) {
endwin(); endwin();
@@ -294,9 +295,14 @@ lo_server_thread_add_method(st, "/joystick/xy", "ii",
xy_handler, NULL); xy_handler, NULL);
lo_server_thread_start(st); lo_server_thread_start(st);
sprintf(ligne, "process %d on board, captain", getpid()); #if DEBUG_LEVEL
fprintf(stderr, "pid %d: osc server thread started\n", getpid());
#endif
sprintf(ligne, "process %d on board, captain ", getpid());
blast_error_message(ligne, 0, 0); blast_error_message(ligne, 0, 0);
sleep(1); sleep(3);
erase_error_message(' ');
for (;;) { for (;;) {
/* wait for un event from liblo threads */ /* wait for un event from liblo threads */

View File

@@ -17,7 +17,7 @@
int verbosity = 0; int verbosity = 0;
char *my_id = MY_TEXT_ID; char *my_id = MY_TEXT_ID;
int wait_time = 100; /* in milliseconds */ int wait_time = 80; /* in milliseconds */
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
int megaloop(FILE *fp, lo_address loa) int megaloop(FILE *fp, lo_address loa)
@@ -38,7 +38,7 @@ while (EOF != (caractere=getc(fp))) {
char_count++; char_count++;
if (verbosity) fprintf(stderr, "car = %4d %c\n", if (verbosity) fprintf(stderr, "char = %4d %c\n",
caractere, caractere); caractere, caractere);
if (isalpha(caractere)) { if (isalpha(caractere)) {

View File

@@ -79,12 +79,15 @@ do {
if (verbosity) { if (verbosity) {
gettimeofday(&tp, NULL); gettimeofday(&tp, NULL);
curtime = tp.tv_sec + tp.tv_usec / 1e6; curtime = tp.tv_sec + tp.tv_usec / 1e6;
printf("----+ %4ld %5d b ts: %.3f\n", printf("----+ frame %4ld %5d bytes t= %.3f sec.\n",
serial, foo, curtime - starttime); serial, foo, curtime - starttime);
/*
* MUST display ip:port of the sender !
*/
} }
for (bar=0; bar<=foo; bar+=16) { for (bar=0; bar<=foo; bar+=16) {
printf("%3ld | ", bar); printf("%3d | ", bar);
dumpln(buffer+bar); dumpln(buffer+bar);
} }
serial++; serial++;