#define MAX_OPTIONS 10 //Maximum number of options for each menu #define MAX_MENUS 10 #define MAX_GRAPH 10 #define __DEBUG__ #include #include #include #include #include #include #define DISP_WIDTH 128 // OLED display width #define DISP_HEIGHT 64 // OLED display height Adafruit_SSD1306 display(DISP_WIDTH, DISP_HEIGHT, &Wire, -1); void setDisp(bool fullsetting){ if(fullsetting){ //Adafruit_SSD1306 display(DISP_WIDTH, DISP_HEIGHT, &Wire, -1); Serial.begin(115200); if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { #ifdef __DEBUG__ Serial.println("No se encuentra la pantalla OLED"); #endif while (true); } } display.clearDisplay(); // Tamaño del texto display.setTextSize(2); // Color del texto display.setTextColor(SSD1306_WHITE); // Posición del texto display.setCursor(0, 16); // Escribir texto display.println("Hola"); display.display(); display.setCursor(0, 32); display.println("mundo!!"); display.display(); } class Option{ private: int sizex; int sizey; String content; int pos; bool fill = false; bool disp = false; void (*f)(void); public: //Option(){} void configure(String content, int sizex, int sizey, int pos){ this->sizex = sizex; this->sizey = sizey; this->content = content; this->pos = pos; this->disp = true; } void drawopt(int page, int pos){ if(this->disp){ if(this->pos == pos){ display.fillRect(0, (this->sizey)*(this->pos) - (page*DISP_WIDTH), this->sizex, this->sizey, WHITE); display.setTextColor(SSD1306_BLACK); display.setCursor((this->sizex) + 3, (this->sizey) - 3); display.println(this->content); display.setTextColor(SSD1306_WHITE); } else{ display.drawRect(0, (this->sizey)*(this->pos), this->sizex, this->sizey, WHITE); display.setCursor((this->sizex) + 3, (this->sizey) - 3 - (DISP_WIDTH*128)); display.println(this->content); } } } void task(void (*f)(void)){ this->f = f; } }; class Menu{ private: int id; int sizex; int sizey; int options = 0; //This indicates the number of options created int pos = 0; //This indicates the position of the cursor int page = 0; //If the menu is too long, this indicates the page that is being displayed Option opt[MAX_OPTIONS]; public: void configure(int id, int sizex, int sizey){ this->id = id; this->sizex = sizex; this->sizey = sizey; } void createOption(String content){ this->opt[this->options].configure(content, this->sizex, this->sizey, this->options++); } void function(int optionindex, void (*f)(void)){ //Defines functions for each option this->opt[optionindex].task(f); } void drawMenu(){ int dir; this->page = pos/3; for(int i = 0; i < options; i++){ this->opt[i].drawopt(this->page, this->pos); } } int getid(){ int id = this->id; return id; } int getoptions(){ int options = this->options; return options; } void increasePos(){ this->pos++; } void decreasePos(){ this->pos--; } }; class Screen{ private: Menu menu[MAX_MENUS]; int ids[MAX_MENUS]; int counter = 0; int actualScreen; public: void createMenu(int id, int sizex, int sizey){ this->menu[counter].configure(id, sizex, sizey); counter++; } void createOption(int idMenu, String content){ int mem = 0; for(int i = 0; i < counter; i++){ if(this->ids[i] == idMenu) mem = i; break; } this->menu[mem].createOption(content); } void control(){ } }; void setup(){ } void loop(){ }