Control Surface  1.2.0
MIDI Control Surface library for Arduino
DisplayInterface.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <Def/Def.hpp>
5 #include <Print.h>
6 
8 
14 class DisplayInterface : public Print, public DoublyLinkable<DisplayInterface> {
15  protected:
19 
20  public:
23  // Note to self: don't forget to make destructor = default
24  // instead of deleting it altogether
25  virtual ~DisplayInterface() { elements.remove(this); }
26 
28  virtual void begin();
29 
31  virtual void clear() = 0;
33  virtual void drawBackground(){};
35  virtual void display() = 0;
36 
38  virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
39 
41  virtual void setTextColor(uint16_t color) = 0;
43  virtual void setTextSize(uint8_t size) = 0;
45  virtual void setCursor(int16_t x, int16_t y) = 0;
46 
54  size_t write(uint8_t c) override = 0;
55 
57  virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
58  uint16_t color) = 0;
60  virtual void drawFastVLine(int16_t x, int16_t y, int16_t h,
61  uint16_t color) = 0;
63  virtual void drawFastHLine(int16_t x, int16_t y, int16_t w,
64  uint16_t color) = 0;
65 
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 
71  virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
72  uint16_t color);
73 
75  virtual void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
76 
78  virtual void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
79 
82  static void beginAll();
83 
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 
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 
110  bool isEnabled() { return elements.couldContain(this); }
111 
118  clear();
119  drawBackground();
120  }
121 
122  private:
124 };
125 
DisplayInterface::display
virtual void display()=0
Write the frame buffer to the display.
DisplayInterface::isEnabled
bool isEnabled()
Check if this display is enabled.
Definition: DisplayInterface.hpp:110
DisplayInterface::elements
static DoublyLinkedList< DisplayInterface > elements
Definition: DisplayInterface.hpp:123
DisplayInterface::drawLine
virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)=0
Draw a line between two points.
DisplayInterface::clear
virtual void clear()=0
Clear the frame buffer or display.
DisplayInterface
An interface for displays.
Definition: DisplayInterface.hpp:14
DisplayInterface::beginAll
static void beginAll()
Initialize all displays.
Definition: DisplayInterface.cpp:61
DisplayInterface::~DisplayInterface
virtual ~DisplayInterface()
Definition: DisplayInterface.hpp:25
DisplayInterface::drawPixel
virtual void drawPixel(int16_t x, int16_t y, uint16_t color)=0
Paint a single pixel with the given color.
Def.hpp
DisplayInterface::write
size_t write(uint8_t c) override=0
Write a character to the display.
DisplayInterface::setCursor
virtual void setCursor(int16_t x, int16_t y)=0
Set the cursor position.
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
DoublyLinkedList::couldContain
bool couldContain(const Node *node) const
Check if the linked list could contain the given node.
Definition: LinkedList.hpp:281
DoublyLinkedList::append
void append(Node *node)
Append a node to a linked list.
Definition: LinkedList.hpp:115
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
LinkedList.hpp
DisplayInterface::enable
void enable()
Enable this display: insert it into the linked list of instances, so it gets updated automatically.
Definition: DisplayInterface.hpp:86
ERROR
#define ERROR(msg, errc)
Print the error message and error code, and stop the execution if FATAL_ERRORS are enabled.
Definition: Error.hpp:42
DisplayInterface::fillCircle
virtual void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draw a disk (filled circle).
Definition: DisplayInterface.cpp:42
DoublyLinkedList::remove
void remove(Node *node)
Remove a node from the linked list.
Definition: LinkedList.hpp:198
DisplayInterface::DisplayInterface
DisplayInterface()
Definition: DisplayInterface.hpp:18
DisplayInterface::drawFastVLine
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)=0
Draw a vertical line.
DisplayInterface::disable
void disable()
Disable this display: remove it from the linked list of instances, so it no longer gets updated autom...
Definition: DisplayInterface.hpp:96
DisplayInterface::drawXBitmap
virtual void drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)=0
Draw a bitmap to the display.
MIDI_Notes::F
constexpr int8_t F
Definition: Notes.hpp:23
DisplayInterface::setTextColor
virtual void setTextColor(uint16_t color)=0
Set the text color.
DoublyLinkedList< DisplayInterface >
DisplayInterface::begin
virtual void begin()
Initialize the display.
Definition: DisplayInterface.cpp:7
DisplayInterface::clearAndDrawBackground
void clearAndDrawBackground()
Clear the frame buffer, and draw the custom background.
Definition: DisplayInterface.hpp:117
DoublyLinkable
A class that can be inherited from to allow inserting into a DoublyLinkedList.
Definition: LinkedList.hpp:320
DisplayInterface::fillRect
virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draw a filled rectangle.
Definition: DisplayInterface.cpp:13
DisplayInterface::drawBackground
virtual void drawBackground()
Draw a custom background.
Definition: DisplayInterface.hpp:33
DisplayInterface::drawFastHLine
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)=0
Draw a horizontal line.
DisplayInterface::setTextSize
virtual void setTextSize(uint8_t size)=0
Set the text size.
DisplayInterface::drawCircle
virtual void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draw a circle.
Definition: DisplayInterface.cpp:19