se

Dependencies:   SDFileSystem circular_buffer MPU6050 SoftSerial

Revision:
3:b2087af18efe
Parent:
1:2cc1c9a45be7
Child:
4:147bbe6f9626
--- a/source/main.cpp	Wed Feb 01 11:23:59 2017 +0000
+++ b/source/main.cpp	Wed Jun 21 16:00:36 2017 +0000
@@ -7,38 +7,45 @@
 #include "MPUService.h"
 #include <string> 
 #include <stdio.h>
-Serial pc(p30, p31);
+#include "SoftSerial.h"
+Serial pc(p6, p8);
+//SoftSerial pc1(p9, p10);
 MPU6050 mpu6050;
-
-InterruptIn pin(p10);
-
-
-DigitalOut led(LED1, 1);
-DigitalOut led2(LED2, 1);
+//InterruptIn pin(p10);
+//DigitalOut led(LED1, 1);
+//DigitalOut led2(LED2, 1);
 uint16_t customServiceUUID  = 0xA000;
 uint16_t readCharUUID       = 0xA001;
-uint16_t writeCharUUID      = 0xA002;
+uint16_t interruptUUID      = 0xA002;
 DigitalOut alivenessLED(LED1, 0);
 const static char     DEVICE_NAME[] = "MPU";
 static const uint16_t uuid16_list[] = {0x0A0A};
-static int counter;
+//static int counter;
 /* Set Up custom Characteristics */
 static float readValue[3] = {0};
+static float interruptValue[3] = {0};
 ReadOnlyArrayGattCharacteristic<float, sizeof(readValue)> readChar(readCharUUID, readValue, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
+ReadOnlyArrayGattCharacteristic<float, sizeof(interruptValue)> interrupt(interruptUUID, interruptValue, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
 
 //static float writeValue[2] = {3,4};
 //WriteOnlyArrayGattCharacteristic<float, sizeof(writeValue)> writeChar(writeCharUUID, writeValue);
 
 /* Set up custom service */
-GattCharacteristic *characteristics[] = {&readChar/*, &writeChar*/};
+GattCharacteristic *characteristics[] = {&readChar/*, &writeChar*/, &interrupt};
 GattService        customService(customServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
 
 
 
 static EventQueue eventQueue(/* event count */ 10 * /* event size */ 32);
-//InterruptIn button(BUTTON1);
+InterruptIn button(BUTTON1);
+
+
+
+
 void updateReadValue() {
     alivenessLED = !alivenessLED; 
+    mpu6050.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
+    
     
     //mpu6050.readAccelData(accelData);
     //mpu6050.getAres();
@@ -55,8 +62,13 @@
     //float newValue[3] = {gx,gy,gz};*/
     //counter++;
     //pc.printf("| Before | ax=%.3f | ay=%.3f | az=%.3f \r\n",gx,gy,gz);
-    //pc.printf("| Acce | ax=%.3f | ay=%.3f | az=%.3f | Gyro | gx=%.3f | gy=%.3f | gz=%.3f\r\n",ax,ay,az,gx,gy,gz);
+    pc.printf("| Acce | ax=%.3f | ay=%.3f | az=%.3f | Gyro | gx=%.3f | gy=%.3f | gz=%.3f\r\n",ax,ay,az,gx,gy,gz);
     //len_send = strlen((const char *)newValue);
+    
+
+    uint8_t motionByte = mpu6050.readThisByte(MPU6050_RA_MOT_DETECT_STATUS);
+    pc.printf("Motion byte: %d\r\n",motionByte);
+    BLE::Instance(BLE::DEFAULT_INSTANCE).gattServer().write(interrupt.getValueHandle(), (uint8_t*)motionByte, 8);
     BLE::Instance(BLE::DEFAULT_INSTANCE).gattServer().write(readChar.getValueHandle(), (uint8_t*)newValue, 12);
 }
 void periodicCallback(void)
@@ -113,7 +125,7 @@
 
 }
 void flip() {
-    pc.printf("Desio se interupt");
+    //pc.printf("Desio se interupt");
 }
 bool XnegMD, XposMD, YnegMD, YposMD, ZnegMD, ZposMD;
 int main()
@@ -121,8 +133,11 @@
     //mpu6050.whoAmI();
     //mpu6050.calibrate(accelBias, gyroBias);
     //mpu6050.init();
-
-
+    mpu6050.calibrate(accelBias, gyroBias);
+    mpu6050.initialize();
+    mpu6050.setSleepEnabled(0);
+    pc.baud(115200);
+    mpu6050.setDHPFMode(1);
     //setMotionDetectionThreshold
     //char myChar = mpu6050.readByte(MPU6050_ADDRESS, 0x1F);
     //pc.printf("Prije postavljanja\n");
@@ -160,5 +175,19 @@
     ble.onEventsToProcess(scheduleBleEventsProcessing);
     ble.init(bleInitComplete);  
     eventQueue.dispatch_forever();
-    return 0;
+    while (ble.hasInitialized()  == false) { /* spin loop */ }
+  
+  
+  
+  
+  
+  
+   // pc1.baud(9600);
+    //while (true) {
+        //ble.waitForEvent();
+      //  pc1.printf("tare ");
+        //wait_ms(1000);
+        
+    //}
+    //return 0;
 }