Alexander Lea / Mbed 2 deprecated BLE_GATT_test1

Dependencies:   BLE_API mbed nRF51822

Revision:
4:ac0ee88ea0ed
Parent:
3:f3d20b36b7ea
Child:
5:b3f8e10b9602
--- a/main.cpp	Tue Feb 17 13:57:28 2015 +0000
+++ b/main.cpp	Tue Feb 17 15:57:48 2015 +0000
@@ -6,7 +6,7 @@
 #include "mbed.h"
 #include "BLEDevice.h"
 #include "CarCommsService.h"
-#include "TestGattService.h"
+#include "BroadcasterService.h"
 #include <string>
 
 using namespace std;
@@ -40,17 +40,20 @@
 }
 
 int main(void)
-{    
+{
     //TODO: I want to be able to send something like:
-    uint8_t command[8] = { 0x4d,0x32,0x81,0xc0,0x4d,0x32,0x81,0xc0 }; 
+    uint8_t command[8] = { 0x4d,0x32,0x81,0xc0,0x4d,0x32,0x81,0xc0 };
     //with first 4 bits being type code, and last 4 being command, or something
-       
+
     uint8_t testCommand = 0x12; //max value is 255
-    
+
+    uint8_t cmdOn = 0x01;
+    uint8_t cmdOff = 0x02;
+
     //blinky
-    led1 = 1;               
+    led1 = 1;
     Ticker t;
-    t.attach(blink, 5.0f);
+    t.attach(blink, 1.0f);
 
     //Create BLE stuff
     ble.init();
@@ -58,8 +61,8 @@
     ble.onConnection(connectionCallback);
 
     //CarCommsService commsService(ble, cmd);
-    TestGattService testService(ble, testCommand);
-        
+    BroadcasterService broadcasterService(ble, testCommand);
+
     /*
     **BREDR_NOT_SUPPORTED = BLE only
     **LE_GENERAL_DISCOVERABLE = Device is discoverable at any moment (no time out)
@@ -75,18 +78,29 @@
     ble.startAdvertising();
 
     pc.printf("Advertising node %s\n\r", DEVICE_NAME);
+    bool x = true;
 
     while(true) {
 
         ble.waitForEvent(); // this will return upon any system event (such as an interrupt or a ticker wakeup)
 
-        testCommand++;
-        
-        if (testCommand > 100) {
-            testCommand = 0;
+        if(x) {
+            pc.printf("Command = %u\r\n", cmdOn);
+            broadcasterService.sendCommand(cmdOn);
+            x = false;
+        } else {
+            pc.printf("Command = %u\r\n", cmdOff);
+            broadcasterService.sendCommand(cmdOff);
+            x = true;
         }
 
-        pc.printf("Level = %u\r\n", testCommand);
-        testService.sendCommand(testCommand);        
+        //testCommand++;
+
+        //if (testCommand > 100) {
+//            testCommand = 0;
+//        }
+//
+//        pc.printf("Level = %u\r\n", testCommand);
+//        testService.sendCommand(testCommand);
     }
 }
\ No newline at end of file