Subversion Repositories libOLED

Rev

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