first real run on the phytotron

This commit is contained in:
phyto 2019-03-28 12:04:40 +01:00
parent 17ec8dd47d
commit b47e467d21
5 changed files with 51 additions and 17 deletions

View File

@ -10,8 +10,10 @@ all: essai fake-values
# --------------------------------------------- # ---------------------------------------------
O = serial/serial.o serial/funcs.o
essai: essai.c Makefile $(CLIB) essai: essai.c Makefile $(CLIB)
$(CC) ${CCOPT} $< $(CLIB) -lncurses -o $@ $(CC) ${CCOPT} $< $(CLIB) ${O} -lncurses -o $@
fake-values: fake-values.c Makefile $(CLIB) fake-values: fake-values.c Makefile $(CLIB)
$(CC) ${CCOPT} $< $(CLIB) -o $@ $(CC) ${CCOPT} $< $(CLIB) -o $@

50
essai.c
View File

@ -11,26 +11,36 @@
#include "core/utils.h" #include "core/utils.h"
#include "core/sysmetrics.h" #include "core/sysmetrics.h"
#include "serial/serial.h"
#include "viz/curses/ecran.h" #include "viz/curses/ecran.h"
int verbosity; int verbosity;
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
int affiche_loadavg(int nbloops, int k) int affiche_valeurs(int sfd, int nbloops)
{ {
int idx, foo; int idx, foo;
float lds[3]; char ligne[200], buff[200];
float datas[4];
for (idx=0; idx<nbloops; idx++) { for (idx=0; idx<nbloops; idx++) {
foo = get_loadavg(lds); foo = getline_to(sfd, ligne, 100, 0);
if (foo) fprintf(stderr, "get loadavg -> %d\n", foo); #if DEBUG_LEVEL
if (foo) fprintf(stderr, "get values -> %d\n", foo);
#endif
foo = aff7segs_float(stdscr, 4, 9, lds[0]); foo = parse4values(ligne, 'T', datas);
foo = aff7segs_float(stdscr, 14, 9, lds[1]); #if DEBUG_LEVEL
foo = aff7segs_float(stdscr, 24, 9, lds[2]); 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]);
usleep(200*1000);
} }
return 0; return 0;
} }
@ -42,25 +52,45 @@ fprintf(stderr, "end of pid %d\n", getpid());
exit(0); exit(0);
} }
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
void help(int k)
{
puts("options : ");
puts("\t-d\tserial device to read.");
puts("\t-v\tincrease verbosity.");
exit(0);
}
/* --------------------------------------------------------------- */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int opt, foo; int opt, foo;
int serial_in;
char *device = "/dev/ttyACM0";
while ((opt = getopt(argc, argv, "v")) != -1) { while ((opt = getopt(argc, argv, "d:hv")) != -1) {
switch (opt) { switch (opt) {
case 'd': device = optarg; break;
case 'h': help(0); break;
case 'v': verbosity++; break; case 'v': verbosity++; break;
default: break; default: break;
} }
} }
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);
}
initscr(); initscr();
nonl(); cbreak(); noecho(); nonl(); cbreak(); noecho();
keypad(stdscr, TRUE); /* acces aux touches 'curseur' */ keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
fond_ecran(" Demonstrator "); fond_ecran(" Demonstrator ");
affiche_loadavg(10000, 0); affiche_valeurs(serial_in, 10000);
/* /*
* plop, on a fini, il faut restaurer la console * plop, on a fini, il faut restaurer la console

View File

@ -1,5 +1,7 @@
OPT = -Wall -DDEBUG_LEVEL=0 OPT = -Wall -DDEBUG_LEVEL=0
OBJS = serial.o funcs.o
# ---------------------------------------------------
serial.o: serial.c serial.h Makefile serial.o: serial.c serial.h Makefile
gcc ${OPT} -c $< gcc ${OPT} -c $<
@ -7,6 +9,8 @@ serial.o: serial.c serial.h Makefile
funcs.o: funcs.c serial.h Makefile funcs.o: funcs.c serial.h Makefile
gcc ${OPT} -c $< gcc ${OPT} -c $<
t: t.c serial.o funcs.o Makefile # ---------------------------------------------------
gcc ${OPT} $< serial.o funcs.o -o $@
t: t.c Makefile ${OBJS}
gcc ${OPT} $< ${OBJS} -o $@

View File

@ -5,7 +5,7 @@ DATAFILE="foo.dat"
TMPFILE="/tmp/dd2data" TMPFILE="/tmp/dd2data"
IMAGE="graphe.png" IMAGE="graphe.png"
NB_READ=100 NB_READ=10
./t -n ${NB_READ} -d ${DEVICE} | tee -a ${DATAFILE} ./t -n ${NB_READ} -d ${DEVICE} | tee -a ${DATAFILE}

View File

@ -4,7 +4,7 @@
/* -------------------------------------------------- */ /* -------------------------------------------------- */
#define NBVAL 4 #define NBVAL 4
#define DELAI 2000 #define DELAI 5000
/* -------------------------------------------------- */ /* -------------------------------------------------- */
void setup() { void setup() {
@ -32,9 +32,7 @@ void updatevalues(short *ptr)
int foo; int foo;
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
for (foo=0; foo<NBVAL; foo++) { for (foo=0; foo<NBVAL; foo++) {
ptr[foo] = analogRead(adc_pins[foo]); ptr[foo] = analogRead(adc_pins[foo]);
// ptr[foo] = analogRead(A0);
delay(100); delay(100);
} }
digitalWrite(LED_BUILTIN, LOW); digitalWrite(LED_BUILTIN, LOW);