Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // **************************************************************************
- //
- // Demo program for labs
- //
- // Subject: Computer Architectures and Parallel systems
- // Author: Petr Olivka, petr.olivka@vsb.cz, 08/2016
- // Organization: Department of Computer Science, FEECS,
- // VSB-Technical University of Ostrava, CZ
- //
- // File: Main program for LCD module
- //
- // **************************************************************************
- #include "mbed.h"
- #include "lcd_lib.h"
- #include <font12x20_lsb.h>
- // Serial line for printf output
- Serial pc(USBTX, USBRX);
- // two dimensional array with fixed size font
- extern uint8_t g_font8x8[256][8];
- #define height 12
- #define width 20
- struct Point2D
- {
- int32_t x, y;
- };
- struct RGB
- {
- uint8_t r, g, b;
- };
- class GraphElement
- {
- public:
- // foreground and background color
- RGB fg_color, bg_color;
- // constructor
- GraphElement( RGB t_fg_color, RGB t_bg_color ) :
- fg_color( t_fg_color ), bg_color( t_bg_color ) {}
- // ONLY ONE INTERFACE WITH LCD HARDWARE!!!
- void drawPixel( int32_t t_x, int32_t t_y ) { lcd_put_pixel( t_x, t_y, convert_RGB888_to_RGB565( fg_color ) ); }
- // Draw graphics element
- virtual void draw() = 0;
- // Hide graphics element
- virtual void hide() { swap_fg_bg_color(); draw(); swap_fg_bg_color(); }
- void setColor(RGB c){ fg_color = c;}
- private:
- // swap foreground and backgroud colors
- void swap_fg_bg_color() { RGB l_tmp = fg_color; fg_color = bg_color; bg_color = l_tmp; }
- // conversion of 24-bit RGB color into 16-bit color format
- int convert_RGB888_to_RGB565( RGB t_color ) {
- int red = (t_color.r >> 3) << 11;
- int green = (t_color.g >> 2) << 5;
- int blue = t_color.b >> 3;
- return red | green | blue;
- }
- };
- class Pixel : public GraphElement
- {
- public:
- // constructor
- Pixel( Point2D t_pos, RGB t_fg_color, RGB t_bg_color ) : pos( t_pos ), GraphElement( t_fg_color, t_bg_color ) {}
- // Draw method implementation
- virtual void draw() { drawPixel( pos.x, pos.y ); }
- // Position of Pixel
- Point2D pos;
- };
- class Character : public GraphElement
- {
- public:
- // position of character
- Point2D pos;
- // character
- char character;
- Character( Point2D t_pos, char t_char, RGB t_fg, RGB t_bg ) :
- pos( t_pos ), character( t_char ), GraphElement( t_fg, t_bg ) {};
- void draw() {
- for (int i = 0 ;i < height + 8; i++) {
- for(int j = 0;j < width; j++) {
- if (font[character][i] & (1 << j))
- drawPixel(j + pos.x, i + pos.y);
- }
- }
- }
- };
- int main() {
- lcd_init();
- lcd_clear();
- // Demo code
- int l_color_red = 0xF800;
- int l_color_green = 0x07E0;
- int l_color_blue = 0x001F;
- int l_color_white = 0xFFFF;
- //moje premenne
- struct Point2D point;
- point.x = 100;
- point.y = 100;
- struct RGB fgColor;
- fgColor.b = 0;
- fgColor.g = 0;
- fgColor.r = 255;
- struct RGB bgColor;
- bgColor.b = 0;
- bgColor.g = 0;
- bgColor.r = 0;
- Character ch(point, 'Z', fgColor, bgColor);
- ch.draw();
- point.x += 20;
- Character ch2(point, 'd', fgColor, bgColor);
- ch2.draw();
- point.x += 20;
- Character ch3(point, 'e', fgColor, bgColor);
- ch3.draw();
- point.x += 20;
- Character ch4(point, 'n', fgColor, bgColor);
- ch4.draw();
- point.x += 20;
- Character ch5(point, 'k', fgColor, bgColor);
- ch5.draw();
- point.x += 20;
- Character ch6(point, 'a', fgColor, bgColor);
- ch6.draw();
- point.x -= 60;
- point.y += 30;
- Character ch7(point, '2', fgColor, bgColor);
- ch7.draw();
- point.x += 20;
- Character ch8(point, 'b', fgColor, bgColor);
- ch8.draw();
- while (1) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement