// menu_oled.cpp // Affiche un menu sur LCD Oled 1306 // Affichage/Saisie depuis le menu et retourne le choix de l'utilisateur // Castoo // Décembre 2019 /* menu_oled.cpp - Objet destiné à être utilisé avec Arduino ou ESPxxx. Possibilité de supporter différents LCD mais l'objet a été créée avec un OLED SD1306 Possibilité de supporter différents Encodeurs rotatifs mais l'objet a été créée avec un KY-040 30 pas Création Jean Michel Castille décembre 2019 / castoo.fr Cette bibliothèque est un logiciel libre; Vous pouvez la redistribuer et ou la modifier. Cette bibliothèque est distribuée dans l'espoir qu'elle sera utile, mais SANS AUCUNE GARANTIE, sans même la garantie implicite de QUALITÉ MARCHANDE ou ADÉQUATION À UN USAGE PARTICULIER. */ #include "menu_oled.h" // Constructeur permet de passer les cnx du bouton de commande et le nom du LCD menu_oled::menu_oled(uint8_t vclk, uint8_t vdt, uint8_t vsw, SSD1306Wire &ecran){ this->PinCLK = vclk; pinMode (this->PinCLK, INPUT); // Clk du selecteur rotatif this->PinDT = vdt; pinMode (this->PinDT, INPUT); // DT du selecteur rotatif this->PinSW = vsw; pinMode (this->PinSW, INPUT); // SW du selecteur rotatif this->_ecran = &ecran; // Ecran OLED } // Initialisation du menu permet de passer le nb de choix et un tableau des chaines de choix uint8_t menu_oled::init(int nb_ch_menu, String &ch_menu){ this->_ecran->flipScreenVertically(); this->_ecran->setFont(ArialMT_Plain_10); this->_ecran->setTextAlignment(TEXT_ALIGN_LEFT); this->max_ch = nb_ch_menu; this->_ch_menu = &ch_menu; return this->sel_menu(this->max_ch); } // Affichage du menu et encadrement de la valeur en cours de selection void menu_oled::aff_menu(int pos){ this->_ecran->clear(); for (uint8_t i = 0; i < this->max_ch; i++) this->_ecran->drawString(0, (12*i), this->_ch_menu[i+1]); this->_ecran->drawRect(0, (12*pos), (this->_ch_menu[pos+1].length()*5)+2, 13); this->_ecran->display(); } // Selection dans le menu à l'aide du selecteur rotatif uint8_t menu_oled::sel_menu(int max){ max--; bool B_val = false, val_clk = true, memo_clk = true; int B_choix = 0; this->aff_menu(B_choix); while (! B_val){ val_clk = digitalRead(PinCLK); if (val_clk != memo_clk){ if (digitalRead(PinDT) != val_clk) { B_choix++; if (B_choix > max) B_choix = max;} else { B_choix--; if (B_choix < 0) B_choix = 0;} this->aff_menu(B_choix); delay(10); } if (!(digitalRead(PinSW))) { B_val = true; } // Bouton validation memo_clk = val_clk; delay(5); } this->aff_menu(B_choix); return B_choix; }