Browse Source

Claire arrive dans le brotch...

phyto 1 year ago
parent
commit
431e94fb48
3 changed files with 80 additions and 18 deletions
  1. 1
    1
      essai.c
  2. 57
    12
      serial/t.c
  3. 22
    5
      simulator/rdtemp/rdtemp.ino

+ 1
- 1
essai.c View File

@@ -121,7 +121,7 @@ nonl();         cbreak();       noecho();
121 121
 keypad(stdscr, TRUE);           /* acces aux touches 'curseur' */
122 122
 fond_ecran(" Demonstrator ");
123 123
 
124
-affiche_valeurs(serial_in, 5000000);
124
+affiche_valeurs(serial_in, 50000000);
125 125
 
126 126
 /*
127 127
  *      plop, on a fini, il faut restaurer la console

+ 57
- 12
serial/t.c View File

@@ -18,16 +18,51 @@
18 18
 
19 19
 int	verbosity;
20 20
 
21
+
22
+/* ---------------------------------------------------------------- */
23
+int read_temps(char *buff, int k)
24
+{
25
+float		datas[4];
26
+int		raw[4], foo;
27
+long		temps;
28
+
29
+foo = parse4_Ivalues(buff, 'T', raw);
30
+	// 
31
+if (foo >= 0) {
32
+	temps = time(NULL);
33
+	values2temperature(raw, datas);
34
+	printf("%ld %f %f %f %f\n", temps,
35
+			datas[0], datas[1], datas[2], datas[3]);
36
+	fflush(stdout);
37
+	}
38
+else	{
39
+	fprintf(stderr, "%s: parse -> %d\n", __func__, foo);
40
+	}
41
+
42
+return 0;
43
+}
44
+/* ---------------------------------------------------------------- */
45
+int read_light(char *buff, int k)
46
+{
47
+int		val;
48
+
49
+if (1 == sscanf(buff+1, "%d", &val)) {
50
+	printf("--------- %04X ----------\n", val);
51
+	return 0;
52
+	}
53
+return -3;
54
+}
21 55
 /* ---------------------------------------------------------------- */
56
+
22 57
 int loop(int sfd, int iters)
23 58
 {
24 59
 int		count, foo;
25 60
 long		temps;
26 61
 char		ligne[200], buff[200];
27
-float		datas[4];
28 62
 struct tm       *p_tms;
29 63
 
30 64
 for (count=0; count<iters; count++) {
65
+	//
31 66
 	foo = getline_to(sfd, ligne, 100, 0);
32 67
 	//
33 68
 	if (verbosity) {
@@ -42,19 +77,29 @@ for (count=0; count<iters; count++) {
42 77
 		(void)strftime(buff, 19, "%H:%M:%S", p_tms);
43 78
 		fprintf(stderr, "%s    %6d / %d\n", buff, count, iters);
44 79
 		}
45
-	//
46
-	foo = parse4values(ligne, 'T', datas);
47
-	// 
48
-	if (foo >= 0) {
49
-		temps = time(NULL);
50
-		values2temperature(datas);
51
-		printf("%ld %f %f %f %f\n", temps,
52
-				datas[0], datas[1], datas[2], datas[3]);
53
-		fflush(stdout);
80
+
81
+	foo = 0;
82
+	switch (ligne[0]) {
83
+		case 'L':
84
+			foo = read_light(ligne, 0);
85
+			break;
86
+		case 'T':
87
+			foo = read_temps(ligne, 0);
88
+			break;
89
+
90
+		default:
91
+			fprintf(stderr, "*** WTF '%s' ?\n", ligne);
92
+			foo = -1;
93
+			break;
94
+			
54 95
 		}
55
-	else	{
56
-		fprintf(stderr, "%s: parse -> %d\n", __func__, foo);
96
+		
97
+	if (foo) {
98
+		fprintf(stderr, "%s : error %d after switch\n",
99
+					__func__, foo);
57 100
 		}
101
+	if (verbosity)		puts("");
102
+	
58 103
 	}
59 104
 return 0;
60 105
 }

+ 22
- 5
simulator/rdtemp/rdtemp.ino View File

@@ -24,9 +24,21 @@ void setup() {
24 24
   Serial.print("M running now\n");
25 25
   
26 26
 }
27
-/* -------------------------------------------------- */
28 27
 /* ================================================== */
29
-short adc_pins[] = { A0, A1, A2, A4 };
28
+/*
29
+ * the light captor is on A4 pin
30
+ */
31
+void readlight(void)
32
+{
33
+  short value;
34
+  delay(100);
35
+  value = analogRead(A4);
36
+  Serial.print("L ");
37
+  Serial.print(value);
38
+  Serial.print('\n');
39
+}
40
+/* ================================================== */
41
+short adc_pins[] = { A0, A1, A2, A3 };
30 42
 #define NB_PASSE  4
31 43
 /* -------------------------------------------------- */
32 44
 void updatevalues(short *ptr)
@@ -57,7 +69,7 @@ void sendvalues(short *ptr)
57 69
     Serial.print(" ");
58 70
     Serial.print(ptr[foo]);
59 71
     }
60
-  Serial.print("\n");
72
+  Serial.print('\n');
61 73
 }
62 74
 /* -------------------------------------------------- */
63 75
 void update_and_send(void)
@@ -66,12 +78,17 @@ void update_and_send(void)
66 78
   
67 79
   updatevalues(values);
68 80
   sendvalues(values);
69
-  
70
-  
81
+ 
71 82
 }
72 83
 /* ================================================== */
73 84
 void loop() {
85
+  static int foo = 0;
74 86
   update_and_send();
87
+
88
+  if (foo++ > 5) {
89
+    readlight();    foo = 0;
90
+  }
91
+ 
75 92
   delay(DELAI);
76 93
 }
77 94
 

Loading…
Cancel
Save