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.
main.cpp@0:6cf6e566c0da, 2016-01-04 (annotated)
- Committer:
- petter
- Date:
- Mon Jan 04 15:31:12 2016 +0000
- Revision:
- 0:6cf6e566c0da
- Child:
- 2:10c60edc8573
First commit.; Fully working cdc emulator. Control Playback with steering wheel buttons.; Debug outputs on SID.; Playback information to NAV unit not perfect.; RN52 not upgraded to 1.16 so no handling of track metadata.; No handling of phone profile.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
petter | 0:6cf6e566c0da | 1 | // Inspired from BlueSaab |
petter | 0:6cf6e566c0da | 2 | // Project/Hardware: http://bluesaab.blogspot.com/ |
petter | 0:6cf6e566c0da | 3 | // Code: https://github.com/kveilands/SAAB-CDC/tree/master/SAAB-CDC |
petter | 0:6cf6e566c0da | 4 | // I-Bus information from http://pikkupossu.1g.fi/tomi/projects/i-bus/i-bus.html |
petter | 0:6cf6e566c0da | 5 | |
petter | 0:6cf6e566c0da | 6 | #include "mbed.h" |
petter | 0:6cf6e566c0da | 7 | #include "CDC.h" |
petter | 0:6cf6e566c0da | 8 | #include "RN52.h" |
petter | 0:6cf6e566c0da | 9 | |
petter | 0:6cf6e566c0da | 10 | CDC cdc; |
petter | 0:6cf6e566c0da | 11 | RN52 rn52; |
petter | 0:6cf6e566c0da | 12 | RN52_RESULT res; |
petter | 0:6cf6e566c0da | 13 | |
petter | 0:6cf6e566c0da | 14 | Timer playback; |
petter | 0:6cf6e566c0da | 15 | |
petter | 0:6cf6e566c0da | 16 | |
petter | 0:6cf6e566c0da | 17 | Serial pc(USBTX, USBRX); // tx, rx |
petter | 0:6cf6e566c0da | 18 | |
petter | 0:6cf6e566c0da | 19 | int main() { |
petter | 0:6cf6e566c0da | 20 | printf("Petters BT CDC-emulator\r\n"); |
petter | 0:6cf6e566c0da | 21 | printf("Initializing\r\n"); |
petter | 0:6cf6e566c0da | 22 | cdc.init(); |
petter | 0:6cf6e566c0da | 23 | rn52.init(); |
petter | 0:6cf6e566c0da | 24 | printf("Starting loop\r\n"); |
petter | 0:6cf6e566c0da | 25 | playback.start(); //only for debug |
petter | 0:6cf6e566c0da | 26 | while(1) { |
petter | 0:6cf6e566c0da | 27 | if(pc.readable()) { |
petter | 0:6cf6e566c0da | 28 | switch (pc.getc()) { |
petter | 0:6cf6e566c0da | 29 | case 'p': |
petter | 0:6cf6e566c0da | 30 | if(rn52.set(RN52_PLAYPAUSE)) { |
petter | 0:6cf6e566c0da | 31 | printf("play/pause\r\n"); |
petter | 0:6cf6e566c0da | 32 | } |
petter | 0:6cf6e566c0da | 33 | break; |
petter | 0:6cf6e566c0da | 34 | case 'v': |
petter | 0:6cf6e566c0da | 35 | printf("volume up\r\n"); |
petter | 0:6cf6e566c0da | 36 | rn52.set(RN52_VOLUMEUP); |
petter | 0:6cf6e566c0da | 37 | break; |
petter | 0:6cf6e566c0da | 38 | case 'n': |
petter | 0:6cf6e566c0da | 39 | printf("next track\r\n"); |
petter | 0:6cf6e566c0da | 40 | rn52.set(RN52_NEXTTRACK); |
petter | 0:6cf6e566c0da | 41 | break; |
petter | 0:6cf6e566c0da | 42 | case 'q': |
petter | 0:6cf6e566c0da | 43 | printf("getting status\r\n"); |
petter | 0:6cf6e566c0da | 44 | rn52.get(RN52_GETSTATUS, &res); |
petter | 0:6cf6e566c0da | 45 | printf("%s", res.response); |
petter | 0:6cf6e566c0da | 46 | case 't': |
petter | 0:6cf6e566c0da | 47 | rn52.get(RN52_CALLER_ID, &res); |
petter | 0:6cf6e566c0da | 48 | printf("%s", res.response); |
petter | 0:6cf6e566c0da | 49 | } |
petter | 0:6cf6e566c0da | 50 | } |
petter | 0:6cf6e566c0da | 51 | cdc.set_time((char)(((int)playback.read())/60),(char)(((int)playback.read())%60)); |
petter | 0:6cf6e566c0da | 52 | switch (cdc.get_cmd()) { |
petter | 0:6cf6e566c0da | 53 | case IBUS_OTHER_MESSAGE: |
petter | 0:6cf6e566c0da | 54 | break; |
petter | 0:6cf6e566c0da | 55 | case IBUS_DOORS_LOCKED: |
petter | 0:6cf6e566c0da | 56 | break; |
petter | 0:6cf6e566c0da | 57 | case IBUS_DOORS_UNLOCKED: |
petter | 0:6cf6e566c0da | 58 | break; |
petter | 0:6cf6e566c0da | 59 | case IBUS_NEXT: |
petter | 0:6cf6e566c0da | 60 | cdc.display("NEXT"); |
petter | 0:6cf6e566c0da | 61 | rn52.set(RN52_PLAYPAUSE); |
petter | 0:6cf6e566c0da | 62 | break; |
petter | 0:6cf6e566c0da | 63 | case IBUS_CDC_ON: |
petter | 0:6cf6e566c0da | 64 | cdc.display("CDC ON"); |
petter | 0:6cf6e566c0da | 65 | break; |
petter | 0:6cf6e566c0da | 66 | case IBUS_CDC_OFF: |
petter | 0:6cf6e566c0da | 67 | cdc.display("CDC OFF"); |
petter | 0:6cf6e566c0da | 68 | break; |
petter | 0:6cf6e566c0da | 69 | case IBUS_VOLUME_UP: |
petter | 0:6cf6e566c0da | 70 | cdc.display("VOLUME UP"); |
petter | 0:6cf6e566c0da | 71 | rn52.set(RN52_VOLUMEUP); |
petter | 0:6cf6e566c0da | 72 | break; |
petter | 0:6cf6e566c0da | 73 | case IBUS_VOLUME_DOWN: |
petter | 0:6cf6e566c0da | 74 | cdc.display("VOLUME DOWN"); |
petter | 0:6cf6e566c0da | 75 | break; |
petter | 0:6cf6e566c0da | 76 | case IBUS_SKIP_FW: |
petter | 0:6cf6e566c0da | 77 | cdc.display("SKIP FW"); |
petter | 0:6cf6e566c0da | 78 | rn52.set(RN52_NEXTTRACK); |
petter | 0:6cf6e566c0da | 79 | break; |
petter | 0:6cf6e566c0da | 80 | case IBUS_SKIP_BW: |
petter | 0:6cf6e566c0da | 81 | cdc.display("SKIP BW"); |
petter | 0:6cf6e566c0da | 82 | rn52.set(RN52_PREVTRACK); |
petter | 0:6cf6e566c0da | 83 | break; |
petter | 0:6cf6e566c0da | 84 | case IBUS_SET: |
petter | 0:6cf6e566c0da | 85 | cdc.display("SET"); |
petter | 0:6cf6e566c0da | 86 | rn52.set(RN52_CONNECT); |
petter | 0:6cf6e566c0da | 87 | break; |
petter | 0:6cf6e566c0da | 88 | case IBUS_CLEAR: |
petter | 0:6cf6e566c0da | 89 | cdc.display("CLEAR"); |
petter | 0:6cf6e566c0da | 90 | rn52.set(RN52_DISCONNECT); |
petter | 0:6cf6e566c0da | 91 | break; |
petter | 0:6cf6e566c0da | 92 | } |
petter | 0:6cf6e566c0da | 93 | if(rn52.changed()) { |
petter | 0:6cf6e566c0da | 94 | rn52.get(RN52_GETSTATUS, &res); |
petter | 0:6cf6e566c0da | 95 | switch (res.event) { |
petter | 0:6cf6e566c0da | 96 | case RN52_CALLER_ID_EVENT: |
petter | 0:6cf6e566c0da | 97 | rn52.get(RN52_CALLER_ID, &res); |
petter | 0:6cf6e566c0da | 98 | break; |
petter | 0:6cf6e566c0da | 99 | case RN52_TRACK_CHANGE_EVENT: |
petter | 0:6cf6e566c0da | 100 | rn52.get(RN52_TRACK_METADATA, &res); |
petter | 0:6cf6e566c0da | 101 | playback.reset(); |
petter | 0:6cf6e566c0da | 102 | break; |
petter | 0:6cf6e566c0da | 103 | default: //no event occured, check connection status |
petter | 0:6cf6e566c0da | 104 | if(res.connection == RN52_AUDIO_STREAMING) { |
petter | 0:6cf6e566c0da | 105 | cdc.display("BT SPELAR"); |
petter | 0:6cf6e566c0da | 106 | playback.start(); |
petter | 0:6cf6e566c0da | 107 | } |
petter | 0:6cf6e566c0da | 108 | else { |
petter | 0:6cf6e566c0da | 109 | playback.stop(); |
petter | 0:6cf6e566c0da | 110 | playback.reset(); |
petter | 0:6cf6e566c0da | 111 | } |
petter | 0:6cf6e566c0da | 112 | |
petter | 0:6cf6e566c0da | 113 | } |
petter | 0:6cf6e566c0da | 114 | |
petter | 0:6cf6e566c0da | 115 | } |
petter | 0:6cf6e566c0da | 116 | } |
petter | 0:6cf6e566c0da | 117 | } |