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: main.cpp
- Revision:
- 13:968af0520530
- Parent:
- 12:4194c47ca60b
- Child:
- 14:3f4098e94c29
--- a/main.cpp Fri Jan 29 20:27:37 2016 +0000 +++ b/main.cpp Sat Jan 30 21:03:52 2016 +0000 @@ -16,9 +16,11 @@ CDC cdc; RN52 rn52; RN52_RESULT res; + Ticker wakeup; - Serial pc(USBTX, USBRX); // tx, rx +DigitalOut led3(LED3, 0); +DigitalOut led4(LED4, 0); bool active = 1; void handle_pc_input(); @@ -32,8 +34,8 @@ printf("Disabling unused peripherals to decrease power consumption\r\n"); PHY_PowerDown(); // Power down Ethernet interface - saves around 175mW semihost_powerdown(); // If you don't need the PC host USB interface power down magic USB interface chip - saves around 150mW | Needs new firmware (URL below) and USB cable not connected http://mbed.org/users/simon/notebook/interface-powerdown/ + rn52.init(); cdc.init(); - rn52.init(); printf("Adding wakeup routine\r\n"); wakeup.attach(&check_for_wakeup, 1); printf("Starting loop\r\n"); @@ -50,12 +52,23 @@ } void check_for_wakeup(){ + led3 = !led3; if(!active) { + led4 = !led4; IBUS_COMMAND cmd = IBUS_OTHER_MESSAGE; - while(cmd != IBUS_NO_MESSAGE) { + while(cmd != IBUS_HEAD_UNIT_OFF) { cmd = cdc.get_cmd(); if(cmd == IBUS_HEAD_UNIT_ON) { active = 1; + rn52.enable(); + cdc.enable(); + } + } + while(pc.readable()) { + if(pc.getc() == '1') { + active = 1; + rn52.enable(); + cdc.enable(); } } } @@ -87,9 +100,11 @@ rn52.get_caller_id(&res); printf("%s\r\n", res.response); break; - case 'a': + case '0': printf("deactivating\r\n"); active = 0; + rn52.disable(); + cdc.disable(); break; } } @@ -99,7 +114,9 @@ switch (cdc.get_cmd()) { case IBUS_HEAD_UNIT_OFF: cdc.display("Shutdown"); -// active = 0; + active = 0; + rn52.disable(); + cdc.disable(); break; case IBUS_NEXT: rn52.toggle_play();