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: mbed
main.cpp
- Committer:
- Dot
- Date:
- 2015-04-26
- Revision:
- 1:9468a44a1815
- Parent:
- 0:7df0c8b20953
- Child:
- 2:38b75c9771fc
File content as of revision 1:9468a44a1815:
#include "mbed.h"
#include<string>
/*
DEV_INFO =
ACCESSORY_NAME=Arc Chest Strap
MANUFACTURER_NAME=Aegle
MODEL_NAME=Arc CS1
SERIAL_NO=0000000000
HARDWARE_VER=0 5 2
FIRMWARE_VER=0 5 2
ENABLE_A2DP=(value)
ENABLE_AVRCP=(value)
ENABLE_HFP=(value)
ENABLE_HFP_WBS=(value)
ENABLE_IAP=(value)
ENABLE_IAP_V2=(value)
ENABLE_MAP=(value)
ENABLE_SPP=(value)
*/
const string protocolCommands[9]={"ENABLE_A2DP",
"ENABLE_AVRCP",
"ENABLE_HFP",
"ENABLE_HFP_WBS",
"ENABLE_IAP",
"ENABLE_IAP_V2",
"ENABLE_MAP",
"ENABLE_SPP"
};
//LED
PwmOut stm_led(LED1);
//Bluetooth
Serial bluetooth(PB_6,PA_10);//pc(USBTX,USBRX); //tx,rx
Serial pc(SERIAL_TX, SERIAL_RX);//pc(USBTX,USBRX); //tx,rx
// consider using "RawSerial" instead of "Serial" if/when transmitting char's
DigitalOut bt_pair(PA_7);
DigitalOut bt_reset(PA_9);
DigitalOut rts(PA_8); //Bug, nets are swapped on the 5.02
DigitalIn cts(PB_10); //Bug, nets are swapped on the 5.02
Timer timeout;
char responseBuff[4];
char responseOk[4] = {'\r','\n','K','O'};
bool BC127_confirm = false;
bool bluetooth_command(string command){
BC127_confirm=false;
timeout.reset();
timeout.start();
bluetooth.printf("%s\r",command);
while(timeout.read_ms()<2000){
if(memcmp(&responseOk[0],&responseBuff[0],4) == 0){
pc.printf("%dms/r",timeout.read_ms());
timeout.stop();
return true;
}
}
timeout.stop();
return false;
}
void ledBlink(int blinks,int delay){
for(int i=2*blinks; i>0; i--){
stm_led = !stm_led;
wait_ms(delay);
}
}
void bluetoothInitializer(){
bt_reset = 0;
wait(0.5);
bt_reset = 1;
wait(0.5);
bt_pair =1;
wait(0.5);
bt_pair =0;
wait(0.5);
bluetooth.baud(9600);
wait(.1);
/*bluetooth.printf("SET NAME=ARC502RB\r");
wait(1.2);
bluetooth.printf("SET NAME_SHORT=ARC5\r");
wait(1.2);
//bluetooth.printf("SET FLOW_CTRL=ON\r");
//wait(1.2);
bluetooth.printf("SET BLE_ROLE=1\r");
wait(1.2);
bluetooth.printf("SET ADVERTISING=ON\r");
wait(1.2);
bluetooth.printf("WRITE\r");
wait(1.2);
bluetooth.printf("RESET\r");
wait(1);*/
//bluetooth.set_flow_control(Serial::RTSCTS,rts,cts);
//wait(.5);
//bluetooth.printf("SET BAUD=115200\r");
//wait(0.5);
//bluetooth.baud(115200);
//wait(0.1);
//bluetooth.printf("ENTER_DATA\r");
//wait(2);
}
void readResponse(){
stm_led=!stm_led;
for(int z=2;z>0;z--){
responseBuff[z+1]=responseBuff[z];
}
responseBuff[1]=responseBuff[0];
responseBuff[0]=bluetooth.getc();
pc.putc(responseBuff[0]);
if(memcmp(&responseOk[0],&responseBuff[0],4) == 0){
pc.printf("YA/r/r");
BC127_confirm=true;
}
}
int main() {
bluetoothInitializer();
bluetooth.attach(&readResponse);
wait(5);
pc.printf("Starting\r");
bool debug=true;
stm_led=1;
wait(1);
pc.printf("Atempting to send command\r");
debug&=bluetooth_command("SET ENABLE_SPP=OFF");
//bluetooth.printf("SET ENABLE_SPP=OFF\r");
wait(2);
//debug&=bluetooth_command("WRITE");
//debug&=bluetooth_command("RESET");
pc.printf("Finished sending command\r");
while(1) {
if(debug){
stm_led=!stm_led;
}
}
}