programme final projet s4

Dependencies:   BSP_DISCO_F746NG SDFileSystem TS_DISCO_F746NG affichage_des_ecrans mbed rtc_lib

Revision:
4:c6e9b4449a5f
Parent:
3:53f3194a919e
--- a/main_glb.cpp	Fri Oct 14 11:59:38 2016 +0000
+++ b/main_glb.cpp	Sun Oct 23 17:44:20 2016 +0000
@@ -4,6 +4,7 @@
 #include "ds1338.h"
 #include "horloge.h"
 #include "Ecran.h"
+#include "SDFileSystem.h"
 //définition de la zone tactile dans l'ecran principal
 #define TOUCHADMINISTRATEUR ((TS_State.touchDetected) && ( TS_State.touchX[0]>0) &&( TS_State.touchX[0]< 240)&& ( TS_State.touchY[0]>0) && (TS_State.touchY[0] < 272))
 #define TOUCHUTILISATEUR ((TS_State.touchDetected) && ( TS_State.touchX[0]> 240) &&( TS_State.touchX[0]< 480)&& ( TS_State.touchY[0]> 0) && (TS_State.touchY[0] < 272))
@@ -28,7 +29,7 @@
 #define TOUCHSeconde ((TS_State.touchDetected) && ( TS_State.touchX[0]> 172) &&( TS_State.touchX[0]< 240)&& ( TS_State.touchY[0]> 164) && (TS_State.touchY[0] < 204))  
 
 //définition des touches tactiles pour le réglage de la fréquence d'envoi des données sur la carte SD 
-#define TOUCHPerHour ((TS_State.touchDetected) && ( TS_State.touchX[0]> 25) &&( TS_State.touchX[0]< 175)&& ( TS_State.touchY[0]> 115) && (TS_State.touchY[0] < 145))
+#define TOUCHAcquire ((TS_State.touchDetected) && ( TS_State.touchX[0]> 25) &&( TS_State.touchX[0]< 175)&& ( TS_State.touchY[0]> 115) && (TS_State.touchY[0] < 145))
 #define TOUCHPerDay ((TS_State.touchDetected) && ( TS_State.touchX[0]> 245) &&( TS_State.touchX[0]< 405)&& ( TS_State.touchY[0]> 115) && (TS_State.touchY[0] < 145))
 #define TOUCHPerWeek ((TS_State.touchDetected) && ( TS_State.touchX[0]> 25) &&( TS_State.touchX[0]< 175)&& ( TS_State.touchY[0]> 155) && (TS_State.touchY[0] < 185))
 #define TOUCHPermonth ((TS_State.touchDetected) && ( TS_State.touchX[0]> 245) &&( TS_State.touchX[0]< 405)&& ( TS_State.touchY[0]> 155) && (TS_State.touchY[0] < 185))  
@@ -36,35 +37,71 @@
 //définition de l'attente avant l'affichage d'un nouvel écran
 #define ATTENTE wait(0.2);
 
+// définition des touche des chiffres pour la saisie du mot passe
+
+#define TOUCH1 (( TS_State.touchDetected) && ( TS_State.touchX[0]>135) &&( TS_State.touchX[0]<185)&& ( TS_State.touchY[0]>90) && (TS_State.touchY[0]<115))
+#define TOUCH2 (( TS_State.touchDetected) && ( TS_State.touchX[0]>215) &&( TS_State.touchX[0]<260)&& ( TS_State.touchY[0]>90) && (TS_State.touchY[0]<115))
+#define TOUCH3 (( TS_State.touchDetected) && ( TS_State.touchX[0]>295) &&( TS_State.touchX[0]<345)&& ( TS_State.touchY[0]>90) && (TS_State.touchY[0]<115))
+#define TOUCH4 (( TS_State.touchDetected) && ( TS_State.touchX[0]>135) &&( TS_State.touchX[0]<185)&& ( TS_State.touchY[0]>130) && (TS_State.touchY[0]<155))
+#define TOUCH5 (( TS_State.touchDetected) && ( TS_State.touchX[0]>215) &&( TS_State.touchX[0]<260)&& ( TS_State.touchY[0]>130) && (TS_State.touchY[0]<155))
+#define TOUCH6 (( TS_State.touchDetected) && ( TS_State.touchX[0]>295) &&( TS_State.touchX[0]<345)&& ( TS_State.touchY[0]>130) && (TS_State.touchY[0]<155))
+#define TOUCH7 (( TS_State.touchDetected) && ( TS_State.touchX[0]>135) &&( TS_State.touchX[0]<185)&& ( TS_State.touchY[0]>170) && (TS_State.touchY[0]<195))
+#define TOUCH8 (( TS_State.touchDetected) && ( TS_State.touchX[0]>215) &&( TS_State.touchX[0]<260)&& ( TS_State.touchY[0]>170) && (TS_State.touchY[0]<195))
+#define TOUCH9 (( TS_State.touchDetected) && ( TS_State.touchX[0]>295) &&( TS_State.touchX[0]<345)&& ( TS_State.touchY[0]>170) && (TS_State.touchY[0]<195))
+#define TOUCHVALID (( TS_State.touchDetected) && ( TS_State.touchX[0]>210) &&( TS_State.touchX[0]<280)&& ( TS_State.touchY[0]>210) && (TS_State.touchY[0]<235))
+/////affichage de l'heure
+#define TOUCHSHOWTIME ((TS_State.touchDetected) && ( TS_State.touchX[0]>395 ) &&( TS_State.touchX[0]<475)&& ( TS_State.touchY[0]>10) && (TS_State.touchY[0] <40)) 
+
 int affiche=0;
-/*void horloge();
-char jour[6];   
-char mois[6];
-char annee[6]; 
-char heure[6];   
-char minute[6];
-char seconde[6]; */
-
-
+int password=0;
 
 
 TS_DISCO_F746NG ts;  
 
 DigitalOut led1(LED1);
-
+Serial pc(USBTX, USBRX);
                   
   int main()
   {
+    unsigned int day =00;
+unsigned int month =00;
+unsigned int year=2000;
+unsigned int hour =00;
+unsigned int min =00;
+unsigned int sec=00;
+    SDFileSystem sd(D11,D12,D13 , D3, "sd");
+    AnalogIn Vpan(A0);
+    AnalogIn Ipan(A1);
+    AnalogIn Tpan(A2);
+    AnalogIn Irr(A3);
+    AnalogIn Vbat(A4);
+    AnalogIn Ibat(A5);
     DS1338 ds1338(D14,D15);
-    wait(0.5);
-    void principal();
+    LCD_DISCO_F746NG lcd;
+    lcd.Clear(LCD_COLOR_BLACK);
+    lcd.SetBackColor(LCD_COLOR_BLACK);
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+    lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"WELCOME TO LAOS PROJET", CENTER_MODE);  
+    wait(1); 
+    affiche=1; 
+    
     struct tm time;
-    wait(1); 
-    affiche=1;    
-         
+       
+    
       TS_StateTypeDef TS_State;
       ts.Init(480, 272);
-     ds1338.writeTime(&time);
+      
+    time.tm_sec=0;
+    time.tm_min=28;
+    time.tm_hour=11;
+    time.tm_mday=19;
+    time.tm_year=116;
+    time.tm_mon=9;
+    time.tm_wday=3;
+    time.tm_yday=0;
+    time.tm_isdst=0;
+    ds1338.writeTime(&time);
+    
           while(1)
       {
          ts.GetState(&TS_State);  
@@ -72,7 +109,7 @@
          ds1338.readTime(&time);
         
          
-    typedef enum  {etat0, etat1, etat1_1,etat_reg_minute, etat3, etat4 ,etat2, etat_reg_day, etat_reg_month,etat_reg_year, etat_reg_hour} type_etat;
+    typedef enum  {etat0, etat1,etat_reg_minute, etat_mot_de_passe,Etat_ecran_affichage,Etat_ecranUtilis,etat3,etat2, etat_reg_day, etat_reg_month,etat_reg_year, etat_reg_hour} type_etat;
     static type_etat etat= etat0;
     
     switch (etat)
@@ -86,52 +123,91 @@
 
          if (TOUCHUTILISATEUR)
             { 
-          etat= etat1_1;
+          etat= Etat_ecranUtilis;
           affiche=1;
            ATTENTE
              }  
              
           if (TOUCHADMINISTRATEUR)
              { 
-             etat= etat1;
+             etat= etat_mot_de_passe;
              affiche=1;
              ATTENTE
              }               
              break;
-
-        case etat1_1:
-        if(affiche==1)
-          { 
-           ATTENTE
-          EcranUtilis ();
-          affiche=0;
-          }  
-        /*if (TOUCHAFF)    
+//////////////////////Mot de passe///////////////////////
+               
+             case etat_mot_de_passe:
+             if(affiche==1)
           { 
-          etat=etat4;
-          affiche=1;
-            }*/  
-            if (TOUCHRETOUR)
+          MotDePasse ();
+          affiche=0;
+         password=0;
+          }  
+         if (TOUCH2)
+          {
+            lcd.SetBackColor(LCD_COLOR_WHITE);
+            lcd.SetTextColor(LCD_COLOR_BLACK);
+            lcd.DisplayStringAt(180, LINE(1), (uint8_t *)"*",LEFT_MODE);
+                password=2;}
+         if(password==2&&TOUCH7)
+           {
+                lcd.SetBackColor(LCD_COLOR_WHITE);
+                lcd.SetTextColor(LCD_COLOR_BLACK);
+                lcd.DisplayStringAt(210, LINE(1), (uint8_t *)"*",LEFT_MODE);
+                    password=7;}
+         if(password==7&&TOUCH5)
               {
-                etat= etat0;
-                affiche=1;
-                ATTENTE
-              }
+                lcd.SetBackColor(LCD_COLOR_WHITE);
+                lcd.SetTextColor(LCD_COLOR_BLACK);
+                lcd.DisplayStringAt(240, LINE(1), (uint8_t *)"*",LEFT_MODE);
+                password=5;}
+         if(password==5&&TOUCHVALID)
+         {
+            etat= etat1;
+             affiche=1;
+            ATTENTE
+             }
+             
+         if ( TOUCH1|| TOUCH3 || TOUCH4 || TOUCH6|| TOUCH8|| TOUCH9)
+       
+           { 
+           lcd.SetBackColor(LCD_COLOR_WHITE);
+           lcd.SetTextColor(LCD_COLOR_BLACK);
+           lcd.DisplayStringAt(140, LINE(2), (uint8_t *)"pass invalid",LEFT_MODE); 
+           wait (1);
+           affiche=1;
+           
+          if(affiche==1)
+          { 
+          MotDePasse ();
+          affiche=0;
+         password=0;
+          } 
+           }
+           if(TOUCHRETOUR)
+           {
+              etat= etat0;
+             affiche=1;
+             ATTENTE
+            } 
              break;
              
+             ////////////////////////////////////////////////////////
+             
            case etat1: 
           if (affiche==1)
           { 
            ATTENTE
            EcranAdminis ();
-            ;
+            
            affiche=0;
             }  
 
            if (TOUCHTIMEDATE)     
              {
-              etat = etat2;
-              affiche=1; 
+              etat= etat2;
+             affiche=1; 
              }
            if  (TOUCHFREQ) 
            {
@@ -140,9 +216,15 @@
             } 
           if (TOUCHAFFICHAGE)
              {
-               etat=etat4; 
-               affiche=1; 
+               ATTENTE
+              etat=Etat_ecran_affichage;
+              affiche=1;
              }
+          if (TOUCHSHOWTIME)     
+             {
+              reg_time();
+              affiche=1; 
+             }    
           if (TOUCHRETOUR)
               {
                 etat= etat0;
@@ -198,12 +280,18 @@
              {
                time.tm_sec=0; 
                affiche=1; 
-             }        
+             } 
+             if (TOUCHSHOWTIME)     
+             {
+              reg_time();
+              affiche=1; 
+             }           
           break;
           
       
       
            
+            
          case etat_reg_day:   
             if (affiche==1)
             {   
@@ -212,17 +300,17 @@
             }
             
             if(TOUCHPlus){
-                 time.tm_mday=time.tm_mday+1;
+                 day=day+1;
                  ATTENTE
                  Ecran2_Day();
-                 //if(day>30) day=0;
+                 if(day>30) day=0;
             }
             if(TOUCHMoins)
              {
-                 time.tm_mday=time.tm_mday-1;
+                 day=day-1;
                  wait (0.3);
                  Ecran2_Day();
-                 //if(day<2) day=32;
+                 if(day<2) day=32;
              }    
            if ( (TOUCHOK)||(TOUCHRETOUR) )
               {
@@ -239,17 +327,17 @@
                 }
             if(TOUCHPlus)
              {
-                 time.tm_mon=time.tm_mon+1;
+                 month=month+1;
                   ATTENTE
                  Ecran2_Month();
-                 //if(month>11) month=0;
+                 if(month>11) month=0;
                  }
             if(TOUCHMoins)
              {
-                  time.tm_mon=time.tm_mon-1;
+                  month=month-1;
                   ATTENTE
                  Ecran2_Month();
-                  //if(month<2) month=13;
+                  if(month<2) month=13;
                  
             }
             if ( (TOUCHOK)|| (TOUCHRETOUR))
@@ -268,17 +356,17 @@
             
                 if(TOUCHPlus)
                  {
-                   time.tm_year=time.tm_year+1;
+                   year=year+1;
                    ATTENTE
                      Ecran2_Year();
-                   //if(year>3000) year=2000;
+                   if(year>3000) year=2000;
                  }
                 if(TOUCHMoins)
                   {
-                   time.tm_year=time.tm_year-1;
+                   year=year-1;
                    ATTENTE
                    Ecran2_Year();
-                   //if(year<2000) year=3000;
+                   if(year<2000) year=3000;
                    }
                 if ((TOUCHOK) ||(TOUCHRETOUR))
                   {
@@ -296,16 +384,16 @@
             }     
             
                 if(TOUCHPlus){
-                    time.tm_hour=time.tm_hour+1;
+                    hour=hour+1;
                     ATTENTE
                      Ecran2_Hour();
-                    //if(hour>22) hour=0;
+                    if(hour>22) hour=0;
                 }
                 if(TOUCHMoins){
-                    time.tm_hour=time.tm_hour-1;
+                    hour=hour-1;
                     ATTENTE
                      Ecran2_Hour();
-                    //if(hour<1) hour=24;
+                    if(hour<1) hour=24;
                 }
             
             if ((TOUCHOK)||(TOUCHRETOUR)){
@@ -324,17 +412,17 @@
            
             if(TOUCHPlus)
              {
-                 time.tm_min=time.tm_min+1;
+                 min=min+1;
                  ATTENTE
                  Ecran2_Minutes();
-                 //if(min>58) min=0;
+                 if(min>58) min=0;
                  }
             if(TOUCHMoins)
              {
-                time.tm_min=time.tm_min-1;
+                min=min-1;
                 wait (0.3);
                  Ecran2_Minutes();
-                //if(min>2) min=59;
+                if(min>2) min=59;
                  }
             if ((TOUCHOK) || (TOUCHRETOUR)){
                 etat= etat2;
@@ -342,13 +430,39 @@
                 ATTENTE
             }              
        break;  
-        
         case etat3: 
          if (affiche==1)
          { 
              Ecran3();
              affiche=0;
-          }  
+          } 
+          
+          if(TOUCHAcquire)
+            {
+                printf("debut d'acquisition!\n");   
+ 
+                mkdir("/sd/mydir", 0777);
+    
+                FILE *fp = fopen("/sd/mydir/Aquisition panneau.txt", "w");
+                if(fp == NULL) {
+                    error("Could not open file for write\n");
+                             }
+                       fprintf(fp,"valeur d'irradiation %f\n",Vpan.read()*3.3);
+                       fprintf(fp," valeur tension panneau %f\n",Ipan.read()*3.3);
+                       fprintf(fp," valeur temperature panneau %f\n",Tpan.read()*3.3);
+                       fprintf(fp," valeur irradiation panneau %f\n",Irr.read()*3.3);
+                       fprintf(fp," valeur tension batterie %f\n",Vbat.read()*3.3);
+                       fprintf(fp," valeur courant batterie %f\n",Ibat.read()*3.3);
+                       fclose(fp); 
+ 
+                         printf("acquisition reussi!\n");
+                         
+            }   
+            if (TOUCHSHOWTIME)     
+             {
+              reg_time();
+              affiche=1; 
+             }      
           if (TOUCHRETOUR)
               {
                 etat= etat1;
@@ -356,20 +470,53 @@
                  ATTENTE
               }
         break;
-        
-        case etat4:
-        if (affiche==1)
+    /////////////////
+        case Etat_ecran_affichage:
+         if (((Vpan.read())||(Ipan.read())||(Tpan.read())||(Irr.read())||(Vbat.read())||(Ibat.read()))&&affiche==1)
         { 
-          Ecran4();
-          affiche=0;
-        }  
-        if (TOUCHRETOUR)
+           EcranUtilis_ok();
+           affiche=0;
+          
+        } if(~((Vpan.read())||(Ipan.read())||(Tpan.read())||(Irr.read())||(Vbat.read())||(Ibat.read()))&&affiche==1)
+        {   
+               EcranUtilis_fail();
+                affiche=0;
+               }
+        if (TOUCHSHOWTIME)     
+             {
+              reg_time();
+              affiche=1; 
+             }    
+         if (TOUCHRETOUR)
           {
           etat= etat1;
           affiche=1;
            ATTENTE
           }
         break; 
+        /////////////
+         case Etat_ecranUtilis:
+         if (((Vpan.read())||(Ipan.read())||(Tpan.read())||(Irr.read())||(Vbat.read())||(Ibat.read()))&&affiche==1)
+        { 
+           EcranUtilis_ok();
+           affiche=0;
+          
+        }else if(affiche==1){   
+               EcranUtilis_fail();
+                affiche=0;
+               }
+        if (TOUCHSHOWTIME)     
+             {
+              reg_time();
+              affiche=1; 
+             }    
+         if (TOUCHRETOUR)
+          {
+          etat= etat0;
+          affiche=1;
+           ATTENTE
+          }
+        break; 
        }   
      } 
    }