Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.81 KB | None | 0 0
  1. // **************************************************************************
  2. //
  3. //               Demo program for labs
  4. //
  5. // Subject:      Computer Architectures and Parallel systems
  6. // Author:       Petr Olivka, petr.olivka@vsb.cz, 08/2016
  7. // Organization: Department of Computer Science, FEECS,
  8. //               VSB-Technical University of Ostrava, CZ
  9. //
  10. // File:         Main program for LCD module
  11. //
  12. // **************************************************************************
  13.  
  14. #include "mbed.h"
  15. #include "lcd_lib.h"
  16. #include <font12x20_lsb.h>
  17.  
  18. // Serial line for printf output
  19. Serial pc(USBTX, USBRX);
  20.  
  21. // two dimensional array with fixed size font
  22. extern uint8_t g_font8x8[256][8];
  23.  
  24. #define height 12
  25. #define width 20
  26.  
  27. struct Point2D
  28. {
  29.     int32_t x, y;
  30. };
  31.  
  32. struct RGB
  33. {
  34.     uint8_t r, g, b;
  35. };
  36.  
  37. class GraphElement
  38. {
  39. public:
  40.     // foreground and background color
  41.     RGB fg_color, bg_color;
  42.  
  43.     // constructor
  44.     GraphElement( RGB t_fg_color, RGB t_bg_color ) :
  45.         fg_color( t_fg_color ), bg_color( t_bg_color ) {}
  46.  
  47.     // ONLY ONE INTERFACE WITH LCD HARDWARE!!!
  48.     void drawPixel( int32_t t_x, int32_t t_y ) { lcd_put_pixel( t_x, t_y, convert_RGB888_to_RGB565( fg_color ) ); }
  49.  
  50.     // Draw graphics element
  51.     virtual void draw() = 0;
  52.  
  53.     // Hide graphics element
  54.     virtual void hide() { swap_fg_bg_color(); draw(); swap_fg_bg_color(); }
  55.     void setColor(RGB c){ fg_color = c;}
  56. private:
  57.     // swap foreground and backgroud colors
  58.     void swap_fg_bg_color() { RGB l_tmp = fg_color; fg_color = bg_color; bg_color = l_tmp; }
  59.  
  60.     // conversion of 24-bit RGB color into 16-bit color format
  61.     int convert_RGB888_to_RGB565( RGB t_color ) {
  62.         int red = (t_color.r >> 3) << 11;
  63.         int green = (t_color.g >> 2) << 5;
  64.         int blue = t_color.b >> 3;
  65.         return red | green | blue;
  66.     }
  67. };
  68.  
  69. class Pixel : public GraphElement
  70. {
  71. public:
  72.     // constructor
  73.     Pixel( Point2D t_pos, RGB t_fg_color, RGB t_bg_color ) : pos( t_pos ), GraphElement( t_fg_color, t_bg_color ) {}
  74.     // Draw method implementation
  75.     virtual void draw() { drawPixel( pos.x, pos.y ); }
  76.     // Position of Pixel
  77.     Point2D pos;
  78. };
  79.  
  80. class Character : public GraphElement
  81. {
  82. public:
  83.     // position of character
  84.     Point2D pos;
  85.     // character
  86.     char character;
  87.  
  88.     Character( Point2D t_pos, char t_char, RGB t_fg, RGB t_bg ) :
  89.       pos( t_pos ), character( t_char ), GraphElement( t_fg, t_bg ) {};
  90.  
  91.     void draw() {
  92.         for (int i = 0 ;i < height + 8; i++) {
  93.                 for(int j = 0;j < width; j++) {
  94.                     if (font[character][i] & (1 << j))
  95.                         drawPixel(j + pos.x, i + pos.y);
  96.                 }
  97.          }
  98.     }
  99.  
  100. };
  101.  
  102.  
  103.  
  104. int main() {
  105.     lcd_init();
  106.     lcd_clear();
  107.  
  108.     // Demo code
  109.     int l_color_red = 0xF800;
  110.     int l_color_green = 0x07E0;
  111.     int l_color_blue = 0x001F;
  112.     int l_color_white = 0xFFFF;
  113.  
  114.     //moje premenne
  115.     struct Point2D point;
  116.     point.x = 100;
  117.     point.y = 100;
  118.  
  119.     struct RGB fgColor;
  120.     fgColor.b = 0;
  121.     fgColor.g = 0;
  122.     fgColor.r = 255;
  123.  
  124.     struct RGB bgColor;
  125.     bgColor.b = 0;
  126.     bgColor.g = 0;
  127.     bgColor.r = 0;
  128.  
  129.     Character ch(point, 'Z', fgColor, bgColor);
  130.     ch.draw();
  131.  
  132.     point.x += 20;
  133.     Character ch2(point, 'd', fgColor, bgColor);
  134.     ch2.draw();
  135.  
  136.     point.x += 20;
  137.     Character ch3(point, 'e', fgColor, bgColor);
  138.     ch3.draw();
  139.  
  140.     point.x += 20;
  141.     Character ch4(point, 'n', fgColor, bgColor);
  142.     ch4.draw();
  143.  
  144.     point.x += 20;
  145.     Character ch5(point, 'k', fgColor, bgColor);
  146.     ch5.draw();
  147.  
  148.     point.x += 20;
  149.     Character ch6(point, 'a', fgColor, bgColor);
  150.     ch6.draw();
  151.  
  152.     point.x -= 60;
  153.     point.y += 30;
  154.     Character ch7(point, '2', fgColor, bgColor);
  155.     ch7.draw();
  156.  
  157.     point.x += 20;
  158.     Character ch8(point, 'b', fgColor, bgColor);
  159.     ch8.draw();
  160.  
  161.     while (1) {
  162.  
  163.     }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement