![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Version 8, working version with Alix, sams and ollies code. Displays time, date and sensor info onto terminal, LCD and networking, and saves onto SD card.
Dependencies: BMP280 ELEC350-Practicals-FZ429 TextLCD BME280 ntp-client
Diff: SDcard.hpp
- Revision:
- 12:4c7eaac8ceef
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDcard.hpp Mon Dec 31 19:20:22 2018 +0000 @@ -0,0 +1,105 @@ +#ifndef _SDCARD_ +#define _SDCARD_ +#include "mbed.h" +#include "SDBlockDevice.h" +#include "FATFileSystem.h" +#include "sample_hardware.hpp" + + + +class SDcard + +{ + + private: + float temp; //current temperature of sensor + float pressure; //current pressure of sensor + float fLDR; //current light level from LDR + + void update_temp(double t) //use this function to update the current temperature value + { + temp = t; + } + + void update_pressure(double p) //use this function to update the current pressure value + { + pressure = p; + } + + void update_LDR(double L) + { + fLDR = L; + } + + + + public: + EventQueue SDcard_Queue; + + SDcard(){ //constructor, + + } + + + + ~SDcard(){ //Deconstructor, + + } + + + + + void update_sensor_info(sample_message msg) //updates all current sensor information, this is called by a ticker every 5 seconds to read from the mailbox + { + update_temp(msg.temp); // Include message class passing of data + update_pressure(msg.pressure); + update_LDR(msg.ldr); + } + + + + + void Save_Data() { + + + // initalising the SD card + if ( sd.init() != 0) { + printf("Init failed \n"); + errorCode(FATAL); + } + + //Create a filing system for SD Card + + FATFileSystem fs("sd", &sd); + + FILE* fp = fopen("/sd/SensorData.csv","a"); + + if (fp == NULL) { + error("Could not open file for write\n"); + errorCode(FATAL); + } + + //Storing sensor data in csv file + + fprintf(fp, " Temperature(C) , %4.2f , Pressure(mbar) , %4.2f , Lux , %4.2f \n", temp , pressure , fLDR ); + + //Close the file + fclose(fp); + + //Close down SD card + sd.deinit(); + + errorCode(OK); + + temp = 0; + pressure = 0; + fLDR = 0; + + } +}; +// creating the instance SD of the class SDcard + + +SDcard m_oSD; + +#endif \ No newline at end of file