Smart coffee machine with facial recognition and remote control
Dependencies: Camera_LS_Y201 EthernetInterface EthernetNetIf HTTPClient SRF05 TextLCD mbed-rtos mbed-src
ecran_lcd.cpp@0:43669f623d43, 2014-01-15 (annotated)
- Committer:
- projetmacintel
- Date:
- Wed Jan 15 11:09:52 2014 +0000
- Revision:
- 0:43669f623d43
dep?t final PAO Macintel
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
projetmacintel | 0:43669f623d43 | 1 | #include "ecran_lcd.h" |
projetmacintel | 0:43669f623d43 | 2 | |
projetmacintel | 0:43669f623d43 | 3 | TextLCD ecranLCD(p30, p26, p25, p27, p28, p29); // rs, e, d4-d7 |
projetmacintel | 0:43669f623d43 | 4 | char message_ecran_1_haut[50], message_ecran_1_bas[50], message_ecran_2_haut[50], message_ecran_2_bas[50]; |
projetmacintel | 0:43669f623d43 | 5 | bool afficher_double_message, mettre_a_jour_ecran; |
projetmacintel | 0:43669f623d43 | 6 | |
projetmacintel | 0:43669f623d43 | 7 | void thread_ecran(void const *args) |
projetmacintel | 0:43669f623d43 | 8 | { |
projetmacintel | 0:43669f623d43 | 9 | Timer t; |
projetmacintel | 0:43669f623d43 | 10 | mettre_a_jour_ecran = false; |
projetmacintel | 0:43669f623d43 | 11 | wait(1); |
projetmacintel | 0:43669f623d43 | 12 | |
projetmacintel | 0:43669f623d43 | 13 | while(1) |
projetmacintel | 0:43669f623d43 | 14 | { |
projetmacintel | 0:43669f623d43 | 15 | if(mettre_a_jour_ecran) |
projetmacintel | 0:43669f623d43 | 16 | { |
projetmacintel | 0:43669f623d43 | 17 | ecranLCD.cls(); |
projetmacintel | 0:43669f623d43 | 18 | mettre_a_jour_ecran = false; |
projetmacintel | 0:43669f623d43 | 19 | |
projetmacintel | 0:43669f623d43 | 20 | if(!afficher_double_message) |
projetmacintel | 0:43669f623d43 | 21 | { |
projetmacintel | 0:43669f623d43 | 22 | afficherSurUneLigne(message_ecran_1_haut, 1); |
projetmacintel | 0:43669f623d43 | 23 | afficherSurUneLigne(message_ecran_1_bas, 2); |
projetmacintel | 0:43669f623d43 | 24 | } |
projetmacintel | 0:43669f623d43 | 25 | |
projetmacintel | 0:43669f623d43 | 26 | else |
projetmacintel | 0:43669f623d43 | 27 | { |
projetmacintel | 0:43669f623d43 | 28 | t.reset(); |
projetmacintel | 0:43669f623d43 | 29 | t.start(); |
projetmacintel | 0:43669f623d43 | 30 | bool mise_a_jour_1 = false, mise_a_jour_2 = false; |
projetmacintel | 0:43669f623d43 | 31 | |
projetmacintel | 0:43669f623d43 | 32 | while(!mettre_a_jour_ecran) |
projetmacintel | 0:43669f623d43 | 33 | { |
projetmacintel | 0:43669f623d43 | 34 | if(t.read() < 1.5) |
projetmacintel | 0:43669f623d43 | 35 | { |
projetmacintel | 0:43669f623d43 | 36 | if(!mise_a_jour_1) |
projetmacintel | 0:43669f623d43 | 37 | { |
projetmacintel | 0:43669f623d43 | 38 | ecranLCD.cls(); |
projetmacintel | 0:43669f623d43 | 39 | afficherSurUneLigne(message_ecran_1_haut, 1); |
projetmacintel | 0:43669f623d43 | 40 | afficherSurUneLigne(message_ecran_1_bas, 2); |
projetmacintel | 0:43669f623d43 | 41 | mise_a_jour_1 = true; |
projetmacintel | 0:43669f623d43 | 42 | } |
projetmacintel | 0:43669f623d43 | 43 | } |
projetmacintel | 0:43669f623d43 | 44 | |
projetmacintel | 0:43669f623d43 | 45 | else if(t.read() > 1.5*2) |
projetmacintel | 0:43669f623d43 | 46 | { |
projetmacintel | 0:43669f623d43 | 47 | t.reset(); |
projetmacintel | 0:43669f623d43 | 48 | mise_a_jour_1 = false; |
projetmacintel | 0:43669f623d43 | 49 | mise_a_jour_2 = false; |
projetmacintel | 0:43669f623d43 | 50 | } |
projetmacintel | 0:43669f623d43 | 51 | |
projetmacintel | 0:43669f623d43 | 52 | else |
projetmacintel | 0:43669f623d43 | 53 | { |
projetmacintel | 0:43669f623d43 | 54 | if(!mise_a_jour_2) |
projetmacintel | 0:43669f623d43 | 55 | { |
projetmacintel | 0:43669f623d43 | 56 | ecranLCD.cls(); |
projetmacintel | 0:43669f623d43 | 57 | afficherSurUneLigne(message_ecran_2_haut, 1); |
projetmacintel | 0:43669f623d43 | 58 | afficherSurUneLigne(message_ecran_2_bas, 2); |
projetmacintel | 0:43669f623d43 | 59 | mise_a_jour_2 = true; |
projetmacintel | 0:43669f623d43 | 60 | } |
projetmacintel | 0:43669f623d43 | 61 | } |
projetmacintel | 0:43669f623d43 | 62 | } |
projetmacintel | 0:43669f623d43 | 63 | |
projetmacintel | 0:43669f623d43 | 64 | t.stop(); |
projetmacintel | 0:43669f623d43 | 65 | } |
projetmacintel | 0:43669f623d43 | 66 | |
projetmacintel | 0:43669f623d43 | 67 | } |
projetmacintel | 0:43669f623d43 | 68 | } |
projetmacintel | 0:43669f623d43 | 69 | } |
projetmacintel | 0:43669f623d43 | 70 | |
projetmacintel | 0:43669f623d43 | 71 | void afficherSurUneLigne(const char* texte_brut, int ligne) |
projetmacintel | 0:43669f623d43 | 72 | { |
projetmacintel | 0:43669f623d43 | 73 | int i; |
projetmacintel | 0:43669f623d43 | 74 | char texte[17]; |
projetmacintel | 0:43669f623d43 | 75 | for(i = 0 ; i < 16 ; i ++) |
projetmacintel | 0:43669f623d43 | 76 | texte[i] = texte_brut[i]; |
projetmacintel | 0:43669f623d43 | 77 | |
projetmacintel | 0:43669f623d43 | 78 | texte[i] = '\0'; |
projetmacintel | 0:43669f623d43 | 79 | |
projetmacintel | 0:43669f623d43 | 80 | int nb_espaces_a_ajouter = (ecranLCD.columns() - strlen(texte)) / 2; |
projetmacintel | 0:43669f623d43 | 81 | |
projetmacintel | 0:43669f623d43 | 82 | if(nb_espaces_a_ajouter < 0) |
projetmacintel | 0:43669f623d43 | 83 | nb_espaces_a_ajouter = 0; |
projetmacintel | 0:43669f623d43 | 84 | |
projetmacintel | 0:43669f623d43 | 85 | ecranLCD.locate(nb_espaces_a_ajouter, ligne - 1); |
projetmacintel | 0:43669f623d43 | 86 | ecranLCD.printf(texte); |
projetmacintel | 0:43669f623d43 | 87 | |
projetmacintel | 0:43669f623d43 | 88 | if(ligne == 1) |
projetmacintel | 0:43669f623d43 | 89 | printf("Affichage ecran : "); |
projetmacintel | 0:43669f623d43 | 90 | |
projetmacintel | 0:43669f623d43 | 91 | printf("%s ", texte); |
projetmacintel | 0:43669f623d43 | 92 | |
projetmacintel | 0:43669f623d43 | 93 | if(ligne == 2) |
projetmacintel | 0:43669f623d43 | 94 | printf("\n\r"); |
projetmacintel | 0:43669f623d43 | 95 | } |
projetmacintel | 0:43669f623d43 | 96 | |
projetmacintel | 0:43669f623d43 | 97 | /* Surement deprecated */ |
projetmacintel | 0:43669f623d43 | 98 | void faireDefilerSurEcran(const char* texte, int vitesse) |
projetmacintel | 0:43669f623d43 | 99 | { |
projetmacintel | 0:43669f623d43 | 100 | int k = 0; |
projetmacintel | 0:43669f623d43 | 101 | |
projetmacintel | 0:43669f623d43 | 102 | for(int i = 0 ; i < 999 ; i ++) |
projetmacintel | 0:43669f623d43 | 103 | { |
projetmacintel | 0:43669f623d43 | 104 | ecranLCD.cls(); |
projetmacintel | 0:43669f623d43 | 105 | |
projetmacintel | 0:43669f623d43 | 106 | for(int j = 0 ; j < strlen(texte) - k ; j ++) |
projetmacintel | 0:43669f623d43 | 107 | ecranLCD.printf("%c", texte[k + j]); |
projetmacintel | 0:43669f623d43 | 108 | |
projetmacintel | 0:43669f623d43 | 109 | for(int j = strlen(texte) - k ; j < 15 - k ; j ++) |
projetmacintel | 0:43669f623d43 | 110 | ecranLCD.printf(" "); |
projetmacintel | 0:43669f623d43 | 111 | |
projetmacintel | 0:43669f623d43 | 112 | for(int j = 15 - k ; j < 15 ; j ++) |
projetmacintel | 0:43669f623d43 | 113 | ecranLCD.printf("%c", texte[j - (15 - k)]); |
projetmacintel | 0:43669f623d43 | 114 | |
projetmacintel | 0:43669f623d43 | 115 | wait(0.3); |
projetmacintel | 0:43669f623d43 | 116 | |
projetmacintel | 0:43669f623d43 | 117 | k ++; |
projetmacintel | 0:43669f623d43 | 118 | |
projetmacintel | 0:43669f623d43 | 119 | if(k == 15) |
projetmacintel | 0:43669f623d43 | 120 | k = 0; |
projetmacintel | 0:43669f623d43 | 121 | } |
projetmacintel | 0:43669f623d43 | 122 | } |
projetmacintel | 0:43669f623d43 | 123 | |
projetmacintel | 0:43669f623d43 | 124 | void afficherAuCentreDeLEcran(const char* texte_haut, const char* texte_bas) |
projetmacintel | 0:43669f623d43 | 125 | { |
projetmacintel | 0:43669f623d43 | 126 | sprintf(message_ecran_1_haut, "%s", texte_haut); |
projetmacintel | 0:43669f623d43 | 127 | sprintf(message_ecran_1_bas, "%s", texte_bas); |
projetmacintel | 0:43669f623d43 | 128 | sprintf(message_ecran_2_haut, ""); |
projetmacintel | 0:43669f623d43 | 129 | sprintf(message_ecran_2_bas, ""); |
projetmacintel | 0:43669f623d43 | 130 | afficher_double_message = false; |
projetmacintel | 0:43669f623d43 | 131 | mettre_a_jour_ecran = true; |
projetmacintel | 0:43669f623d43 | 132 | } |
projetmacintel | 0:43669f623d43 | 133 | |
projetmacintel | 0:43669f623d43 | 134 | void afficherAuCentreDeLEcran(const char* texte_1_haut, const char* texte_1_bas, const char* texte_2_haut, const char* texte_2_bas) |
projetmacintel | 0:43669f623d43 | 135 | { |
projetmacintel | 0:43669f623d43 | 136 | sprintf(message_ecran_1_haut, "%s", texte_1_haut); |
projetmacintel | 0:43669f623d43 | 137 | sprintf(message_ecran_1_bas, "%s", texte_1_bas); |
projetmacintel | 0:43669f623d43 | 138 | sprintf(message_ecran_2_haut, "%s", texte_2_haut); |
projetmacintel | 0:43669f623d43 | 139 | sprintf(message_ecran_2_bas, "%s", texte_2_bas); |
projetmacintel | 0:43669f623d43 | 140 | afficher_double_message = true; |
projetmacintel | 0:43669f623d43 | 141 | mettre_a_jour_ecran = true; |
projetmacintel | 0:43669f623d43 | 142 | } |
projetmacintel | 0:43669f623d43 | 143 | |
projetmacintel | 0:43669f623d43 | 144 | void afficherAuCentreDeLEcran(int nombre1, int nombre2) |
projetmacintel | 0:43669f623d43 | 145 | { |
projetmacintel | 0:43669f623d43 | 146 | char s1[20], s2[20]; |
projetmacintel | 0:43669f623d43 | 147 | sprintf(s1, "%i", nombre1); |
projetmacintel | 0:43669f623d43 | 148 | sprintf(s2, "%i", nombre2); |
projetmacintel | 0:43669f623d43 | 149 | afficherAuCentreDeLEcran(s1, s2); |
projetmacintel | 0:43669f623d43 | 150 | } |