diff --git a/section_3/arduino.c b/section_3/arduino.c index e68b61e..48f669a 100644 --- a/section_3/arduino.c +++ b/section_3/arduino.c @@ -79,10 +79,11 @@ return tv.tv_sec*1000+tv.tv_usec/1000; static void handleEvents(int sd){ struct pollfd fds[2]; char line[MAX_LINE]; -unsigned char packet[MAX_SERIAL]; + int ret; // my variables -int i; +unsigned char packet[MAX_SERIAL]; + // fds[0].fd=STDIN_FILENO; fds[0].events=POLLIN; @@ -91,13 +92,9 @@ fds[1].events=POLLIN; while(1){ - if (butstates[0] == 1) + if (butstates[0] == 1 && butstates[1] == 0 && butstates[2] == 0 && butstates[3] == 0) { - - i = 0; - while (i <= BUTTONS_NB && butstates[i]) - i += 1; - if(i <= BUTTONS_NB) loop(); + loop(); } ret=poll(fds,2,SLEEP_DELAY); if(ret==-1){ perror("poll"); exit(EXIT_FAILURE); } @@ -119,16 +116,20 @@ while(1){ printf("serial in: "); #endif int i; + for(i=0;i0){ if(write(sd,outbuf,outsize)!=outsize) break; #ifdef DEBUG diff --git a/section_3/main.c b/section_3/main.c index 58ad95b..12a1e81 100644 --- a/section_3/main.c +++ b/section_3/main.c @@ -5,13 +5,19 @@ //// // Include files //// -#include "arduino.h" #include +#include +#include "arduino.h" +#define MAX_SERIAL 1024 //// // Global variables // my variables int i; long now; +bool decod; +unsigned char decoded_packet[MAX_SERIAL]; +int j; +int nb_0C; // //// @@ -21,17 +27,44 @@ long now; void setup(void){ i = 0; + j = 0; + decod = false; + nb_0C = 0; } void loop(void){ - led((i-1 + LEDS_NB) % LEDS_NB, 0); - led(i % LEDS_NB, 1); - now = millis(); - while(millis() != now+300); - i = (i+1) % LEDS_NB; + if(millis() > now+300){ + led((i-1 + LEDS_NB) % LEDS_NB, 0); + led(i % LEDS_NB, 1); + i = (i+1) % LEDS_NB; + } } void serialInHandler(unsigned char byte){ + if(byte == '\xdb') { + decod = true; + } + else if(byte == '\x0c') nb_0C += 1; + else if(decod){ + if(byte == '\xdc') + decoded_packet[j] = '\xc0'; + else if(byte== '\xdd') + decoded_packet[j] = '\xdb'; + j += 1; + decod = false; + }else{ + + decoded_packet[j] = byte; + j += 1; + } + + if(nb_0C == 2){ + printf("le packet décodé est de taille %d:\n", j); + nb_0C = 0; + } + /*for(int i = 0; i < j; i++) + printf("%02x ", decoded_packet[i]); + printf("\n");*/ } -- libgit2 0.21.2