lucas kovaci / Mbed OS SOFT253_Assignment_Group_K

Dependencies:   LPS25H hts221

Fork of SOFT253_Assignment_V4 by lucas kovaci

Revision:
45:4ed55fd0f06f
Parent:
44:5bb7e0a2387a
Child:
46:ca411482a095
diff -r 5bb7e0a2387a -r 4ed55fd0f06f main.cpp
--- a/main.cpp	Mon May 15 00:27:39 2017 +0000
+++ b/main.cpp	Mon May 15 01:44:11 2017 +0000
@@ -36,6 +36,8 @@
 int counters = 0;
 int res;
 int res2;
+int resSet1;
+int resSet2;
 
 LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR);
 HTS221 humidity(I2C_SDA, I2C_SCL);
@@ -128,42 +130,75 @@
             //INPUT 2  
            
                      strcpy (input1,cmd);   //INPUT 1
+                     strcpy (inputSet1,cmd);
                      pc.printf("you entered: %s\n\r",input1);
                      strcpy (input2,cmd2);
+                     strcpy (inputSet2,cmd2);
                      strcpy (stringToCompare1,"READ"); //STRING TO COMPARE 1
                      strcpy (stringToCompare2,input2); //STRING TO COMPARE 2
+                     strcpy (stringToCompareSet1,"DELETE"); //STRING TO COMPARE 1
+                     strcpy (stringToCompareSet2,inputSet2);
                      res = strncmp(input1,stringToCompare1,20);
                      res2 = strncmp(input2,stringToCompare2,20);
+                     resSet1 = strncmp(input1,stringToCompareSet1,20);
+                     resSet2 = strncmp(input2,stringToCompareSet2,20);
                      int val = atoi(input2);
+                     int valDel = atoi(inputSet2);
                      if (val <=10 && val >=1)
                         {
                             if (res==0 && res2==0)
                                 {   
-                                for (unsigned int n=0; n<val; n++)
-                                            {  
-                                               pc.printf("the element of %d is %4.2f\n\r",n,tempArray[n]);
-                                            }
-                                           
-                                           
+                                  for (unsigned int n=0; n<val; n++)
+                                      {  
+                                         pc.printf("the element of %d is %4.2f\n\r",n,tempArray[n]);
+                                      }
                                 }
                         } 
-                        else //2
+                        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]);
-                                 pc.printf("the Counter: %d\n",counters);
-                               }
+                                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]);
+                                      pc.printf("the Counter: %d\n",counters);
+                                 }
+                                else 
+                                    {   
+                                        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);
+                                                 counters=0;
+                                            } 
+                                            
+                                    }
                                       
                                         
                               }       
                                    
-                                  
+                            int startDel=(counters - valDel);
+                            if (valDel <=10 && valDel >=1)
+                                 {
+                                if(resSet1==0 && resSet2==0)
+                                  {
+                                    for (unsigned int n=startDel; n<counters; n++) 
+                                          {
+                                               tempArray[n]=0.00; 
+                                                
+                                            }
+                                             pc.printf("Deleted %d records\n",valDel);
+                                             counters=counters - valDel;
+                                      }
+                            }       
                     
          }//while
     }
@@ -241,14 +276,14 @@
                      strcpy (inputSet2,cmdSet2);
                      strcpy (stringToCompareSet1,"SETT"); //STRING TO COMPARE 1
                      strcpy (stringToCompareSet2,inputSet2); //STRING TO COMPARE 2
-                     res = strncmp(inputSet1,stringToCompareSet1,20);
-                     res2 = strncmp(inputSet2,stringToCompareSet2,20);
+                     resSet1 = strncmp(inputSet1,stringToCompareSet1,20);
+                     resSet2 = strncmp(inputSet2,stringToCompareSet2,20);
                      int inputSpeed = atoi(inputSet2);
                       
                       
                      if (inputSpeed <=60 && inputSpeed >=0.1)
                         {
-                            if (res==0 && res2==0)
+                            if (resSet1==0 && resSet2==0)
                                 {   
                                 pc.printf("CURRENT SPEED %d \n",inputSpeed);
                                     sampleSpeed = inputSpeed;
@@ -269,10 +304,10 @@
     
     t1 =  new Thread(thread1);
     t2 = new Thread(threadReadComun);
-    t3 = new Thread( threadDeleteComun);
-    t4 = new Thread( threadSetTComun);
+  //  t3 = new Thread( threadDeleteComun);
+   //t4 = new Thread( threadSetTComun);
      
-   // Thread thread(thread1);
+   // Thread (thread1);
     //threadcomun();
     
     //Thread thread(threadcomun);