Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BMP280 ELEC350-Practicals-FZ429 TextLCD BME280 ntp-client
LCD.hpp
00001 #ifndef _LCD_ 00002 #define _LCD_ 00003 #include "mbed.h" 00004 #include "messageStruct.hpp" 00005 #include "sample_hardware.hpp" 00006 #include "Network.hpp" 00007 #include <stdio.h> 00008 #include <string> 00009 00010 00011 class LCD_Data 00012 { 00013 friend class Network; 00014 00015 private: //private variables can only be changed via functions in this class 00016 float temp; //current temperature of sensor, updated every 15 seconds 00017 float pressure; //current pressure of sensor, updated every 15 seconds 00018 float fLDR; //current light level from LDR, updated every 15 seconds 00019 00020 int flip; //integer used to flip the bottom line of LCD 00021 00022 string day; //string containing the current day when pulled from NTP server 00023 string month; //string containing the current month when pulled from NTP server 00024 string date; //string containing the current date when pulled from NTP server 00025 string time; //string containing the current time when pulled from NTP server 00026 string year; //string containing the current year when pulled from NTP server 00027 00028 00029 private: 00030 struct tm Time_Date; //decale instance Time_Date of structure tm which is defined by mbed / C 00031 00032 00033 void update_temp(double t) //used to update the current temperature value with an input 00034 { 00035 temp = t; //sets private variable temp 00036 } 00037 void update_pressure(double p) //used to update the current pressure value with an input 00038 { 00039 pressure = p; 00040 } 00041 void update_LDR(double L) //used to update the LDR value with an input 00042 { 00043 fLDR = L; 00044 } 00045 00046 00047 00048 public: 00049 00050 EventQueue LCD_Queue; //create an event queue for main to run 00051 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(×tamp); 00052 00053 00054 00055 LCD_Data(){ //constructor, initializes the FLIP variable for use in toggling the bottom line of the LCD 00056 flip = 1; //initalize what state the bottom line starts on 00057 temp = 0; //set temperature to start at 0 00058 pressure = 0; //set pressure to start at 0 00059 fLDR = 0; //set LDR value to start at 0 00060 00061 00062 } 00063 00064 00065 00066 void update_sensor_info(sample_message msg) //updates all current sensor information. recieves sensor info in structure type sample_message and takes it apart 00067 { 00068 update_temp(msg.temp); // takes temperature from sample_message and feeds to update temp function 00069 update_pressure(msg.pressure); //takes pressure from sample_message and feeds to update pressure function 00070 update_LDR(msg.ldr); //takes the LDR value from sample_message and feeds to update LDR function 00071 } 00072 00073 00074 00075 00076 void display_LCD() //updates the current LCD display with the new sensor information, and flips bottom line of LCD 00077 { 00078 lcd.cls(); //clear current LCD display 00079 00080 lcd.printf("%4.2fC", temp); //print temperature to the top line of LCD, 2dp celcius 00081 00082 00083 switch(flip){ 00084 case 1: 00085 lcd.printf("\n%4.2f mbar", pressure); //print pressure to bottom line of LCD, 2dp mbar 00086 flip = 2; //swaps to case 2 next time function is run so LDR is printed instead 00087 break; 00088 case 2: 00089 lcd.printf("\n%4.2f Lux", fLDR); //print LDR value to bottom line of LCD, 2dp 00090 flip = 1; //swaps to case 1 next time function is run so pressure is printed instead 00091 break; 00092 case 3: //only ever used when the interupt button is pressed to update time 00093 lcd.printf("\nTime updated"); //informs the user the current time has been set by printing onto bottom line 00094 printf("Current time is %s\r\n", ctime(×tamp)); //prints current time and date in human readable time to terminal 00095 flip = 1; //swaps back to case 1 next time function is run 00096 break; 00097 default: 00098 printf("Error in LCD flip function"); //only reached if the case is set incorrectly 00099 break; 00100 } 00101 } 00102 00103 00104 00105 void update_time_date (){ //used to update time and date, called only when button interrupt is pressed 00106 00107 timestamp = ntp.get_timestamp(); //reads the current time from a local NTP server in UNIX format 00108 00109 string current_time = ctime(×tamp); //converts time to human readable format string 00110 00111 printf("%s", current_time); //prints current time and date onto terminal 00112 00113 00114 day.assign(current_time, 0, 3); //extract only day from current_time string 00115 month.assign(current_time, 4, 3); //extract only month from current_time string 00116 date.assign(current_time, 9, 1); //extract only date from current_time string 00117 time.assign(current_time, 11, 8); //extract only time from current_time string 00118 year.assign(current_time, 20, 4); //extract only year from current_time string 00119 00120 00121 //printf("current day is: %s\n", day); 00122 // printf("current year is: %s\n", year); 00123 // printf("current time is: %s\n", time); 00124 // printf("current date is: %s\n", date); 00125 // printf("current month is: %s\n", month); 00126 00127 00128 00129 m_oNet.Network_Queue.call(&m_oNet, &Network::update_Time, current_time); //sends the whole time and date string to networking to be displayed 00130 00131 time_and_date Timemsg; // Define instance of message structure, used by serial communications 00132 Timemsg.day = day; 00133 Timemsg.month = month; 00134 Timemsg.date = date; 00135 Timemsg.time = time; 00136 Timemsg.year = year; 00137 Timemsg.current_time = current_time; 00138 00139 flip = 3; //will tell the user that the time has been updated on next FLIP instance with the LCD 00140 00141 // return Timemsg; //swap this for a function that sends the structure to ollie? 00142 00143 } 00144 00145 00146 }; //end of LCD class 00147 00148 00149 00150 // Define the member object for the LCD 00151 LCD_Data m_oDisplay; 00152 #endif
Generated on Sat Jul 16 2022 02:51:17 by
