Auto updating alarm watch - accepts alarm settings from a BLE device like a Raspberry Pi and buzzes at the appropriate time - also displays binary time
Dependencies: BLE_API mbed-src nRF51822 nrf51_rtc
Diff: main.cpp
- Revision:
- 4:f0b030a3223f
- Parent:
- 3:a4b8d67de1b1
- Child:
- 5:2682353a8c32
--- a/main.cpp Mon Jul 27 15:25:59 2015 +0000 +++ b/main.cpp Mon Jul 27 19:30:11 2015 +0000 @@ -6,6 +6,7 @@ #include "BLE.h" #include "ButtonService.h" #include "WatchTimeService.h" +#include "nrf51_rtc.h" // BLE platform BLE ble; @@ -60,6 +61,10 @@ void periodicCallback(void) { led1 = !led1; /* Do blinky on LED1 to indicate system aliveness. */ + + // Update the rtc library time (it says in the notes on the rtc lib that this needs to happen + // more than once every few hundred seconds to avoid a rollover + rtc.time(); } time_t watchTimeToUnix(const uint8_t* pWatchTime) @@ -95,11 +100,24 @@ time_t timest = watchTimeToUnix(params->data); retval = timest; if (timest != -1) - set_time(timest); + rtc.set_time(timest); } } } +// TEST CODE +void print_time() +{ + time_t rawtime=rtc.time(); + + // massage the time into a human-friendly format for printing + struct tm * timeinfo; + timeinfo = localtime(&rawtime); + char date[24]; + strftime(date,sizeof(date),"%H:%M:%S on %m/%d/%G",timeinfo); + printf("The current time is %s.\r\n",date); +} + int main(void) { printf("AlarmWatch\r\n"); @@ -152,6 +170,7 @@ testbuf[1], testbuf[2], testbuf[3], testbuf[4], testbuf[5], testbuf[6], retval); printf ("serv %d buflen %d mycode %d offs %d butcode %d\r\n", servcode, buflen, mycode, offs, butcode); printf ("val %ld\r\n", watchTimeService.getValueHandle()); + print_time(); } }