LCOV - code coverage report
Current view: top level - src/Display - DisplayInterface.hpp (source / functions) Hit Total Coverage
Test: e224b347cd670555e44f06608ac41bd1ace9d9d8 Lines: 0 7 0.0 %
Date: 2020-09-08 17:44:46 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <AH/Containers/LinkedList.hpp>
       4             : #include <Def/Def.hpp>
       5             : #include <Print.h>
       6             : 
       7             : BEGIN_CS_NAMESPACE
       8             : 
       9             : /**
      10             :  * @brief   An interface for displays. 
      11             :  * 
      12             :  * Inspired by the Adafruit GFX library for easy compatibility.
      13             :  */
      14             : class DisplayInterface : public Print, public DoublyLinkable<DisplayInterface> {
      15             :   protected:
      16             :     /// @todo   Do I need to keep a list now that I have sorted all
      17             :     ///         DisplayElement%s?
      18             :     DisplayInterface() { elements.append(this); }
      19             : 
      20             :   public:
      21             :     /// @todo   Do I need to keep a list now that I have sorted all
      22             :     ///         DisplayElement%s?
      23             :     // Note to self:    don't forget to make destructor = default
      24             :     //                  instead of deleting it altogether
      25           0 :     virtual ~DisplayInterface() { elements.remove(this); }
      26             : 
      27             :     /// Initialize the display.
      28             :     virtual void begin();
      29             : 
      30             :     /// Clear the frame buffer or display.
      31             :     virtual void clear() = 0;
      32             :     /// Draw a custom background.
      33           0 :     virtual void drawBackground(){};
      34             :     /// Write the frame buffer to the display.
      35             :     virtual void display() = 0;
      36             : 
      37             :     /// Paint a single pixel with the given color.
      38             :     virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
      39             : 
      40             :     /// Set the text color.
      41             :     virtual void setTextColor(uint16_t color) = 0;
      42             :     /// Set the text size.
      43             :     virtual void setTextSize(uint8_t size) = 0;
      44             :     /// Set the cursor position.
      45             :     virtual void setCursor(int16_t x, int16_t y) = 0;
      46             : 
      47             :     /**
      48             :      * @brief   Write a character to the display.
      49             :      * 
      50             :      * @see     setCursor
      51             :      * @see     setTextSize
      52             :      * @see     setTextColor
      53             :      */
      54             :     size_t write(uint8_t c) override = 0;
      55             : 
      56             :     /// Draw a line between two points.
      57             :     virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
      58             :                           uint16_t color) = 0;
      59             :     /// Draw a vertical line.
      60             :     virtual void drawFastVLine(int16_t x, int16_t y, int16_t h,
      61             :                                uint16_t color) = 0;
      62             :     /// Draw a horizontal line.
      63             :     virtual void drawFastHLine(int16_t x, int16_t y, int16_t w,
      64             :                                uint16_t color) = 0;
      65             : 
      66             :     /// Draw a bitmap to the display.
      67             :     virtual void drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
      68             :                              int16_t w, int16_t h, uint16_t color) = 0;
      69             : 
      70             :     /// Draw a filled rectangle.
      71             :     virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
      72             :                           uint16_t color);
      73             : 
      74             :     /// Draw a circle.
      75             :     virtual void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
      76             : 
      77             :     /// Draw a disk (filled circle).
      78             :     virtual void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
      79             : 
      80             :     /// Initialize all displays.
      81             :     /// @see    begin
      82             :     static void beginAll();
      83             : 
      84             :     /// Enable this display: insert it into the linked list of instances,
      85             :     /// so it gets updated automatically
      86             :     void enable() {
      87             :         if (isEnabled()) {
      88             :             ERROR(F("Error: This display is already enabled."), 0x1214);
      89             :             return;
      90             :         }
      91             :         elements.append(this);
      92             :     }
      93             : 
      94             :     /// Disable this display: remove it from the linked list of instances,
      95             :     /// so it no longer gets updated automatically
      96             :     void disable() {
      97             :         if (!isEnabled()) {
      98             :             ERROR(F("Error: This display is already disabled."), 0x1215);
      99             :             return;
     100             :         }
     101             :         elements.remove(this);
     102             :     }
     103             : 
     104             :     /**
     105             :      * @brief   Check if this display is enabled.
     106             :      * 
     107             :      * @note    Assumes that the display is not added to a different linked 
     108             :      *          list by the user.
     109             :      */
     110           0 :     bool isEnabled() { return elements.couldContain(this); }
     111             : 
     112             :     /**
     113             :      * @brief   Clear the frame buffer, and draw the custom background.
     114             :      * @see    clear
     115             :      * @see    drawBackground
     116             :      */
     117           0 :     void clearAndDrawBackground() {
     118           0 :         clear();
     119           0 :         drawBackground();
     120           0 :     }
     121             : 
     122             :   private:
     123             :     static DoublyLinkedList<DisplayInterface> elements;
     124             : };
     125             : 
     126             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-6-g40580cd