DD2-monitor/essai.c

105 lines
2.1 KiB
C
Raw Normal View History

2018-12-08 13:02:24 +01:00
/*
* essai.c
*/
2019-02-06 17:22:32 +01:00
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
2019-01-30 19:14:40 +01:00
#include <curses.h>
2019-02-06 17:22:32 +01:00
#include <time.h>
2018-12-08 13:02:24 +01:00
2019-02-06 17:22:32 +01:00
#include "core/utils.h"
#include "core/sysmetrics.h"
2019-03-28 12:04:40 +01:00
#include "serial/serial.h"
2019-02-06 17:22:32 +01:00
#include "viz/curses/ecran.h"
2018-12-08 13:02:24 +01:00
2019-01-17 18:37:30 +01:00
int verbosity;
/* --------------------------------------------------------------- */
2019-03-28 12:04:40 +01:00
int affiche_valeurs(int sfd, int nbloops)
2019-01-30 19:14:40 +01:00
{
int idx, foo;
2019-03-28 12:04:40 +01:00
char ligne[200], buff[200];
float datas[4];
2019-01-30 19:14:40 +01:00
for (idx=0; idx<nbloops; idx++) {
2019-03-28 12:04:40 +01:00
foo = getline_to(sfd, ligne, 100, 0);
#if DEBUG_LEVEL
if (foo) fprintf(stderr, "get values -> %d\n", foo);
#endif
2019-01-30 19:14:40 +01:00
2019-03-28 12:04:40 +01:00
foo = parse4values(ligne, 'T', datas);
#if DEBUG_LEVEL
if (foo) fprintf(stderr, "parse -> %d\n", foo);
#endif
values2temperature(datas);
foo = aff7segs_float(stdscr, 3, 5, datas[0]);
foo = aff7segs_float(stdscr, 14, 5, datas[1]);
foo = aff7segs_float(stdscr, 25, 5, datas[2]);
2019-01-30 19:14:40 +01:00
}
return 0;
}
/* --------------------------------------------------------------- */
static void finish(int signal)
{
2019-02-02 03:52:30 +01:00
endwin();
fprintf(stderr, "end of pid %d\n", getpid());
exit(0);
2019-01-30 19:14:40 +01:00
}
2018-12-08 13:02:24 +01:00
/* --------------------------------------------------------------- */
2019-03-28 12:04:40 +01:00
void help(int k)
{
puts("options : ");
puts("\t-d\tserial device to read.");
puts("\t-v\tincrease verbosity.");
exit(0);
}
/* --------------------------------------------------------------- */
2018-12-08 13:02:24 +01:00
int main(int argc, char *argv[])
{
int opt, foo;
2019-03-28 12:04:40 +01:00
int serial_in;
char *device = "/dev/ttyACM0";
2018-12-08 13:02:24 +01:00
2019-03-28 12:04:40 +01:00
while ((opt = getopt(argc, argv, "d:hv")) != -1) {
2018-12-08 13:02:24 +01:00
switch (opt) {
2019-03-28 12:04:40 +01:00
case 'd': device = optarg; break;
case 'h': help(0); break;
2018-12-08 13:02:24 +01:00
case 'v': verbosity++; break;
default: break;
}
}
2019-03-28 12:04:40 +01:00
serial_in = prepare_UART(device, 9600);
if (serial_in < 0) {
fprintf(stderr, "%s : open device : error %d on %s\n",
argv[0], serial_in, device);
exit(1);
}
2019-01-30 19:14:40 +01:00
initscr();
nonl(); cbreak(); noecho();
keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
fond_ecran(" Demonstrator ");
2019-03-28 12:04:40 +01:00
affiche_valeurs(serial_in, 10000);
2019-01-30 19:14:40 +01:00
/*
* plop, on a fini, il faut restaurer la console
*/
finish(0);
2018-12-08 13:02:24 +01:00
return 0;
}
/* --------------------------------------------------------------- */