Smart coffee machine with facial recognition and remote control
Dependencies: Camera_LS_Y201 EthernetInterface EthernetNetIf HTTPClient SRF05 TextLCD mbed-rtos mbed-src
intelligence.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 | // Variable globale partagée entre threads |
projetmacintel | 0:43669f623d43 | 16 | bool p_detection_visage; |
projetmacintel | 0:43669f623d43 | 17 | bool p_prendre_et_envoyer_photos_en_continu; |
projetmacintel | 0:43669f623d43 | 18 | |
projetmacintel | 0:43669f623d43 | 19 | bool communiquerAuServeurPreferencesUtilisateur(int preference_intensite, int preference_longueur) |
projetmacintel | 0:43669f623d43 | 20 | { |
projetmacintel | 0:43669f623d43 | 21 | printf("\tCommunication des prefs au serveur : %d | %d\n\r", preference_intensite, preference_longueur); |
projetmacintel | 0:43669f623d43 | 22 | char requete[9], reponse[10]; |
projetmacintel | 0:43669f623d43 | 23 | sprintf(requete, "SAVE %d %d", preference_intensite, preference_longueur); |
projetmacintel | 0:43669f623d43 | 24 | printf("\tTentative connexion socket\n\r"); |
projetmacintel | 0:43669f623d43 | 25 | if(connexionSocket()) |
projetmacintel | 0:43669f623d43 | 26 | { |
projetmacintel | 0:43669f623d43 | 27 | envoyerChaineSocket(requete, 9, reponse, 10); |
projetmacintel | 0:43669f623d43 | 28 | printf("\tEnvoi de [%s]\n\r", requete); |
projetmacintel | 0:43669f623d43 | 29 | printf("\tTentative deconnexion socket\n\r"); |
projetmacintel | 0:43669f623d43 | 30 | deconnexionSocket(); |
projetmacintel | 0:43669f623d43 | 31 | return strcmp("SAVE OK", reponse); |
projetmacintel | 0:43669f623d43 | 32 | } |
projetmacintel | 0:43669f623d43 | 33 | return false; |
projetmacintel | 0:43669f623d43 | 34 | } |
projetmacintel | 0:43669f623d43 | 35 | |
projetmacintel | 0:43669f623d43 | 36 | /*bool detecterUtilisateur() |
projetmacintel | 0:43669f623d43 | 37 | { |
projetmacintel | 0:43669f623d43 | 38 | return true; |
projetmacintel | 0:43669f623d43 | 39 | }*/ |
projetmacintel | 0:43669f623d43 | 40 | |
projetmacintel | 0:43669f623d43 | 41 | |
projetmacintel | 0:43669f623d43 | 42 | |
projetmacintel | 0:43669f623d43 | 43 | |
projetmacintel | 0:43669f623d43 | 44 | void async_desactiverDetectionVisage() |
projetmacintel | 0:43669f623d43 | 45 | { |
projetmacintel | 0:43669f623d43 | 46 | p_detection_visage = false; |
projetmacintel | 0:43669f623d43 | 47 | } |
projetmacintel | 0:43669f623d43 | 48 | |
projetmacintel | 0:43669f623d43 | 49 | void async_activerDetectionVisage() |
projetmacintel | 0:43669f623d43 | 50 | { |
projetmacintel | 0:43669f623d43 | 51 | p_detection_visage = true; |
projetmacintel | 0:43669f623d43 | 52 | } |
projetmacintel | 0:43669f623d43 | 53 | |
projetmacintel | 0:43669f623d43 | 54 | bool async_visageDetecte() |
projetmacintel | 0:43669f623d43 | 55 | { |
projetmacintel | 0:43669f623d43 | 56 | return p_detection_visage; |
projetmacintel | 0:43669f623d43 | 57 | } |
projetmacintel | 0:43669f623d43 | 58 | |
projetmacintel | 0:43669f623d43 | 59 | void thread_detection_visage(void const *args) |
projetmacintel | 0:43669f623d43 | 60 | { |
projetmacintel | 0:43669f623d43 | 61 | do |
projetmacintel | 0:43669f623d43 | 62 | { |
projetmacintel | 0:43669f623d43 | 63 | //p_detection_visage = detecterUtilisateur(); |
projetmacintel | 0:43669f623d43 | 64 | } while(p_detection_visage); |
projetmacintel | 0:43669f623d43 | 65 | } |
projetmacintel | 0:43669f623d43 | 66 | |
projetmacintel | 0:43669f623d43 | 67 | void communiquerAuServeurEmissionsPhotos() |
projetmacintel | 0:43669f623d43 | 68 | { |
projetmacintel | 0:43669f623d43 | 69 | |
projetmacintel | 0:43669f623d43 | 70 | } |
projetmacintel | 0:43669f623d43 | 71 | |
projetmacintel | 0:43669f623d43 | 72 | void communiquerAuServeurFinEmissionPhotos() |
projetmacintel | 0:43669f623d43 | 73 | { |
projetmacintel | 0:43669f623d43 | 74 | |
projetmacintel | 0:43669f623d43 | 75 | } |
projetmacintel | 0:43669f623d43 | 76 | |
projetmacintel | 0:43669f623d43 | 77 | void thread_prendreEtEnvoyerPhotosEnContinu(void const *args) |
projetmacintel | 0:43669f623d43 | 78 | { |
projetmacintel | 0:43669f623d43 | 79 | // Le serveur se prépare à recevoir plusieurs photos |
projetmacintel | 0:43669f623d43 | 80 | communiquerAuServeurEmissionsPhotos(); |
projetmacintel | 0:43669f623d43 | 81 | |
projetmacintel | 0:43669f623d43 | 82 | while(p_prendre_et_envoyer_photos_en_continu) |
projetmacintel | 0:43669f623d43 | 83 | { |
projetmacintel | 0:43669f623d43 | 84 | // La machine prend une photo et l'envoi en traitement au serveur |
projetmacintel | 0:43669f623d43 | 85 | |
projetmacintel | 0:43669f623d43 | 86 | } |
projetmacintel | 0:43669f623d43 | 87 | |
projetmacintel | 0:43669f623d43 | 88 | // On informe le serveur de la fin de prise de photos |
projetmacintel | 0:43669f623d43 | 89 | communiquerAuServeurFinEmissionPhotos(); |
projetmacintel | 0:43669f623d43 | 90 | } |
projetmacintel | 0:43669f623d43 | 91 | |
projetmacintel | 0:43669f623d43 | 92 | void async_lancerPriseEtEnvoiPhotosEnContinu() |
projetmacintel | 0:43669f623d43 | 93 | { |
projetmacintel | 0:43669f623d43 | 94 | p_prendre_et_envoyer_photos_en_continu = true; |
projetmacintel | 0:43669f623d43 | 95 | Thread thread_PEEPEC(thread_prendreEtEnvoyerPhotosEnContinu); |
projetmacintel | 0:43669f623d43 | 96 | } |
projetmacintel | 0:43669f623d43 | 97 | |
projetmacintel | 0:43669f623d43 | 98 | void async_stopperPriseEtEnvoiPhotosEnContinu() |
projetmacintel | 0:43669f623d43 | 99 | { |
projetmacintel | 0:43669f623d43 | 100 | p_prendre_et_envoyer_photos_en_continu = false; |
projetmacintel | 0:43669f623d43 | 101 | } |
projetmacintel | 0:43669f623d43 | 102 | |
projetmacintel | 0:43669f623d43 | 103 | void thread_check(void const *args) |
projetmacintel | 0:43669f623d43 | 104 | { |
projetmacintel | 0:43669f623d43 | 105 | checkContenanceReserveEau(true); // initialisation |
projetmacintel | 0:43669f623d43 | 106 | |
projetmacintel | 0:43669f623d43 | 107 | while(1) |
projetmacintel | 0:43669f623d43 | 108 | { |
projetmacintel | 0:43669f623d43 | 109 | checkPurge(); |
projetmacintel | 0:43669f623d43 | 110 | checkCafe(); |
projetmacintel | 0:43669f623d43 | 111 | checkContenanceReserveEau(false); |
projetmacintel | 0:43669f623d43 | 112 | wait(0.5); |
projetmacintel | 0:43669f623d43 | 113 | } |
projetmacintel | 0:43669f623d43 | 114 | } |