Advertisement
Guest User

Char

a guest
Oct 10th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.52 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. //extern uint16_t font12x20_lsb[256][20];
  24.  
  25. #define height 12
  26. #define width 20
  27. //#define printableFont font12x20_lsb
  28. //#define printableFont g_font8x8
  29.  
  30. struct Point2D
  31. {
  32.     int32_t x, y;
  33. };
  34.  
  35. struct RGB
  36. {
  37.     uint8_t r, g, b;
  38.  
  39.     //RGB(uint8_t r,uint8_t g,uint8_t b) : r(r), g(g), b(b){}
  40.  
  41. };
  42.  
  43. class GraphElement
  44. {
  45. public:
  46.     // foreground and background color
  47.     RGB fg_color, bg_color;
  48.  
  49.     // constructor
  50.     GraphElement( RGB t_fg_color, RGB t_bg_color ) :
  51.         fg_color( t_fg_color ), bg_color( t_bg_color ) {}
  52.  
  53.     // ONLY ONE INTERFACE WITH LCD HARDWARE!!!
  54.     void drawPixel( int32_t t_x, int32_t t_y ) { lcd_put_pixel( t_x, t_y, convert_RGB888_to_RGB565( fg_color ) ); }
  55.  
  56.     // Draw graphics element
  57.     virtual void draw() = 0;
  58.  
  59.     // Hide graphics element
  60.     virtual void hide() { swap_fg_bg_color(); draw(); swap_fg_bg_color(); }
  61.     void setColor(RGB c){ fg_color = c;}
  62. private:
  63.     // swap foreground and backgroud colors
  64.     void swap_fg_bg_color() { RGB l_tmp = fg_color; fg_color = bg_color; bg_color = l_tmp; }
  65.  
  66.     // conversion of 24-bit RGB color into 16-bit color format
  67.     int convert_RGB888_to_RGB565( RGB t_color ) {
  68.         int red = (t_color.r >> 3) << 11;
  69.         int green = (t_color.g >> 2) << 5;
  70.         int blue = t_color.b >> 3;
  71.         return red | green | blue;
  72.     }
  73. };
  74.  
  75. class Pixel : public GraphElement
  76. {
  77. public:
  78.     // constructor
  79.     Pixel( Point2D t_pos, RGB t_fg_color, RGB t_bg_color ) : pos( t_pos ), GraphElement( t_fg_color, t_bg_color ) {}
  80.     // Draw method implementation
  81.     virtual void draw() { drawPixel( pos.x, pos.y ); }
  82.     void delCurrent(){lcd_put_pixel(pos.x, pos.y, 0x0);}
  83.     void setPos(int x, int y){pos.x = x; pos.y = y;}
  84.     // Position of Pixel
  85.     Point2D pos;
  86. };
  87.  
  88. class Character : public GraphElement
  89. {
  90. public:
  91.     // position of character
  92.     Point2D pos;
  93.     // character
  94.     char character;
  95.  
  96.     Character( Point2D t_pos, char t_char, RGB t_fg, RGB t_bg ) :
  97.       pos( t_pos ), character( t_char ), GraphElement( t_fg, t_bg ) {};
  98.  
  99.     void draw() {
  100.         for (int i = 0 ;i < height; i++) {
  101.                 for(int j = 0;j < width; j++) {
  102.                     if (font[character][i] & (1 << j))
  103.                         drawPixel(j + pos.x, i + pos.y);
  104.                 }
  105.          }
  106.     }
  107.  
  108. };
  109.  
  110. int main() {
  111.     lcd_init();
  112.     lcd_clear();
  113.  
  114.     // Demo code
  115.     int l_color_red = 0xF800;
  116.     int l_color_green = 0x07E0;
  117.     int l_color_blue = 0x001F;
  118.     int l_color_white = 0xFFFF;
  119.  
  120.     //moje premenne
  121.     struct Point2D point;
  122.     point.x = 100;
  123.     point.y = 100;
  124.  
  125.     struct RGB fgColor;
  126.     fgColor.b = 0;
  127.     fgColor.g = 0;
  128.     fgColor.r = 255;
  129.  
  130.     struct RGB bgColor;
  131.     bgColor.b = 0;
  132.     bgColor.g = 0;
  133.     bgColor.r = 0;
  134.  
  135.     Character ch(point, 'M', fgColor, bgColor);
  136.     ch.draw();
  137.     while (1) {
  138.  
  139.     }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement