Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MODSERIAL mbed-rtos mbed
Fork of Master by
Diff: bluetooth.cpp
- Revision:
- 4:aaaadb45cbd9
- Parent:
- 3:12e1f116ea42
- Child:
- 5:37733f175430
diff -r 12e1f116ea42 -r aaaadb45cbd9 bluetooth.cpp
--- 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 ){
