APS SO

Dependencies:   WebSocketClient mbed

Fork of APS_SO by Ian Bolfarini

Revision:
1:3da12598c635
Parent:
0:f603fa86c646
Child:
2:27a7a42b2bae
--- a/main.cpp	Thu Oct 26 21:12:28 2017 +0000
+++ b/main.cpp	Sat Oct 28 22:45:10 2017 +0000
@@ -16,12 +16,16 @@
  {
     int hora, min, seg, dia, mes, ano, opt;
     
-    gSerial.printf("1-Ajuste de Hora, 2-Ajuste de Data, 3-Ajuste de Data/Hora);
+    gSerial.printf("\n1-Ajuste de Hora, 2-Ajuste de Data, 3-Ajuste de Data/Hora: ");
     gSerial.scanf("%d",&opt);
+   /* if(opt >=1 && opt <=3){
+        
+        
+                }  */
     
     if(opt == 1 || opt ==3 ) {
                     
-    gSerial.printf("Insira a hora(HH MM SS): ");
+    gSerial.printf("\nInsira a hora(HH MM SS): ");
     gSerial.scanf("%d %d %d", &hora, &min, &seg);
     
     if( (hora < 24 && hora>=0) && (min>=0 && min <60) && (seg>=0 && seg <60)) 
@@ -31,6 +35,9 @@
                    alarm_time.hour = hora;
                    alarm_time.min = min;
                    alarm_time.sec = seg;      
+                   //alarm_time.date = 28;
+                   //alarm_time.mon = 10;
+                   //alarm_time.year = 2017;
                    rtc.setTime(alarm_time, true, false);
                    rtc.getTime(alarm_time);
                    gSerial.printf("\nHora Ajustada: %2d:%02d:%02d \n",alarm_time.hour,alarm_time.min,alarm_time.sec);
@@ -44,36 +51,69 @@
              } 
              
              
-             if(opt==2 || opt ==3)
+          if(opt==2 || opt ==3)
              {
                  
                 gSerial.printf("Insira a data(DIA MES ANO): ");
                 gSerial.scanf("%d %d %d", &dia, &mes, &ano);
+                if((dia < 32 && dia >0 && mes<13 && mes>0  && ano>2000) && !(mes == 2 && dia >=29 ) && !((mes == 4 || mes == 6 || mes == 9 || mes == 11)  && dia >30))
+                {
                  
+                    
+                   rtc.getTime(alarm_time);
+                   alarm_time.date = dia;
+                   alarm_time.mon = mes;
+                   alarm_time.year = ano;      
+                   rtc.setTime(alarm_time, true, false);
+                   rtc.getTime(alarm_time);
+                   gSerial.printf("\nData Ajustada: %2d/%02d/%d \n",alarm_time.date,alarm_time.mon,alarm_time.year);
                  
+                 }
+                 
+                 else gSerial.printf("Entrada Incorreta.\n");  
                  
                  
             } 
+            
+            else gSerial.printf("Opcao Invalida!.\n");
              
+
              
              
                 
  }               
+ 
+void ajus_data_hora()
+    
+{
+
+   char hadj;
+   gSerial.printf("Deseja ajustar a hora? - Caso sim digite s: ");
+   gSerial.scanf("%c",&hadj);
+   if(hadj=='s')
+   {
+    set_time_serial();
+    
+    }
+
+}
+  
                 
 
 
 int main()
 {   
-    //alarm_time.hour=16;
-    //alarm_time.min=59;
-    //alarm_time.sec=40;
-    //rtc.setTime(alarm_time, true, false);
-   // int hora=0;
-  // gSerial.printf("Insira a hora:");
-   //gSerial.scanf("%d",&hora);
-    //gSerial.printf("Hora Inserida: %d" , hora);
-   // rtc.getTime(alarm_time);
-    //gSerial.printf("Data: %d/%d/%d\n\r",alarm_time.date,alarm_time.mon,alarm_time.year);
+
+   char hadj; //opcao do ajuste do rtc
+   gSerial.printf("Deseja ajustar a hora? - Caso sim digite s: ");
+   gSerial.scanf("%c",&hadj);
+   if(hadj=='s') //caso seja digitado s exibe as opcoes de ajuste 
+   {
+    set_time_serial();
+    
+    }
+
+
   
     while (true) {
 
@@ -85,8 +125,6 @@
                 }
                 
                 
-              //set_time_serial();
-