v3 soft

Dependencies:   LPS25H hts221

Fork of SOFT253_Assignment_V3 by Panagiotis Mitseas

Revision:
42:ac413d9fb994
Parent:
41:0f4a18bb1f83
Child:
43:d7cb544ad771
diff -r 0f4a18bb1f83 -r ac413d9fb994 main.cpp
--- a/main.cpp	Sat May 13 20:28:50 2017 +0000
+++ b/main.cpp	Sun May 14 00:09:28 2017 +0000
@@ -5,7 +5,7 @@
 
 Serial pc(USBTX, USBRX);
 
-#define NUMTHRDS 2
+
 #define N 10
 DigitalOut myled(D7);
 Ticker t;
@@ -17,9 +17,9 @@
 char cmd[20];
 char cmd2[20];
 char input1[20];
-char input11[20];
+char input2[20];
+char stringToCompare1[20];
 char stringToCompare2[20];
-char stringToCompare22[20];
 float tempArray[N];
 float humArray[N];
 float pressArray[N];
@@ -54,6 +54,7 @@
 
 void adcISR()
 {
+      
        message_t *message = mail_box.alloc();
        message->tempVal = tempCelsius;
        message->humVal = humi;
@@ -97,87 +98,64 @@
 {
   int res;
   int res2;
-  
-  
-
          pc.baud(115200);
          pc.printf("Temperature,Humidity,Pressure\n\n");
          //while(cmd==NULL){cmd=getchar();}
          while(1)
          {
             scanf("%s%s",&cmd,&cmd2);
-        
             //READ ALL------------------------------------------
-            //pc.printf("YOU ENTERED: %s \n",cmd);
-            
-            
-            strcpy (input1,cmd);   //INPUT 1
-            strcpy (input11,cmd2); //INPUT 2  
-            strcpy (stringToCompare2,"READ"); //STRING TO COMPARE 1
-            strcpy (stringToCompare22,"ALL"); //STRING TO COMPARE 2
-            res = strncmp(input1,stringToCompare2,20);
-            res2 = strncmp(input11,stringToCompare22,20);
+            //INPUT 2  
            
-            if (res==0 && res2==0)
-            {             
-               for (unsigned int n=0; n<N; n++)
-                {
-                  pc.printf("the element of %d is %4.2f\n\r ",n,tempArray[n]);
-                  // wait(1.0);
-                }
-            }
-            else //1
-           {   
-                strcpy (stringToCompare2,"DELETE");
-                strcpy (stringToCompare22,"ALL");
-                res = strncmp(input1,stringToCompare2,20);
-                res2 = strncmp(input11,stringToCompare22,20);
+                     strcpy (input1,cmd);   //INPUT 1
+                     pc.printf("you entered: %s\n\r ",input1);
+                     strcpy (input2,cmd2);
+                     strcpy (stringToCompare1,"READ"); //STRING TO COMPARE 1
+                     strcpy (stringToCompare2,input2); //STRING TO COMPARE 2
+                     res = strncmp(input1,stringToCompare1,20);
+                     res2 = strncmp(input2,stringToCompare2,20);
+                     int val = atoi(input2);
+                     if (val <=10 && val >=1)
+                        {
+                            if (res==0 && res2==0)
+                                {      
+                                    pc.printf("the element of %d is %4.2f\n\r ",val,tempArray[val]);
+                                }
+                        } 
+                      
+                    else //1
+                      {
+                         strcpy (stringToCompare1,"READ"); //STRING TO COMPARE 1
+                         strcpy (stringToCompare2,"ALL"); //STRING TO COMPARE 2
+                         res = strncmp(input1,stringToCompare1,20);
+                         res2 = strncmp(input2,stringToCompare2,20);
+           
+                            if (res==0 && res2==0)
+                                     {
+                                        for (unsigned int n=0; n<N; n++)
+                                            {
+                                               pc.printf("the element of %d is %4.2f\n\r ",n,tempArray[n]);
+                                            }
+                                      }
+                             else //2
+                                         {   
+                                             strcpy (stringToCompare1,"DELETE");
+                                             strcpy (stringToCompare2,"ALL");
+                                             res = strncmp(input1,stringToCompare1,20);
+                                             res2 = strncmp(input2,stringToCompare2,20);
                 
-                if(res==0 && res2==0)
-                {
-                    //Delete every element.
-                    memset(tempArray, 0, sizeof tempArray);               
-                    pc.printf("%d Elements deleted\n",N);
-                }
-                else //2
-                {
-                    strcpy (stringToCompare2,"READ");
-                    strcpy (stringToCompare22,"Kapoion arithmo");
-                    res = strncmp(input1,stringToCompare2,20);
-                    res2 = strncmp(input11,stringToCompare22,20);
-
-                    if(res==0 && res2==0)
-                    {
-                        
-                    }
-                    else //3
-                    {
-                        strcpy (stringToCompare2,"DELETE");
-//                        strcpy (stringToCompare22,"Kapoion arithmo");
-//                        res = strncmp(input1,stringToCompare2,20);
-//                        res2 = strncmp(input11,stringToCompare22,20);
-                        
-//                        int numberOfElements; //To input sto DELETE <n>
-                        
-                        
-//                        if(res==0 && res2==0)
-//                        {
-//                            memset(tempArray, 0, numberOfElements);  
-//                        }
-//                        else //4
-//                        {
-                            //EDW tha paei to setDate
-                            
-//                        }//End of else 4
-                    }//End of else 3
-                }//End of else 2
-            }//End of else 1    
-            
-   
-            
-          }//End of while
+                                             if(res==0 && res2==0)
+                                                {
+                                                     //Delete every element.
+                                                      memset(tempArray, 0, sizeof tempArray);               
+                                                    pc.printf("%d Elements deleted\n",N);
+                                                } 
+                                         }//else 2  
+                     }//else1
+         }//while
+    }
  
- }
+ 
  char answer;
 int main(void)
   { 
@@ -191,7 +169,7 @@
     //threadcomun();
     
     //Thread thread(threadcomun);
-    t.attach(&adcISR,5); // timer of measurements 
+    t.attach(&adcISR,15); // timer of measurements 
     
     while(1) 
     {