summaryrefslogtreecommitdiffhomepage
path: root/digital/lcd
diff options
context:
space:
mode:
Diffstat (limited to 'digital/lcd')
-rw-r--r--digital/lcd/src/lcd.cc50
-rw-r--r--digital/lcd/src/main.cc33
2 files changed, 47 insertions, 36 deletions
diff --git a/digital/lcd/src/lcd.cc b/digital/lcd/src/lcd.cc
index 60fded3d..bac2bc51 100644
--- a/digital/lcd/src/lcd.cc
+++ b/digital/lcd/src/lcd.cc
@@ -227,22 +227,24 @@ void
LCD::rectangle_fill (uint16_t color,Rect format, Rect pos)//make a filled rectangle
{
set_cursor(pos.x , pos.y);
- if(format.x+pos.x> x_max){format.x=x_max-pos.x;}
- if(format.y+pos.y> y_max){format.y=y_max-pos.y;}
+ if(format.x+pos.x> x_max)
+ format.x=x_max-pos.x;
+ if(format.y+pos.y> y_max)
+ format.y=y_max-pos.y;
if(format.x>=0 && format.y >=0)
{
- for(int i=0 ; i<format.y ; i++)
- {
- cs_.reset();
- write_index (0x0022);
- for(int j=0 ; j<format.x ; j++)
+ for(int i=0 ; i<format.y ; i++)
{
- write_data(color);
+ cs_.reset();
+ write_index (0x0022);
+ for(int j=0 ; j<format.x ; j++)
+ {
+ write_data(color);
+ }
+ cs_.set();
+ pos.y++;
+ set_cursor(pos.x , pos.y);
}
- cs_.set();
- pos.y++;
- set_cursor(pos.x , pos.y);
- }
}
}
@@ -282,7 +284,8 @@ LCD::rectangle_empty (uint16_t color,Rect format, Rect pos) //make the border of
void
LCD::blit_pixel ( uint16_t color , int x , int y)//blit a pixel if he is on the screen
{
- if(x<0 || x>x_max ||y<0 || y>y_max){return;}
+ if(x<0 || x>x_max ||y<0 || y>y_max)
+ return;
set_cursor(x,y);
cs_.reset();
write_index (0x0022);
@@ -299,28 +302,28 @@ LCD::circle ( uint16_t color , int radius , Rect pos) //draw a circle (no proble
while(x<=y)
{
if(belong (x+pos.x , y+pos.y))
- {blit_pixel(color , x+pos.x , y+pos.y);}
+ blit_pixel(color , x+pos.x , y+pos.y);
if(belong ( y+pos.x , x+pos.y))
- {blit_pixel(color , y+pos.x , x+pos.y);}
+ blit_pixel(color , y+pos.x , x+pos.y);
if(belong (-x+pos.x , y+pos.y))
- {blit_pixel(color , -x+pos.x , y+pos.y);}
+ blit_pixel(color , -x+pos.x , y+pos.y);
if(belong (-y+pos.x , x+pos.y))
- {blit_pixel(color , -y+pos.x , x+pos.y);}
+ blit_pixel(color , -y+pos.x , x+pos.y);
if(belong (x+pos.x , -y+pos.y))
- {blit_pixel(color , x+pos.x , -y+pos.y);}
+ blit_pixel(color , x+pos.x , -y+pos.y);
if(belong ( y+pos.x , -x+pos.y))
- {blit_pixel(color , y+pos.x , -x+pos.y);}
+ blit_pixel(color , y+pos.x , -x+pos.y);
if(belong (-x+pos.x , -y+pos.y))
- {blit_pixel(color , -x+pos.x , -y+pos.y);}
+ blit_pixel(color , -x+pos.x , -y+pos.y);
if(belong (-y+pos.x , -x+pos.y))
- {blit_pixel(color , -y+pos.x , -x+pos.y);}
+ blit_pixel(color , -y+pos.x , -x+pos.y);
if(m > 0)
{
@@ -335,7 +338,7 @@ bool
LCD::belong (int x , int y) //test if the point A(x,y) belong to the screen
{
if(0<=x && x<=x_max && 0<=y && y<=y_max)
- {return true;}
+ return true;
return false;
}
void
@@ -347,7 +350,8 @@ LCD::draw_char( uint16_t color ,char caract, Rect pos)//draw a caracter
{
for( int j =7 ; j>=0 ; j--)
{
- if(Ascii[caract][i]&(1<<j)){blit_pixel(color,8-j+pos.x,i+pos.y);}
+ if(Ascii[caract][i]&(1<<j))
+ blit_pixel(color,8-j+pos.x,i+pos.y);
}
}
}
diff --git a/digital/lcd/src/main.cc b/digital/lcd/src/main.cc
index 0361fba6..31075f6c 100644
--- a/digital/lcd/src/main.cc
+++ b/digital/lcd/src/main.cc
@@ -57,7 +57,8 @@ conv_pos (Rect &pos)
pos.x=(3000-pos.x) *320/3000;
pos.y=(2000-pos.y) *240/2000;
if(LCD::belong(pos.x,pos.y))
- {return false;} return true;
+ return false;
+ return true;
}
void
@@ -89,14 +90,15 @@ i2c_handle (LCD &lcd, const char *buf, int size)
i2c_color[2]=arg[2];
break;
case 't':
- if(arg[0]>90){strcpy(i2c_cmd,"ERROR I2C time");}
+ if(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] );//position in mm
pos_r.y=ucoo::bytes_pack (arg[2] ,arg [3] );
if(!conv_pos(pos_r))
- {strcpy(i2c_cmd,"ERROR I2C position");}
+ strcpy(i2c_cmd,"ERROR I2C position");
break;
case 'm': //message
strcpy(i2c_cmd,arg);
@@ -111,14 +113,14 @@ i2c_handle (LCD &lcd, const char *buf, int size)
pos_obs[j].y=ucoo::bytes_pack (arg[i+2] ,arg [i+3] );
j++;
if(!conv_pos(pos_obs[j]))
- {strcpy(i2c_cmd,"ERROR I2C obstacle");}
+ 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] );
pos_r_n.y=ucoo::bytes_pack (arg[2] ,arg [3] );
if(!conv_pos(pos_r_n))
- {strcpy(i2c_cmd,"ERROR I2C next pos");}
+ strcpy(i2c_cmd,"ERROR I2C next pos");
break;
default:
// Unknown command.
@@ -177,10 +179,15 @@ draw_time (LCD lcd) //write the remaining time
Rect pos_d;pos_d.x=292;pos_d.y=223;//digit one
char dizaine = i2c_time/10 +48;
char unite = i2c_time%10 +48;
- if(i2c_time<0){lcd.draw_sentence (0,"ERROR",pos_d);}
- else{
- if(i2c_time/10!=0){lcd.draw_char( 0 ,dizaine,pos_d);}
- lcd.draw_char( 0 ,unite,pos_u);}
+
+ if(i2c_time<0)
+ lcd.draw_sentence (0,"ERROR",pos_d);
+ else
+ {
+ if(i2c_time/10!=0)
+ lcd.draw_char( 0 ,dizaine,pos_d);
+ lcd.draw_char( 0 ,unite,pos_u);
+ }
}
void
@@ -253,10 +260,10 @@ main (int argc, const char **argv)
ucoo::I2cSlaveDataBufferSize<i2c_status_size, i2c_command_size> 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;
+ 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);