a fork to test out advertising process

Dependencies:   BLE_API TxIR mbed nRF51822

Fork of ir-puck by Nordic Pucks

Files at this revision

API Documentation at this revision

Comitter:
stiaje
Date:
Tue Jul 08 09:38:31 2014 +0000
Parent:
0:c94311378ec1
Commit message:
Rewrite all the things!; ; printing and advertising mostly.

Changed in this revision

IR.cpp 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r c94311378ec1 -r 6ba27220d1da IR.cpp
--- a/IR.cpp	Wed Jul 02 10:48:58 2014 +0000
+++ b/IR.cpp	Tue Jul 08 09:38:31 2014 +0000
@@ -5,10 +5,17 @@
 #define WORD(x, i) ((x)[(i)] << 8 | (x)[(i) + 1])
 
 TxIR txir(p14);
-Serial px(USBTX, USBRX);
+
+#define DEBUG 1
+#ifdef DEBUG
+    Serial px(USBTX, USBRX);
+    #define LOG(args...)    px.printf(args)
+#else
+    #define LOG(args...)
+#endif
 
 void fireIRCode(uint8_t* header, uint8_t* one, uint8_t* zero, uint8_t* ptrail, uint8_t* predata, uint8_t* code) {
-    px.printf("Going to fire.\n");
+    LOG("Going to fire.\n");
     int raw_codes_length = 67;
     unsigned raw_codes[raw_codes_length];
     raw_codes[0] = WORD(header, 0);
@@ -33,5 +40,5 @@
     
     txir.txSeq(26.32 / 1000000.0, 67, raw_codes);
     
-    px.printf("Wrote message :)\n");
+    LOG("Wrote message :)\n");
 }
\ No newline at end of file
diff -r c94311378ec1 -r 6ba27220d1da main.cpp
--- a/main.cpp	Wed Jul 02 10:48:58 2014 +0000
+++ b/main.cpp	Tue Jul 08 09:38:31 2014 +0000
@@ -7,9 +7,14 @@
 
 DigitalOut myled(LED1);
 DigitalOut yourled(LED2);
-nRF51822n nrf;
 
-Serial py(USBTX, USBRX);
+#define DEBUG 1
+#ifdef DEBUG
+    Serial py(USBTX, USBRX);
+    #define LOG(args...)    py.printf(args)
+#else
+    #define LOG(args...)
+#endif
 
 const static uint8_t beaconPayload[] = {
     0x00, 0x4C, // Company identifier code (0x004C == Apple)
@@ -18,7 +23,7 @@
     0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, // UUID
     0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61,
     0x13, 0x37, // the major value to differenciate a location
-    0xFA, 0xCE, // the minor value to differenciate a location
+    0xBA, 0xCE, // the minor value to differenciate a location
     0xC8        // 2's complement of the Tx power (-56dB)
 };
 
@@ -27,7 +32,7 @@
 
 void onDataWritten(uint16_t handle)
 {
-    py.printf("Data written! %i\n", handle);
+    LOG("Data written! %i\n", handle);
     for (int i = 0; i < ir_service.getCharacteristicCount(); i++) {
         GattCharacteristic* characteristic = ir_service.getCharacteristic(i);
         characteristic->getMaxLength();
@@ -45,19 +50,19 @@
 
 void disconnectionCallback(void)
 {
-    py.printf("Disconnected!\n");
-    py.printf("Restarting the advertising process\n");
+    LOG("Disconnected!\n");
+    LOG("Restarting the advertising process\n");
     ble.startAdvertising();
 }
 
 void connectionCallback(void)
 {
-    py.printf("Connected!\n");    
+    LOG("Connected!\n");
 }
 
 void onDataSent(uint16_t data)
 {
-    py.printf("onDataSent!\n");
+    LOG("onDataSent!\n");
 }
 
 int main() {
@@ -70,17 +75,20 @@
     ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
     ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
     
+    uint8_t uuid_array_service[16]   = {'b', 'f', 't', 'j', ' ', 'i', 'r', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::INCOMPLETE_LIST_128BIT_SERVICE_IDS,
+                                        uuid_array_service, sizeof(uuid_array_service));
     
     ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA,
                     beaconPayload, sizeof(beaconPayload));
     
     ble.startAdvertising();
-
+    
     ble.addService(ir_service);
     
     myled = 1;
     
-    py.printf("Starting up.\n");
+    LOG("Starting up.\n");
     
     
 
@@ -88,5 +96,4 @@
         ble.waitForEvent();
         myled = !myled;
     }
-    
 }
\ No newline at end of file
diff -r c94311378ec1 -r 6ba27220d1da mbed.bld
--- a/mbed.bld	Wed Jul 02 10:48:58 2014 +0000
+++ b/mbed.bld	Tue Jul 08 09:38:31 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae
\ No newline at end of file