Network, SD, Readall. comments added

Dependencies:   Peripherals Buffer_lib_v2 SD_Lib_EffedUP_ERP Time_Lib_v2 Year3_Version5 BMP280 Network_Lib TextLCD BME280

main.cpp

Committer:
erolleyparnell
Date:
2018-11-23
Revision:
8:dde5976445b4
Parent:
7:981670f59caf
Child:
11:799025124e87

File content as of revision 8:dde5976445b4:

#include "mbed.h"
#include "TextLCD.h"
#include "SDBlockDevice.h"
#include "FATFileSystem.h"
#include "sample_hardware.hpp"
#include "thread_functions.hpp"



//Function declarations
void displayOnLcd();
void updateRealTimeClock(char *buffer);
void getLineFromSerial(char *keyBuffer, int bufferLength);
void displayMessageOnConsole();
void SettingTimeWithButtons ();
void FunctionSensor();
void FunctionTime();
void FunctionSerial();

TextLCD lcd(D9, D8, D7, D6, D4, D2); // rs, e, d4-d7
SDBlockDevice sd(PB_5, D12, D13, D10); // mosi, miso, sclk, cs
Serial pc(SERIAL_TX, SERIAL_RX);
time_t currentTime;
char lcdBuffer[32];
DigitalOut myled(LED1);
Ticker ticker;
DigitalIn SWUser(USER_BUTTON); 
Mutex date_mutex;
int setting;
int t;
//InterruptIn SW1;

Thread t1;
Thread t2;
Thread t3; 


//LDR sensor
AnalogIn LDD_ADC_In(A1);
float fLDR = 0.0;
float volts = 0.0;



//Main thread
int main() {
   
    lcd.printf("Select Time Option\n\n");
    
    post();
    
    //Initialise the SD card
    if ( sd.init() != 0) {
        printf("Init failed \n");
        errorCode(FATAL);
    } 
    
    //Create a filing system for SD Card
    FATFileSystem fs("sd", &sd);     

    //Open to WRITE
    FILE* fp = fopen("/sd/test.csv","a");
    if (fp == NULL) {
        error("Could not open file for write\n");
        errorCode(FATAL);
    }
    
    // run threads
    t1.start(FunctionSensor);           
    t2.start(FunctionTime);   
    t3.start(FunctionSerial); 
       
}