Ben Parkes / Mbed OS Thread_Communication_V5

Dependencies:   BMP280

Fork of Thread_Communication_V4_fortest by BDG

Files at this revision

API Documentation at this revision

Comitter:
dnonoo
Date:
Sat Jan 06 12:22:12 2018 +0000
Parent:
13:089f3adb3813
Child:
15:864d936b51cf
Commit message:
EVERYTHING WORKING pre object orientated

Changed in this revision

LCD.cpp Show annotated file Show diff for this revision Revisions of this file
LCD.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/LCD.cpp	Fri Jan 05 19:47:33 2018 +0000
+++ b/LCD.cpp	Sat Jan 06 12:22:12 2018 +0000
@@ -93,6 +93,12 @@
         case 1:
             DATA(LINE2,CMD); 
             break;
+        case 2:
+            DATA(LINE3,CMD);
+            break;
+        case 3:
+            DATA(LINE4,CMD);
+            break;
         default:
             DATA(LINE1,CMD);
             break;
@@ -135,7 +141,7 @@
         _E = 0;                 //DISABLE LCD DATA LINE
 }
 /*---------------------------------------------------------------------*/
-void LCD::Write(char text[16]){   
+void LCD::Write(char text[80]){   
     int i = 0;
       
     
--- a/LCD.h	Fri Jan 05 19:47:33 2018 +0000
+++ b/LCD.h	Sat Jan 06 12:22:12 2018 +0000
@@ -13,6 +13,8 @@
 
 #define LINE1    0x80        // Start address of first line
 #define LINE2    0xC0        // Start address of second line
+#define LINE3    0x94
+#define LINE4    0xD4
 
 #define LCD_CLR             (LCD_DATA(CLEAR,CMD))
 #define LCD_HOME            (LCD_DATA(HOME,CMD))
@@ -21,7 +23,7 @@
 public:
 LCD(PinName RS, PinName E, PinName d4, PinName d5, PinName d6, PinName d7);
 void Clear(void);
-void Write(char text[16]);
+void Write(char text[80]);
 void RowSelect(int row);
 
 protected:
--- a/main.cpp	Fri Jan 05 19:47:33 2018 +0000
+++ b/main.cpp	Sat Jan 06 12:22:12 2018 +0000
@@ -18,6 +18,7 @@
 void circBuff();
 void writeRemove_SD();
 void Network1();
+void LCD_timerISR();
 
 // USER_BUTTON ISRs (Debounce)
 
@@ -28,7 +29,7 @@
 // Tickers & Timeouts
 Timeout userButtonTimeout; // FOR debouncing User Switch
 Ticker read;            //  ***Sets sampling period!*** (ISR Signals sampling Thread)
-
+Ticker refresh;
 /* LOCKS */ 
 Mutex DataBuffer;
 Mutex dataLock;
@@ -46,6 +47,7 @@
 volatile char TIME[21];
 
 volatile double sampleTime = 15.0;
+//int LCD_refresh = 1;
 // int to hold current switch state
 int userButtonState = FallingEdge;
 
@@ -94,6 +96,7 @@
     
     userButton.rise(&userButtonRise);
     read.attach(&readISR, sampleTime);
+    refresh.attach(&LCD_timerISR, LCD_REFRESH);
     
     while (1) {
         Yellow_ext = ON;
@@ -184,61 +187,88 @@
 /*--------------------------------------------------------------------*/    
 
 /*--------------------------------LCD---------------------------------*/
+void LCD_timerISR () {
+    _PrintLCD.signal_set(LCD_READY);
+    }
+
 void PrintLCD () {
     
     int i = 0;
+    int j = 4;
+    char lightString[16];
+    char tempString[16];
+    char pressString[16];
+    char lcd_TIME[21];
+    
     while(1){
-        char lightString[16];
-        char tempString[16];
-        char pressString[16];
+        
+        lcd.RowSelect(3);
+        
+
+        if (j == 4) {
 
-        lcd.Clear();
-        lcd.RowSelect(0);
-         
-        switch (i){
-            case 0:{
-                osEvent evt = mail_box.get();
-        
-                if (evt.status == osEventMail) {
-                    mail_t *mail = (mail_t*)evt.value.p;
-            
-                    sprintf(lightString,"%.4f", mail->LDR_Value);
-                    sprintf(tempString,"%2.2f", mail->temp_Value);
-                    sprintf(pressString,"%4.2f", mail->press_Value);    
-                
-                    mail_box.free(mail);
+            lcd.Clear();
+            lcd.RowSelect(0);
+            switch (i) {
+                case 0: {
+                    osEvent evt = mail_box.get();
+
+                    if (evt.status == osEventMail) {
+                        mail_t *mail = (mail_t*)evt.value.p;
+
+                        sprintf(lightString,"%.4f", mail->LDR_Value);
+                        sprintf(tempString,"%2.2f", mail->temp_Value);
+                        sprintf(pressString,"%4.2f", mail->press_Value);
+
+                        mail_box.free(mail);
+                    }
+
+                    lcd.Write("Light:");
+                    lcd.RowSelect(1);
+                    lcd.Write(lightString);
+                    i++;
+                    j = 0;
+                    break;
                 }
-               
-                lcd.Write("Light:");
-                lcd.RowSelect(1);
-                lcd.Write(lightString);
-                i++;                
-            break;
-            }
-            case 1:
-                lcd.Write("Temperature(C):");
-                lcd.RowSelect(1);
-                lcd.Write(tempString);
-                i++;
-            break;
-        
-            case 2:
-                lcd.Write("Pressure(mBar):");
-                lcd.RowSelect(1);
-                lcd.Write(pressString);
-                i =0;                
-            break;
-            
-            default:            
-                i = 0;                
-            break;
+                case 1:
+                    lcd.Write("Temperature(C):");
+                    lcd.RowSelect(1);
+                    lcd.Write(tempString);
+                    i++;
+                    j = 0;
+                    break;
+
+                case 2:
+                    lcd.Write("Pressure(mBar):");
+                    lcd.RowSelect(1);
+                    lcd.Write(pressString);
+                    i =0;
+                    j = 0;
+                    break;
+
+                default:
+                    i = 0;
+                    j = 0;
+                    break;
+            }//end switch
+        }// end if
+        else{
+            j++;
         }
-        
-        Red_int = !Red_int;        
+        lcd.RowSelect(3);
 
-        Thread::wait (5000);
-    }
-}
+        dataLock.lock();
+        memset(lcd_TIME, NULL, 21);
+        time(&raw_time);
+        sample_epoch = localtime(&raw_time);
+        strftime( lcd_TIME,21,"%d/%m/%Y  %X", sample_epoch);
+        dataLock.unlock();
+
+        lcd.Write(lcd_TIME);
+        Thread::signal_wait(LCD_READY);
+        Red_int = !Red_int;
+    }//end while
+}// end thread
 /*--------------------------------------------------------------------*/
 
 /*------------------------------SERIAL_CMD----------------------------*/
@@ -749,10 +779,15 @@
     pc.printf("LCD Test\n\r");
     
     lcd.Clear();
+    lcd.RowSelect(0);
+    lcd.Write("1******LCD*********1");
     lcd.RowSelect(1);
-    lcd.Write("*******LCD******");
+    lcd.Write("2******TEST********2");
     lcd.RowSelect(2);
-    lcd.Write("******TEST******");
+    lcd.Write("3******LCD*********3");
+    lcd.RowSelect(3);
+    lcd.Write("4******TEST********4");
+    
     wait(1);
     lcd.Clear();
     pc.printf("Basic POST end\n\r");    
--- a/main.h	Fri Jan 05 19:47:33 2018 +0000
+++ b/main.h	Sat Jan 06 12:22:12 2018 +0000
@@ -7,6 +7,8 @@
 #define MAX_SAMPLES 120
 #define SENSOR_UPDATE 1
 #define DATA_READY 1
+#define LCD_REFRESH 1  // define time for LCD to refresh (ever 1 second for clock)
+#define LCD_READY 1         // LCD ISR to LCD thread Signal
 #define ON 1
 #define OFF 0