FM-test

Dependencies:   MODSERIAL mbed-rtos mbed

Fork of Master by Ohnishi_Gundan

Files at this revision

API Documentation at this revision

Comitter:
9uS7
Date:
Fri Sep 12 08:08:21 2014 +0000
Parent:
3:12e1f116ea42
Child:
5:37733f175430
Commit message:
09/12/17

Changed in this revision

bluetooth.cpp Show annotated file Show diff for this revision Revisions of this file
bluetooth.h 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
--- a/bluetooth.cpp	Fri Sep 12 05:11:39 2014 +0000
+++ b/bluetooth.cpp	Fri Sep 12 08:08:21 2014 +0000
@@ -7,7 +7,11 @@
 //slave
 //Serial bt(p28, p27);
 
+Serial pc(USBTX, USBRX);   // tx, rx
+
 DigitalOut l1(LED1);
+DigitalOut l2(LED2);
+DigitalOut l4(LED4);
 
 void btSetup(int role)
 {
@@ -27,7 +31,7 @@
 
 void sync(char option, char* b_data, float* f_data)
 {
-    char pac[PACK_SIZE];
+    char pac[PACK_SIZE]={};
     Cvt temp;
     
     //making pac
@@ -52,23 +56,23 @@
     
     //send pac
     for( int i=0 ; i<PACK_SIZE ; i++ ){
-        pc.putc( pac[i] );
+        bt.putc( pac[i] );
+        pc.printf("%02x ",pac[i]);
     }
+    pc.printf("\n");
 }
 
 void slaveRecieve(void)
 {
-    static int i;
-    char buf[PACK_SIZE];
-    char pac[PACK_SIZE];
-    float val[PACK_SIZE/4+1];
+    static int i=0;
+    char buf[PACK_SIZE]={};
+    char pac[PACK_SIZE]={};
+    float val[PACK_SIZE/4+1]={};
     Cvt temp;
     
     wait(1/1000.0);
     
-    l1=1;
-    wait(0.2);
-    l1=2;
+    l1=( l1 ? 0 : 1 );
     
     for( int i=0 ; i<PACK_SIZE ; i++ ){
         buf[i]=bt.getc();
@@ -106,7 +110,11 @@
         //send pac
         for( int i=0 ; i<PACK_SIZE ; i++ ){
             bt.putc( pac[i] );
+            pc.printf("%02x ",pac[i]);
         }
+        pc.printf("\n");
+        
+        l2 = l2 ? 0 : 1;
     }
     else if( buf[0]==SYNC_FM ){
         ;       //not yet
@@ -120,16 +128,34 @@
 
 void receiveSensor(float* _ir, float* _fsr)
 {
-    char buf[PACK_SIZE];
+    char buf[PACK_SIZE]={};
     Cvt temp;
     
-    wait(1/1000.0);
+    wait(0.05);
+    
+    l1= l1 ? 0 : 1;
     
+    for( int i=0 ; ; i++ ){
+        if( bt.readable() ){
+            pc.printf("readable\n");
+            break;
+        }
+        else if( i>5 ){
+            l4 = 0;
+            pc.printf("enable\n");
+            return;
+        }    
+    }
+    
+    l4 = 1;
+
     //Read
     for( int i=0 ; i<PACK_SIZE ; i++ ){
         buf[i]=bt.getc();
     }
     
+    return;
+    
     //PACK:     [option/ir*4/fsr*4];
     //option
     if( buf[0]!=SYNC_SENSOR ){
--- a/bluetooth.h	Fri Sep 12 05:11:39 2014 +0000
+++ b/bluetooth.h	Fri Sep 12 08:08:21 2014 +0000
@@ -11,9 +11,7 @@
 #define SYNC_MOTOR 0x20
 #define SYNC_FM 0x21
 
-
-
-#define PACK_SIZE 20
+#define PACK_SIZE 15
 
 typedef union _cvt{
     char byte[4];
--- a/main.cpp	Fri Sep 12 05:11:39 2014 +0000
+++ b/main.cpp	Fri Sep 12 08:08:21 2014 +0000
@@ -8,7 +8,7 @@
 //BT_MASTER or BT_SLAVE
 #define DEVICE_ROLE BT_MASTER
 
-Serial pc(USBTX, USBRX);   // tx, rx
+//Serial pc(USBTX, USBRX);   // tx, rx
  
 //debug
 DigitalOut led1(LED1);
@@ -48,6 +48,7 @@
     float ir_s,fsr_s;   //sensor of slave
     sync(SYNC_SENSOR,NULL,NULL);
     receiveSensor( &ir_s, &fsr_s );
-    led1 = ( ir_s>0.5 ? 1 : 0 );
-    wait(0.5);
+    led4 = ( ir_s>0.5 ? 1 : 0 );
+    led2 = ( led2 ? 0 : 1 );
+    wait(1);
 }
\ No newline at end of file