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/lcd.cc | 174 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) (limited to 'digital/lcd/src/lcd.cc') diff --git a/digital/lcd/src/lcd.cc b/digital/lcd/src/lcd.cc index f2171025..38fbc25f 100644 --- a/digital/lcd/src/lcd.cc +++ b/digital/lcd/src/lcd.cc @@ -23,6 +23,8 @@ // }}} #include "lcd.hh" #include "ucoolib/utils/delay.hh" +#include "font.hh" + LCD::LCD () : cs_ (GPIOB, 10), rs_ (GPIOB, 11), wr_ (GPIOC, 9), rd_ (GPIOC, 6), @@ -221,4 +223,176 @@ LCD::read_reg (uint16_t index) cs_.set (); return data; } +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>=0 && format.y >=0) + { + for(int i=0 ; ix_max ||y<0 || y>y_max){return;} + set_cursor(x,y); + cs_.reset(); + write_index (0x0022); + write_data(color); + cs_.set(); +} + +void +LCD::circle ( uint16_t color , int radius , Rect pos) //draw a circle (no problem if a part of the circle is not on the screen) +{ + int x=0; + int y=radius; + int m=5-4*radius; + while(x<=y) + { + if(belong (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);} + + if(belong (-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);} + + if(belong (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);} + + if(belong (-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);} + + if(m > 0) + { + y=y-1; + m = m-8*y; + } + x=x+1; + m=m+8*x+4; + } +} +int +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 1;} + return 0; +} +void +LCD::draw_char( uint16_t color ,char caract, Rect pos)//draw a caracter +{ + if(pos.x+8> x_max || pos.y+16>y_max){return;} + caract =caract-32; + for( int i = 0 ; i<=16 ; i++) + { + for( int j =7 ; j>=0 ; j--) + { + if(Ascii[caract][i]&(1<