Urm didnt i write this already? Mostly same as georges code, except: buffer and sensor reads in seperate threads (Not Main) some other bits

Dependencies:   BMP280

Fork of Sample_LCD_Serial_Buffer by BDG

Revision:
3:73497379c0cb
Parent:
2:28d12a3db239
Child:
4:93d6d13d4de3
--- a/main.cpp	Thu Dec 14 15:44:49 2017 +0000
+++ b/main.cpp	Thu Dec 14 19:23:45 2017 +0000
@@ -1,20 +1,23 @@
 #include "mbed.h"
 #include "main.h"
 
-
+LCD  lcd(PD_15, PF_12, PF_13, PE_9, PF_14, PF_15); 
+BMP280 Sensor(D14, D15);
 
 
-LCD  lcd(PD_15, PF_12, PF_13, PE_9, PF_14, PF_15); 
-
-BMP280 Sensor(D14, D15);
 void PrintLCD ();
 void Rx_interrupt();
 void Serial_CMD();
 
+//Serial_CMD
 volatile int rx_in=0;
 char rx_line[80];
 int s_cmd = 0;
 
+//Time date
+time_t raw_time = time(NULL);
+char time_buffer[80];
+
 /* Mail */
 typedef struct {
     float LDR_Value;
@@ -24,11 +27,35 @@
 
 Mail<mail_t, 16> mail_box;
 
-
+//Threads
 Thread t1;
 Thread t2;
 Thread S_CMD;
+    
+/*--------------------------------MAIN--------------------------------*/
+int main() {
 
+    t1.start(PrintLCD);
+    
+    pc.baud(9600);
+    pc.attach(&Rx_interrupt, Serial::RxIrq);
+    S_CMD.start(Serial_CMD);
+
+        while(1) {
+            Green_int = !Green_int;
+
+            mail_t *mail = mail_box.alloc();
+            mail->LDR_Value = LDR_In.read(); 
+            mail->temp_Value = Sensor.getTemperature();
+            mail->press_Value = Sensor.getPressure();
+            mail_box.put(mail);        
+        
+            Thread::wait (15000);
+        }
+}
+/*--------------------------------------------------------------------*/
+
+/*--------------------------------LCD---------------------------------*/
 void PrintLCD () {
     
     int i = 0;
@@ -92,30 +119,9 @@
         Thread::wait (5000);
     }
 }
-    
-
-int main() {
-
-    t1.start(PrintLCD);
-    
-    pc.baud(9600);
-    pc.attach(&Rx_interrupt, Serial::RxIrq);
-    S_CMD.start(Serial_CMD);
+/*--------------------------------------------------------------------*/
 
-        while(1) {
-            Green_int = !Green_int;
-
-            mail_t *mail = mail_box.alloc();
-            mail->LDR_Value = LDR_In.read(); 
-            mail->temp_Value = Sensor.getTemperature();
-            mail->press_Value = Sensor.getPressure();
-            mail_box.put(mail);        
-        
-            Thread::wait (15000);
-        }
-
-}
-
+/*------------------------------SERIAL_CMD----------------------------*/
 void Rx_interrupt() {
     
     while (pc.readable()) {
@@ -136,9 +142,15 @@
     while(1){
     if(s_cmd == 1){
         pc.attach(NULL, Serial::RxIrq);
-    
+        
+        struct tm * s_time;
+        char tm_n[4];
+        
         if(strstr(rx_line, "READ ALL")){
-            pc.printf("READ ALL\n\r");
+            time ( &raw_time );
+            s_time = localtime ( &raw_time );
+            strftime(time_buffer, 80, "%d/%m/%Y, %X\n\r", s_time);
+            pc.puts(time_buffer);
         }
         else if(strstr(rx_line, "DELETE ALL")){
             pc.printf("DELETE ALL\n\r");
@@ -147,10 +159,47 @@
             pc.printf("READ\n\r");
         }
         else if(strstr(rx_line, "DELETE")){
-            pc.printf("SETDATE\n\r");
+            pc.printf("DELETE\n\r");
+        }
+        else if(strstr(rx_line, "SETDATE")){
+            time ( &raw_time );
+            s_time = localtime ( &raw_time );
+            
+            int dd = atoi(strncpy(tm_n,&rx_line[8],2));
+            s_time->tm_mday = dd;
+            memset(tm_n, NULL, 4);
+            
+            int mm = atoi(strncpy(tm_n,&rx_line[11],2));
+            s_time->tm_mon = mm-1;
+            memset(tm_n, NULL, 4);
+            
+            int yyyy = atoi(strncpy(tm_n,&rx_line[14],4));
+            s_time->tm_year = yyyy-1900;
+            memset(tm_n, NULL, 4);
+            
+            set_time(mktime(s_time));
+            strftime(time_buffer, 80, "%d/%m/%Y\n\r", s_time);
+            pc.puts(time_buffer);
         }
         else if(strstr(rx_line, "SETTIME")){
-            pc.printf("SETTIME\n\r");
+            time ( &raw_time );
+            s_time = localtime ( &raw_time );
+            
+            int ss = atoi(strncpy(tm_n,&rx_line[14],2));
+            s_time->tm_sec = ss;
+            memset(tm_n, NULL, 4);
+            
+            int mm = atoi(strncpy(tm_n,&rx_line[11],2));
+            s_time->tm_min = mm;
+            memset(tm_n, NULL, 4);
+            
+            int hh = atoi(strncpy(tm_n,&rx_line[8],2));
+            s_time->tm_hour = hh;
+            memset(tm_n, NULL, 4);
+            
+            set_time(mktime(s_time));
+            strftime(time_buffer, 80, "%X\n\r", s_time);
+            pc.puts(time_buffer);
         }
         else if(strstr(rx_line, "SETT")){
             pc.printf("SETT\n\r");
@@ -164,7 +213,8 @@
         else{
             pc.printf("ERROR\n\r");    
         }
-    
+        
+        memset(time_buffer, NULL, 80);
         memset(rx_line, NULL, 80);
         rx_in = 0;
     
@@ -174,3 +224,4 @@
     Thread::wait(5);
     }
 }
+/*--------------------------------------------------------------------*/
\ No newline at end of file