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.
Diff: RN52.cpp
- Revision:
- 15:82c3cc87bd02
- Parent:
- 14:3f4098e94c29
- Child:
- 16:7bb8b161e00b
diff -r 3f4098e94c29 -r 82c3cc87bd02 RN52.cpp --- a/RN52.cpp Sun Jan 31 20:58:42 2016 +0000 +++ b/RN52.cpp Sun Feb 07 18:24:13 2016 +0000 @@ -15,7 +15,7 @@ #define CALLER_ID "T\r" #define TRACK_METADATA "AD\r" -#define RESPONSE_TIMEOUT 30 //ms +#define RESPONSE_TIMEOUT 20 //ms Serial serial(p13, p14); // tx, rx DigitalIn event_pin(p20); @@ -25,15 +25,9 @@ void RN52::init(){ - enable(); serial.baud(115200); printf("Serial baudrate set\r\n"); - - //make sure event pin is pulled low - if(event_pin == 0) { - serial.printf(GETSTATUS); - capture_response(temp_response); - } + enable(); } void RN52::enable(){ @@ -48,7 +42,7 @@ bool RN52::check_event(RN52_RESULT * result){ clear_serial(); - if(event_pin == 0) { + if((enable_pin == 1) && (event_pin == 0)) { clear_result(result); get_status(result); switch (result->event) { @@ -121,12 +115,11 @@ //parse the response return 1; } - - bool RN52::get_track_metadata(RN52_RESULT * result){ + clear_serial(); serial.printf(TRACK_METADATA); if(capture_response(result->response)) {//AOK - while(result->response[3] != 'e') { //time(ms) - always the last one + while(result->response[4] != '(') { //time(ms) - always the last one capture_response(result->response); switch (result->response[3]) { case 'l': //Title @@ -154,7 +147,7 @@ } } break; - case 'e': //time(ms) - always the last one + case 'e': { char duration_string[10]; copy_response(result->response, duration_string, 9); @@ -181,12 +174,12 @@ } else if(responsetime.read_ms() > RESPONSE_TIMEOUT) { clear_serial(); - printf("timeout occured\r\n last response: %s\r\n", str); return 0; } } str[n-2] = '\0'; //terminate string before \r\n - return (str[0] == 'A'); + //return (str[0] == 'A'); + return 1; } void RN52::clear_serial(){ @@ -217,4 +210,16 @@ result->track_number = 1; result->track_count = 1; result->response[0] = '\0'; +} + +void RN52::config(char * name) { + bool en = enable_pin; + enable_pin = 1; + wait(0.5); //make sure booted up, not sure if needed + serial.printf("S%%,18E7\r"); //extended features + serial.printf("SC,040420\r"); //device type + serial.printf("SN,%s\r", name); //name + serial.printf(REBOOT); + clear_serial(); + enable_pin = en; //restore status } \ No newline at end of file