trabalho

Dependencies:   X_NUCLEO_IKS01A1 mbed-rtos mbed

Fork of HelloWorld_IKS01A1 by ST

Files at this revision

API Documentation at this revision

Comitter:
Jacinta
Date:
Mon May 09 01:42:41 2016 +0000
Parent:
28:840000670c88
Child:
30:673e342f1932
Commit message:
Still can't figure the problem with "ticker.attach", however fixed some other errors that showed when I commented out ticker.attach. Apart from this, the remaining errors are related with "t", which is a variable of type thread being used for time...

Changed in this revision

expansionBoard.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
userInteractions.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/expansionBoard.cpp	Sun May 08 14:49:34 2016 +0000
+++ b/expansionBoard.cpp	Mon May 09 01:42:41 2016 +0000
@@ -4,6 +4,7 @@
 
 using namespace std;
 
+
 /* Instantiate the expansion board */
 static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15);
 
@@ -16,10 +17,13 @@
 static TempSensor *temp_sensor2 = mems_expansion_board->pt_sensor;
 
 static Ticker ticker;
-float T;
 void readData();
 
+
 class ExpansionBoard {
+public:
+    float T;
+    
 private:
     /* Helper function for printing floats & doubles */
     static char *printDouble(char* str, double v, int decimalDigits=2) {
--- a/main.cpp	Sun May 08 14:49:34 2016 +0000
+++ b/main.cpp	Mon May 09 01:42:41 2016 +0000
@@ -17,7 +17,7 @@
 #include <stdexcept>
 
 ExpansionBoard e;
-thread *t;
+Thread *t;
 
 void getData(const void*){
     while(true){
@@ -31,7 +31,7 @@
         else if (event.status == osEventMail) {
             // Successful, store log_data
             //TODO Store it somewhere
-            log_data *log_d = (log_d) event.value.p;
+            log_data *log_d = (log_data*)event.value.p;
             mail_box.free(log_d);
         }
     }
@@ -119,7 +119,7 @@
     else if (strcmp("SETT", command)==0) {
         scanf("%s", arg);
         if (atof(arg) >= 0.1 && atof(arg) <= 60.0 ) {
-            e.T = stof(arg);
+            e.T = atof(arg);
             printf("T UPDATED TO %.1f", e.T);
         }
         //else throw std::out_of_range ("T MUST BE WITHIN 0.1 AND 60.0");
@@ -137,9 +137,10 @@
         scanf("%s", arg);
         if (strcmp("ON", arg)==0)
             startLogging();
-        else if (strcmp("OFF", arg)==0)
+        else if (strcmp("OFF", arg)==0){
             stopLogging();
             printf("LOGGING OFF");
+        }
         else printf("The argument is invalid");
     }
     else printf("There is no command matching. Please try again");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/userInteractions.cpp	Mon May 09 01:42:41 2016 +0000
@@ -0,0 +1,124 @@
+#include "buffer.cpp"
+
+struct tm t;
+
+ class UserMethods {
+    Buffer buffer;
+  
+  public: 
+         
+    int readAll() {
+        //Check if there are samples
+        int32_t Nsamples = samplesInBuffer->wait();
+        
+        Buffer::log_data log;
+        int count = buffer.newestIndex;
+        int nOfRecords = 0;
+        
+        while(count >= buffer.oldestIndex){
+            log = buffer[count];
+            
+            printf("Record %i \nDate: %s, Temp Celcius: %s, Temp Farenheit: %s, Humidity: %s, 
+            "Pressure: , Accelerometer: %s, Gyroscope: %s, Magnetometer: %s\n\n", log->id, 
+            log->date, log->tempCelcius, log->tempFarenheit, log->humidity, 
+            log->pressure, log->accelerometer, log->gyroscope, log->magnetometer);
+
+            count--;
+            nOfRecords++;
+        }
+        
+        return nOfRecords;
+    }
+
+    int deleteAll() {
+        int n = mail.count;
+        mail.recv_thread(n);
+        //int numRecords;
+        return n;
+    }
+
+    int readN(int n) {
+        //Check if there are samples
+        int32_t Nsamples = samplesInBuffer->wait();
+        
+        Buffer::log_data log;
+        int count = buffer.newestIndex;
+        int nOfRecords = 0;
+        
+        while(count >= n){
+            log = buffer[count];
+            
+            printf("Record %i \nDate: %s, Temp Celcius: %s, Temp Farenheit: %s, Humidity: %s, 
+            "Pressure: , Accelerometer: %s, Gyroscope: %s, Magnetometer: %s\n\n", log->id, 
+            log->date, log->tempCelcius, log->tempFarenheit, log->humidity, 
+            log->pressure, log->accelerometer, log->gyroscope, log->magnetometer);
+
+            count--;
+            nOfRecords++;
+        }
+        
+        return nOfRecords;
+    }
+
+    int deleteN(int n) {
+        mail.recv_thread(n);       
+        //int numRecords;
+        return n;
+    }
+
+    bool setDate() {
+        bool success;
+        printf("Enter current date : \n");
+        printf( "YYYY MM DD [enter] \n");
+        scanf ("%d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday);
+
+        // adjust for tm structure required values
+        t.tm_year = t.tm_year - 1900;
+        t.tm_mon = t.tm_mon - 1;
+        // set the time
+        set_time(mktime(&t));
+        success= true;
+
+        return success;
+    }
+
+    bool setTime () {
+        bool success = false;
+
+        // get the current time from the terminal
+        printf("Enter current time:\n");
+        printf("HH MM SS[enter]\n");
+        scanf("%d %d %d", &t.tm_hour, &t.tm_min, &t.tm_sec);
+
+        printf("TIME UPDATED TO %d:%d:%d\n", t.tm_hour, t.tm_min, t.tm_sec);
+
+        // set the time
+        set_time(mktime(&t));
+        success = true;
+
+        return success;
+    }
+
+    void setT(int timePeriod) {
+        scanf("Enter sampling period: %d\n", &timePeriod);
+    }
+    /*
+    void state(char x){
+        printf("Sampling is %s\n", x);
+        printf("Enter state:\n");
+        scanf("%s", x);
+    }*/
+
+    bool logTime (int time, bool state) {
+        return state;
+    }
+
+    bool debugMessages (bool state) {
+        return state;
+    }
+
+    bool  logging(bool state) {
+        return state;
+    }
+       
+ };
\ No newline at end of file