Subversion Repositories libOLED

Rev

Rev 4 | Rev 6 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * displayclass.H
  3.  *
  4.  *  Created on: 31 Oct 2020
  5.  *      Author: mike
  6.  */
  7.  
  8. #pragma once
  9. #include <cstdint>
  10. #include "libOLED/fontclass.H"
  11.  
  12. inline int constexpr
  13. dataSize (int const width, int const height)
  14. {
  15.   return (width * height / 8);
  16. }
  17.  
  18. enum colour_t
  19. {
  20.   BLACK, WHITE, INVERT
  21. };
  22.  
  23. class display_t
  24. {
  25. public:
  26.   display_t (int const width, int const height, int const ramwidth,
  27.              uint8_t *const data);
  28.  
  29.   virtual
  30.   ~display_t ();
  31.  
  32.   uint8_t
  33.   getRotation ();
  34.   int16_t
  35.   width ();
  36.   int16_t
  37.   height ();
  38.  
  39.   void
  40.   init ();
  41.  
  42.   void
  43.   clearDisplay ();
  44.   void
  45.   invertDisplay (uint8_t i);
  46.   void
  47.   display ();
  48.  
  49.   void
  50.   startscrollright (uint8_t start, uint8_t stop);
  51.   void
  52.   startscrollleft (uint8_t start, uint8_t stop);
  53.  
  54.   void
  55.   startscrolldiagright (uint8_t start, uint8_t stop);
  56.   void
  57.   startscrolldiagleft (uint8_t start, uint8_t stop);
  58.   void
  59.   stopscroll (void);
  60.  
  61.   void
  62.   dim (uint8_t contrast);
  63.  
  64.   void
  65.   drawPixel (int16_t x, int16_t y, colour_t color);
  66.  
  67.   void
  68.   drawLine (int16_t x1, int16_t y1, int16_t x2, int16_t y2, colour_t color);
  69.  
  70.   void
  71.   gotoxy (int x, int y)
  72.   {
  73.     m_cursor_x = x;
  74.     m_cursor_y = y;
  75.   }
  76.   ;
  77.  
  78.   // pixel to pixel plotting
  79.   /// \param font The font to use
  80.   /// \param string The characters to plot
  81.   /// \param length The length of the string
  82.   /// \param colour
  83.   void
  84.   printString (font_t &font, char const *string, uint16_t length,
  85.                colour_t colour);
  86.  
  87.   // scaled plotting
  88.   /// \param font The font to use
  89.   /// \param string The characters to plot
  90.   /// \param length The length of the string
  91.   /// \param scale The scale factor is 256/scale so 256 is 1:1, 128 is twice the size
  92.   /// \param colour
  93.   void
  94.   printScaledString (font_t &font, char const *string,
  95.                                   uint16_t length, uint16_t scale,
  96.                                   colour_t colour);
  97.  
  98.   void
  99.   fontDigits (font_t &font, uint8_t digits, uint8_t dp_pos, int val);
  100.  
  101.   void
  102.   fontSigDigits (font_t &font,uint8_t x, uint8_t y, bool right_justify, uint8_t dp_pos,
  103.                  int val);
  104.  
  105.   int
  106.   cursor_x ()
  107.   {
  108.     return m_cursor_x;
  109.   }
  110.   ;
  111.  
  112.   int
  113.   cursor_y ()
  114.   {
  115.     return m_cursor_y;
  116.   }
  117.   ;
  118.  
  119. private:
  120.  
  121.   // set=1 means send data set=0 means send control
  122.   virtual void
  123.   oledSetCD (uint8_t set) =0;
  124.  
  125.   virtual void
  126.   oledWrite (uint8_t d) =0;
  127.  
  128.   virtual void
  129.   oledReset () = 0;
  130.  
  131.   virtual void
  132.   oledWrite (uint8_t *buff, uint8_t len) = 0;
  133.  
  134.  
  135.   uint8_t formatNum (char *buff, uint8_t siz, uint8_t digits, uint8_t dp_pos, int val);
  136.  
  137.  
  138.   int const m_width; // pixel width
  139.   int const m_height; // pixel height
  140.   int const m_ramwidth; // OLED controller ram pixel width
  141.  
  142.   int m_cursor_x;
  143.   int m_cursor_y;
  144.   int m_rotation;
  145.  
  146.   uint8_t *const m_data;
  147.  
  148. };
  149.