From 71779e2b4366f4657cf329d532e831bec8547d77 Mon Sep 17 00:00:00 2001 From: aquazx20 Date: Tue, 25 Apr 2023 22:23:31 -0600 Subject: [PATCH] New class added for variable manipulation. --- DisplayESP32.ino | 79 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/DisplayESP32.ino b/DisplayESP32.ino index e9616ab..2af55b3 100644 --- a/DisplayESP32.ino +++ b/DisplayESP32.ino @@ -14,6 +14,7 @@ #define MAX_OPTIONS 10 //Maximum number of options for each menu #define MAX_MENUS 3 #define MAX_GRAPHS 3 +#define MAX_MODIFIERS 3 #define DISP_WIDTH 128 // OLED display width #define DISP_HEIGHT 64 // OLED display height #define REFRESH 10 //Refresh time in ms @@ -80,7 +81,7 @@ class Option{ } }; -class Menu{ //ContentType (1) +class Menu{ //ContentType (0) private: int sizex; //X size for each option in the menu @@ -166,7 +167,7 @@ class Menu{ //ContentType (1) } }; -class Graph{ +class Graph{ //ContentType (1) private: String title; @@ -411,14 +412,82 @@ class Graph{ }; +class Modifier{ //ContentType (2) + private: + + String title; + int *value; + int max; + int min; + int interval; + + int previousScreen = 0; + int previousContentType = 0; + + public: + + void configure(String title, int *value, int max, int min, int interval){ + this->value = value; + this->max = max; + this->min = min; + this->interval = interval; + } + + void drawModifier(){ + display.clearDisplay(); + display.fillRect(0, 0, 127 , 16, SSD1306_WHITE); + display.setTextColor(SSD1306_BLACK); + display.setTextSize(1); + display.setCursor(2, 4); + display.println(this->title); + + display.setTextColor(SSD1306_WHITE); + display.setTextSize(3); + display.setCursor(2, ((DISP_HEIGHT - 16 - 20)/2) + 20); + display.println(*this->value); + } + + void increaseValue(){ + if((*this->value + interval) <= this->max){ + *this->value += interval; + } + } + + void decreaseValue(){ + if((*this->value - interval) >= this->min){ + *this->value -= interval; + } + } + + void setPreviousScreen(int prev){ + this->previousScreen = prev; + } + + void setPreviousContentType(int prev){ + this->previousContentType = prev; + } + + int getPreviousScreen(){ + int prev = this->previousScreen; + return prev; + } + + int getPreviousContentType(){ + int prev = this->previousContentType; + return prev; + } +}; class Screen{ private: Menu menu[MAX_MENUS]; //Array of menus to use Graph graph[MAX_GRAPHS]; //Array of graphs to use + Modifier modifier[MAX_MODIFIERS]; //Array of modifiers to use + int counterM = 0; //Number of menus created int counterG = 0; //Number of graphs created + int counterMod = 0; bool redraw = true; //Redraw interface for when there is a change of screen int currentScreen = 0; int contentType = 0; @@ -482,6 +551,11 @@ class Screen{ counterG++; } + void createModifier(String title, int *value, int max, int min, int interval){ //This method is used for the creation of a menu + this->modifier[counterMod].configure(title, value, max, min, interval); + this->counterMod++; + } + /* void redrawFlag(){ this->redraw = true; @@ -489,6 +563,7 @@ class Screen{ */ //The following method is used for assingning a value to a graph +//This can be avoided using pointers to the variable to plot in the graph void graphAssignValue(int graphIndex, double value){ this->graph[graphIndex].assignValue(value); this->redraw = true;