motion data on button press

Dependencies:   FXAS21002 FXOS8700 Hexi_KW40Z

Fork of Hexi_Buttons_Example by Hexiwear

Files at this revision

API Documentation at this revision

Comitter:
nrithya
Date:
Sun Jun 03 22:38:17 2018 +0000
Parent:
2:5b025ef2835a
Commit message:
send motion data on button press

Changed in this revision

FXAS21002.lib Show annotated file Show diff for this revision Revisions of this file
FXOS8700.lib 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FXAS21002.lib	Sun Jun 03 22:38:17 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AswinSivakumar/code/FXAS21002/#c9ebfc81e8b6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FXOS8700.lib	Sun Jun 03 22:38:17 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AswinSivakumar/code/FXOS8700/#df2167370234
--- a/main.cpp	Mon Sep 19 03:50:53 2016 +0000
+++ b/main.cpp	Sun Jun 03 22:38:17 2018 +0000
@@ -1,5 +1,7 @@
 #include "mbed.h"
 #include "Hexi_KW40Z.h"
+#include "FXOS8700.h"
+#include "FXAS21002.h"
 
 #define LED_ON      0
 #define LED_OFF     1
@@ -7,6 +9,16 @@
 void StartHaptic(void);
 void StopHaptic(void const *n);
 
+Serial pc(USBTX, USBRX);
+static int count=0;
+bool ges_flag=false;
+
+// Pin connections & address for Hexiwear
+FXAS21002 gyro(PTC11, PTC10);
+FXOS8700 accel(PTC11, PTC10);
+FXOS8700 mag(PTC11, PTC10);
+Timer t;
+
 DigitalOut redLed(LED1);
 DigitalOut greenLed(LED2);
 DigitalOut blueLed(LED3);
@@ -21,10 +33,13 @@
 void ButtonUp(void)
 {
     StartHaptic();
+    count++;
+    ges_flag=true;
     
-    redLed      = LED_ON;
+    /*redLed      = LED_ON;
     greenLed    = LED_OFF;
-    blueLed     = LED_OFF;
+    blueLed     = LED_OFF;*/
+    
 }
 
 void ButtonDown(void)
@@ -67,13 +82,78 @@
 {
     /* Register callbacks to application functions */
     kw40z_device.attach_buttonUp(&ButtonUp);
-    kw40z_device.attach_buttonDown(&ButtonDown);
+    /*kw40z_device.attach_buttonDown(&ButtonDown);
     kw40z_device.attach_buttonLeft(&ButtonLeft);
     kw40z_device.attach_buttonRight(&ButtonRight);
-    kw40z_device.attach_buttonSlide(&ButtonSlide);
+    kw40z_device.attach_buttonSlide(&ButtonSlide);*/
+    
+    accel.accel_config();
+    mag.mag_config();
+    gyro.gyro_config();
+
+    float accel_data[3]; float accel_rms=0.0;
+    float mag_data[3];   float mag_rms=0.0;
+    float gyro_data[3]; 
     
     while (true) {
-        Thread::wait(500);
+        if(ges_flag){
+            
+            while(count==1){
+                 
+                 ges_flag=false;
+                 t.start();
+    //while(1){
+       
+                   gyro.acquire_gyro_data_dps(gyro_data);
+                  //accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
+                  printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),gyro_data[0],gyro_data[1],gyro_data[2]);
+                  wait(0.01);
+                  
+                  accel.acquire_accel_data_g(accel_data);
+                  //accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
+                  printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),accel_data[0],accel_data[1],accel_data[2]);
+                  wait(0.01);
+                  
+                  mag.acquire_mag_data_uT(mag_data);
+                  //mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
+                  printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),mag_data[0],mag_data[1],mag_data[2]);
+                  wait(0.01);
+                  printf("%d\n\r",1);
+                  
+                  Thread::wait(500);
+                }
+                
+            if(count==2){
+                    
+                  ges_flag=false;
+                  count=0;
+                  gyro.acquire_gyro_data_dps(gyro_data);
+                  //accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
+                  printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),gyro_data[0],gyro_data[1],gyro_data[2]);
+                  wait(0.01);
+                  
+                  accel.acquire_accel_data_g(accel_data);
+                  //accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
+                  printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),accel_data[0],accel_data[1],accel_data[2]);
+                  wait(0.01);
+                  
+                  mag.acquire_mag_data_uT(mag_data);
+                  //mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
+                  printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),mag_data[0],mag_data[1],mag_data[2]);
+                  wait(0.01);
+                  printf("%d\n\r",0);
+                  Thread::wait(500);
+                  
+                  t.reset();
+                    
+                    }
+            
+            
+            
+            
+            
+            }
+        Thread::wait(50);
     }
 }