Team HUB / Mbed 2 deprecated nRF51822_Fresh

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_Updated by Nicholas Hazen

Revision:
7:863814fa71c3
Parent:
6:6e0eedc8e0a9
Child:
8:bd3130b890e5
--- a/main.cpp	Thu Aug 06 14:24:53 2015 +0000
+++ b/main.cpp	Thu Oct 22 16:23:36 2015 +0000
@@ -62,13 +62,13 @@
 uint8_t packet3[]  =  {0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c};
 
 int i = 0;
-int currentTrial = 0;
+/*int currentTrial = 0;
 int totalTrials = 100;
 
 Timer t;
-float times[100];
+float times[100];*/
 
-DigitalOut myled(LED1); //corresponds to pin 13 on nRF51822
+//DigitalOut myled(LED1); //corresponds to pin 13 on nRF51822
 
 GattCharacteristic  txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);//GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | 
 
@@ -83,8 +83,8 @@
 
 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
 {
-    //pc.printf("Disconnected \r\n");
-    //pc.("Restart advertising \r\n");
+    /*pc.printf("Disconnected \r\n");
+    pc.printf("Restart advertising \r\n");*/
     ble.startAdvertising();
 }
 
@@ -100,8 +100,8 @@
         ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead);
         
         //t.stop();
-        myled = 0;
-        times[currentTrial] = t.read();
+        //myled = 0;
+        //times[currentTrial] = t.read();
         //pc.printf("%f\r\n", t.read()); //Total time in seconds
 
         bytesRead = 20;
@@ -119,9 +119,9 @@
         
         //t.reset();
         //pc.("T RESET \r\n");*/
-        currentTrial++;
+        //currentTrial++;
         
-        if(currentTrial < totalTrials)
+        /*if(currentTrial < totalTrials)
         {
             //pc.("CT < TT \r\n"); //Current trial less than total trials
             //wait(1);
@@ -144,7 +144,7 @@
                         pc.printf("%5.3f\r\n", difference);
                     }
             }
-            /*float total = 0.0, avg = 0.0;
+            float total = 0.0, avg = 0.0;
             for(int m = 0; m<totalTrials; m++)
             {
                 total = total + times[m];
@@ -152,8 +152,8 @@
                 
             avg = total/100.0;
             pc.printf("AVG: %5.3f\r\n", avg);
-            //pc.("Done. %d trials completed.\r\n", currentTrial);*/
-        }  
+            //pc.("Done. %d trials completed.\r\n", currentTrial);
+        }*/  
     }
 }
 
@@ -194,28 +194,28 @@
     }
     */
 
-    //pc.("Updating Characteristic... \r\n");
+    //pc.printf("Updating Characteristic... \r\n");
 
-    if(currentTrial < 1)
+    //if(currentTrial < 1)
     {
-    wait(1); //trials have shown that the code will not run without a delay before the first trial
-    t.start();
+    wait(0.1); //trials have shown that the code will not run without a delay before the first trial
+    //t.start();
     }
     //t.start();
-    //pc.("T START \r\n");
+    //pc.printf("T START \r\n");
 
-    myled = 1;
+    //myled = 1;
     ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet1, 20);
     //myled = 0;
-    //pc.("T after pckt 1 sent: %f\r\n", t.read());
+    //pc.printf("T after pckt 1 sent: %f\r\n", t.read());
     //myled = 1;
     ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet2, 20);
     //myled = 0;
-    //pc.("T after pckt 2 sent: %f\r\n", t.read());
+    //pc.printf("T after pckt 2 sent: %f\r\n", t.read());
     //myled = 1;
     ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet3, 20);
     //myled = 0;
-    //pc.("T after pckt 3 sent: %f\r\n", t.read());
+    //pc.printf("T after pckt 3 sent: %f\r\n", t.read());
     
 }
 
@@ -226,7 +226,7 @@
     ble.onDataWritten(WrittenHandler);  
     
     pc.baud(460800);
-    //pc.("SimpleChat Init \r\n");
+    pc.printf("SimpleChat Init \r\n");
     
     pc.attach( uartCB , pc.RxIrq);
    // setup advertising 
@@ -244,9 +244,8 @@
     ble.startAdvertising(); 
     //pc.("Advertising Start \r\n");
     
-   while(1) 
+    while(1) 
     {
-        //wait(1);
         //pc.("BEFORE BLE WAIT 4 EVENTS \r\n");
         ble.waitForEvent();
         //pc.("AFTER BLE WAIT 4 EVENTS \r\n");