Rob Dobson / BLE_AlarmWatch

Dependencies:   BLE_API mbed-src nRF51822 nrf51_rtc

Files at this revision

API Documentation at this revision

Comitter:
Bobty
Date:
Mon Jul 27 19:30:11 2015 +0000
Parent:
3:a4b8d67de1b1
Child:
5:2682353a8c32
Commit message:
Now using nrf51_rtc library by Francis Schumacher

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
nrf51_rtc.lib Show annotated file Show diff for this revision Revisions of this file
--- 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();
     }
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nrf51_rtc.lib	Mon Jul 27 19:30:11 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/fxschumacher/code/nrf51_rtc/#3677a016109b