// sai_oled.cpp // Saisie de texte sur LCD Oled 1306 // Affichage/Saisie depuis trois écrans de caractères majuscule/minuscule/numérique ou spéciaux // Castoo // Décembre 2019 /* sai_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 "sai_oled.h" // Constructeur / Initialisation sai_oled::sai_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 this->sortieH = true; // Autorise la sortie du balayage des caracteres par le début } // Initialisation de l'écran void sai_oled::init(void){ this->_ecran->flipScreenVertically(); this->_ecran->setFont(ArialMT_Plain_10); this->_ecran->setTextAlignment(TEXT_ALIGN_LEFT); this->ch_saisie = ""; } // valide ou invalide la sortie du balayage des caracteres aprés chaque saisie void sai_oled::sortie_deb(bool val){ this->sortieH = val; } // Affichage du menu Alpha String sai_oled::aff_menu_Alpha(void){ this->val_ch = 2; while (this->val_ch > 1){ this->sel_menu_Alpha(nb_ch_menu_Alpha); } if (this->val_ch == 1) return this->ch_saisie; else return ""; } // Affichage menu de selection de fonction du menu alpha void sai_oled::aff_menu_alpha_maitre(uint8_t pos){ for (uint8_t i = 0; i < nb_ch_menu_Valid; i++) this->_ecran->drawString(105, (12*i), this->ch_menuAlpha[i]); this->_ecran->drawRect(103, (12*pos), 22, 13); if(this->flech_d){ this->_ecran->drawString(85, 12, "<<");this->_ecran->drawString(85, 24, "<<");} else { this->_ecran->drawString(85, 12, ">>");this->_ecran->drawString(85, 24, ">>");} } // Affichage menu de selection de fonction du menu alpha void sai_oled::aff_menu_alpha_string(){ this->_ecran->setFont(ArialMT_Plain_16); this->_ecran->drawString(0,48, this->ch_saisie); this->_ecran->setFont(ArialMT_Plain_10); } // Un caractere a été selectionné on met à jour la chaine de saisie void sai_oled::maj_ch(uint8_t pos, uint8_t menu){ uint8_t car = 0; switch (menu){ case 0 : car = pos + 64; break; case 1 : car = pos + 95; break; case 2 : car = pos + 32; break; case 3 : switch(pos){ case 0 : // Correction this->ch_saisie.remove((this->ch_saisie.length())-1); break; case 1 : // Tout effacer this->ch_saisie = ""; break; case 2 : // Validation this->val_ch = 1; break; case 3 : // Annulation this->val_ch = 0; break; } break; } if(menu < 3){ char ch_car = car; this->ch_saisie = this->ch_saisie + ch_car; } } // Affichage du menu Alpha Maj. void sai_oled::aff_menu_Alpha_Maj(uint8_t pos, bool en_cours){ char ch_i[2]; uint8_t vx; uint8_t vy; for (uint8_t i = 64; i < 92; i++){ snprintf(ch_i, 2, "%c", i); vy = (12 * ((i - 64) % 4)); vx = ((i - 64) / 4) * 10; this->_ecran->drawString(vx, vy, ch_i ); } if (en_cours) { vy = (12 * (pos % 4)); vx = (pos / 4) * 10; this->_ecran->drawRect(vx, vy, 10, 13); } } // Affichage du menu Alpha Min. void sai_oled::aff_menu_Alpha_Min(uint8_t pos, bool en_cours){ char ch_i[2]; uint8_t vx; uint8_t vy; for (uint8_t i = 95; i < 127; i++){ snprintf(ch_i, 2, "%c", i); vy = (12 * ((i - 95) % 4)); vx = ((i - 95) / 4) * 10; this->_ecran->drawString(vx, vy, ch_i ); } if (en_cours) { vy = (12 * (pos % 4)); vx = (pos / 4) * 10; this->_ecran->drawRect(vx, vy, 10, 13); } } // Affichage du menu Alpha Car. Spe. void sai_oled::aff_menu_Alpha_Spe(uint8_t pos, bool en_cours){ char ch_i[2]; uint8_t vx; uint8_t vy; for (uint8_t i = 32; i < 64; i++){ snprintf(ch_i, 2, "%c", i); vy = (12 * ((i - 32) % 4)); vx = ((i - 32) / 4) * 10; this->_ecran->drawString(vx, vy, ch_i ); } if (en_cours) { vy = (12 * (pos % 4)); vx = (pos / 4) * 10; this->_ecran->drawRect(vx, vy, 10, 13); } } // Affichage du menu Alpha Val/Annul. void sai_oled::aff_menu_Alpha_Val(uint8_t pos, bool en_cours){ for (uint8_t i = 0; i < nb_ch_menu_Valid; i++) this->_ecran->drawString(10, (12*i), this->ch_menuValid[i]); if (en_cours) { this->_ecran->drawRect(0, pos*12, 80, 13); } } // Affichage ensemble void sai_oled::aff_menu_alpha_zones(uint8_t pos, uint8_t menu, bool val_sys, bool val_det){ this->_ecran->clear(); this->aff_menu_alpha_maitre(menu); switch(menu){ case 0 : this->aff_menu_Alpha_Maj(pos, val_det); if(val_sys){ delay(300); this->sel_menu_Alpha_detail(28, menu);} break; case 1 : this->aff_menu_Alpha_Min(pos, val_det); if(val_sys){ delay(300); this->sel_menu_Alpha_detail(28, menu);} break; case 2 : this->aff_menu_Alpha_Spe(pos, val_det); if(val_sys){ delay(300); this->sel_menu_Alpha_detail(32, menu);} break; case 3 : this->aff_menu_Alpha_Val(pos, val_det); if(val_sys){ delay(300); this->sel_menu_Alpha_detail(4, menu);} break; } this->aff_menu_alpha_string(); this->_ecran->display(); } // Selection dans le menu Alpha dans la partie droite uint8_t sai_oled::sel_menu_Alpha(uint8_t max){ this->flech_d = true; max--; bool B_val = false, val_clk = true, memo_clk = true; int B_choix = 0; this->aff_menu_alpha_zones(0, B_choix, false, false); while (! B_val){ val_clk = digitalRead(this->PinCLK); if (val_clk != memo_clk){ if (digitalRead(this->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_alpha_zones(0, B_choix, false, false); delay(10); } if (!(digitalRead(this->PinSW))) { B_val = true; } // Bouton validation memo_clk = val_clk; delay(5); } this->aff_menu_alpha_zones(0, B_choix, true, false); return B_choix; } // Selection dans le menu Alpha dans la partie gauche uint8_t sai_oled::sel_menu_Alpha_detail(uint8_t max, uint8_t menu){ this->flech_d = false; max--; bool B_val = false, val_clk = true, memo_clk = true; int B_choix = 0; this->aff_menu_alpha_zones(B_choix, menu, false, true); while (! B_val){ val_clk = digitalRead(this->PinCLK); if (val_clk != memo_clk){ if (digitalRead(this->PinDT) != val_clk) { B_choix++; if (B_choix > max){ B_choix = 0; return B_choix; } } else { B_choix--; if (B_choix < 0){ B_choix = 0; if(this->sortieH) return B_choix; } } this->aff_menu_alpha_zones(B_choix, menu, false, true); delay(10); } if (!(digitalRead(this->PinSW))) { B_val = true; } // Bouton validation memo_clk = val_clk; delay(5); } maj_ch(B_choix, menu); if(this->val_ch < 2) return 0; delay(100); this->aff_menu_alpha_zones(B_choix, menu, true, false); return B_choix; }