vibratime

Revision:
9:a3c4335a1e09
Parent:
8:281ad9672a53
--- a/main.cpp	Wed Mar 25 14:14:55 2020 +0000
+++ b/main.cpp	Wed Dec 02 15:09:51 2020 +0000
@@ -27,6 +27,42 @@
         char fri[30]="Fri";
         char sat[30]="Sat";
         char sun[30]="Sun"; 
+/*
+Il Software a seconda se è Lunedì, Martedì ecc leggerà
+dalla schedina microSD il file relativo
+
+File EventiRilascioLu.txt
+I campi separati da virgola sono :
+Ora     :
+Settore _n  :
+Settore _n  :
+Settore _n  :
+Settore _n  :
+Esempio righe file :
+0815,S04,S05 ( vuol dire che alle 8,15 dovrà cadere nell’imbuto il Cortisone e il Cardura )
+1200,S06,S09,S12
+1800,S03,S05,S10
+2000,S01,S04
+
+File EventiRilascioMa.txt
+I campi separati da virgola sono :
+Ora     :
+Settore _n  :
+Settore _n  :
+Settore _n  :
+Settore _n  :
+Esempio righe file :
+0815,S01,S05
+1200,S06,S09,S12
+1800,S03,S05,S10
+
+*/
+
+
+// questi dati li caricherò leggendoli dalla scheda microSD
+// all'inizio del programma
+
+
 
 char giorno1[4]="Sun"; 
 char ora1[3]="04";
@@ -70,6 +106,21 @@
 char ora[3];
 char minu[3];       
 
+
+// valori del giorno corrente
+int ora_d=0;
+int min_d=0;
+int sett_d1=0;
+int sett_d2=0;
+int sett_d3=0;
+int sett_d4=0;
+int sett_d5=0;
+int sett_d6=0;
+int sett_d7=0;
+
+
+// pin a cui è collegato il sensore di vibrazione
+// che segnala la caduta della pillola nell'imbuto
 DigitalIn vibra(D7);
 int present_condition = 0;
 int previous_condition = 0;
@@ -82,7 +133,7 @@
 int stato;
 
 
-
+// pin a cui è collegato il motore passo-passo
 DigitalOut IN1(D8);
 DigitalOut IN2(D9);
 DigitalOut IN3(D10);
@@ -91,6 +142,63 @@
 const int MotoreOFF = 99; // motore spento
 
 
+void leggomicroSD()
+{
+    
+}
+void leggoSD(int gg)
+{
+// leggo da microSD il file EventiRilascioLu.txt
+// in ragione del parametro del giorno della settimana
+// passato come parametro
+    if (gg==1)
+    {
+   //    leggo da SD EventiRilascioLu.txt
+   // 0815,S04,S05
+   // 1200,S06,S09,S12
+   // 1800,S03,S05,S10 
+   
+   ora_d=8;
+   min_d=15;
+   sett_d1=4;
+   sett_d2=5;
+
+   
+    }
+
+    if (gg==2)
+    {
+   //    leggo da SD EventiRilascioLu.txt
+  //  0815,S01,S05
+  //  1200,S06,S09,S12
+  //  1800,S03,S05,S10
+   
+   ora_d=8;
+   min_d=15;
+   sett_d1=1;
+   sett_d2=5;
+   
+    }
+    
+       if (gg==3)
+    {
+   //    leggo da SD EventiRilascioLu.txt
+  //  0815,S01,S05
+  //  1200,S06,S09,S12
+  //  1800,S03,S05,S10
+   
+   ora_d=9;
+   min_d=20;
+   sett_d1=3;
+   sett_d2=6;
+   
+    }
+
+     printf(" ora: %d\r\n", ora_d);
+    printf(" minuto settore: %d\r\n", min_d);       
+     printf(" Settore1 : %d\r\n", sett_d1);
+    printf(" Settore2 : %d\r\n", sett_d2);
+}
 
 void Uscita( int i4,int i3,int i2,int i1)
 {
@@ -98,12 +206,7 @@
     if (i2==1) IN2=1; else IN2=0;
     if (i3==1) IN3=1; else IN3=0;
     if (i4==1) IN4=1; else IN4=0;
-/*
-  if (i1==1) digitalWrite(IN1,HIGH); else digitalWrite(IN1,LOW);
-  if (i2==1) digitalWrite(IN2,HIGH); else digitalWrite(IN2,LOW);
-  if (i3==1) digitalWrite(IN3,HIGH); else digitalWrite(IN3,LOW);
-  if (i4==1) digitalWrite(IN4,HIGH); else digitalWrite(IN4,LOW);
-  */
+
 }
 
 
@@ -129,7 +232,7 @@
        case 12: Uscita(0,1,0,0); break;
        case 13: Uscita(1,1,0,0); break;
        case 14: Uscita(1,0,0,0); break;
-//       case 7: Uscita(1,0,0,1); break;
+
        case MotoreOFF: //OFF
           Uscita(0,0,0,0); break;
     } 
@@ -142,12 +245,7 @@
   EseguiPasso(MotoreOFF); 
   for(int i=0; i<10; i++)
    {
-//     digitalWrite(13,HIGH);
-//    wait_ms(250);
- //    delay(250);
-//     digitalWrite(13,LOW);
-//    wait_ms(250);
-  //   delay(250);
+
    } 
 }  
 
@@ -222,21 +320,27 @@
 
 //    set_time(1256729737);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
 
-    set_time(dataUnix);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
-   
+    set_time(dataUnix);  // Set RTC time to Data KB
+
+// leggo dalla scheda microD le scadenze Medicine e le metto in apposite variabili
+
+    //    leggomicroSD();
+          
     while (true) {
         previous_condition = present_condition;
         present_condition = vibra.read();    
         printf(" VALORE : %d\r\n", present_condition);   
         if (previous_condition != present_condition) {
-            printf(" Pillola caduta : %d\r\n", present_condition);  
+            printf(" Pillola caduta : %d\r\n", present_condition);
+ // attesa per verificare a video il messaggio di pillola caduta           
+                wait_ms(1000);   
                     }
  
  
         time_t seconds = time(NULL);
         
-        printf("Time as seconds since January 1, 1970 = %u\n", (unsigned int)seconds);
-        
+ //       printf("Time as seconds since January 1, 1970 = %u\n", (unsigned int)seconds);
+ //       
         printf("Time as a basic string = %s", ctime(&seconds));
 
         char bufH[15];
@@ -248,16 +352,22 @@
 
    if(strncmp(buf, mon, 3)==0)
     {
-        printf("Ho letto LUNEDI  \r\n");    
+        printf("Ho letto LUNEDI  \r\n");
+        // se non la ho già letta leggo il file   EventiRilascioLu.txt
+                   leggoSD(1);        
+
+ 
     }
    if(strncmp(buf, tue, 3)==0)
     {
-        printf("Ho letto MARTEDI  \r\n");    
+        printf("Ho letto MARTEDI  \r\n"); 
+                    leggoSD(2);      
     }
 
    if(strncmp(buf, wed, 3)==0)
     {
-        printf("Ho letto MERCOLEDIì  \r\n");    
+        printf("Ho letto MERCOLEDI  \r\n"); 
+                           leggoSD(3);        
     }  
    if(strncmp(buf, thu, 3)==0)
     {
@@ -276,33 +386,70 @@
     {
         printf("Ho letto DOMENICA  \r\n");    
     }  
+ 
+ 
+ 
     
+// metto l'0ra di sistema in buffer per poi estrarre l'ora , i minuti , e ampm
+// che in seguito confronterò con quelli memorizzati sulla scheda microSD
+// caricati dal medico via WiFi
         char buffer[32];
         strftime(buffer, 8, "%I:%M %p\n", localtime(&seconds));
   //      printf("Time as a custom formatted string = %s\r\n", buffer);
+  
+  // estraggo ora dal buffer
         ora[0] = buffer[0];
         ora[1] = buffer[1];
+  // estraggo i minuti dal buffer
         minu[0] = buffer[3];
         minu[1] = buffer[4];
                         
         printf("ora = %s\r\n", ora);
         printf("minuti = %s\r\n", minu);
- 
+  // estraggo ampm (mattina-pomeriggio) dal buffer 
         ampm[0] = buffer[6];
         ampm[1] = buffer[7];        
 
 
         printf("Mattina/Pomeriggio= %s\r\n", ampm);
+
+                wait_ms(1000);
+
+
     if(strncmp(ora, ora1, 2)==0 and strncmp(minu, min1, 2)==0)
     {
         printf("è ora medicina e minuto prima MEDICINA  \r\n");    
     } 
 
-
+// verifico
     if(strncmp(buf, giorno1, 3)==0 and strncmp(ora, ora1, 2)==0 and strncmp(minu, min1, 2)==0 and strncmp(ampm, am1, 2)==0)
     {
         printf("Vai a settore S1  \r\n");    
     } 
+    if(strncmp(buf, giorno2, 3)==0 and strncmp(ora, ora1, 2)==0 and strncmp(minu, min1, 2)==0 and strncmp(ampm, am1, 2)==0)
+    {
+        printf("Vai a settore S2  \r\n");    
+    } 
+    if(strncmp(buf, giorno3, 3)==0 and strncmp(ora, ora1, 2)==0 and strncmp(minu, min1, 2)==0 and strncmp(ampm, am1, 2)==0)
+    {
+        printf("Vai a settore S3 \r\n");    
+    } 
+    if(strncmp(buf, giorno4, 3)==0 and strncmp(ora, ora1, 2)==0 and strncmp(minu, min1, 2)==0 and strncmp(ampm, am1, 2)==0)
+    {
+        printf("Vai a settore S4 \r\n");    
+    } 
+    if(strncmp(buf, giorno5, 3)==0 and strncmp(ora, ora1, 2)==0 and strncmp(minu, min1, 2)==0 and strncmp(ampm, am1, 2)==0)
+    {
+        printf("Vai a settore S5  \r\n");    
+    } 
+    if(strncmp(buf, giorno6, 3)==0 and strncmp(ora, ora1, 2)==0 and strncmp(minu, min1, 2)==0 and strncmp(ampm, am1, 2)==0)
+    {
+        printf("Vai a settore S6  \r\n");    
+    } 
+    if(strncmp(buf, giorno7, 3)==0 and strncmp(ora, ora1, 2)==0 and strncmp(minu, min1, 2)==0 and strncmp(ampm, am1, 2)==0)
+    {
+        printf("Vai a settore S7  \r\n");    
+    } 
 
 
     if(strncmp(ora, ora2, 2)==0 and strncmp(minu, min2, 2)==0)
@@ -319,7 +466,7 @@
     {
         printf("è minuto  medicina 1  \r\n");    
     }  
-                                           
+ /*                                          
     if(strncmp(ampm, am, 2)==0)
     {
         printf("è mattino  \r\n");    
@@ -328,6 +475,6 @@
     {
         printf("è pomeriggio  \r\n");    
     }  
-
+*/
     }
-}
+}
\ No newline at end of file