Browse Source

New explanatory commentaries added.

master
parent
commit
0b4359033a
1 changed files with 42 additions and 39 deletions
  1. +42
    -39
      DisplayESP32.ino

+ 42
- 39
DisplayESP32.ino View File

@ -13,13 +13,13 @@
#define MAX_OPTIONS 10 //Maximum number of options for each menu
#define MAX_MENUS 3
#define MAX_GRAPH 3
#define MAX_GRAPHS 3
#define DISP_WIDTH 128 // OLED display width
#define DISP_HEIGHT 64 // OLED display height
#define REFRESH 10 //Refresh time in ms
#define ADDRESS 0x3C //I2C address of the display
Adafruit_SSD1306 display(DISP_WIDTH, DISP_HEIGHT, &Wire, -1);
int i = 0;
class Option{
private:
@ -80,7 +80,7 @@ class Option{
}
};
class Menu{ //ContentTypeMenu true, it is a menu
class Menu{ //ContentType (1)
private:
int sizex; //X size for each option in the menu
@ -118,31 +118,34 @@ class Menu{ //ContentTypeMenu true, it is a menu
return destinationIndex;
}
//The following method draws the whole menu by drawing every option configured within it
void drawMenu(){
display.clearDisplay();
this->page = pos/this->optPPage;
this->page = pos/this->optPPage; //The current page is obtained by dividing the position by the number of options per page (only integer)
for(int i = 0; i < options; i++){
this->opt[i].drawopt(this->page, this->pos, this->optPPage);
}
display.display();
}
int extractPos(){
//Methods used by Screen
int extractPos(){ //Gets the current position of the cursor
return(this->pos);
}
int extractOptNumber(){
int extractOptNumber(){ //Gets the number of options in the menu
return(this->options);
}
void increasePos(){
void increasePos(){ //Increases the position of the cursor
this->pos++;
}
void decreasePos(){
void decreasePos(){ //Decreases the position of the cursor
this->pos--;
}
//Both of the following methods store the values of the previous screen passed as parameters by Screen
void setPreviousScreen(int prev){
this->previousScreen = prev;
}
@ -151,6 +154,7 @@ class Menu{ //ContentTypeMenu true, it is a menu
this->previousContentType = prev;
}
//Both of the following methods retrieve the values of the screen previous to the menu containing these data.
int getPreviousScreen(){
int prev = this->previousScreen;
return prev;
@ -162,7 +166,7 @@ class Menu{ //ContentTypeMenu true, it is a menu
}
};
class Graph{ //ContentTypeMenu false, it is not a menu
class Graph{
private:
String title;
@ -181,7 +185,7 @@ class Graph{ //ContentTypeMenu false, it is not a menu
double xmaximum; //For: Horizontal Bar Cartesian
double yStepSize; //For: Vertical Bar Cartesian
double xStepSize; //For: Horizontal Bar Cartesian
double digit; //For: Vertical Bar Horizontal Bar Cartesian
int digit; //For: Vertical Bar Horizontal Bar Cartesian
double x;
double yrange;
double xrange;
@ -196,8 +200,9 @@ class Graph{ //ContentTypeMenu false, it is not a menu
public:
//This method configures the graph created, defines its parameters according the type of graph selected.
void configure(String title, char graphType, double xpos, double ypos, double width, double height,
double yminimum, double ymaximum, double xminimum, double xmaximum, double yStepSize, double xStepSize, double digit){
double yminimum, double ymaximum, double xminimum, double xmaximum, double yStepSize, double xStepSize, int digit){
this->title = title;
this->graphType = graphType;
this->yminimum = yminimum;
@ -236,7 +241,7 @@ class Graph{ //ContentTypeMenu false, it is not a menu
case 'a':
double my;
if (this->redraw) {
if (this->redraw) { //Prints the labels
display.clearDisplay();
this->redraw = false;
display.fillRect(0, 0, 127 , 14, SSD1306_WHITE);
@ -374,7 +379,7 @@ class Graph{ //ContentTypeMenu false, it is not a menu
}
}
void redrawFlag(){
void redrawFlag(){ // Activates the redraw bool to get the graph printed correctly
this->redraw = true;
}
@ -410,21 +415,22 @@ class Graph{ //ContentTypeMenu false, it is not a menu
class Screen{
private:
Menu menu[MAX_MENUS];
Graph graph[MAX_GRAPH];
int counterM = 0;
int counterG = 0;
bool redraw = true;
Menu menu[MAX_MENUS]; //Array of menus to use
Graph graph[MAX_GRAPHS]; //Array of graphs to use
int counterM = 0; //Number of menus created
int counterG = 0; //Number of graphs created
bool redraw = true; //Redraw interface for when there is a change of screen
int currentScreen = 0;
int contentType = 0;
public:
void configure(bool fullsetting){
void configure(bool fullsetting){ //This method allows the configuration of the display when the parameter is true. Otherwise only prints a greeting message.
if(fullsetting){
//Adafruit_SSD1306 display(DISP_WIDTH, DISP_HEIGHT, &Wire, -1);
Serial.begin(115200);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
if (!display.begin(SSD1306_SWITCHCAPVCC, ADDRESS)) {
#ifdef __DEBUG__
Serial.println("Display not found!");
#endif
@ -449,29 +455,29 @@ class Screen{
delay(5000);
}
void createMenu(int sizex, int sizey){
void createMenu(int sizex, int sizey){ //This method is used for the creation of a menu
this->menu[counterM].configure(sizex, sizey);
this->counterM++;
}
void createOption(int menuIndex, String content, bool destinationTypeMenu, int destinationIndex){
void createOption(int menuIndex, String content, bool destinationTypeMenu, int destinationIndex){ //this method should be used for creating an option in a menu
this->menu[menuIndex].createOption(content, destinationTypeMenu, destinationIndex);
}
void createVGraph(String title, double xpos, double ypos, double width, double height,
double yminimum, double ymaximum, double yStepSize, double digit){
double yminimum, double ymaximum, double yStepSize, int digit){ //this method calls the configure() of graph for a vertical graph
this->graph[counterG].configure(title, 'a', xpos, ypos, width, height, yminimum, ymaximum, 0, 0, yStepSize, 0, digit);
this->counterG++;
}
void createHGraph(String title, double xpos, double ypos, double width, double height,
double xminimum, double xmaximum, double xStepSize, double digit){
double xminimum, double xmaximum, double xStepSize, int digit){ //this method calls the configure() of graph for a horizontal graph
this->graph[counterG].configure(title, 'b', xpos, ypos, width, height, 0, 0, xminimum, xmaximum, 0, xStepSize, digit);
counterG++;
}
void createCGraph(String title, double xpos, double ypos, double width, double height,
double yminimum, double ymaximum, double xminimum, double xmaximum, double yStepSize, double xStepSize, double digit){
double yminimum, double ymaximum, double xminimum, double xmaximum, double yStepSize, double xStepSize, int digit){ //this method calls the configure() of graph for a cartesian chart
this->graph[counterG].configure(title, 'c', xpos, ypos, width, height, yminimum, ymaximum, xminimum, xmaximum, yStepSize, xStepSize, digit);
counterG++;
}
@ -482,11 +488,13 @@ class Screen{
}
*/
//The following method is used for assingning a value to a graph
void graphAssignValue(int graphIndex, double value){
this->graph[graphIndex].assignValue(value);
this->redraw = true;
}
//This method controls the whole interface, it needs to be called within a loop
void control(){
if (redraw){
if (contentType == 0){
@ -499,6 +507,7 @@ class Screen{
}
}
//The following two methods allow the change in position of the cursor
void increasePos(){
if(this->menu[this->currentScreen].extractPos() < this->menu[this->currentScreen].extractOptNumber() - 1)
this->menu[this->currentScreen].increasePos();
@ -509,6 +518,7 @@ class Screen{
this->menu[this->currentScreen].decreasePos();
}
//This method lets the user go into another screen by selecting an option
void goTo(){
if(this->contentType == 0){
int newScreen = this->menu[this->currentScreen].extractDestinationIndex();
@ -545,6 +555,7 @@ class Screen{
}
}
//These methods control the plus and minus button actions
void plusAction(){
if(contentType == 0){
increasePos();
@ -572,6 +583,7 @@ class Keyboard{
public:
//Keyboard constructor
Keyboard(byte goTo, byte goBack, byte plus, byte minus, byte debounceTime, Screen * screen){
this->goTo = goTo;
this->goBack = goBack;
@ -586,7 +598,7 @@ class Keyboard{
pinMode(plus, INPUT_PULLUP);
pinMode(minus, INPUT_PULLUP);
}
//Debouncing functions
void checkGoTo(){
static char cont;
if(digitalRead(this->goTo) == LOW)
@ -594,10 +606,7 @@ class Keyboard{
else
cont = 0;
if(cont == debounceTime/REFRESH){
cont = 0;
this->screen->goTo();
while(digitalRead(this->goTo) == LOW){
}
}
}
@ -609,10 +618,7 @@ class Keyboard{
else
cont = 0;
if(cont == debounceTime/REFRESH){
cont = 0;
this->screen->goBack();
while(digitalRead(this->goBack) == LOW){
}
}
}
@ -623,10 +629,7 @@ class Keyboard{
else
cont = 0;
if(cont == debounceTime/REFRESH){
cont = 0;
this->screen->plusAction();
while(digitalRead(this->plus) == LOW){
}
}
}
@ -637,13 +640,11 @@ class Keyboard{
else
cont = 0;
if(cont == debounceTime/REFRESH){
cont = 0;
this->screen->minusAction();
while(digitalRead(this->minus) == LOW){
}
}
}
// All buttons are checked with this method
void control(){
this->checkGoTo();
this->checkGoBack();
@ -652,6 +653,8 @@ class Keyboard{
}
};
int i = 0;
Screen screen;
Keyboard keyboard(13, 12, 14, 27, 30, &screen);


Loading…
Cancel
Save