v3 soft

Dependencies:   LPS25H hts221

Fork of SOFT253_Assignment_V3 by Panagiotis Mitseas

Files at this revision

API Documentation at this revision

Comitter:
akovaci
Date:
Sun May 14 13:18:58 2017 +0000
Parent:
42:ac413d9fb994
Commit message:
Delete

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ac413d9fb994 -r d7cb544ad771 main.cpp
--- a/main.cpp	Sun May 14 00:09:28 2017 +0000
+++ b/main.cpp	Sun May 14 13:18:58 2017 +0000
@@ -1,3 +1,4 @@
+
 #include "mbed.h"
 #include "rtos.h"
 #include "hts221.h"
@@ -25,7 +26,7 @@
 float pressArray[N];
 uint32_t seconds = 0, minutes=0, hours=0; 
 
-
+int counters = 0;
 
 
 LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR);
@@ -42,13 +43,12 @@
 
 
 
-
 typedef struct {
       
       float tempVal ;
       float humVal;
       float pressVal;
-    }message_t;
+    }message_t; 
     
 Mail<message_t, 10> mail_box;
 
@@ -60,6 +60,18 @@
        message->humVal = humi;
        message->pressVal = barometer.pressure();
        myled=1;
+       if (counters < 10)
+       {
+           counters= counters + 1;
+       }
+       else 
+       {
+        counters =10;
+        }
+        
+           
+       
+          
        mail_box.put(message);
        //Thread::wait(1000);
        
@@ -118,10 +130,38 @@
                      if (val <=10 && val >=1)
                         {
                             if (res==0 && res2==0)
-                                {      
-                                    pc.printf("the element of %d is %4.2f\n\r ",val,tempArray[val]);
+                                {   
+                                  for (unsigned int n=0; n<val; n++)
+                                            {  
+                                               pc.printf("the element of %d is %4.2f\n\r ",n,tempArray[n]);
+                                            }
                                 }
                         } 
+                         else 
+                              {
+                                   scanf("%s%s",&cmd,&cmd2);   
+                                   strcpy (input1,cmd);
+                                    strcpy (input2,cmd2);
+                                                 
+                                  strcpy (stringToCompare1,"DELETE");
+                                  strcpy (stringToCompare2,input2);
+                                  res = strncmp(input1,stringToCompare1,20);
+                                  res2 = strncmp(input2,stringToCompare2,20);
+                                  int vals = atoi(input2);
+                                    int startDel=(counters - vals);
+                                    if(res==0 && res2==0)
+                                         {
+                                          for (unsigned int n=startDel; n<counters; n++) 
+                                              {
+                                                    tempArray[n]=0.00; 
+                                                   // pc.printf("%d number of Elements deleted\n",val);
+                                                            
+                                               }//END FOR LOOP
+                            
+                                                    //counter = counter - numberOfElements; 
+                                                  pc.printf("number of Elements deleted");
+                                        }
+                                                
                       
                     else //1
                       {
@@ -135,7 +175,9 @@
                                         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 //2
                                          {   
@@ -147,9 +189,14 @@
                                              if(res==0 && res2==0)
                                                 {
                                                      //Delete every element.
-                                                      memset(tempArray, 0, sizeof tempArray);               
-                                                    pc.printf("%d Elements deleted\n",N);
+                                                     memset(tempArray, 0, sizeof tempArray);               
+                                                     pc.printf("%d Elements deleted\n",N);
+                                                     counters=0;
                                                 } 
+                                             
+                                                
+                                              }  
+                                                
                                          }//else 2  
                      }//else1
          }//while