From a94bf33ee6ead56ad970f6a359612c00a74fe32f Mon Sep 17 00:00:00 2001 From: aquazx20 Date: Tue, 4 Apr 2023 21:54:44 -0600 Subject: [PATCH] Documentation expanded --- DisplayESP32.ino | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/DisplayESP32.ino b/DisplayESP32.ino index 7493f96..a95fd84 100644 --- a/DisplayESP32.ino +++ b/DisplayESP32.ino @@ -4,6 +4,13 @@ #include #define __DEBUG__ +//The following constants are used to configure the behaviour of the interface +// MAX_OPTIONS defines the maximum number of options a menu can hold +// MAX_MENUS declares the maximum number of menu screens in the interface +// MAX_GRAPHS is the maximum number of graphs to create +// DISP_WIDTH and DISP_HEIGHT are hardware specific (SSD1306) +// REFRESH: is the time in miliseconds the interface will take in refreshing (this time affects the loop, keep that in mind) + #define MAX_OPTIONS 10 //Maximum number of options for each menu #define MAX_MENUS 3 #define MAX_GRAPH 3 @@ -17,20 +24,21 @@ int i = 0; class Option{ private: - int sizex; - int sizey; - String content; - int pos; - int textSpacing; - bool fill = false; - bool disp = false; - int destinationType; - int destinationIndex; + int sizex; //Defines the size it will occupy in the x axis (width), this value is gotten from the menu + int sizey; //Defines the height of the option (this value is gotten from the menu it belongs to) + String content; //Text of the option + int pos; //Defines the position it has in the menu + int textSpacing; //According to the height, defines the space for the text, so that it's vertically centered + bool fill = false; //In case an option is not selected this should be false + bool disp = false; //In case an option is not configured, it should be false and, thus hidden + int destinationType; //Defines what the option leads to (another menu, graph, something else) + int destinationIndex; //Defines where the option leads to (index of the destination) public: //Option(){} + //Method to configure an option, all attributes are assigned, and disp is true, so the option can be displayed void configure(String content, int sizex, int sizey, int pos, int destinationType, int destinationIndex){ this->sizex = sizex; this->sizey = sizey; @@ -52,16 +60,18 @@ class Option{ return destinationIndex; } +//This method draws each option + void drawopt(int page, int pos, int optPPage){ - if(this->disp){ - if(this->pos == pos){ + if(this->disp){ //Checks if the option was configured and, as a result, is displayable + if(this->pos == pos){ //If the position of the option corresponds to the position passed to the function, then it should be selected display.fillRect(0, (this->sizey)*(this->pos) + 1 - (page*optPPage*this->sizey), this->sizex, this->sizey, WHITE); display.setTextColor(SSD1306_BLACK); display.setCursor(5, (this->sizey)*(this->pos + 1) - (page*optPPage*this->sizey) - this->textSpacing); display.print(this->content); display.setTextColor(SSD1306_WHITE); } - else{ + else{ //If the option is not selected, the rectangle containing it shouldn't be filled display.drawRect(0, (this->sizey)*(this->pos) + 1 - (page*optPPage*this->sizey), this->sizex, this->sizey, WHITE); display.setCursor(5, (this->sizey)*(this->pos + 1) - (page*optPPage*this->sizey) - this->textSpacing); display.print(this->content); @@ -73,7 +83,7 @@ class Option{ class Menu{ //ContentTypeMenu true, it is a menu private: - int sizex; + int sizex; //X size for each option in the menu int sizey; //Y size of each option in the menu int options = 0; //This indicates the number of options created int pos = 0; //This indicates the position of the cursor @@ -86,13 +96,15 @@ class Menu{ //ContentTypeMenu true, it is a menu public: - void configure(int sizex, int sizey){ + void configure(int sizex, int sizey){ //This method configures the menu created from Screen this->sizex = sizex; this->sizey = sizey; this->optPPage = DISP_HEIGHT / this->sizey; } + //The following method is used to created an option for the menu void createOption(String content, bool destinationTypeMenu, int destinationIndex){ + //The option takes the place in the array defined by the options number variable (options), which is later increased. this->opt[this->options].configure(content, this->sizex, this->sizey, this->options++, destinationTypeMenu, destinationIndex); }