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
- Committer:
- petter
- Date:
- 2016-01-11
- Revision:
- 5:8e468fef2754
- Parent:
- 4:3041a571b7a7
- Child:
- 6:c454f88524d6
File content as of revision 5:8e468fef2754:
// Inspired from BlueSaab // Project/Hardware: http://bluesaab.blogspot.com/ // Code: https://github.com/kveilands/SAAB-CDC/tree/master/SAAB-CDC // I-Bus information from http://pikkupossu.1g.fi/tomi/projects/i-bus/i-bus.html #include "mbed.h" #include "CDC.h" #include "RN52.h" CDC cdc; RN52 rn52; RN52_RESULT res; Serial pc(USBTX, USBRX); // tx, rx void handle_pc_input() { //Debug connection to PC if(pc.readable()) { switch (pc.getc()) { case 'p': if(rn52.toggle_play()) { printf("play/pause\r\n"); } break; case 'v': printf("volume up\r\n"); rn52.maxvolume(); break; case 'n': printf("next track\r\n"); rn52.next_track(); break; case 'q': printf("getting status\r\n"); rn52.get(RN52_GETSTATUS, &res); printf("%s", res.response); break; case 't': rn52.get(RN52_CALLER_ID, &res); printf("%s", res.response); break; } } } void handle_cdc_input() { switch (cdc.get_cmd()) { case IBUS_OTHER_MESSAGE: break; case IBUS_DOORS_LOCKED: //Goto sleep break; case IBUS_DOORS_UNLOCKED: //wake up break; case IBUS_NEXT: rn52.toggle_play(); break; case IBUS_CDC_ON: rn52.connect(); break; case IBUS_CDC_OFF: rn52.disconnect(); break; case IBUS_VOLUME_UP: break; case IBUS_VOLUME_DOWN: break; case IBUS_SKIP_FW: rn52.next_track(); break; case IBUS_SKIP_BW: rn52.prev_track(); break; case IBUS_SET: rn52.connect(); break; case IBUS_CLEAR: break; } } void handle_bt_input() { if(rn52.check_event(&res)) { switch (res.event) { case RN52_CALLER_ID_EVENT: break; case RN52_TRACK_CHANGE_EVENT: cdc.reset_elapsed_time(); break; case RN52_NO_EVENT: //no specific event occured, check connection status switch(res.connection) { case RN52_CONNECTED: cdc.display("BT ANSLUTEN"); rn52.maxvolume(); break; case RN52_AUDIO_STREAMING: cdc.display("BT SPELAR"); cdc.start_elapsed_time(); break; } if(res.connection != RN52_AUDIO_STREAMING) { cdc.stop_elapsed_time(); cdc.reset_elapsed_time(); } } } } int main() { printf("Petters BT CDC-emulator\r\n"); printf("Initializing\r\n"); cdc.init(); rn52.init(); printf("Starting loop\r\n"); while(1) { handle_pc_input(); handle_cdc_input(); handle_bt_input(); } }