https://mbed.org/forum/ja/topic/4890/

Dependencies:   USBHost mbed

Fork of BTstack by Norimasa Okamoto

Revision:
3:316daabf0d24
Parent:
1:b657594559be
--- a/spp_demo.cpp	Fri Mar 22 22:35:57 2013 +0000
+++ b/spp_demo.cpp	Fri May 09 15:54:35 2014 +0000
@@ -1,4 +1,4 @@
-#if 0
+#if 1
 /*
  * spp_demo
  */
@@ -19,7 +19,7 @@
 #include "bd_addr.h"  // class bd_addr
 
 Serial pc(USBTX, USBRX);
-DigitalOut led1(LED1), led2(LED2), led3(LED3);
+DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
 
 #define HEARTBEAT_PERIOD_MS 500
 
@@ -27,6 +27,8 @@
 static uint16_t  rfcomm_channel_id = 0;
 static uint8_t   spp_service_buffer[128];
 
+static void data_recv(uint8_t *packet, uint16_t size);
+
 // Bluetooth logic
 static void packet_handler (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
     bd_addr_t event_addr;
@@ -107,17 +109,43 @@
                     log_info("rfcomm_send_internal -> error %d", err);
                 }
             }
-            led3 = !led3;
+            
+            data_recv(packet, size);
+            
+//            led3 = !led3;
             break;
         default:
             break;
     }
 }
 
+static void data_recv(uint8_t *packet, uint16_t size){
+    int i;
+    log_info("packet(size:%d) = ", size);
+    for (i = 0; i < size; i++){
+        log_info("%c", packet[i]);
+        switch (packet[i]) {
+            case 'a':
+                led1 = !led1;
+                break;
+            case 'b':
+                led2 = !led2;
+                break;
+            case 'c':
+                led3 = !led3;
+                break;
+            case 'd':
+                led4 = !led4;
+                break;
+        }
+    }
+    log_info("\n\r");
+}
+
 static void  heartbeat_handler(struct timer *ts){
     run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS);
     run_loop_add_timer(ts);
-    led2 = !led2;
+//    led2 = !led2;
 } 
 
 // main
@@ -127,7 +155,7 @@
     log_info("%s\n", __FILE__);
 
     // init LEDs
-    led1 = led2 = led3 = 1;
+    led1 = led2 = led3 = led4 = 0;
     
     /// GET STARTED with BTstack ///
     btstack_memory_init();