enable eternity mode on main loop

This commit is contained in:
phyto 2019-05-24 16:59:29 +02:00
parent 2e4854c411
commit 094de74445

34
essai.c
View File

@ -21,9 +21,10 @@ int run_the_terminal(int fd_serial, char *title, WINDOW *win); /* XXX */
int verbosity;
/* --------------------------------------------------------------- */
int traite_les_messages(int sfd, int nbloops)
int traite_les_messages(int sfd, int nbloops, int notused)
{
int idx, foo, key;
int foo, key;
int loop_forever;
char ligne[200];
int Idatas[4];
float Fdatas[4];
@ -37,7 +38,16 @@ if (NULL==fp) {
return -1;
}
for (idx=0; idx<nbloops; idx++) {
if (0==nbloops) {
fprintf(stderr, "looping forever...\n");
loop_forever = 1;
}
else {
fprintf(stderr, "looping %d rounds\n", nbloops);
loop_forever = 0;
}
do {
if (kbhit()) {
static char valid_k[] = "+-01";
@ -107,7 +117,9 @@ for (idx=0; idx<nbloops; idx++) {
fflush(stderr); /* really WTF? here */
}
if ( loop_forever ) nbloops = 1;
} while (0 != nbloops);
fclose(fp);
@ -126,6 +138,7 @@ void help(int k)
puts("options : ");
puts("\t-d\tserial device to read.");
puts("\t-K\tset the K parameter.");
puts("\t-n NN\tnumber of loops, 0 is infinity");
puts("\t-v\tincrease verbosity.");
exit(0);
}
@ -138,20 +151,23 @@ int serial_in;
char *device = "/dev/ttyACM0";
int K = 0;
char ligne[100];
int nbreloops;
while ((opt = getopt(argc, argv, "d:hv")) != -1) {
printf("\n**** %s **** compiled the %s at %s ***\n",
argv[0], __DATE__, __TIME__);
while ((opt = getopt(argc, argv, "d:hn:v")) != -1) {
switch (opt) {
case 'd': device = optarg; break;
case 'h': help(0); break;
case 'K': K = atoi(optarg); break;
case 'n': nbreloops=atoi(optarg); break;
case 'v': verbosity++; break;
default: break;
}
}
printf("\n**** %s **** compiled the %s at %s ***\n",
argv[0], __DATE__, __TIME__);
serial_in = prepare_UART(device, 9600);
if (serial_in < 0) {
fprintf(stderr, "\n%s : open device : error %d on %s\n",
@ -167,7 +183,7 @@ keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
sprintf(ligne, " Demonstrator pid:%d %s ", getpid(), device);
fond_ecran(ligne);
traite_les_messages(serial_in, 50000000);
traite_les_messages(serial_in, nbreloops, K);
/*
* plop, on a fini, il faut restaurer la console