Smart coffee machine with facial recognition and remote control
Dependencies: Camera_LS_Y201 EthernetInterface EthernetNetIf HTTPClient SRF05 TextLCD mbed-rtos mbed-src
main.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 "mbed.h" |
projetmacintel | 0:43669f623d43 | 2 | #include "rtos.h" |
projetmacintel | 0:43669f623d43 | 3 | #include "cafe.h" |
projetmacintel | 0:43669f623d43 | 4 | #include "camera.h" |
projetmacintel | 0:43669f623d43 | 5 | #include "capteur_tasse.h" |
projetmacintel | 0:43669f623d43 | 6 | #include "eau.h" |
projetmacintel | 0:43669f623d43 | 7 | #include "ethernet.h" |
projetmacintel | 0:43669f623d43 | 8 | #include "led.h" |
projetmacintel | 0:43669f623d43 | 9 | #include "machine.h" |
projetmacintel | 0:43669f623d43 | 10 | #include "preferences.h" |
projetmacintel | 0:43669f623d43 | 11 | #include "purge.h" |
projetmacintel | 0:43669f623d43 | 12 | #include "ecran_lcd.h" |
projetmacintel | 0:43669f623d43 | 13 | #include "intelligence.h" |
projetmacintel | 0:43669f623d43 | 14 | |
projetmacintel | 0:43669f623d43 | 15 | #define TIMEOUT_DETECTION 20.0 |
projetmacintel | 0:43669f623d43 | 16 | |
projetmacintel | 0:43669f623d43 | 17 | int main() |
projetmacintel | 0:43669f623d43 | 18 | { |
projetmacintel | 0:43669f623d43 | 19 | //thread_checkCapteurs(); |
projetmacintel | 0:43669f623d43 | 20 | /*if(getPreferenceIntensite() == -1) |
projetmacintel | 0:43669f623d43 | 21 | allumerMachine();*/ |
projetmacintel | 0:43669f623d43 | 22 | //printf("%d\n\r", getPreferenceIntensite()); |
projetmacintel | 0:43669f623d43 | 23 | |
projetmacintel | 0:43669f623d43 | 24 | Thread threadEcran(thread_ecran); |
projetmacintel | 0:43669f623d43 | 25 | wait(1); |
projetmacintel | 0:43669f623d43 | 26 | afficherAuCentreDeLEcran("Demarrage", "du systeme"); |
projetmacintel | 0:43669f623d43 | 27 | |
projetmacintel | 0:43669f623d43 | 28 | Timer t; |
projetmacintel | 0:43669f623d43 | 29 | char nom_utilisateur[25]; |
projetmacintel | 0:43669f623d43 | 30 | DigitalIn boutonPoussoir(p12); |
projetmacintel | 0:43669f623d43 | 31 | int preference_longueur = 0, preference_intensite = 0; |
projetmacintel | 0:43669f623d43 | 32 | bool detection_visage = false, utilisateur_reconnu = false; |
projetmacintel | 0:43669f623d43 | 33 | wait(1); |
projetmacintel | 0:43669f623d43 | 34 | |
projetmacintel | 0:43669f623d43 | 35 | if(preparationEthernet()) |
projetmacintel | 0:43669f623d43 | 36 | { |
projetmacintel | 0:43669f623d43 | 37 | checkContenanceReserveEau(true); |
projetmacintel | 0:43669f623d43 | 38 | wait(1); // Pour laisser l'affichage du message |
projetmacintel | 0:43669f623d43 | 39 | |
projetmacintel | 0:43669f623d43 | 40 | if(initialiserCamera()) |
projetmacintel | 0:43669f623d43 | 41 | { |
projetmacintel | 0:43669f623d43 | 42 | wait(1); // Pour laisser l'affichage du message |
projetmacintel | 0:43669f623d43 | 43 | while(boutonPoussoir.read() != 1) // Arret du système avec pression sur BP |
projetmacintel | 0:43669f623d43 | 44 | { |
projetmacintel | 0:43669f623d43 | 45 | t.reset(); |
projetmacintel | 0:43669f623d43 | 46 | |
projetmacintel | 0:43669f623d43 | 47 | do |
projetmacintel | 0:43669f623d43 | 48 | { |
projetmacintel | 0:43669f623d43 | 49 | checkPurge(); |
projetmacintel | 0:43669f623d43 | 50 | checkCafe(); |
projetmacintel | 0:43669f623d43 | 51 | checkContenanceReserveEau(false); |
projetmacintel | 0:43669f623d43 | 52 | afficherAuCentreDeLEcran("Pret a", "vous servir"); |
projetmacintel | 0:43669f623d43 | 53 | |
projetmacintel | 0:43669f623d43 | 54 | if(boutonPoussoir.read() == 1) |
projetmacintel | 0:43669f623d43 | 55 | break; |
projetmacintel | 0:43669f623d43 | 56 | |
projetmacintel | 0:43669f623d43 | 57 | // Recherche d'un visage en permanence |
projetmacintel | 0:43669f623d43 | 58 | detection_visage = detecterUtilisateur(&utilisateur_reconnu, |
projetmacintel | 0:43669f623d43 | 59 | nom_utilisateur, |
projetmacintel | 0:43669f623d43 | 60 | &preference_intensite, |
projetmacintel | 0:43669f623d43 | 61 | &preference_longueur); |
projetmacintel | 0:43669f623d43 | 62 | } while(!detection_visage); |
projetmacintel | 0:43669f623d43 | 63 | |
projetmacintel | 0:43669f623d43 | 64 | if(boutonPoussoir.read() == 1) |
projetmacintel | 0:43669f623d43 | 65 | break; |
projetmacintel | 0:43669f623d43 | 66 | |
projetmacintel | 0:43669f623d43 | 67 | //async_desactiverDetectionVisage(); |
projetmacintel | 0:43669f623d43 | 68 | // Lancement d'une détection en boucle |
projetmacintel | 0:43669f623d43 | 69 | //Thread threadDetectionVisage(thread_detection_visage); |
projetmacintel | 0:43669f623d43 | 70 | //wait(3); |
projetmacintel | 0:43669f623d43 | 71 | |
projetmacintel | 0:43669f623d43 | 72 | if(utilisateur_reconnu) |
projetmacintel | 0:43669f623d43 | 73 | { |
projetmacintel | 0:43669f623d43 | 74 | afficherAuCentreDeLEcran("Bonjour", nom_utilisateur); |
projetmacintel | 0:43669f623d43 | 75 | setPreferenceLongueur(preference_longueur); |
projetmacintel | 0:43669f623d43 | 76 | setPreferenceIntensite(preference_intensite); |
projetmacintel | 0:43669f623d43 | 77 | wait(3); |
projetmacintel | 0:43669f623d43 | 78 | |
projetmacintel | 0:43669f623d43 | 79 | t.start(); |
projetmacintel | 0:43669f623d43 | 80 | afficherAuCentreDeLEcran("Veuillez changer", "vos preferences", "puis placer", "votre tasse"); |
projetmacintel | 0:43669f623d43 | 81 | while(/*async_visageDetecte() && */!tasseEnPlace() && t.read() < TIMEOUT_DETECTION); |
projetmacintel | 0:43669f623d43 | 82 | t.stop(); |
projetmacintel | 0:43669f623d43 | 83 | |
projetmacintel | 0:43669f623d43 | 84 | if(t.read() >= TIMEOUT_DETECTION) |
projetmacintel | 0:43669f623d43 | 85 | continue; |
projetmacintel | 0:43669f623d43 | 86 | |
projetmacintel | 0:43669f623d43 | 87 | /*if(!async_visageDetecte()) |
projetmacintel | 0:43669f623d43 | 88 | continue;*/ |
projetmacintel | 0:43669f623d43 | 89 | |
projetmacintel | 0:43669f623d43 | 90 | // Sinon, c'est que l'utilisateur a placé sa tasse |
projetmacintel | 0:43669f623d43 | 91 | |
projetmacintel | 0:43669f623d43 | 92 | // On lance la prise de photos en continu pour enrichir la base |
projetmacintel | 0:43669f623d43 | 93 | //async_lancerPriseEtEnvoiPhotosEnContinu(); |
projetmacintel | 0:43669f623d43 | 94 | |
projetmacintel | 0:43669f623d43 | 95 | // On lance la production de café |
projetmacintel | 0:43669f623d43 | 96 | faireUnCafe(); |
projetmacintel | 0:43669f623d43 | 97 | |
projetmacintel | 0:43669f623d43 | 98 | afficherAuCentreDeLEcran("Sauvegarde de", "vos preferences"); |
projetmacintel | 0:43669f623d43 | 99 | communiquerAuServeurPreferencesUtilisateur(getPreferenceIntensite(), getPreferenceLongueur()); |
projetmacintel | 0:43669f623d43 | 100 | wait(2); |
projetmacintel | 0:43669f623d43 | 101 | afficherAuCentreDeLEcran("Retirez", "votre tasse"); |
projetmacintel | 0:43669f623d43 | 102 | |
projetmacintel | 0:43669f623d43 | 103 | // On arrete la prise de photos et on en informe le serveur |
projetmacintel | 0:43669f623d43 | 104 | //async_stopperPriseEtEnvoiPhotosEnContinu(); |
projetmacintel | 0:43669f623d43 | 105 | |
projetmacintel | 0:43669f623d43 | 106 | // On attend que l'utilisateur retire sa tasse |
projetmacintel | 0:43669f623d43 | 107 | while(tasseEnPlace()); |
projetmacintel | 0:43669f623d43 | 108 | } |
projetmacintel | 0:43669f623d43 | 109 | |
projetmacintel | 0:43669f623d43 | 110 | else |
projetmacintel | 0:43669f623d43 | 111 | { |
projetmacintel | 0:43669f623d43 | 112 | t.start(); |
projetmacintel | 0:43669f623d43 | 113 | afficherAuCentreDeLEcran("Nouvel", "utilisateur", "Veuillez placer", "votre tasse"); |
projetmacintel | 0:43669f623d43 | 114 | while(/*async_visageDetecte() && */!tasseEnPlace() && t.read() < TIMEOUT_DETECTION); |
projetmacintel | 0:43669f623d43 | 115 | t.stop(); |
projetmacintel | 0:43669f623d43 | 116 | |
projetmacintel | 0:43669f623d43 | 117 | if(t.read() >= TIMEOUT_DETECTION) |
projetmacintel | 0:43669f623d43 | 118 | continue; |
projetmacintel | 0:43669f623d43 | 119 | |
projetmacintel | 0:43669f623d43 | 120 | /*if(!async_visageDetecte()) |
projetmacintel | 0:43669f623d43 | 121 | continue;*/ |
projetmacintel | 0:43669f623d43 | 122 | |
projetmacintel | 0:43669f623d43 | 123 | // Sinon, c'est que l'utilisateur a placé sa tasse |
projetmacintel | 0:43669f623d43 | 124 | |
projetmacintel | 0:43669f623d43 | 125 | // On lance la prise de photos en continu pour enrichir la base |
projetmacintel | 0:43669f623d43 | 126 | //async_lancerPriseEtEnvoiPhotosEnContinu(); |
projetmacintel | 0:43669f623d43 | 127 | |
projetmacintel | 0:43669f623d43 | 128 | afficherAuCentreDeLEcran("Faites votre", "selection", "puis", "validez"); |
projetmacintel | 0:43669f623d43 | 129 | while(!capteurChauffeClignotant()); |
projetmacintel | 0:43669f623d43 | 130 | |
projetmacintel | 0:43669f623d43 | 131 | afficherAuCentreDeLEcran("Merci de", "patienter"); |
projetmacintel | 0:43669f623d43 | 132 | while(capteurChauffeClignotant()); // on attend la fin de café |
projetmacintel | 0:43669f623d43 | 133 | |
projetmacintel | 0:43669f623d43 | 134 | // On recherche les préférences de l'utilisateur et on les communique au serveur |
projetmacintel | 0:43669f623d43 | 135 | afficherAuCentreDeLEcran("Lecture de", "vos preferences"); |
projetmacintel | 0:43669f623d43 | 136 | if(communiquerAuServeurPreferencesUtilisateur(getPreferenceIntensite(), getPreferenceLongueur())) |
projetmacintel | 0:43669f623d43 | 137 | { |
projetmacintel | 0:43669f623d43 | 138 | afficherAuCentreDeLEcran("Echec de ", "sauvegarde"); |
projetmacintel | 0:43669f623d43 | 139 | wait(1); |
projetmacintel | 0:43669f623d43 | 140 | } |
projetmacintel | 0:43669f623d43 | 141 | |
projetmacintel | 0:43669f623d43 | 142 | // On arrete la prise de photos et on en informe le serveur |
projetmacintel | 0:43669f623d43 | 143 | //async_stopperPriseEtEnvoiPhotosEnContinu(); |
projetmacintel | 0:43669f623d43 | 144 | |
projetmacintel | 0:43669f623d43 | 145 | // On attend que l'utilisateur retire sa tasse |
projetmacintel | 0:43669f623d43 | 146 | afficherAuCentreDeLEcran("Retirez", "votre tasse"); |
projetmacintel | 0:43669f623d43 | 147 | while(tasseEnPlace()); |
projetmacintel | 0:43669f623d43 | 148 | } |
projetmacintel | 0:43669f623d43 | 149 | } |
projetmacintel | 0:43669f623d43 | 150 | } |
projetmacintel | 0:43669f623d43 | 151 | |
projetmacintel | 0:43669f623d43 | 152 | deconnexionEthernet(); |
projetmacintel | 0:43669f623d43 | 153 | } |
projetmacintel | 0:43669f623d43 | 154 | |
projetmacintel | 0:43669f623d43 | 155 | return 0; |
projetmacintel | 0:43669f623d43 | 156 | } |