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.
Revision 16:7bb8b161e00b, committed 2016-03-18
- Comitter:
- petter
- Date:
- Fri Mar 18 20:58:36 2016 +0000
- Parent:
- 15:82c3cc87bd02
- Commit message:
- Added can.monitor in a trial to get the sleep mode working
Changed in this revision
--- a/CDC.cpp Sun Feb 07 18:24:13 2016 +0000 +++ b/CDC.cpp Fri Mar 18 20:58:36 2016 +0000 @@ -67,14 +67,16 @@ /** Enables CAN traciever transmit **/ void CDC::enable() { - enable_transceiver = 0; //active + //enable_transceiver = 0; //active + can.monitor(0); sleep_timer.reset(); sleep_timer.start(); } /** Disables CAN traciever transmit **/ void CDC::disable() { - enable_transceiver = 1; //sleep + //enable_transceiver = 1; //sleep + can.monitor(1); sleep_timer.stop(); } @@ -115,7 +117,6 @@ IBUS_COMMAND CDC::get_cmd() { if(can.read(CAN_RxMsg)) { led2 = !led2; - CAN_TxMsg.data[0]++; switch (CAN_RxMsg.id) { case DISPLAY_RESOURCE_REQ: sleep_timer.reset(); @@ -123,6 +124,7 @@ update_elapsed_time(); send_can_frame(GENERAL_STATUS_CDC, cdc_status_cmd); led1 = !led1; + printf("cdc_acttive = %i", cdc_active); return IBUS_HEAD_UNIT_ON; case NODE_STATUS_RX: send_can_frame(NODE_STATUS_TX, ninefive_cmd);
--- a/RN52.cpp Sun Feb 07 18:24:13 2016 +0000 +++ b/RN52.cpp Fri Mar 18 20:58:36 2016 +0000 @@ -16,11 +16,14 @@ #define TRACK_METADATA "AD\r" #define RESPONSE_TIMEOUT 20 //ms +#define METADATA_RESPONSE_TIMEOUT 100 //ms Serial serial(p13, p14); // tx, rx DigitalIn event_pin(p20); DigitalOut enable_pin(p5); Timer responsetime; +Timer metadata_responsetime; + char temp_response[255]; @@ -52,6 +55,11 @@ case RN52_TRACK_CHANGE_EVENT: get_track_metadata(result); break; + case RN52_OTHER_EVENT: + if(result->connection == RN52_AUDIO_STREAMING) { + get_track_metadata(result); + } + break; } return 1; } @@ -117,47 +125,52 @@ } bool RN52::get_track_metadata(RN52_RESULT * result){ clear_serial(); + metadata_responsetime.start(); + metadata_responsetime.reset(); 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); - } + 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); } - break; - case 'e': - { - char duration_string[10]; - copy_response(result->response, duration_string, 9); - result->duration = strtoul(duration_string, NULL, 10); + else { //TrackCount + copy_response(result->response, number_string, 11); + result->track_count = strtoul(number_string, NULL, 10); } - break; - } + } + break; + case 'e': + { + char duration_string[10]; + copy_response(result->response, duration_string, 9); + result->duration = strtoul(duration_string, NULL, 10); + } + break; } - clear_serial(); + if(metadata_responsetime.read_ms() > METADATA_RESPONSE_TIMEOUT) { + clear_serial(); + return 0; + } } + clear_serial(); return 1; } @@ -217,7 +230,7 @@ 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("SC,200420\r"); //device type serial.printf("SN,%s\r", name); //name serial.printf(REBOOT); clear_serial();
--- a/main.cpp Sun Feb 07 18:24:13 2016 +0000 +++ b/main.cpp Fri Mar 18 20:58:36 2016 +0000 @@ -5,6 +5,15 @@ // Due to power saving functions special firmware required http://mbed.org/users/simon/notebook/interface-powerdown/ +/**** TODO **** +Fix sleep mode +Implement caller ID retreival +Change some public functions to private for both CDC & RN52 +Instead of sending &res to RN52, add public variables for all data to be communicated +rn52.check_event should return event instead of writing to res, (remove if and use switch directly in handle_bt_input + +**** END TODO****/ + #include "mbed.h" #include "PowerControl/PowerControl.h" #include "PowerControl/EthernetPowerControl.h" @@ -12,7 +21,6 @@ #include "CDC.h" #include "RN52.h" - CDC cdc; RN52 rn52; RN52_RESULT res; @@ -63,16 +71,6 @@ rn52.enable(); } } - while(pc.readable()) { - switch (pc.getc()) { - case '1': - printf("enabling\r\n"); - active = 1; - cdc.enable(); - rn52.enable(); - break; - } - } } } @@ -175,7 +173,6 @@ case RN52_CONNECTED: cdc.display("BT ANSLUTEN"); rn52.maxvolume(); - rn52.toggle_play(); break; case RN52_AUDIO_STREAMING: cdc.display(res.title);