software opt

Dependencies:   Hexi_KW40Z Hexi_OLED_SSD1351

Fork of Hexi_BLE_Time by Adam S

Revision:
5:0076f669169f
Parent:
4:20d4eebfa986
Child:
6:ae8a23b0735b
--- a/main.cpp	Fri May 04 08:56:11 2018 +0000
+++ b/main.cpp	Sat Jun 09 16:56:45 2018 +0000
@@ -4,6 +4,7 @@
 #include "OLED_types.h"
 #include "OpenSans_Font.h"
 #include "string.h"
+#include "time.h"
 
 #define LED_ON      0
 #define LED_OFF     1
@@ -31,9 +32,12 @@
 
 /*Create a Thread to handle sending BLE Sensor Data */ 
 Thread txThread;
+Thread broadcastThread;
 
  /* Text Buffer */ 
 char text[20]; 
+char time_text[20];
+char date_text[25];
 
 uint8_t battery = 100;
 uint8_t light = 0;
@@ -45,6 +49,8 @@
 uint16_t z = 10000;
 
 /****************************Call Back Functions*******************************/
+
+
 void ButtonRight(void)
 {
     StartHaptic();
@@ -55,8 +61,10 @@
 {
     StartHaptic();
     kw40z_device.ToggleAdvertisementMode();
+
 }
 
+
 void PassKey(void)
 {
     StartHaptic();
@@ -91,6 +99,7 @@
         blueLed = LED_OFF;
         pc.printf("off\n\r", data);
     }
+    
 }
 /***********************End of Call Back Functions*****************************/
 
@@ -103,7 +112,8 @@
     kw40z_device.attach_buttonRight(&ButtonRight);
     kw40z_device.attach_passkey(&PassKey);
     kw40z_device.attach_alert(&AlertReceived);
-
+    
+       
     pc.printf("hello\n\r");
     
     /* Turn on the backlight of the OLED Display */
@@ -132,16 +142,51 @@
     /* Display Label at x=22,y=80 */ 
     strcpy((char *) text,"Tap Below");
     oled.Label((uint8_t *)text,22,80);
-         
-    uint8_t prevLinkState = 0; 
-    uint8_t currLinkState = 0;
-     
-    txThread.start(txTask); /*Start transmitting Sensor Tag Data */
+
+    // txThread.start(txTask); /*Start transmitting Sensor Tag Data */
+    
+    int counter = 0;
+    int status = 0;
     
     while (true) 
     {
-        // blueLed = !kw40z_device.GetAdvertisementMode(); /*Indicate BLE Advertisment Mode*/   
-        Thread::wait(50);
+        counter += 1; 
+        status = !kw40z_device.GetAdvertisementMode(); /*Indicate BLE Advertisment Mode*/   
+        blueLed = status;
+        pc.printf("[%i] blueLed = %i\r\n",counter, status);
+        
+        time_t seconds = time(&seconds); 
+        const tm *t = localtime(&seconds); // Convert the unix time to actual time
+        /*
+        int h = (t->tm_hour); // The hours
+        int year = (t->tm_year);
+          
+        // Format the time
+        sprintf(time_text,"%d:%d:%d",h, t->tm_min, t->tm_sec);  
+        sprintf(date_text,"%d-%d-%d",year, (t->tm_mon), (t->tm_mday));
+        */
+        char buf[80];
+        struct tm  ts;
+         // Format time, "ddd yyyy-mm-dd hh:mm:ss zzz"
+        ts = *localtime(&seconds);
+        strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &ts);
+        printf("%s\r\n", buf);
+       
+        pc.printf(time_text);
+        pc.printf("\r\n");
+        pc.printf(date_text);
+        pc.printf("\r\n");
+        
+        // Display the time on screen
+        // oled_status_t SSD1351::TextBox(const uint8_t* text, int8_t xCrd, int8_t yCrd,uint8_t width,uint8_t height)
+        oled.TextBox((uint8_t *)time_text,2,2, 91, 15); 
+        oled.TextBox((uint8_t *)date_text,2,16, 91, 15); 
+        redLed = !redLed;
+        
+        Thread::wait(500);
+        
+
+        
     }
 }
 
@@ -184,6 +229,7 @@
     }
 }
 
+
 void UpdateSensorData(void)
 {    
     battery -= 5;