diff --git a/essai.c b/essai.c index 10d0eec..b17a131 100644 --- a/essai.c +++ b/essai.c @@ -121,7 +121,7 @@ nonl(); cbreak(); noecho(); keypad(stdscr, TRUE); /* acces aux touches 'curseur' */ fond_ecran(" Demonstrator "); -affiche_valeurs(serial_in, 5000000); +affiche_valeurs(serial_in, 50000000); /* * plop, on a fini, il faut restaurer la console diff --git a/serial/t.c b/serial/t.c index 3eef5fe..7d69f5b 100644 --- a/serial/t.c +++ b/serial/t.c @@ -18,16 +18,51 @@ int verbosity; + /* ---------------------------------------------------------------- */ +int read_temps(char *buff, int k) +{ +float datas[4]; +int raw[4], foo; +long temps; + +foo = parse4_Ivalues(buff, 'T', raw); + // +if (foo >= 0) { + temps = time(NULL); + values2temperature(raw, datas); + printf("%ld %f %f %f %f\n", temps, + datas[0], datas[1], datas[2], datas[3]); + fflush(stdout); + } +else { + fprintf(stderr, "%s: parse -> %d\n", __func__, foo); + } + +return 0; +} +/* ---------------------------------------------------------------- */ +int read_light(char *buff, int k) +{ +int val; + +if (1 == sscanf(buff+1, "%d", &val)) { + printf("--------- %04X ----------\n", val); + return 0; + } +return -3; +} +/* ---------------------------------------------------------------- */ + int loop(int sfd, int iters) { int count, foo; long temps; char ligne[200], buff[200]; -float datas[4]; struct tm *p_tms; for (count=0; count= 0) { - temps = time(NULL); - values2temperature(datas); - printf("%ld %f %f %f %f\n", temps, - datas[0], datas[1], datas[2], datas[3]); - fflush(stdout); + + foo = 0; + switch (ligne[0]) { + case 'L': + foo = read_light(ligne, 0); + break; + case 'T': + foo = read_temps(ligne, 0); + break; + + default: + fprintf(stderr, "*** WTF '%s' ?\n", ligne); + foo = -1; + break; + } - else { - fprintf(stderr, "%s: parse -> %d\n", __func__, foo); + + if (foo) { + fprintf(stderr, "%s : error %d after switch\n", + __func__, foo); } + if (verbosity) puts(""); + } return 0; } diff --git a/simulator/rdtemp/rdtemp.ino b/simulator/rdtemp/rdtemp.ino index 2e99aa5..e373bf1 100644 --- a/simulator/rdtemp/rdtemp.ino +++ b/simulator/rdtemp/rdtemp.ino @@ -24,9 +24,21 @@ void setup() { Serial.print("M running now\n"); } -/* -------------------------------------------------- */ /* ================================================== */ -short adc_pins[] = { A0, A1, A2, A4 }; +/* + * the light captor is on A4 pin + */ +void readlight(void) +{ + short value; + delay(100); + value = analogRead(A4); + Serial.print("L "); + Serial.print(value); + Serial.print('\n'); +} +/* ================================================== */ +short adc_pins[] = { A0, A1, A2, A3 }; #define NB_PASSE 4 /* -------------------------------------------------- */ void updatevalues(short *ptr) @@ -57,7 +69,7 @@ void sendvalues(short *ptr) Serial.print(" "); Serial.print(ptr[foo]); } - Serial.print("\n"); + Serial.print('\n'); } /* -------------------------------------------------- */ void update_and_send(void) @@ -66,12 +78,17 @@ void update_and_send(void) updatevalues(values); sendvalues(values); - - + } /* ================================================== */ void loop() { + static int foo = 0; update_and_send(); + + if (foo++ > 5) { + readlight(); foo = 0; + } + delay(DELAI); }