Claire arrive dans le brotch...

This commit is contained in:
phyto 2019-04-27 21:44:48 +02:00
parent a95e2846d4
commit 431e94fb48
3 changed files with 80 additions and 18 deletions

View File

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

View File

@ -18,16 +18,51 @@
int verbosity; 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 loop(int sfd, int iters)
{ {
int count, foo; int count, foo;
long temps; long temps;
char ligne[200], buff[200]; char ligne[200], buff[200];
float datas[4];
struct tm *p_tms; struct tm *p_tms;
for (count=0; count<iters; count++) { for (count=0; count<iters; count++) {
//
foo = getline_to(sfd, ligne, 100, 0); foo = getline_to(sfd, ligne, 100, 0);
// //
if (verbosity) { if (verbosity) {
@ -42,19 +77,29 @@ for (count=0; count<iters; count++) {
(void)strftime(buff, 19, "%H:%M:%S", p_tms); (void)strftime(buff, 19, "%H:%M:%S", p_tms);
fprintf(stderr, "%s %6d / %d\n", buff, count, iters); fprintf(stderr, "%s %6d / %d\n", buff, count, iters);
} }
//
foo = parse4values(ligne, 'T', datas); foo = 0;
// switch (ligne[0]) {
if (foo >= 0) { case 'L':
temps = time(NULL); foo = read_light(ligne, 0);
values2temperature(datas); break;
printf("%ld %f %f %f %f\n", temps, case 'T':
datas[0], datas[1], datas[2], datas[3]); foo = read_temps(ligne, 0);
fflush(stdout); 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; return 0;
} }

View File

@ -24,9 +24,21 @@ void setup() {
Serial.print("M running now\n"); 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 #define NB_PASSE 4
/* -------------------------------------------------- */ /* -------------------------------------------------- */
void updatevalues(short *ptr) void updatevalues(short *ptr)
@ -57,7 +69,7 @@ void sendvalues(short *ptr)
Serial.print(" "); Serial.print(" ");
Serial.print(ptr[foo]); Serial.print(ptr[foo]);
} }
Serial.print("\n"); Serial.print('\n');
} }
/* -------------------------------------------------- */ /* -------------------------------------------------- */
void update_and_send(void) void update_and_send(void)
@ -67,11 +79,16 @@ void update_and_send(void)
updatevalues(values); updatevalues(values);
sendvalues(values); sendvalues(values);
} }
/* ================================================== */ /* ================================================== */
void loop() { void loop() {
static int foo = 0;
update_and_send(); update_and_send();
if (foo++ > 5) {
readlight(); foo = 0;
}
delay(DELAI); delay(DELAI);
} }