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:
Fri May 06 15:25:58 2016 +0000
Parent:
17:37294fc50c80
Child:
19:d442ff60498c
Commit message:
Implemented a few more methods and fixed the previous errors.; An example of how to call the struct and save the data in the mailbox is also available on main.cppf

Changed in this revision

X_NUCLEO_IKS01A1.lib Show annotated file Show diff for this revision Revisions of this file
mailBox.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- a/X_NUCLEO_IKS01A1.lib	Fri May 06 01:04:28 2016 +0000
+++ b/X_NUCLEO_IKS01A1.lib	Fri May 06 15:25:58 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/ST/code/X_NUCLEO_IKS01A1/#8a5184f66cd9
+https://developer.mbed.org/users/Jacinta/code/X_NUCLEO_IKS01A1/#42f2db88e54b
--- a/mailBox.cpp	Fri May 06 01:04:28 2016 +0000
+++ b/mailBox.cpp	Fri May 06 15:25:58 2016 +0000
@@ -1,42 +1,42 @@
 #include "mbed.h"
 #include "rtos.h"
-#include <logData.cpp>
  
- typedef struct {
-  uint8_t   id;
-  float    tempCelcius;
-  float    tempFarenheit;
-  float    humidity;
-  float    pressure;
-  int      accelerometer;
-  int      gyroscope;
-  int      magnetometer;
-  
-  
-  }log_data;
-
-Mail<log_data, 120> mail_box;
+ class MailBox{
  
-void send_thread (void const *args) {
-    while (true) {     
-        log_data *log = mail_box.alloc();
-        log->id; 
-        log->tempCelcius;
-        log->tempFarenheit;
-        log->humidity;
-        log->pressure;
-        log->accelerometer;
-        log->gyroscope;
-        log->magnetometer;
-    //    log->dd;
-     ////   log->mm;
-   //     log->yyyy;
-      //  log->hh;
-     //   log->min;
-      //  log->ss;
-        
-        mail_box.put(log);
-        Thread::wait(1000);
+    public:
+     typedef struct {
+        uint8_t   id;
+        float    tempCelcius;
+        float    tempFarenheit;
+        float    humidity;
+        float    pressure;
+        int      accelerometer;
+        int      gyroscope;
+        int      magnetometer;
+    } log_data;
+
+    Mail<log_data, 120> mail_box;
+
+    void send_thread (log_data newLog) {
+        while (true) {
+            log_data *log = mail_box.alloc();
+            log->tempCelcius = newLog.tempCelcius;
+            log->tempFarenheit = newLog.tempFarenheit;
+            log->humidity = newLog.humidity;
+            log->pressure = newLog.pressure;
+            log->accelerometer = newLog.accelerometer;
+            log->gyroscope = newLog.gyroscope;
+            log->magnetometer = newLog.magnetometer;
+            //    log->dd;
+            ////   log->mm;
+            //     log->yyyy;
+            //  log->hh;
+            //   log->min;
+            //  log->ss;
+
+            mail_box.put(log);
+            Thread::wait(1000);
+        }
     }
-}
+};
  
--- a/main.cpp	Fri May 06 01:04:28 2016 +0000
+++ b/main.cpp	Fri May 06 15:25:58 2016 +0000
@@ -39,6 +39,7 @@
 /* Includes */
 #include "mbed.h"
 #include "x_nucleo_iks01a1.h"
+#include "mailBox.cpp"
 
 /* Instantiate the expansion board */
 static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15);
@@ -91,35 +92,30 @@
 
 int readAll()
 {
-
     int numRecords;
 
     return numRecords;
+}
 
-}
 int deleteAll()
 {
-
     int numRecords;
     return numRecords;
+}
 
-}
 int readN(int n)
 {
-
     int numRecords;
     return numRecords;
-
 }
 
 int deleteN( int n)
 {
-
     int numRecords;
     return numRecords;
+}
 
-}
-bool setDate( int hh, int mm, int yyyy)
+bool setDate()
 {
     bool success;
     printf("Enter current date : \n");
@@ -130,49 +126,53 @@
     t.tm_year = t.tm_year - 1900;
     t.tm_mon = t.tm_mon - 1;
      // set the time
-    set_time(mktime(&t));
-    
+    set_time(mktime(&t));    
     success= true;
-
-    
+       
     return success;
+}
 
-}
-bool setTime (int hh, int mm, int ss)
+bool setTime ()
 {
-
     bool success = false;
 
-    // get the current time from the terminal
-    
+    // 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;
+    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;
+}
 
-    return state;
-
-}
 bool  logging(bool state)
 {
-
     return state;
-
 }
 
 /* Simple main function */
@@ -184,6 +184,11 @@
     int32_t axes[3];
     int userInstruction;
     int n;
+    int samplePeriod = 15;
+    char* state = "ON";
+    bool logState = true;
+    MailBox mail;
+    MailBox::log_data log;
 
     printf("\r\n--- Starting new run ---\r\n");
 
@@ -203,31 +208,39 @@
         printf ("Please select and option: \n" );
         scanf ("%d", &userInstruction);
         
-        switch (userInstruction){
-            
+        switch (userInstruction){   
             case 1:
-            readAll();
-            break;
-            
+                readAll();
+                break;           
             case 2:
-            deleteAll();
-            break;
-            
+                deleteAll();
+                break;
             case 3:
-            readN();
-            
+                readN(n);
+                break;            
             case 4:
-            
-            
-            
-            
-            }
-        
-        
-    
+                deleteN(n);
+                break;            
+            case 5:
+                setDate();
+                break;            
+            case 6:
+                setTime();
+                break;            
+            case 7:
+                setT(samplePeriod);
+                printf("T UPDATED TO %d\n", samplePeriod);
+                break;            
+            case 8:
+                //state(state);
+                break;            
+            case 9:
+                logging(logState);
+                break;                    
+        }     
     }
 
-    /*
+    
     while(1) {
         printf("\r\n");
 
@@ -250,7 +263,20 @@
         gyroscope->Get_G_Axes(axes);
         printf("LSM6DS0 [gyro/mdps]:   %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
 
-        wait(1.5);
+        wait(samplePeriod);
     }
-    */
+    
+    
+    while(state == "ON"){
+        
+        //JUST AN EXAMPLE
+        log.pressure = 4;
+        log.tempCelcius = 3;
+        
+        mail.send_thread(log);
+        
+        wait(samplePeriod);
+    }
+    
+    
 }
--- a/mbed-rtos.lib	Fri May 06 01:04:28 2016 +0000
+++ b/mbed-rtos.lib	Fri May 06 15:25:58 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#162b12aea5f2
+http://mbed.org/users/mbed_official/code/mbed-rtos/#bdd541595fc5