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

Committer:
Alix955
Date:
Thu Dec 13 15:24:22 2018 +0000
Revision:
10:eea19f8e6122
Parent:
9:f5eae5211225
Child:
11:42b0c567cc8c
Alix & Sams versions combined;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
O_Thom 6:b7f6e0c0f646 1 #ifndef _LCD_
O_Thom 6:b7f6e0c0f646 2 #define _LCD_
O_Thom 6:b7f6e0c0f646 3 #include "mbed.h"
O_Thom 6:b7f6e0c0f646 4 #include "messageStruct.hpp"
O_Thom 6:b7f6e0c0f646 5 #include "sample_hardware.hpp"
Alix955 9:f5eae5211225 6 #include "Network.hpp"
Alix955 10:eea19f8e6122 7 #include <stdio.h>
Alix955 10:eea19f8e6122 8 #include <string.h>
Alix955 10:eea19f8e6122 9
Alix955 9:f5eae5211225 10
Alix955 9:f5eae5211225 11
O_Thom 6:b7f6e0c0f646 12 class LCD_Data
O_Thom 5:f87129ac8bf3 13 {
Alix955 9:f5eae5211225 14 friend class Network;
Alix955 9:f5eae5211225 15
Alix955 9:f5eae5211225 16 private: //private variables can only be changed via functions in this class
O_Thom 6:b7f6e0c0f646 17 float temp; //current temperature of sensor, updated every 15 seconds
O_Thom 6:b7f6e0c0f646 18 float pressure; //current pressure of sensor, updated every 15 seconds
O_Thom 6:b7f6e0c0f646 19 float fLDR; //current light level from LDR, updated every 15 seconds
O_Thom 6:b7f6e0c0f646 20 int flip;
Alix955 10:eea19f8e6122 21 string day;
Alix955 10:eea19f8e6122 22 string month;
Alix955 10:eea19f8e6122 23 string date;
Alix955 10:eea19f8e6122 24 string time;
Alix955 10:eea19f8e6122 25 string year;
O_Thom 6:b7f6e0c0f646 26
Alix955 9:f5eae5211225 27
Alix955 9:f5eae5211225 28 private:
Alix955 9:f5eae5211225 29 struct tm Time_Date; //decale instance Time_Date of structure tm which is defined by mbed / C
Alix955 9:f5eae5211225 30
Alix955 9:f5eae5211225 31
O_Thom 6:b7f6e0c0f646 32 void update_temp(double t) //use this function to update the current temperature value
O_Thom 6:b7f6e0c0f646 33 {
O_Thom 6:b7f6e0c0f646 34 temp = t;
O_Thom 6:b7f6e0c0f646 35 }
O_Thom 6:b7f6e0c0f646 36 void update_pressure(double p) //use this function to update the current pressure value
O_Thom 6:b7f6e0c0f646 37 {
O_Thom 6:b7f6e0c0f646 38 pressure = p;
O_Thom 6:b7f6e0c0f646 39 }
O_Thom 6:b7f6e0c0f646 40 void update_LDR(double L)
O_Thom 6:b7f6e0c0f646 41 {
O_Thom 6:b7f6e0c0f646 42 fLDR = L;
O_Thom 6:b7f6e0c0f646 43 }
O_Thom 6:b7f6e0c0f646 44
Alix955 9:f5eae5211225 45
Alix955 9:f5eae5211225 46
O_Thom 5:f87129ac8bf3 47 public:
Alix955 9:f5eae5211225 48
O_Thom 5:f87129ac8bf3 49 EventQueue LCD_Queue; //create an event queue for main
Alix955 9:f5eae5211225 50 time_t timestamp; //current time in format of unix time, can be converted to DAY_OF_WEEK MONTH DAY HOUR:MINUTE:SECOND YEAR using ctime(&timestamp);
Alix955 9:f5eae5211225 51
Alix955 9:f5eae5211225 52
Alix955 9:f5eae5211225 53
O_Thom 5:f87129ac8bf3 54 LCD_Data(){ //constructor, initializes the FLIP variable for use in toggling the bottom line of the LCD
O_Thom 5:f87129ac8bf3 55 flip = 1;
O_Thom 6:b7f6e0c0f646 56 temp = 0;
O_Thom 6:b7f6e0c0f646 57 pressure = 0;
O_Thom 6:b7f6e0c0f646 58 fLDR = 0;
Alix955 9:f5eae5211225 59
Alix955 9:f5eae5211225 60
O_Thom 5:f87129ac8bf3 61 }
Alix955 9:f5eae5211225 62
Alix955 9:f5eae5211225 63
Alix955 9:f5eae5211225 64
O_Thom 6:b7f6e0c0f646 65 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
O_Thom 5:f87129ac8bf3 66 {
O_Thom 6:b7f6e0c0f646 67 update_temp(msg.temp); // Include message class passing of data
O_Thom 6:b7f6e0c0f646 68 update_pressure(msg.pressure);
O_Thom 6:b7f6e0c0f646 69 update_LDR(msg.ldr);
O_Thom 5:f87129ac8bf3 70 }
Alix955 9:f5eae5211225 71
Alix955 10:eea19f8e6122 72
Alix955 9:f5eae5211225 73
Alix955 9:f5eae5211225 74
O_Thom 5:f87129ac8bf3 75 void display_LCD() //updates the current LCD display with the new sensor information
O_Thom 5:f87129ac8bf3 76 {
O_Thom 5:f87129ac8bf3 77 lcd.cls(); //clear current LCD display
Alix955 9:f5eae5211225 78
O_Thom 5:f87129ac8bf3 79 lcd.printf("%4.2fC", temp); //print temperature to the top line of LCD, 2dp celcius
Alix955 9:f5eae5211225 80
Alix955 9:f5eae5211225 81
O_Thom 5:f87129ac8bf3 82 switch(flip){
O_Thom 5:f87129ac8bf3 83 case 1:
O_Thom 5:f87129ac8bf3 84 lcd.printf("\n%4.2f mbar", pressure); //print pressure to bottom line of LCD, 2dp mbar
O_Thom 6:b7f6e0c0f646 85 flip = 2;
O_Thom 6:b7f6e0c0f646 86 break;
O_Thom 6:b7f6e0c0f646 87 case 2:
O_Thom 6:b7f6e0c0f646 88 lcd.printf("\n%4.2f Lux", fLDR); //print pressure to bottom line of LCD, 2dp mbar
O_Thom 6:b7f6e0c0f646 89 flip = 1;
Alix955 9:f5eae5211225 90 break;
Alix955 9:f5eae5211225 91 case 3: //only ever called when the interupt button is pressed to update time
Alix955 9:f5eae5211225 92 lcd.printf("\nTime updated"); //informs the user the current time has been set
Alix955 9:f5eae5211225 93 printf("Current time is %s\r\n", ctime(&timestamp)); //prints current time and date in human readable time to terminal
Alix955 9:f5eae5211225 94 flip = 1;
Alix955 9:f5eae5211225 95 break;
O_Thom 6:b7f6e0c0f646 96 default:
O_Thom 5:f87129ac8bf3 97 printf("Error in LCD flip function");
O_Thom 5:f87129ac8bf3 98 break;
O_Thom 5:f87129ac8bf3 99 }
O_Thom 5:f87129ac8bf3 100 }
Alix955 9:f5eae5211225 101
Alix955 9:f5eae5211225 102
Alix955 9:f5eae5211225 103
Alix955 10:eea19f8e6122 104 time_and_date update_time_date (){
Alix955 10:eea19f8e6122 105
Alix955 10:eea19f8e6122 106 timestamp = ntp.get_timestamp(); //reads the current time from a local NTP server in UNIX format
Alix955 10:eea19f8e6122 107
Alix955 10:eea19f8e6122 108 string current_time = ctime(&timestamp); //converts time to human readable format string
Alix955 10:eea19f8e6122 109
Alix955 10:eea19f8e6122 110
Alix955 10:eea19f8e6122 111
Alix955 10:eea19f8e6122 112 day.assign(current_time, 0, 3); //extract only day from current_time string
Alix955 10:eea19f8e6122 113 month.assign(current_time, 4, 3); //extract only month from ""
Alix955 10:eea19f8e6122 114 date.assign(current_time, 9, 1); //extract only date from ""
Alix955 10:eea19f8e6122 115 time.assign(current_time, 11, 8); //extract only time from ""
Alix955 10:eea19f8e6122 116 year.assign(current_time, 20, 4); //extract only year from ""
Alix955 10:eea19f8e6122 117
Alix955 10:eea19f8e6122 118
Alix955 10:eea19f8e6122 119 //printf("current day is: %s\n", day);
Alix955 10:eea19f8e6122 120 // printf("current year is: %s\n", year);
Alix955 10:eea19f8e6122 121 // printf("current time is: %s\n", time);
Alix955 10:eea19f8e6122 122 // printf("current date is: %s\n", date);
Alix955 10:eea19f8e6122 123 // printf("current month is: %s\n", month);
Alix955 10:eea19f8e6122 124
Alix955 10:eea19f8e6122 125
Alix955 10:eea19f8e6122 126
Alix955 10:eea19f8e6122 127 m_oNet.Network_Queue.call(&m_oNet, &Network::update_Time, current_time);
Alix955 9:f5eae5211225 128
Alix955 10:eea19f8e6122 129 time_and_date Timemsg; // Define instance of message structure
Alix955 10:eea19f8e6122 130 Timemsg.day = day;
Alix955 10:eea19f8e6122 131 Timemsg.month = month;
Alix955 10:eea19f8e6122 132 Timemsg.date = date;
Alix955 10:eea19f8e6122 133 Timemsg.time = time;
Alix955 10:eea19f8e6122 134 Timemsg.year = year;
Alix955 10:eea19f8e6122 135 Timemsg.current_time = current_time;
Alix955 10:eea19f8e6122 136 return Timemsg;
Alix955 10:eea19f8e6122 137
Alix955 10:eea19f8e6122 138 flip = 3; //will tell the user that the time has been updated on next FLIP instance with the LCD
Alix955 9:f5eae5211225 139
Alix955 9:f5eae5211225 140 }
Alix955 9:f5eae5211225 141
Alix955 9:f5eae5211225 142
Alix955 9:f5eae5211225 143 }; //end of LCD class
Alix955 9:f5eae5211225 144
Alix955 9:f5eae5211225 145
Alix955 9:f5eae5211225 146
O_Thom 6:b7f6e0c0f646 147 // Define the member object for the LCD
O_Thom 5:f87129ac8bf3 148 LCD_Data m_oDisplay;
O_Thom 6:b7f6e0c0f646 149 #endif