Commit d2403640 authored by Vít Ramba's avatar Vít Ramba
Browse files

Changes to my_lcd_text.c

parent c1a0391f
......@@ -3,20 +3,16 @@
#define LCD_FB_START 0xffe00000
#define LCD_FB_END 0xffe4afff
//gab between two characters, size two
#define GAB 2
//display properities
#define LCD_WIDTH 480
#define LCD_HEIGHT 320
//border of the draw field
#define DRAW_BORDER 255
#define GAB 2 // Gab between two characters, size two
#define LCD_WIDTH 480 // Display width
#define LCD_HEIGHT 320 // Display height
#define DRAW_BORDER 255 // Border of the canvas
//lcd buffer
uint16_t text_field[LCD_WIDTH * LCD_HEIGHT];
uint16_t text_field[LCD_WIDTH * LCD_HEIGHT]; // LCD buffer
//16 bites colors
/* 16 bit colors */
rgb_color_16b_t Gcolor16b =
{
{
.red = 0xF800,
.blue = 0x1F,
.green = 0x7E0,
......@@ -25,9 +21,9 @@ rgb_color_16b_t Gcolor16b =
.yellow = 0xFF00,
};
//64 bites colors
/* 64 bit colors */
rgb_color_64b_t Gcolor64b =
{
{
.red = 0xFF0000,
.blue = 0x0000FF,
.green = 0x00FF00,
......@@ -36,9 +32,9 @@ rgb_color_64b_t Gcolor64b =
.yellow = 0xFFFF00,
};
//Function for getting the width of a char from a fond for lcd display
int get_width_of_char(font_descriptor_t *file_des, int ch_char)
{
/* Function for getting the width of a char from a fond for lcd display */
int get_width_of_char(font_descriptor_t *file_des, int ch_char) {
int ch_width = 0;
int cond1 = file_des->firstchar <= ch_char;
int cond2 = file_des->size > (ch_char - file_des->firstchar);
......@@ -57,18 +53,18 @@ int get_width_of_char(font_descriptor_t *file_des, int ch_char)
return ch_width;
}
//Erase whole text field (buffer) to black (zero)
void erase_text_field(void)
{
/* Erase whole text field (buffer) to black (zero) */
void erase_text_field(void) {
for (int i = 0; i < LCD_WIDTH * LCD_HEIGHT; ++i)
{
text_field[i] = 0;
}
}
//Colors pixels in field according to inputs
void color_pixels(uint16_t pix_color, int start_pos, int block_size)
{
/* Colors pixels in field according to inputs */
void color_pixels(uint16_t pix_color, int start_pos, int block_size) {
for (int m = 0; m < block_size; ++m)
{
for (int k = 0; k < block_size; ++k)
......@@ -78,9 +74,9 @@ void color_pixels(uint16_t pix_color, int start_pos, int block_size)
}
}
//Makes draw frame in field
void make_draw_frame(uint16_t pix_color)
{
/* Makes draw frame in field */
void make_draw_frame(uint16_t pix_color) {
int size_of_num = 1;
int side_num = DRAW_BORDER + 10;
//vertical line
......@@ -96,16 +92,21 @@ void make_draw_frame(uint16_t pix_color)
text_field[y + x * LCD_WIDTH] = pix_color;
}
//draws numbers to the draw field
draw_line(size_of_num, 1, Gcolor16b.white, &font_winFreeSystem14x16, side_num, "0");
draw_line(size_of_num, 127, Gcolor16b.white, &font_winFreeSystem14x16, side_num, "127");
draw_line(size_of_num, lower_line, Gcolor16b.white, &font_winFreeSystem14x16, side_num, "255");
draw_line(size_of_num, lower_line, Gcolor16b.white, &font_winFreeSystem14x16, 2, "0");
draw_line(size_of_num, lower_line, Gcolor16b.white, &font_winFreeSystem14x16, 127, "127");
draw_line(size_of_num, 1, Gcolor16b.white, &font_winFreeSystem14x16,
side_num, "0");
draw_line(size_of_num, 127, Gcolor16b.white, &font_winFreeSystem14x16,
side_num, "127");
draw_line(size_of_num, lower_line, Gcolor16b.white,
&font_winFreeSystem14x16, side_num, "255");
draw_line(size_of_num, lower_line, Gcolor16b.white,
&font_winFreeSystem14x16, 2, "0");
draw_line(size_of_num, lower_line, Gcolor16b.white,
&font_winFreeSystem14x16, 127, "127");
}
//Returns text length according to file descriptor
int get_text_lenght(font_descriptor_t *file_des, int *text_size, char *str_text)
{
/* Returns text length according to file descriptor */
int get_text_lenght(font_descriptor_t *file_des, int *text_size, char *str_text) {
int ret = 0;
int lenght = 0;
*text_size = 0;
......@@ -123,10 +124,11 @@ int get_text_lenght(font_descriptor_t *file_des, int *text_size, char *str_text)
return ret;
}
//Writes one character into the text field
void write_character(int ch_size, int start, uint16_t char_color, font_descriptor_t *file_des, char character,
int line_number)
{
/* Writes one character into the text field */
void write_character(int ch_size, int start, uint16_t char_color,
font_descriptor_t *file_des, char character,
int line_number) {
int char_width = get_width_of_char(file_des, character);
for (int i = 0; i < file_des->height; ++i)
{
......@@ -153,13 +155,14 @@ void write_character(int ch_size, int start, uint16_t char_color, font_descripto
}
}
//Writes one line of a string according to inputs
void draw_line(int size_of_font, int line_number, uint16_t text_color, font_descriptor_t *file_des, int idx,
char *str_text)
{
/* Writes one line of a string according to inputs */
void draw_line(int size_of_font, int line_number, uint16_t text_color,
font_descriptor_t *file_des, int idx, char *str_text) {
int text_size = 0;
int str_lenght = get_text_lenght(file_des, &text_size, str_text);
int length = text_size * size_of_font + (str_lenght - 1) * size_of_font * GAB;
int length = text_size * size_of_font +
(str_lenght - 1) * size_of_font * GAB;
int cond = (file_des->height * size_of_font + line_number) >= LCD_HEIGHT;
if (length > LCD_WIDTH)
{
......@@ -182,15 +185,17 @@ void draw_line(int size_of_font, int line_number, uint16_t text_color, font_desc
}
for (int j = 0; j < str_lenght; ++j)
{
write_character(size_of_font, index, text_color, file_des, str_text[j], line_number);
index = index + (get_width_of_char(file_des, str_text[j]) + GAB) * size_of_font;
write_character(size_of_font, index, text_color, file_des,
str_text[j], line_number);
index = index + (get_width_of_char(file_des, str_text[j]) +
GAB) * size_of_font;
}
}
}
//Redraws whole text field into the lcd
void draw_to_lcd(void)
{
/* Redraws whole text field into the lcd */
void draw_to_lcd(void) {
volatile uint16_t *lcd_t = (typeof(lcd_t))LCD_FB_START;
for (int e = 0; e < LCD_WIDTH * LCD_HEIGHT; ++e)
{
......@@ -198,9 +203,10 @@ void draw_to_lcd(void)
}
}
//Draws initialization message to lcd display
void init_lcd_message(int size_of_font, uint16_t text_color, font_descriptor_t *file_des)
{
/* Draws initialization message to lcd display */
void init_lcd_message(int size_of_font, uint16_t text_color,
font_descriptor_t *file_des) {
int bigger_font = 2;
int left_side = DRAW_BORDER + 40;
int middle = -1;
......@@ -213,31 +219,42 @@ void init_lcd_message(int size_of_font, uint16_t text_color, font_descriptor_t *
//whole drawing of lcd screen
make_draw_frame(Gcolor16b.white);
draw_line(bigger_font, 1, text_color, file_des, left_side, " GRAFO");
draw_line(size_of_font, 36, text_color, &font_winFreeSystem14x16, left_side, " <-- DRAW SCREEN");
draw_line(size_of_font, 56, text_color, &font_winFreeSystem14x16, left_side, " PICK COLOR");
draw_line(size_of_font, 36, text_color, &font_winFreeSystem14x16,
left_side, " <-- DRAW SCREEN");
draw_line(size_of_font, 56, text_color, &font_winFreeSystem14x16,
left_side, " PICK COLOR");
pick_color(size_of_font, text_color, file_des);
draw_line(size_of_font, 176, text_color, &font_winFreeSystem14x16, left_side, " TYPE 'P' TO ERASE");
draw_line(size_of_font, 196, text_color, &font_winFreeSystem14x16, left_side, " TYPE 'Q' TO QUIT");
draw_line(size_of_font, 290, Gcolor16b.green, &font_winFreeSystem14x16, middle, "BY: MATEJ KOPECKY AND VIT RAMBA");
draw_line(size_of_font, 176, text_color, &font_winFreeSystem14x16,
left_side, " TYPE 'P' TO ERASE");
draw_line(size_of_font, 196, text_color, &font_winFreeSystem14x16,
left_side, " TYPE 'Q' TO QUIT");
draw_line(size_of_font, 290, Gcolor16b.green, &font_winFreeSystem14x16,
middle, "BY: MATEJ KOPECKY AND VIT RAMBA");
draw_to_lcd();
print_str_on_terminal("TYPE TO INPUT TO PICK COLOR!\n");
}
//Draw color options to lcd
void pick_color(int size_of_font, uint16_t text_color, font_descriptor_t *file_des)
{
/* Draw color options to lcd */
void pick_color(int size_of_font, uint16_t text_color,
font_descriptor_t *file_des) {
//draws colors options
int left_side = DRAW_BORDER + 40;
draw_line(size_of_font, 76, Gcolor16b.red, &font_winFreeSystem14x16, left_side, " 'R' - RED");
draw_line(size_of_font, 96, Gcolor16b.green, &font_winFreeSystem14x16, left_side, " 'G' - GREEN");
draw_line(size_of_font, 116, Gcolor16b.blue, &font_winFreeSystem14x16, left_side, " 'B' - BLUE");
draw_line(size_of_font, 136, Gcolor16b.yellow, &font_winFreeSystem14x16, left_side, " 'Y' - YELLOW");
draw_line(size_of_font, 156, Gcolor16b.white, &font_winFreeSystem14x16, left_side, " 'W' - WHITE");
draw_line(size_of_font, 76, Gcolor16b.red, &font_winFreeSystem14x16,
left_side, " 'R' - RED");
draw_line(size_of_font, 96, Gcolor16b.green, &font_winFreeSystem14x16,
left_side, " 'G' - GREEN");
draw_line(size_of_font, 116, Gcolor16b.blue, &font_winFreeSystem14x16,
left_side, " 'B' - BLUE");
draw_line(size_of_font, 136, Gcolor16b.yellow, &font_winFreeSystem14x16,
left_side, " 'Y' - YELLOW");
draw_line(size_of_font, 156, Gcolor16b.white, &font_winFreeSystem14x16,
left_side, " 'W' - WHITE");
}
//Erases the whole lcd display
void black_the_lcd(void)
{
/* Erases the whole lcd display */
void black_the_lcd(void) {
print_str_on_terminal("WAIT FOR BLACK SCREEN!\n");
volatile uint16_t *lcd_t = (typeof(lcd_t))LCD_FB_START;
for (int i = 0; i < LCD_HEIGHT * LCD_WIDTH; ++i)
......@@ -247,9 +264,9 @@ void black_the_lcd(void)
print_str_on_terminal("READY TO DRAW!\n");
}
//Erases just the draw frame for new drawing
void black_the_draw_frame(void)
{
/* Erases just the draw frame for new drawing */
void black_the_draw_frame(void) {
int block_size = DRAW_BORDER;
print_str_on_terminal("WAIT FOR BLACK FRAME!\n");
volatile uint16_t *lcd_t = (typeof(lcd_t))LCD_FB_START;
......@@ -261,4 +278,5 @@ void black_the_draw_frame(void)
}
}
print_str_on_terminal("READY TO DRAW!\n");
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment