Subversion Repositories libOLED

Rev

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 dataSize(int const width, int const height)
  13. {
  14.   return (width * height / 8);
  15. }
  16.  
  17. enum colour_t
  18. {
  19.   BLACK,   /* and 0, invert 0 */
  20.   WHITE,   /* and 0, invert 1 */
  21.   OVERLAY, /* and 1, invert 0 */
  22.   INVERT,  /* and 1, invert 1 */
  23. };
  24.  
  25. class display_t
  26. {
  27. public:
  28.   display_t(int const width, int const height, int const ramwidth,
  29.             uint8_t *const data);
  30.  
  31.   virtual ~display_t();
  32.  
  33.   /// \brief get the current rotation of the display
  34.   uint8_t
  35.   getRotation();
  36.  
  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 = WHITE, int8_t pattern = 1);
  84.  
  85.   void
  86.   drawRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2,
  87.                 colour_t color=WHITE);
  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.   /// \brief Display signed integer value with expected field width, and optional
  127.   /// decimal point position
  128.   /// \param font Reference to font in use
  129.   /// \param digits Number of digits to display (not including decimal point)
  130.   /// \param dp_pos If less than 10, attempt to place decimal point in given position.
  131.   /// set to > 10 to not try to display decimal point
  132.   /// \param val value to display
  133.   /// \param colour Drawing colour for font.
  134.   void
  135.   fontDigits(font_t &font, uint8_t digits, uint8_t dp_pos, int val,
  136.              colour_t colour = WHITE);
  137.  
  138.   /// \brief Calculate the length of the numeric string, and display it justified or padded
  139.   /// \return The formatted width : returned as signed so calculations which have negative results
  140.   ///  can be performed using width without type casting.
  141.   int8_t
  142.   fontSigDigits(font_t &font, uint8_t x, uint8_t y, bool right_justify,
  143.                 uint8_t dp_pos, int val, colour_t colour = WHITE);
  144.  
  145.   int cursor_x()
  146.   {
  147.     return m_cursor_x;
  148.   };
  149.  
  150.   int cursor_y()
  151.   {
  152.     return m_cursor_y;
  153.   };
  154.  
  155. private:
  156.   // set=1 means send data set=0 means send control
  157.   virtual void
  158.   oledSetCD(uint8_t set) = 0;
  159.  
  160.   virtual void
  161.   oledWrite(uint8_t d) = 0;
  162.  
  163.   virtual void
  164.   oledReset() = 0;
  165.  
  166.   virtual void
  167.   oledWrite(uint8_t *buff, uint8_t len) = 0;
  168.  
  169.   uint8_t
  170.   formatNum(char *buff, uint8_t siz, uint8_t digits, uint8_t dp_pos, int val);
  171.  
  172.   int const m_width;    // pixel width
  173.   int const m_height;   // pixel height
  174.   int const m_ramwidth; // OLED controller ram pixel width
  175.  
  176.   int m_cursor_x;
  177.   int m_cursor_y;
  178.   int m_rotation;
  179.  
  180.   // currently selected colour mode
  181.   colour_t m_colour;
  182.  
  183.   uint8_t *const m_data;
  184. };
  185.