From 04b3d6d78ab60ab7c15dd9affbef521acf584f1f Mon Sep 17 00:00:00 2001 From: Guillaume Milan Date: Fri, 10 May 2013 00:20:31 +0200 Subject: digital/lcd/src: give to the user some information of the robot status Give the color, the remaining time, the robot position, the robot destination. --- digital/lcd/src/main.cc | 149 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 2 deletions(-) (limited to 'digital/lcd/src/main.cc') diff --git a/digital/lcd/src/main.cc b/digital/lcd/src/main.cc index 38016cd2..34dcbfe8 100644 --- a/digital/lcd/src/main.cc +++ b/digital/lcd/src/main.cc @@ -26,9 +26,23 @@ #include "ucoolib/arch/arch.hh" #include "ucoolib/utils/delay.hh" #include +#include + #include "ucoolib/hal/i2c/i2c.hh" #include "ucoolib/utils/crc.hh" +#include "ucoolib/utils/bytes.hh" +//uint16_t ucoo::bytes_pack (arg 1 ,arg 2 ); + + + +static char i2c_color[3]; +static int i2c_time; +static char i2c_cmd[100]="..."; +static Rect pos_r;//position du robot +static int nb_obs=0;//nb d'obstacle +static Rect pos_obs[4]; +static Rect pos_r_n; //next position of the robot static const int i2c_status_size = 3; static const int i2c_command_size = 16; @@ -56,14 +70,41 @@ 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; switch (cmd) { case 'c': // Team color. if (arg_nb != 3) return; - lcd.clear (LCD::color (arg[0], arg[1], arg[2])); + i2c_color[0]=arg[0]; + i2c_color[1]=arg[1]; + i2c_color[2]=arg[2]; break; + case 't': + 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; + break; + case 'm': //message + strcpy(i2c_cmd,arg); + 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; + + pos_obs[j].y=ucoo::bytes_pack (arg[i+2] ,arg [i+3] )*0.10666; + j++; + } + 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; + break; default: // Unknown command. return; @@ -89,6 +130,99 @@ i2c_poll (LCD &lcd, ucoo::I2cSlaveDataBuffer &i2c_data) sizeof (status) - 1); i2c_data.update (status, sizeof (status)); } +void +draw_bar (LCD lcd)//draw barrier (make a red circle where is approximatly the barrier) +{ + for(int i=0; i i2c_data; i2c.register_data (0x20, i2c_data); + //Init global variable + i2c_color[0]=0;i2c_color[1]=0;i2c_color[2]=0; + i2c_time=90; + pos_r_n.x=160;pos_r_n.y=120; + pos_r.x=160;pos_r.y=120; // Init. + LCD lcd; + //ucoo::delay_ms (1000); + 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 i2c_poll (lcd, i2c_data); - ucoo::delay_ms (1); + ucoo::delay_ms (1000); + } } -- cgit v1.2.3