From e679cd626352858262e49e8632954b8b4d21d1bb Mon Sep 17 00:00:00 2001 From: Guillaume Milan Date: Fri, 10 May 2013 13:46:24 +0200 Subject: digital/ld/src: fix the bug of i2c communication if th io/hub givewrong information the lcd give an error message --- digital/lcd/src/lcd.cc | 22 ++++++++++++++++++++++ digital/lcd/src/lcd.hh | 4 +++- digital/lcd/src/main.cc | 38 ++++++++++++++++++++++++++------------ 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/digital/lcd/src/lcd.cc b/digital/lcd/src/lcd.cc index 38fbc25f..e3358d9f 100644 --- a/digital/lcd/src/lcd.cc +++ b/digital/lcd/src/lcd.cc @@ -373,6 +373,28 @@ LCD::draw_sentence( uint16_t color ,const char *sentence, Rect pos) //write a se car_act =sentence[i]; } } +int +LCD::draw_sentence_left( uint16_t color ,const char *sentence, Rect pos) //write a sentence non center +{ + char car_act='A'; //carat actuel + int i=0; + car_act =sentence[i]; + while(car_act!='\0') + { + i++; + car_act =sentence[i]; + } + i=0; + car_act =sentence[i]; + while(car_act!='\0') + { + draw_char (color ,car_act,pos); + pos.x=pos.x+8; + i++; + car_act =sentence[i]; + } + return pos.x+8; +} diff --git a/digital/lcd/src/lcd.hh b/digital/lcd/src/lcd.hh index 5540c179..a3caced1 100644 --- a/digital/lcd/src/lcd.hh +++ b/digital/lcd/src/lcd.hh @@ -66,6 +66,9 @@ class LCD void draw_char( uint16_t color ,char caract, Rect pos); ///write a sentence center on pos void draw_sentence( uint16_t color ,const char *sentence, Rect pos); + ///write a sentence first caractere has pos as position + int draw_sentence_left( uint16_t color ,const char *sentence, Rect pos); + int belong ( int x, int y); //does the point belong to the screen? private: void set_cursor (int x, int y); void write_index (uint16_t index); @@ -73,7 +76,6 @@ class LCD uint16_t read_data (); void write_reg (uint16_t index, uint16_t data); uint16_t read_reg (uint16_t index); - int belong ( int x, int y); //does the point belong to the screen? private: ucoo::Gpio cs_, rs_, wr_, rd_, reset_, bl_; }; diff --git a/digital/lcd/src/main.cc b/digital/lcd/src/main.cc index 34dcbfe8..758a4d2f 100644 --- a/digital/lcd/src/main.cc +++ b/digital/lcd/src/main.cc @@ -70,7 +70,9 @@ i2c_handle (LCD &lcd, const char *buf, int size) char cmd = buf[2]; const char *arg = &buf[3]; int arg_nb = size - 3; - int j; + int j;//for incrementation + int x; + int y; switch (cmd) { case 'c': @@ -82,28 +84,42 @@ i2c_handle (LCD &lcd, const char *buf, int size) i2c_color[2]=arg[2]; break; case 't': + if(arg[0]<0 || arg[0]>90){strcpy(i2c_cmd,"ERROR I2C time");} i2c_time=arg[0]; break; case 'p': //position of the robot - pos_r.x=ucoo::bytes_pack (arg[0] ,arg [1] )*0.10666; - pos_r.y=ucoo::bytes_pack (arg[2] ,arg [3] )*0.10666; + x=ucoo::bytes_pack (arg[0] ,arg [1] )*0.10666; + y=ucoo::bytes_pack (arg[2] ,arg [3] )*0.10666; + if(lcd.belong (x,y)) + {pos_r.x=ucoo::bytes_pack (arg[0] ,arg [1] )*0.10666; + pos_r.y=ucoo::bytes_pack (arg[2] ,arg [3] )*0.10666;} + else{strcpy(i2c_cmd,"ERROR I2C position");} break; case 'm': //message strcpy(i2c_cmd,arg); + break; + case 'o': //obstacle (barrier) j=0; nb_obs=arg[0]; for(int i=1 ; i<=nb_obs*4 ; i=i+4) { - pos_obs[j].x=ucoo::bytes_pack (arg[i] ,arg [i+1] )*0.10666; + x=ucoo::bytes_pack (arg[i] ,arg [i+1] )*0.10666; + y=ucoo::bytes_pack (arg[i+2] ,arg [i+3] )*0.10666; + if(lcd.belong (x,y)) + { pos_obs[j].x=ucoo::bytes_pack (arg[i] ,arg [i+1] )*0.10666; pos_obs[j].y=ucoo::bytes_pack (arg[i+2] ,arg [i+3] )*0.10666; - j++; + j++;} + else{strcpy(i2c_cmd,"ERROR I2C obstacle");} } break; case 'n'://next position of the robot - pos_r_n.x=ucoo::bytes_pack (arg[0] ,arg [1] )*0.10666; - pos_r_n.y=ucoo::bytes_pack (arg[2] ,arg [3] )*0.10666; + x=ucoo::bytes_pack (arg[0] ,arg [1] )*0.10666; + y=ucoo::bytes_pack (arg[2] ,arg [3] )*0.10666; + if(lcd.belong (x,y)) + {pos_r_n.x=ucoo::bytes_pack (arg[0] ,arg [1] )*0.10666; + pos_r_n.y=ucoo::bytes_pack (arg[2] ,arg [3] )*0.10666;} break; default: // Unknown command. @@ -151,9 +167,6 @@ draw_robot (LCD lcd) //draw of the robot and his barriers lcd.rectangle_fill (LCD::color (0,255,0),size_dest ,pos_rob_n); } - - - void draw_time (LCD lcd) //write the remaining time { @@ -250,9 +263,10 @@ main (int argc, const char **argv) draw_table (lcd); // Wait orders. while (1) - { + { draw_table (lcd);//draw the table - draw_robot (lcd);//draw the robot and his destination on the table + draw_robot (lcd);//draw the robot and his destination on the table + i2c_poll (lcd, i2c_data); ucoo::delay_ms (1000); -- cgit v1.2.3