ir-puck

Dependencies:   Puck IRSender mbed

Fork of ir-puck by Nordic Pucks

Revision:
4:24d9873936e6
Parent:
1:e92c3b50191d
Child:
5:3642c0af497e
--- a/main.cpp	Mon Jul 14 07:44:51 2014 +0000
+++ b/main.cpp	Tue Jul 15 08:49:45 2014 +0000
@@ -12,7 +12,7 @@
 Serial py(USBTX, USBRX);
 
 const static uint8_t beaconPayload[] = {
-    0x00, 0x4C, // Company identifier code (0x004C == Apple)
+    0x00, 0x00, // Company identifier code (0x004C == Apple) - Should be all zero until we figure out this weird iOS bug
     0x02,       // ID
     0x15,       // length of the remaining payload
     0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, // UUID
@@ -25,7 +25,9 @@
 extern GattService ir_service;
 extern GattCharacteristic header, one, zero, ptrail, predata, code;
 
-int received_ir_transmission = 0;
+bool received_ir_transmission = false;
+bool device_disconnected = true;
+
 void onDataWritten(uint16_t handle)
 {
     py.printf("Data written! %i\n", handle);
@@ -43,20 +45,21 @@
     }
 
     if (code.getHandle() == handle) {
-        received_ir_transmission = 1;
+        py.printf("Received complete instruction\n");
+        received_ir_transmission = true;
     }
 }
 
 void disconnectionCallback(void)
 {
     py.printf("Disconnected!\n");
-    py.printf("Restarting the advertising process\n");
-    ble.startAdvertising();
+    device_disconnected = true;
 }
 
 void connectionCallback(void)
 {
     py.printf("Connected!\n");
+    device_disconnected = false;
 }
 
 void onDataSent(uint16_t data)
@@ -90,9 +93,10 @@
 
     while (true) {
         ble.waitForEvent();
-        if (received_ir_transmission == 1) {
+        if (received_ir_transmission && device_disconnected) {
             fireIRCode(header.getValuePtr(), one.getValuePtr(), zero.getValuePtr(), ptrail.getValuePtr(), predata.getValuePtr(), code.getValuePtr());
-            received_ir_transmission = 0;
+            received_ir_transmission = false;
+            ble.startAdvertising();
         }
         myled = !myled;
     }