Network, SD, Readall. comments added

Dependencies:   Peripherals Buffer_lib_v2 SD_Lib_EffedUP_ERP Time_Lib_v2 Year3_Version5 BMP280 Network_Lib TextLCD BME280

Revision:
8:dde5976445b4
Parent:
7:981670f59caf
Child:
11:799025124e87
--- a/main.cpp	Fri Nov 23 14:20:10 2018 +0000
+++ b/main.cpp	Fri Nov 23 20:12:19 2018 +0000
@@ -3,20 +3,16 @@
 #include "SDBlockDevice.h"
 #include "FATFileSystem.h"
 #include "sample_hardware.hpp"
+#include "thread_functions.hpp"
 
-#define Day 1
-#define Month 2
-#define Year 3
-#define Hour  4
-#define Minute 5
-#define Second 6
+
 
 //Function declarations
 void displayOnLcd();
 void updateRealTimeClock(char *buffer);
 void getLineFromSerial(char *keyBuffer, int bufferLength);
 void displayMessageOnConsole();
-void SetingTimeWithButtons ();
+void SettingTimeWithButtons ();
 void FunctionSensor();
 void FunctionTime();
 void FunctionSerial();
@@ -75,309 +71,3 @@
     t3.start(FunctionSerial); 
        
 }
-    
-
-void displayOnLcd() {
-    date_mutex.lock();
-    
-    myled = !myled;
- 
-    currentTime = time(NULL);
-    strftime(lcdBuffer, 32, "%d/%m/%Y  %H:%M:%S", localtime(&currentTime));
- 
-    //lcd.cls();
-//    lcd.locate(0,0);
-    pc.printf("%s\n\r", lcdBuffer);
- 
-    myled = !myled;   
-    date_mutex.unlock();   
-};
-
-void updateRealTimeClock(char *buffer) {
-    date_mutex.lock();
-    
-    char *tp;
-    char *timeArray[6];
-    int arrayIndex;
-    struct tm struct_time;
-    
-    // extract number from string
-    arrayIndex = 0;
-    tp = strtok( buffer, " /:-" );
-    timeArray[arrayIndex++] = tp;
-    printf("%d ", atoi(tp));
-    while ( tp != NULL && arrayIndex < 6 ) {
-        tp = strtok( NULL," /:-" );
-        timeArray[arrayIndex++] = tp;
-        if ( tp != NULL ) {
-            printf("%d ", atoi(tp));
-        }
-}
-    printf("\r\n");
-    
-    // store number into time struct   
-    struct_time.tm_mday = atoi(timeArray[0]);
-    struct_time.tm_mon  = atoi(timeArray[1]) - 1;
-    struct_time.tm_year = atoi(timeArray[2]) - 1900;
-    struct_time.tm_hour = atoi(timeArray[3]);
-    struct_time.tm_min  = atoi(timeArray[4]);
-    struct_time.tm_sec  = atoi(timeArray[5]);
- 
-    currentTime = mktime(&struct_time);
-    set_time(currentTime);
-    
-    date_mutex.unlock(); 
-}
-
-void getLineFromSerial(char *keyBuffer, int bufferLength)
-{
-    date_mutex.lock();
-    
-    char c;
-    int index = 0;
- 
-    for (;;) {
-        // break if keyBuffer is full
-        if (index >= bufferLength) {
-            break;
-        }
- 
-        // read input
-        c = pc.getc();
-        //printf(" %d ", c);
-        pc.putc(c);
-        
-        // break if end
-        if (c == '\r') {
-            keyBuffer[index++] = c;
-            printf("\n");
-            break;
-        }
- 
-        // store in keyBuffer
-        keyBuffer[index++] = c;    
-        
-        date_mutex.unlock();     
-    }
-}
-
-void displayMessageOnConsole() {
-    date_mutex.lock();
-    
-    currentTime = time(NULL);
-    //strftime(lcdBuffer, 32, "%Y/%m/%d %H:%M:%S", localtime(&currentTime));
-    strftime(lcdBuffer, 32, "%d/%m/%Y %H:%M:%S", localtime(&currentTime));
- 
-    printf("Current Time:%s\r\n", lcdBuffer);
-    printf("Enter new Time (dd/mm/YYYY HH:MM:SS)\r\n");
-    
-    date_mutex.unlock(); 
-}
-
-void SetingTimeWithButtons () {
-        
-   int day = 0;
-   int month = 0;
-   int year = 2017;
-   int hour = 0;
-   int min = 0;
-   int sec = 0;
-   
-   setting = Day;
-   t = 1;
-   
-   while(t == 1) {
-        switch (setting) {
-        case Day:
-           if (SW1 == 1) {
-                wait(0.2);
-                day = day + 1;
-                lcd.cls();
-                lcd.locate(0,0);
-                lcd.printf("Day = %d\n", day);
-                }
-                    if (SW2 == 1) {
-                        setting = Month;
-                        wait(0.5);
-                }
-        break;       
-                
-        case Month:
-            if (SW1 == 1) {
-                wait(0.2);
-                month = month + 1;
-                lcd.cls();
-                lcd.locate(0,0);
-                lcd.printf("Month = %d\n", month);
-                }
-            if (SW2 == 1) {
-                setting = Year;
-                wait(0.5);
-                        }
-        break;                
-            
-        case Year:
-            if (SW1 == 1) {
-                wait(0.2);
-                year = year + 1;
-                lcd.cls();
-                lcd.locate(0,0);
-                lcd.printf("Year = %d\n", year);
-                }
-            if (SW2 == 1) {
-                setting = Hour;
-                wait(0.5);
-                }
-        break;        
-                        
-        case Hour:
-            if (SW1 == 1) {
-                wait(0.2);
-                hour = hour + 1;
-                lcd.cls();
-                lcd.locate(0,0);
-                lcd.printf("Hour = %d\n", hour);
-                }
-            if (SW2 == 1) {
-                setting = Minute;
-                wait(0.5);
-                        } 
-             break;                      
-                        
-        case Minute:
-            if (SW1 == 1) {
-                wait(0.2);
-                min = min + 1;
-                lcd.cls();
-                lcd.locate(0,0);
-                lcd.printf("Minute = %d\n", min);
-                }
-            if (SW2 == 1) {
-                setting = Second;
-                wait(0.5);
-            } 
-         break; 
-         
-         case Second:
-            if (SW1 == 1) {
-                wait(0.2);
-                sec = sec + 1;
-                lcd.cls();
-                lcd.locate(0,0);
-                lcd.printf("Second = %d\n", sec);
-                }
-            if (SW2 == 1) {
-                wait(0.5);
-                t = 0;
-                }                               
-                 break;       
-            }
-      }
-        
-        struct tm struct_time;  
-                
-     //store number into time struct   
-        struct_time.tm_year = year - 1900;
-        struct_time.tm_mon  = month;
-        struct_time.tm_mday = day;
-        struct_time.tm_hour = hour;
-        struct_time.tm_min  = min;
-        struct_time.tm_sec  = sec;
-     
-    // Coverting to time
-    time_t currentTime = mktime(&struct_time);
-    set_time(currentTime);
-        
-        }
-
-
-void FunctionSensor()
-{
-        while (true) {
-            double temp = sensor.getTemperature();
-            double pressure = sensor.getPressure();
-            lcd.cls();
-            lcd.printf("Temp   Pressure\n"); 
-            lcd.printf("%6.1f ",temp);
-            lcd.printf("%.2f\n",pressure);
-            
-            //Write to SD
-            //fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure);
-            
-            Thread::wait(15000); //Updates the state every 15 seconds
-                        }
-}
-
-void FunctionTime()
-{
-    while (true) {    
-        char lineBuffer[32];
-        char *pointer;
-        pointer = lineBuffer;
-        if (SW1 == 1) {                         //Set time on Putty
-         // show initial message on console
-            displayMessageOnConsole();
-            
-            // get input from console
-            getLineFromSerial(pointer, sizeof(lineBuffer));
-             
-             myled = !myled;
-            // update RTC based on input value
-            updateRealTimeClock(pointer);
-            }
-        if (SW2 == 1) {                     // Set time with Buttons
-            pc.printf("Ready");
-            wait(0.5);
-            SetingTimeWithButtons ();
-            }
-        while(true) {
-            displayOnLcd();
-             myled = !myled;
-            Thread::wait(1000); 
-            }
-        }
-             
-}  
-
-void FunctionSerial()
-{      
-  date_mutex.lock();
-    
-      lcd.cls();
-        lcd.printf("Observe Putty\n\n");
-        
-        
-        pc.printf("\n\rEnter command:\n\r");
-        pc.printf("READ ALL \n\r");
-        char str[9] = "READ ALL";
-        // reads for 8 waiting for new line and ignoring spaces
-        pc.scanf("%8[^\n]*c",str);
-        //prints typed command
-        pc.printf("Chosen Command = ");
-        pc.printf("%s\n\r",str);
-        
-        //check if typed command is equal to string
-        if (!strcmp(str, "READ ALL")) {
-        //if (str == "READ ALL") {
-           // pc.printf("yay\n\r");
-            
-            //get current values 
-            double temp = sensor.getTemperature();         
-            double pressure = sensor.getPressure();
-            fLDR = LDD_ADC_In; 
-            volts = fLDR*3.3f;
-            strftime(lcdBuffer, 32, "%d/%m/%Y %H:%M:%S,", localtime(&currentTime));
- 
-            pc.printf("Date and Time = %s\r\n", lcdBuffer);
-            pc.printf("Temperature = %6.1f deg C,\n\r",temp);
-            pc.printf("Pressure = %.2f mB,\n\r",pressure);
-            pc.printf("Light = %6.4f volts,\n\r", volts);
-            
-         }
-        else {
-            pc.printf("INVALID COMMAND\n\r");
-        }   
-    
-    date_mutex.unlock(); 
-    
-}
\ No newline at end of file