projet_Laos / programme_final

Dependencies:   BSP_DISCO_F746NG SDFileSystem TS_DISCO_F746NG affichage_des_ecrans mbed rtc_lib

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main_glb.cpp Source File

main_glb.cpp

00001 #include "mbed.h"
00002 #include "TS_DISCO_F746NG.h"
00003 #include "LCD_DISCO_F746NG.h"
00004 #include "ds1338.h"
00005 #include "horloge.h"
00006 #include "Ecran.h"
00007 #include "SDFileSystem.h"
00008 //définition de la zone tactile dans l'ecran principal
00009 #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))
00010 #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))
00011 
00012 // définitions des touches tactiles qui interviennent dans l'écran 1
00013 #define TOUCHTIMEDATE ((TS_State.touchDetected) && ( TS_State.touchX[0]>10) && (TS_State.touchX[0]< 165)&& (TS_State.touchY[0]>50) && (TS_State.touchY[0] < 180))
00014 #define TOUCHFREQ ((TS_State.touchDetected) && ( TS_State.touchX[0]>170) && (TS_State.touchX[0]< 328)&& (TS_State.touchY[0]>60) && (TS_State.touchY[0] < 180))        
00015 #define TOUCHAFFICHAGE ((TS_State.touchDetected) && ( TS_State.touchX[0]>333) &&( TS_State.touchX[0]< 475)&& ( TS_State.touchY[0]> 60) && (TS_State.touchY[0] < 180))
00016 
00017 //définitions des touches tactiles qui intervient dans les écrans paramettrable  
00018 #define TOUCHRETOUR ((TS_State.touchDetected) && ( TS_State.touchX[0]>30) &&( TS_State.touchX[0]< 110)&& ( TS_State.touchY[0]> 210) && (TS_State.touchY[0] < 240))
00019 #define TOUCHMoins ((TS_State.touchDetected) && ( TS_State.touchX[0]>145) &&( TS_State.touchX[0]< 225)&& ( TS_State.touchY[0]> 210) && (TS_State.touchY[0] < 240))
00020 #define TOUCHPlus ((TS_State.touchDetected) && ( TS_State.touchX[0]> 245) &&( TS_State.touchX[0]< 325)&& ( TS_State.touchY[0]> 210) && (TS_State.touchY[0] < 240))
00021 #define TOUCHOK ((TS_State.touchDetected) && ( TS_State.touchX[0]> 360) &&( TS_State.touchX[0]< 440)&& ( TS_State.touchY[0]> 210) && (TS_State.touchY[0] < 240))
00022 
00023 //définitions des touches tactiles pour régler l'heure et la date 
00024 #define TOUCHDAY ((TS_State.touchDetected) && ( TS_State.touchX[0]> 30) &&( TS_State.touchX[0]< 85)&& ( TS_State.touchY[0]> 82) && (TS_State.touchY[0] < 110))       
00025 #define TOUCHMonth ((TS_State.touchDetected) && ( TS_State.touchX[0]> 100) &&( TS_State.touchX[0]< 160)&& ( TS_State.touchY[0]> 82) && (TS_State.touchY[0] < 110))           
00026 #define TOUCHYear ((TS_State.touchDetected) && ( TS_State.touchX[0]> 170) &&( TS_State.touchX[0]< 240)&& ( TS_State.touchY[0]> 82) && (TS_State.touchY[0] < 110))    
00027 #define TOUCHHour ((TS_State.touchDetected) && ( TS_State.touchX[0]> 30) &&( TS_State.touchX[0]< 60)&& ( TS_State.touchY[0]> 164) && (TS_State.touchY[0] < 204))    
00028 #define TOUCHMinute ((TS_State.touchDetected) && ( TS_State.touchX[0]> 100) &&( TS_State.touchX[0]< 159)&& ( TS_State.touchY[0]> 164) && (TS_State.touchY[0] < 204))    
00029 #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))  
00030 
00031 //définition des touches tactiles pour le réglage de la fréquence d'envoi des données sur la carte SD 
00032 #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))
00033 #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))
00034 #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))
00035 #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))  
00036 
00037 //définition de l'attente avant l'affichage d'un nouvel écran
00038 #define ATTENTE wait(0.2);
00039 
00040 // définition des touche des chiffres pour la saisie du mot passe
00041 
00042 #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))
00043 #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))
00044 #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))
00045 #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))
00046 #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))
00047 #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))
00048 #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))
00049 #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))
00050 #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))
00051 #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))
00052 /////affichage de l'heure
00053 #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)) 
00054 
00055 int affiche=0;
00056 int password=0;
00057 
00058 
00059 TS_DISCO_F746NG ts;  
00060 
00061 DigitalOut led1(LED1);
00062 Serial pc(USBTX, USBRX);
00063                   
00064   int main()
00065   {
00066     unsigned int day =00;
00067 unsigned int month =00;
00068 unsigned int year=2000;
00069 unsigned int hour =00;
00070 unsigned int min =00;
00071 unsigned int sec=00;
00072     SDFileSystem sd(D11,D12,D13 , D3, "sd");
00073     AnalogIn Vpan(A0);
00074     AnalogIn Ipan(A1);
00075     AnalogIn Tpan(A2);
00076     AnalogIn Irr(A3);
00077     AnalogIn Vbat(A4);
00078     AnalogIn Ibat(A5);
00079     DS1338 ds1338(D14,D15);
00080     LCD_DISCO_F746NG lcd;
00081     lcd.Clear(LCD_COLOR_BLACK);
00082     lcd.SetBackColor(LCD_COLOR_BLACK);
00083     lcd.SetTextColor(LCD_COLOR_WHITE);
00084     lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"WELCOME TO LAOS PROJET", CENTER_MODE);  
00085     wait(1); 
00086     affiche=1; 
00087     
00088     struct tm time;
00089        
00090     
00091       TS_StateTypeDef TS_State;
00092       ts.Init(480, 272);
00093       
00094     time.tm_sec=0;
00095     time.tm_min=28;
00096     time.tm_hour=11;
00097     time.tm_mday=19;
00098     time.tm_year=116;
00099     time.tm_mon=9;
00100     time.tm_wday=3;
00101     time.tm_yday=0;
00102     time.tm_isdst=0;
00103     ds1338.writeTime(&time);
00104     
00105           while(1)
00106       {
00107          ts.GetState(&TS_State);  
00108         
00109          ds1338.readTime(&time);
00110         
00111          
00112     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;
00113     static type_etat etat= etat0;
00114     
00115     switch (etat)
00116          { 
00117          case etat0:
00118          if (affiche==1)
00119           { 
00120            Ecranprincipal ();
00121            affiche=0;
00122           }  
00123 
00124          if (TOUCHUTILISATEUR)
00125             { 
00126           etat= Etat_ecranUtilis;
00127           affiche=1;
00128            ATTENTE
00129              }  
00130              
00131           if (TOUCHADMINISTRATEUR)
00132              { 
00133              etat= etat_mot_de_passe;
00134              affiche=1;
00135              ATTENTE
00136              }               
00137              break;
00138 //////////////////////Mot de passe///////////////////////
00139                
00140              case etat_mot_de_passe:
00141              if(affiche==1)
00142           { 
00143           MotDePasse ();
00144           affiche=0;
00145          password=0;
00146           }  
00147          if (TOUCH2)
00148           {
00149             lcd.SetBackColor(LCD_COLOR_WHITE);
00150             lcd.SetTextColor(LCD_COLOR_BLACK);
00151             lcd.DisplayStringAt(180, LINE(1), (uint8_t *)"*",LEFT_MODE);
00152                 password=2;}
00153          if(password==2&&TOUCH7)
00154            {
00155                 lcd.SetBackColor(LCD_COLOR_WHITE);
00156                 lcd.SetTextColor(LCD_COLOR_BLACK);
00157                 lcd.DisplayStringAt(210, LINE(1), (uint8_t *)"*",LEFT_MODE);
00158                     password=7;}
00159          if(password==7&&TOUCH5)
00160               {
00161                 lcd.SetBackColor(LCD_COLOR_WHITE);
00162                 lcd.SetTextColor(LCD_COLOR_BLACK);
00163                 lcd.DisplayStringAt(240, LINE(1), (uint8_t *)"*",LEFT_MODE);
00164                 password=5;}
00165          if(password==5&&TOUCHVALID)
00166          {
00167             etat= etat1;
00168              affiche=1;
00169             ATTENTE
00170              }
00171              
00172          if ( TOUCH1|| TOUCH3 || TOUCH4 || TOUCH6|| TOUCH8|| TOUCH9)
00173        
00174            { 
00175            lcd.SetBackColor(LCD_COLOR_WHITE);
00176            lcd.SetTextColor(LCD_COLOR_BLACK);
00177            lcd.DisplayStringAt(140, LINE(2), (uint8_t *)"pass invalid",LEFT_MODE); 
00178            wait (1);
00179            affiche=1;
00180            
00181           if(affiche==1)
00182           { 
00183           MotDePasse ();
00184           affiche=0;
00185          password=0;
00186           } 
00187            }
00188            if(TOUCHRETOUR)
00189            {
00190               etat= etat0;
00191              affiche=1;
00192              ATTENTE
00193             } 
00194              break;
00195              
00196              ////////////////////////////////////////////////////////
00197              
00198            case etat1: 
00199           if (affiche==1)
00200           { 
00201            ATTENTE
00202            EcranAdminis ();
00203             
00204            affiche=0;
00205             }  
00206 
00207            if (TOUCHTIMEDATE)     
00208              {
00209               etat= etat2;
00210              affiche=1; 
00211              }
00212            if  (TOUCHFREQ) 
00213            {
00214              etat= etat3;
00215              affiche=1; 
00216             } 
00217           if (TOUCHAFFICHAGE)
00218              {
00219                ATTENTE
00220               etat=Etat_ecran_affichage;
00221               affiche=1;
00222              }
00223           if (TOUCHSHOWTIME)     
00224              {
00225               reg_time();
00226               affiche=1; 
00227              }    
00228           if (TOUCHRETOUR)
00229               {
00230                 etat= etat0;
00231                 affiche=1;
00232                  ATTENTE;
00233               }   
00234           break;
00235           
00236          case etat2:   
00237             if (affiche==1)
00238             { 
00239             Ecran2();
00240             affiche=0;
00241             }  
00242             if (TOUCHRETOUR)
00243               {
00244                 etat= etat1;
00245                 affiche=1;
00246                  ATTENTE
00247               }
00248                if (TOUCHDAY)
00249                 {
00250              etat= etat_reg_day;
00251              affiche=1; 
00252             } 
00253               if (TOUCHMonth)
00254              {
00255                etat=etat_reg_month; 
00256                affiche=1; 
00257              }
00258            if (TOUCHYear)
00259              {
00260                etat=etat_reg_year; 
00261                affiche=1; 
00262              }
00263               if (TOUCHHour)
00264              {
00265                etat=etat_reg_hour; 
00266                affiche=1; 
00267              } 
00268               if (TOUCHMinute)
00269              {
00270                etat=etat_reg_minute; 
00271                affiche=1; 
00272              }
00273               if (TOUCHRETOUR)
00274               {
00275                 etat= etat1;
00276                 affiche=1;
00277                 ATTENTE
00278               } 
00279            if (TOUCHSeconde)
00280              {
00281                time.tm_sec=0; 
00282                affiche=1; 
00283              } 
00284              if (TOUCHSHOWTIME)     
00285              {
00286               reg_time();
00287               affiche=1; 
00288              }           
00289           break;
00290           
00291       
00292       
00293            
00294             
00295          case etat_reg_day:   
00296             if (affiche==1)
00297             {   
00298             Ecran2_Day();
00299             affiche=0;
00300             }
00301             
00302             if(TOUCHPlus){
00303                  day=day+1;
00304                  ATTENTE
00305                  Ecran2_Day();
00306                  if(day>30) day=0;
00307             }
00308             if(TOUCHMoins)
00309              {
00310                  day=day-1;
00311                  wait (0.3);
00312                  Ecran2_Day();
00313                  if(day<2) day=32;
00314              }    
00315            if ( (TOUCHOK)||(TOUCHRETOUR) )
00316               {
00317                 etat= etat2;
00318                 affiche=1;
00319                  ATTENTE
00320               }
00321        break;
00322            
00323          case etat_reg_month:   
00324             if (affiche==1){   
00325                 Ecran2_Month();
00326                 affiche=0;
00327                 }
00328             if(TOUCHPlus)
00329              {
00330                  month=month+1;
00331                   ATTENTE
00332                  Ecran2_Month();
00333                  if(month>11) month=0;
00334                  }
00335             if(TOUCHMoins)
00336              {
00337                   month=month-1;
00338                   ATTENTE
00339                  Ecran2_Month();
00340                   if(month<2) month=13;
00341                  
00342             }
00343             if ( (TOUCHOK)|| (TOUCHRETOUR))
00344               {
00345                 etat= etat2;
00346                 affiche=1;
00347                  ATTENTE
00348               }    
00349               
00350           break;
00351        case etat_reg_year:   
00352               if (affiche==1){  
00353                   Ecran2_Year ();
00354                   affiche=0;
00355                    }          
00356             
00357                 if(TOUCHPlus)
00358                  {
00359                    year=year+1;
00360                    ATTENTE
00361                      Ecran2_Year();
00362                    if(year>3000) year=2000;
00363                  }
00364                 if(TOUCHMoins)
00365                   {
00366                    year=year-1;
00367                    ATTENTE
00368                    Ecran2_Year();
00369                    if(year<2000) year=3000;
00370                    }
00371                 if ((TOUCHOK) ||(TOUCHRETOUR))
00372                   {
00373                    etat= etat2;
00374                    affiche=1;
00375                    ATTENTE
00376                   }      
00377            
00378        break;
00379        
00380         case etat_reg_hour:   
00381             if (affiche==1){  
00382                 affiche=0;
00383                 Ecran2_Hour();
00384             }     
00385             
00386                 if(TOUCHPlus){
00387                     hour=hour+1;
00388                     ATTENTE
00389                      Ecran2_Hour();
00390                     if(hour>22) hour=0;
00391                 }
00392                 if(TOUCHMoins){
00393                     hour=hour-1;
00394                     ATTENTE
00395                      Ecran2_Hour();
00396                     if(hour<1) hour=24;
00397                 }
00398             
00399             if ((TOUCHOK)||(TOUCHRETOUR)){
00400                 etat= etat2;
00401                 affiche=1;
00402                 ATTENTE
00403             }        
00404        break;  
00405        
00406        
00407        case etat_reg_minute:   
00408             if (affiche==1)
00409             {   Ecran2_Minutes();
00410                  affiche=0;
00411               } 
00412            
00413             if(TOUCHPlus)
00414              {
00415                  min=min+1;
00416                  ATTENTE
00417                  Ecran2_Minutes();
00418                  if(min>58) min=0;
00419                  }
00420             if(TOUCHMoins)
00421              {
00422                 min=min-1;
00423                 wait (0.3);
00424                  Ecran2_Minutes();
00425                 if(min>2) min=59;
00426                  }
00427             if ((TOUCHOK) || (TOUCHRETOUR)){
00428                 etat= etat2;
00429                 affiche=1;
00430                 ATTENTE
00431             }              
00432        break;  
00433         case etat3: 
00434          if (affiche==1)
00435          { 
00436              Ecran3();
00437              affiche=0;
00438           } 
00439           
00440           if(TOUCHAcquire)
00441             {
00442                 printf("debut d'acquisition!\n");   
00443  
00444                 mkdir("/sd/mydir", 0777);
00445     
00446                 FILE *fp = fopen("/sd/mydir/Aquisition panneau.txt", "w");
00447                 if(fp == NULL) {
00448                     error("Could not open file for write\n");
00449                              }
00450                        fprintf(fp,"valeur d'irradiation %f\n",Vpan.read()*3.3);
00451                        fprintf(fp," valeur tension panneau %f\n",Ipan.read()*3.3);
00452                        fprintf(fp," valeur temperature panneau %f\n",Tpan.read()*3.3);
00453                        fprintf(fp," valeur irradiation panneau %f\n",Irr.read()*3.3);
00454                        fprintf(fp," valeur tension batterie %f\n",Vbat.read()*3.3);
00455                        fprintf(fp," valeur courant batterie %f\n",Ibat.read()*3.3);
00456                        fclose(fp); 
00457  
00458                          printf("acquisition reussi!\n");
00459                          
00460             }   
00461             if (TOUCHSHOWTIME)     
00462              {
00463               reg_time();
00464               affiche=1; 
00465              }      
00466           if (TOUCHRETOUR)
00467               {
00468                 etat= etat1;
00469                 affiche=1;
00470                  ATTENTE
00471               }
00472         break;
00473     /////////////////
00474         case Etat_ecran_affichage:
00475          if (((Vpan.read())||(Ipan.read())||(Tpan.read())||(Irr.read())||(Vbat.read())||(Ibat.read()))&&affiche==1)
00476         { 
00477            EcranUtilis_ok();
00478            affiche=0;
00479           
00480         } if(~((Vpan.read())||(Ipan.read())||(Tpan.read())||(Irr.read())||(Vbat.read())||(Ibat.read()))&&affiche==1)
00481         {   
00482                EcranUtilis_fail();
00483                 affiche=0;
00484                }
00485         if (TOUCHSHOWTIME)     
00486              {
00487               reg_time();
00488               affiche=1; 
00489              }    
00490          if (TOUCHRETOUR)
00491           {
00492           etat= etat1;
00493           affiche=1;
00494            ATTENTE
00495           }
00496         break; 
00497         /////////////
00498          case Etat_ecranUtilis:
00499          if (((Vpan.read())||(Ipan.read())||(Tpan.read())||(Irr.read())||(Vbat.read())||(Ibat.read()))&&affiche==1)
00500         { 
00501            EcranUtilis_ok();
00502            affiche=0;
00503           
00504         }else if(affiche==1){   
00505                EcranUtilis_fail();
00506                 affiche=0;
00507                }
00508         if (TOUCHSHOWTIME)     
00509              {
00510               reg_time();
00511               affiche=1; 
00512              }    
00513          if (TOUCHRETOUR)
00514           {
00515           etat= etat0;
00516           affiche=1;
00517            ATTENTE
00518           }
00519         break; 
00520        }   
00521      } 
00522    }
00523 
00524