Browse Source

first real run on the phytotron

phyto 1 year ago
parent
commit
b47e467d21
5 changed files with 51 additions and 17 deletions
  1. 3
    1
      Makefile
  2. 40
    10
      essai.c
  3. 6
    2
      serial/Makefile
  4. 1
    1
      serial/essai.sh
  5. 1
    3
      simulator/rdtemp/rdtemp.ino

+ 3
- 1
Makefile View File

@@ -10,8 +10,10 @@ all:	essai fake-values
10 10
 
11 11
 # ---------------------------------------------
12 12
 
13
+O	= serial/serial.o serial/funcs.o
14
+
13 15
 essai:	essai.c  Makefile $(CLIB)
14
-	$(CC) ${CCOPT} $< $(CLIB) -lncurses -o $@
16
+	$(CC) ${CCOPT} $< $(CLIB) ${O} -lncurses -o $@
15 17
 
16 18
 fake-values:	fake-values.c  Makefile $(CLIB)
17 19
 	$(CC) ${CCOPT} $< $(CLIB)  -o $@

+ 40
- 10
essai.c View File

@@ -11,26 +11,36 @@
11 11
 
12 12
 #include	"core/utils.h"
13 13
 #include	"core/sysmetrics.h"
14
+#include	"serial/serial.h"
14 15
 #include	"viz/curses/ecran.h"
15 16
 
16 17
 int	verbosity;
17 18
 
18 19
 /* --------------------------------------------------------------- */
19
-int affiche_loadavg(int nbloops, int k)
20
+int affiche_valeurs(int sfd, int nbloops)
20 21
 {
21 22
 int		idx, foo;
22
-float		lds[3];
23
+char		ligne[200], buff[200];
24
+float		datas[4];
23 25
 
24 26
 for (idx=0; idx<nbloops; idx++) {
25 27
 
26
-	foo = get_loadavg(lds);
27
-	if (foo) fprintf(stderr, "get loadavg -> %d\n", foo);
28
+	foo = getline_to(sfd, ligne, 100, 0);
29
+#if DEBUG_LEVEL
30
+	if (foo) fprintf(stderr, "get values -> %d\n", foo);
31
+#endif
28 32
 
29
-	foo = aff7segs_float(stdscr,  4, 9, lds[0]);
30
-	foo = aff7segs_float(stdscr, 14, 9, lds[1]);
31
-	foo = aff7segs_float(stdscr, 24, 9, lds[2]);
33
+	foo = parse4values(ligne, 'T', datas);
34
+#if DEBUG_LEVEL
35
+	if (foo) fprintf(stderr, "parse -> %d\n", foo); 
36
+#endif
37
+
38
+	values2temperature(datas);
39
+
40
+	foo = aff7segs_float(stdscr,  3, 5, datas[0]);
41
+	foo = aff7segs_float(stdscr, 14, 5, datas[1]);
42
+	foo = aff7segs_float(stdscr, 25, 5, datas[2]);
32 43
 
33
-	usleep(200*1000);
34 44
 	}
35 45
 return 0;
36 46
 }
@@ -42,25 +52,45 @@ fprintf(stderr, "end of pid %d\n", getpid());
42 52
 exit(0);
43 53
 }
44 54
 /* --------------------------------------------------------------- */
55
+void help(int k)
56
+{
57
+puts("options : ");
58
+puts("\t-d\tserial device to read.");
59
+puts("\t-v\tincrease verbosity.");
60
+exit(0);
61
+}
62
+/* --------------------------------------------------------------- */
45 63
 
46 64
 int main(int argc, char *argv[])
47 65
 {
48 66
 int		opt, foo;
67
+int		serial_in;
68
+char		*device = "/dev/ttyACM0";
49 69
 
50
-while ((opt = getopt(argc, argv, "v")) != -1) {
70
+while ((opt = getopt(argc, argv, "d:hv")) != -1) {
51 71
 	switch (opt) {
72
+		case 'd':	device = optarg;	break;
73
+		case 'h':	help(0);		break;
52 74
 		case 'v':	verbosity++;		break;
53 75
 		default:				break;
54 76
 		}
55 77
 	}
56 78
 
57 79
 
80
+serial_in = prepare_UART(device, 9600);
81
+if (serial_in < 0) {
82
+	fprintf(stderr, "%s : open device : error %d on %s\n",
83
+				argv[0], serial_in, device);
84
+	exit(1);
85
+	}
86
+
87
+
58 88
 initscr();
59 89
 nonl();         cbreak();       noecho();
60 90
 keypad(stdscr, TRUE);           /* acces aux touches 'curseur' */
61 91
 fond_ecran(" Demonstrator ");
62 92
 
63
-affiche_loadavg(10000, 0);
93
+affiche_valeurs(serial_in, 10000);
64 94
 
65 95
 /*
66 96
  *      plop, on a fini, il faut restaurer la console

+ 6
- 2
serial/Makefile View File

@@ -1,5 +1,7 @@
1 1
 
2 2
 OPT = -Wall -DDEBUG_LEVEL=0
3
+OBJS = serial.o funcs.o
4
+# ---------------------------------------------------
3 5
 
4 6
 serial.o:	serial.c serial.h Makefile
5 7
 	gcc ${OPT} -c $<
@@ -7,6 +9,8 @@ serial.o:	serial.c serial.h Makefile
7 9
 funcs.o:	funcs.c serial.h Makefile
8 10
 	gcc ${OPT} -c $<
9 11
 
10
-t:	t.c serial.o funcs.o Makefile
11
-	gcc ${OPT}  $< serial.o funcs.o -o $@
12
+# ---------------------------------------------------
13
+
14
+t:	t.c  Makefile ${OBJS}
15
+	gcc ${OPT}  $< ${OBJS} -o $@
12 16
 

+ 1
- 1
serial/essai.sh View File

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

+ 1
- 3
simulator/rdtemp/rdtemp.ino View File

@@ -4,7 +4,7 @@
4 4
 /* -------------------------------------------------- */
5 5
 
6 6
 #define NBVAL   4
7
-#define DELAI   2000
7
+#define DELAI   5000
8 8
 
9 9
 /* -------------------------------------------------- */
10 10
 void setup() {
@@ -32,9 +32,7 @@ void updatevalues(short *ptr)
32 32
   int foo;
33 33
   digitalWrite(LED_BUILTIN, HIGH);
34 34
   for (foo=0; foo<NBVAL; foo++) {
35
-    
36 35
     ptr[foo] = analogRead(adc_pins[foo]);
37
-    // ptr[foo] = analogRead(A0);
38 36
     delay(100);
39 37
     }
40 38
   digitalWrite(LED_BUILTIN, LOW);

Loading…
Cancel
Save