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' */
fond_ecran(" Demonstrator ");
affiche_valeurs(serial_in, 5000000);
affiche_valeurs(serial_in, 50000000);
/*
* plop, on a fini, il faut restaurer la console

View File

@ -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<iters; count++) {
//
foo = getline_to(sfd, ligne, 100, 0);
//
if (verbosity) {
@ -42,19 +77,29 @@ for (count=0; count<iters; count++) {
(void)strftime(buff, 19, "%H:%M:%S", p_tms);
fprintf(stderr, "%s %6d / %d\n", buff, count, iters);
}
//
foo = parse4values(ligne, 'T', datas);
//
if (foo >= 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;
}

View File

@ -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)
@ -67,11 +79,16 @@ 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);
}