enable eternity mode on main loop
This commit is contained in:
parent
2e4854c411
commit
094de74445
34
essai.c
34
essai.c
@ -21,9 +21,10 @@ int run_the_terminal(int fd_serial, char *title, WINDOW *win); /* XXX */
|
|||||||
int verbosity;
|
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];
|
char ligne[200];
|
||||||
int Idatas[4];
|
int Idatas[4];
|
||||||
float Fdatas[4];
|
float Fdatas[4];
|
||||||
@ -37,7 +38,16 @@ if (NULL==fp) {
|
|||||||
return -1;
|
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()) {
|
if (kbhit()) {
|
||||||
static char valid_k[] = "+-01";
|
static char valid_k[] = "+-01";
|
||||||
@ -107,7 +117,9 @@ for (idx=0; idx<nbloops; idx++) {
|
|||||||
|
|
||||||
fflush(stderr); /* really WTF? here */
|
fflush(stderr); /* really WTF? here */
|
||||||
|
|
||||||
}
|
if ( loop_forever ) nbloops = 1;
|
||||||
|
|
||||||
|
} while (0 != nbloops);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
@ -126,6 +138,7 @@ void help(int k)
|
|||||||
puts("options : ");
|
puts("options : ");
|
||||||
puts("\t-d\tserial device to read.");
|
puts("\t-d\tserial device to read.");
|
||||||
puts("\t-K\tset the K parameter.");
|
puts("\t-K\tset the K parameter.");
|
||||||
|
puts("\t-n NN\tnumber of loops, 0 is infinity");
|
||||||
puts("\t-v\tincrease verbosity.");
|
puts("\t-v\tincrease verbosity.");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -138,20 +151,23 @@ int serial_in;
|
|||||||
char *device = "/dev/ttyACM0";
|
char *device = "/dev/ttyACM0";
|
||||||
int K = 0;
|
int K = 0;
|
||||||
char ligne[100];
|
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) {
|
switch (opt) {
|
||||||
case 'd': device = optarg; break;
|
case 'd': device = optarg; break;
|
||||||
case 'h': help(0); break;
|
case 'h': help(0); break;
|
||||||
case 'K': K = atoi(optarg); break;
|
case 'K': K = atoi(optarg); break;
|
||||||
|
case 'n': nbreloops=atoi(optarg); break;
|
||||||
case 'v': verbosity++; break;
|
case 'v': verbosity++; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n**** %s **** compiled the %s at %s ***\n",
|
|
||||||
argv[0], __DATE__, __TIME__);
|
|
||||||
|
|
||||||
serial_in = prepare_UART(device, 9600);
|
serial_in = prepare_UART(device, 9600);
|
||||||
if (serial_in < 0) {
|
if (serial_in < 0) {
|
||||||
fprintf(stderr, "\n%s : open device : error %d on %s\n",
|
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);
|
sprintf(ligne, " Demonstrator pid:%d %s ", getpid(), device);
|
||||||
fond_ecran(ligne);
|
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
|
* plop, on a fini, il faut restaurer la console
|
||||||
|
Loading…
Reference in New Issue
Block a user