Subversion Repositories libOLED

Rev

Rev 7 | Rev 10 | 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, /* and 0, invert 0 */
  21.   WHITE, /* and 0, invert 1 */
  22.   OVERLAY, /* and 1, invert 0 */
  23.   INVERT, /* and 1, invert 1 */
  24. };
  25.  
  26. class display_t
  27. {
  28. public:
  29.   display_t (int const width, int const height, int const ramwidth,
  30.              uint8_t *const data);
  31.  
  32.   virtual
  33.   ~display_t ();
  34.  
  35.   uint8_t
  36.   getRotation ();
  37.   int16_t
  38.   width ();
  39.   int16_t
  40.   height ();
  41.  
  42.   // common hardware reset .
  43.   void
  44.   reset ();
  45.  
  46.   void
  47.   init ();
  48.  
  49.   /// \brief Clear display to colour
  50.   void
  51.   clearDisplay (colour_t colour = colour_t::BLACK);
  52.   void
  53.   invertDisplay (uint8_t i);
  54.   void
  55.   display ();
  56.  
  57.   void
  58.   startscrollright (uint8_t start, uint8_t stop);
  59.   void
  60.   startscrollleft (uint8_t start, uint8_t stop);
  61.  
  62.   void
  63.   startscrolldiagright (uint8_t start, uint8_t stop);
  64.   void
  65.   startscrolldiagleft (uint8_t start, uint8_t stop);
  66.   void
  67.   stopscroll (void);
  68.  
  69.   void
  70.   dim (uint8_t contrast);
  71.  
  72.   // set drawing mode
  73.   void
  74.   setPixelMode (colour_t colour)
  75.   {
  76.     m_colour = colour;
  77.   }
  78.  
  79.   void
  80.   drawPixel (int16_t x, int16_t y, bool pixel);
  81.  
  82.   void
  83.   drawLine (int16_t x1, int16_t y1, int16_t x2, int16_t y2, colour_t color);
  84.  
  85.   void
  86.   drawRectangle (int16_t x1, int16_t y1, int16_t x2, int16_t y2,
  87.                  colour_t color);
  88.  
  89. // position cursor absolute
  90.   void
  91.   gotoxy (int x, int y)
  92.   {
  93.     m_cursor_x = x;
  94.     m_cursor_y = y;
  95.   }
  96.  
  97.   // position cursor relative
  98.   void
  99.   moveby (int x, int y)
  100.   {
  101.     m_cursor_x += x;
  102.     m_cursor_y += y;
  103.   }
  104.  
  105.   // pixel to pixel plotting
  106.   /// \param font The font to use
  107.   /// \param string The characters to plot
  108.   /// \param length The length of the string
  109.   /// \param colour
  110.   void
  111.   printString (font_t &font, char const *string, uint16_t length,
  112.                colour_t colour = WHITE);
  113.  
  114.   // scaled plotting
  115.   /// \param font The font to use
  116.   /// \param string The characters to plot
  117.   /// \param length The length of the string
  118.   /// \param scale The scale factor is 256/scale so 256 is 1:1, 128 is twice the size
  119.   /// \param colour
  120.   void
  121.   printScaledString (font_t &font, char const *string, uint16_t length,
  122.                      uint16_t scale, colour_t colour = WHITE);
  123.  
  124.   static const uint8_t NO_DECIMAL = 255;
  125.  
  126.   void
  127.   fontDigits (font_t &font, uint8_t digits, uint8_t dp_pos, int val,
  128.               colour_t colour = WHITE);
  129.  
  130.   void
  131.   fontSigDigits (font_t &font, uint8_t x, uint8_t y, bool right_justify,
  132.                  uint8_t dp_pos, int val, colour_t colour = WHITE);
  133.  
  134.   int
  135.   cursor_x ()
  136.   {
  137.     return m_cursor_x;
  138.   }
  139.   ;
  140.  
  141.   int
  142.   cursor_y ()
  143.   {
  144.     return m_cursor_y;
  145.   }
  146.   ;
  147.  
  148. private:
  149.  
  150.   // set=1 means send data set=0 means send control
  151.   virtual void
  152.   oledSetCD (uint8_t set) =0;
  153.  
  154.   virtual void
  155.   oledWrite (uint8_t d) =0;
  156.  
  157.   virtual void
  158.   oledReset () = 0;
  159.  
  160.   virtual void
  161.   oledWrite (uint8_t *buff, uint8_t len) = 0;
  162.  
  163.   uint8_t
  164.   formatNum (char *buff, uint8_t siz, uint8_t digits, uint8_t dp_pos, int val);
  165.  
  166.   int const m_width; // pixel width
  167.   int const m_height; // pixel height
  168.   int const m_ramwidth; // OLED controller ram pixel width
  169.  
  170.   int m_cursor_x;
  171.   int m_cursor_y;
  172.   int m_rotation;
  173.  
  174.   // currently selected colour mode
  175.   colour_t m_colour;
  176.  
  177.   uint8_t *const m_data;
  178.  
  179. };
  180.