Nelson Santos / Mbed 2 deprecated trabalho

Dependencies:   X_NUCLEO_IKS01A1-f255a2c75ecb mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
nlsantos
Date:
Sun May 15 22:54:04 2016 +0000
Parent:
7:ed4a10ebe720
Child:
10:2f9585ff5a7b
Commit message:
it is now able to specify sampling period;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun May 15 22:07:10 2016 +0000
+++ b/main.cpp	Sun May 15 22:54:04 2016 +0000
@@ -31,26 +31,27 @@
 int main()
 {
 
-
-
     printf("Sampling started...\n");
 
     printf("\n\rWelcome! Type one of the following commands");
+    printf("\n\ Don't forget to use only capitals when typing the commands!");
     printf("\n\r READ ALL\n\r READ <n>\n\r DELETE ALL\n\r DELETE <n>");
     printf("\n\r SETDATE dd mm yyyy\n\r SETTIME hh mm ss");
     printf("\n\r SETT <T>\n\r STATE <x>\n\r LOGGING <x>\n\r EXIT\n\n\r");
 
     //Initialise time
     set_time(0);
+
+    //ISR to sample data
     Ticker ticker;
     ticker.attach(e.sampleData, e.T);
 
 
-    //getThread = new Thread(e.getData);
-
     char command[20];
     char arg[10];
 
+    //User commands
+
     while(1) {
         scanf("%s", command);
 
@@ -67,7 +68,7 @@
 
             else printf("The argument is invalid\n\r");
         }
-
+///////////////////////////////////////////////////////////////////////////////////////////////////////
         else if (strcmp("DELETE", command)==0) {
             scanf("%s", arg);
             printf("\n");
@@ -85,7 +86,7 @@
 
             else printf("The argument is invalid\n\r");
         }
-
+////////////////////////////////////////////////////////////////////////////////////
         else if (strcmp("SETDATE", command)==0) {
             char day[2], month[2], year[4];
             //Read day
@@ -107,7 +108,7 @@
                 printf("DATE UPDATED TO %d %d %d", t.tm_mday,
                        t.tm_mon+1, t.tm_year+1900);
                 set_time(mktime(&t));
-            } else printf("Date inserted is invalid\n\r");
+            } else perror("Date inserted is invalid\n\r");
         }
 
         else if (strcmp("SETTIME", command)==0) {
@@ -130,37 +131,38 @@
             if (mktime(&t)>0) {
                 set_time(mktime(&t));
                 printf("TIME UPDATED TO %d %d %d", t.tm_hour, t.tm_min, t.tm_sec);
-            } else printf("Time inserted is invalid\n\r");
+            } else perror("Time inserted is invalid\n\r");
         }
 
+            // Set sampling period
         else if (strcmp("SETT", command)==0) {
             scanf("%s", arg);
             printf("\n");
             if (atof(arg) >= 0.1 && atof(arg) <= 60.0 ) {
                 e.T = atof(arg);
+                ticker.attach(e.sampleData,e.T);
                 printf("T UPDATED TO %.1f", e.T);
-            }
-            //else throw std::out_of_range ("T MUST BE WITHIN 0.1 AND 60.0");
+            } else perror ("Value must be between 1 and 60");
+    
+            //Toggle sampling on and off
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
         } else if (strcmp("STATE", command)==0) {
             scanf("%s", arg);
             printf("\n");
             if (strcmp("ON", arg)==0) {
                 ticker.attach(e.sampleData, e.T);
-                getThread = new Thread(e.getData);
                 printf("SAMPLING ON");
             } else if (strcmp("OFF", arg)==0) {
                 ticker.detach();
-                getThread->terminate();
                 printf("SAMPLIG OFF");
             }
 
-            else printf("The argument is invalid\n\r");
+            else perror("The argument is invalid\n\r");
         }
-        
-        
-/////////////////////////////////////////////////////////////////////////////////////////////////
+
+            //Toggle debug messages  on and off
+            
+            
         //TODO Create logging thread and log
         else if(strcmp("LOGGING", command)==0) {
             scanf("%s", arg);
@@ -169,7 +171,7 @@
                 logThread = new Thread(u.logging);
             else if (strcmp("OFF", arg)==0)
                 logThread->terminate();
-            else printf("The argument is invalid\n\r");
+            else perror ("The argument is invalid\n\r");
         }
 
         else if (strcmp("Q", command) == 0) {
@@ -180,14 +182,13 @@
             break;
         }
 
-        else printf("\nThere is no command matching. Try again");
+        else perror("\nThere is no command matching. Try again");
 
         // Clear the input to avoid it to being reused in the next cycle
         command[0] = arg[0] = 0;
         printf("\n\r");
     }
 
-    ticker.detach();
 
     return 0;
 }