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:
- 8:beb6c399490a
- Parent:
- 7:2df2c6e8c0df
- Child:
- 9:9a4c81493a3d
--- a/RN52.cpp Thu Jan 14 22:20:38 2016 +0000 +++ b/RN52.cpp Fri Jan 15 20:59:51 2016 +0000 @@ -35,13 +35,13 @@ clear_serial(); if(event_pin == 0) { clear_result(result); - get(RN52_GETSTATUS, result); + get_status(result); switch (result->event) { case RN52_CALLER_ID_EVENT: - get(RN52_CALLER_ID, result); + get_caller_id(result); break; case RN52_TRACK_CHANGE_EVENT: - get(RN52_TRACK_METADATA, result); + get_track_metadata(result); break; } return 1; @@ -85,78 +85,75 @@ return capture_response(response); } -bool RN52::get(RN52_COMMAND cmd, RN52_RESULT * result){ - switch (cmd) { - case RN52_GETSTATUS: { - serial.printf(GETSTATUS); - capture_response(result->response); - int response_value = strtoul(result->response, NULL, 16); - result->media_connected = (response_value & (1 << 10)) >> 10; //byte 0, bit 2 - result->phone_connected = (response_value & (1 << 11)) >> 11; //byte 0, bit 3 - result->connection = (RN52_CONNECTION)(response_value & 0x0F); //byte 1, bits 0-3 - switch (response_value & 0x3000) { - case 0x1000: //byte 0, bit 4 - result->event = RN52_CALLER_ID_EVENT; - break; - case 0x2000: //byte 0, bit 5 - result->event = RN52_TRACK_CHANGE_EVENT; - break; - default: - result->event = RN52_OTHER_EVENT; - break; - } +bool RN52::get_status(RN52_RESULT * result){ + serial.printf(GETSTATUS); + capture_response(result->response); + int response_value = strtoul(result->response, NULL, 16); + result->media_connected = (response_value & (1 << 10)) >> 10; //byte 0, bit 2 + result->phone_connected = (response_value & (1 << 11)) >> 11; //byte 0, bit 3 + result->connection = (RN52_CONNECTION)(response_value & 0x0F); //byte 1, bits 0-3 + switch (response_value & 0x3000) { + case 0x1000: //byte 0, bit 4 + result->event = RN52_CALLER_ID_EVENT; break; - } //added to create local scope of response_value - case RN52_CALLER_ID: - serial.printf(CALLER_ID); - capture_response(result->response); - //parse the response + case 0x2000: //byte 0, bit 5 + result->event = RN52_TRACK_CHANGE_EVENT; + break; + default: + result->event = RN52_OTHER_EVENT; break; - case RN52_TRACK_METADATA: - serial.printf(TRACK_METADATA); - if(capture_response(result->response)) {//AOK - while(result->response[4] != '(') { //time(ms) - always the last one - capture_response(result->response); - switch (result->response[3]) { - case 'l': //Title - copy_response(result->response, result->title, 6); - break; - case 'i': //Artist - copy_response(result->response, result->artist, 7); - break; - case 'u': //Album - copy_response(result->response, result->album, 6); - break; - case 'r': //Genre - copy_response(result->response, result->genre, 6); - break; - case 'c': //TrackNumber or TrackCount - { - char number_string[5]; - if(result->response[5] == 'N') { //TrackNumber - copy_response(result->response, number_string, 12); - result->track_number = strtoul(number_string, NULL, 10); - } - else { //TrackCount - copy_response(result->response, number_string, 11); - result->track_count = strtoul(number_string, NULL, 10); - } - } - break; - case 'e': - { - char duration_string[10]; - copy_response(result->response, duration_string, 9); - result->duration = strtoul(duration_string, NULL, 10); - } - break; + } + return 1; +} + +bool RN52::get_caller_id(RN52_RESULT * result){ + serial.printf(CALLER_ID); + capture_response(result->response); + //parse the response + return 1; +} + +bool RN52::get_track_metadata(RN52_RESULT * result){ + serial.printf(TRACK_METADATA); + if(capture_response(result->response)) {//AOK + while(result->response[4] != '(') { //time(ms) - always the last one + capture_response(result->response); + switch (result->response[3]) { + case 'l': //Title + copy_response(result->response, result->title, 6); + break; + case 'i': //Artist + copy_response(result->response, result->artist, 7); + break; + case 'u': //Album + copy_response(result->response, result->album, 6); + break; + case 'r': //Genre + copy_response(result->response, result->genre, 6); + break; + case 'c': //TrackNumber or TrackCount + { + char number_string[5]; + if(result->response[5] == 'N') { //TrackNumber + copy_response(result->response, number_string, 12); + result->track_number = strtoul(number_string, NULL, 10); + } + else { //TrackCount + copy_response(result->response, number_string, 11); + result->track_count = strtoul(number_string, NULL, 10); } } - clear_serial(); - } - break; - default: - return 0; + break; + case 'e': + { + char duration_string[10]; + copy_response(result->response, duration_string, 9); + result->duration = strtoul(duration_string, NULL, 10); + } + break; + } + } + clear_serial(); } return 1; } @@ -195,7 +192,7 @@ result->event = RN52_NO_EVENT; result->media_connected = 0; result->phone_connected = 0; - result->connection = RN52_LIMBO; + result->connection = RN52_NOT_SET; result->title[0] = '\0'; result->artist[0] = '\0'; result->album[0] = '\0';