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
LCD.hpp@9:f5eae5211225, 2018-12-07 (annotated)
- Committer:
- Alix955
- Date:
- Fri Dec 07 13:24:50 2018 +0000
- Revision:
- 9:f5eae5211225
- Parent:
- 6:b7f6e0c0f646
- Child:
- 10:eea19f8e6122
Version 5, mine & sams versions merged
Who changed what in which revision?
User | Revision | Line number | New 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 | 9:f5eae5211225 | 7 | |
Alix955 | 9:f5eae5211225 | 8 | |
O_Thom | 6:b7f6e0c0f646 | 9 | class LCD_Data |
O_Thom | 5:f87129ac8bf3 | 10 | { |
Alix955 | 9:f5eae5211225 | 11 | friend class Network; |
Alix955 | 9:f5eae5211225 | 12 | |
Alix955 | 9:f5eae5211225 | 13 | private: //private variables can only be changed via functions in this class |
O_Thom | 6:b7f6e0c0f646 | 14 | float temp; //current temperature of sensor, updated every 15 seconds |
O_Thom | 6:b7f6e0c0f646 | 15 | float pressure; //current pressure of sensor, updated every 15 seconds |
O_Thom | 6:b7f6e0c0f646 | 16 | float fLDR; //current light level from LDR, updated every 15 seconds |
O_Thom | 6:b7f6e0c0f646 | 17 | int flip; |
O_Thom | 6:b7f6e0c0f646 | 18 | |
Alix955 | 9:f5eae5211225 | 19 | |
Alix955 | 9:f5eae5211225 | 20 | private: |
Alix955 | 9:f5eae5211225 | 21 | struct tm Time_Date; //decale instance Time_Date of structure tm which is defined by mbed / C |
Alix955 | 9:f5eae5211225 | 22 | |
Alix955 | 9:f5eae5211225 | 23 | |
O_Thom | 6:b7f6e0c0f646 | 24 | void update_temp(double t) //use this function to update the current temperature value |
O_Thom | 6:b7f6e0c0f646 | 25 | { |
O_Thom | 6:b7f6e0c0f646 | 26 | temp = t; |
O_Thom | 6:b7f6e0c0f646 | 27 | } |
O_Thom | 6:b7f6e0c0f646 | 28 | void update_pressure(double p) //use this function to update the current pressure value |
O_Thom | 6:b7f6e0c0f646 | 29 | { |
O_Thom | 6:b7f6e0c0f646 | 30 | pressure = p; |
O_Thom | 6:b7f6e0c0f646 | 31 | } |
O_Thom | 6:b7f6e0c0f646 | 32 | void update_LDR(double L) |
O_Thom | 6:b7f6e0c0f646 | 33 | { |
O_Thom | 6:b7f6e0c0f646 | 34 | fLDR = L; |
O_Thom | 6:b7f6e0c0f646 | 35 | } |
O_Thom | 6:b7f6e0c0f646 | 36 | |
Alix955 | 9:f5eae5211225 | 37 | |
Alix955 | 9:f5eae5211225 | 38 | |
O_Thom | 5:f87129ac8bf3 | 39 | public: |
Alix955 | 9:f5eae5211225 | 40 | |
O_Thom | 5:f87129ac8bf3 | 41 | EventQueue LCD_Queue; //create an event queue for main |
Alix955 | 9:f5eae5211225 | 42 | 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); |
Alix955 | 9:f5eae5211225 | 43 | |
Alix955 | 9:f5eae5211225 | 44 | |
Alix955 | 9:f5eae5211225 | 45 | |
O_Thom | 5:f87129ac8bf3 | 46 | LCD_Data(){ //constructor, initializes the FLIP variable for use in toggling the bottom line of the LCD |
O_Thom | 5:f87129ac8bf3 | 47 | flip = 1; |
O_Thom | 6:b7f6e0c0f646 | 48 | temp = 0; |
O_Thom | 6:b7f6e0c0f646 | 49 | pressure = 0; |
O_Thom | 6:b7f6e0c0f646 | 50 | fLDR = 0; |
Alix955 | 9:f5eae5211225 | 51 | |
Alix955 | 9:f5eae5211225 | 52 | |
O_Thom | 5:f87129ac8bf3 | 53 | } |
Alix955 | 9:f5eae5211225 | 54 | |
Alix955 | 9:f5eae5211225 | 55 | |
Alix955 | 9:f5eae5211225 | 56 | |
O_Thom | 6:b7f6e0c0f646 | 57 | 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 | 58 | { |
O_Thom | 6:b7f6e0c0f646 | 59 | update_temp(msg.temp); // Include message class passing of data |
O_Thom | 6:b7f6e0c0f646 | 60 | update_pressure(msg.pressure); |
O_Thom | 6:b7f6e0c0f646 | 61 | update_LDR(msg.ldr); |
O_Thom | 5:f87129ac8bf3 | 62 | } |
Alix955 | 9:f5eae5211225 | 63 | |
Alix955 | 9:f5eae5211225 | 64 | |
Alix955 | 9:f5eae5211225 | 65 | |
Alix955 | 9:f5eae5211225 | 66 | |
O_Thom | 5:f87129ac8bf3 | 67 | void display_LCD() //updates the current LCD display with the new sensor information |
O_Thom | 5:f87129ac8bf3 | 68 | { |
O_Thom | 5:f87129ac8bf3 | 69 | lcd.cls(); //clear current LCD display |
Alix955 | 9:f5eae5211225 | 70 | |
O_Thom | 5:f87129ac8bf3 | 71 | lcd.printf("%4.2fC", temp); //print temperature to the top line of LCD, 2dp celcius |
Alix955 | 9:f5eae5211225 | 72 | |
Alix955 | 9:f5eae5211225 | 73 | |
O_Thom | 5:f87129ac8bf3 | 74 | switch(flip){ |
O_Thom | 5:f87129ac8bf3 | 75 | case 1: |
O_Thom | 5:f87129ac8bf3 | 76 | lcd.printf("\n%4.2f mbar", pressure); //print pressure to bottom line of LCD, 2dp mbar |
O_Thom | 6:b7f6e0c0f646 | 77 | flip = 2; |
O_Thom | 6:b7f6e0c0f646 | 78 | break; |
O_Thom | 6:b7f6e0c0f646 | 79 | case 2: |
O_Thom | 6:b7f6e0c0f646 | 80 | lcd.printf("\n%4.2f Lux", fLDR); //print pressure to bottom line of LCD, 2dp mbar |
O_Thom | 6:b7f6e0c0f646 | 81 | flip = 1; |
Alix955 | 9:f5eae5211225 | 82 | break; |
Alix955 | 9:f5eae5211225 | 83 | case 3: //only ever called when the interupt button is pressed to update time |
Alix955 | 9:f5eae5211225 | 84 | lcd.printf("\nTime updated"); //informs the user the current time has been set |
Alix955 | 9:f5eae5211225 | 85 | printf("Current time is %s\r\n", ctime(×tamp)); //prints current time and date in human readable time to terminal |
Alix955 | 9:f5eae5211225 | 86 | flip = 1; |
Alix955 | 9:f5eae5211225 | 87 | break; |
O_Thom | 6:b7f6e0c0f646 | 88 | default: |
O_Thom | 5:f87129ac8bf3 | 89 | printf("Error in LCD flip function"); |
O_Thom | 5:f87129ac8bf3 | 90 | break; |
O_Thom | 5:f87129ac8bf3 | 91 | } |
O_Thom | 5:f87129ac8bf3 | 92 | } |
Alix955 | 9:f5eae5211225 | 93 | |
Alix955 | 9:f5eae5211225 | 94 | |
Alix955 | 9:f5eae5211225 | 95 | |
Alix955 | 9:f5eae5211225 | 96 | void update_time_date (){ |
Alix955 | 9:f5eae5211225 | 97 | timestamp = ntp.get_timestamp(); |
Alix955 | 9:f5eae5211225 | 98 | //timestamp = Network::ntp.get_timestamp(); //gets current time and date from NTP server in unix format |
Alix955 | 9:f5eae5211225 | 99 | // timestamp = m_oNet.ntp.get_timestamp(); //gets current time and date from NTP server in unix format |
Alix955 | 9:f5eae5211225 | 100 | |
Alix955 | 9:f5eae5211225 | 101 | flip = 3; //will tell the user that the time has been updated on next FLIP instance |
Alix955 | 9:f5eae5211225 | 102 | |
Alix955 | 9:f5eae5211225 | 103 | } |
Alix955 | 9:f5eae5211225 | 104 | |
Alix955 | 9:f5eae5211225 | 105 | |
Alix955 | 9:f5eae5211225 | 106 | }; //end of LCD class |
Alix955 | 9:f5eae5211225 | 107 | |
Alix955 | 9:f5eae5211225 | 108 | |
Alix955 | 9:f5eae5211225 | 109 | |
O_Thom | 6:b7f6e0c0f646 | 110 | // Define the member object for the LCD |
O_Thom | 5:f87129ac8bf3 | 111 | LCD_Data m_oDisplay; |
O_Thom | 6:b7f6e0c0f646 | 112 | #endif |