Repo. for the ELEC351 Coursework - Oliver Thompson
Dependencies: BMP280 ELEC350-Practicals-FZ429- TextLCD watchdog_RTOS BME280 ntp-client
LCD.hpp@10:08c366434f2b, 2018-12-04 (annotated)
- Committer:
- O_Thom
- Date:
- Tue Dec 04 15:26:46 2018 +0000
- Revision:
- 10:08c366434f2b
- Parent:
- 9:654e14de9d74
- Child:
- 11:b8e8630c7e3b
Serial Callbacks Included. Changing classes to access each others member functions without the use of objects.
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" |
O_Thom | 9:654e14de9d74 | 6 | #include <vector> |
O_Thom | 9:654e14de9d74 | 7 | |
O_Thom | 6:b7f6e0c0f646 | 8 | class LCD_Data |
O_Thom | 5:f87129ac8bf3 | 9 | { |
O_Thom | 5:f87129ac8bf3 | 10 | private: //private variables can only be changed via functions in this function |
O_Thom | 6:b7f6e0c0f646 | 11 | float temp; //current temperature of sensor, updated every 15 seconds |
O_Thom | 6:b7f6e0c0f646 | 12 | float pressure; //current pressure of sensor, updated every 15 seconds |
O_Thom | 6:b7f6e0c0f646 | 13 | float fLDR; //current light level from LDR, updated every 15 seconds |
O_Thom | 6:b7f6e0c0f646 | 14 | int flip; |
O_Thom | 6:b7f6e0c0f646 | 15 | |
O_Thom | 6:b7f6e0c0f646 | 16 | void update_temp(double t) //use this function to update the current temperature value |
O_Thom | 6:b7f6e0c0f646 | 17 | { |
O_Thom | 6:b7f6e0c0f646 | 18 | temp = t; |
O_Thom | 6:b7f6e0c0f646 | 19 | } |
O_Thom | 6:b7f6e0c0f646 | 20 | void update_pressure(double p) //use this function to update the current pressure value |
O_Thom | 6:b7f6e0c0f646 | 21 | { |
O_Thom | 6:b7f6e0c0f646 | 22 | pressure = p; |
O_Thom | 6:b7f6e0c0f646 | 23 | } |
O_Thom | 6:b7f6e0c0f646 | 24 | void update_LDR(double L) |
O_Thom | 6:b7f6e0c0f646 | 25 | { |
O_Thom | 6:b7f6e0c0f646 | 26 | fLDR = L; |
O_Thom | 6:b7f6e0c0f646 | 27 | } |
O_Thom | 6:b7f6e0c0f646 | 28 | |
O_Thom | 5:f87129ac8bf3 | 29 | public: |
O_Thom | 5:f87129ac8bf3 | 30 | EventQueue LCD_Queue; //create an event queue for main |
O_Thom | 5:f87129ac8bf3 | 31 | LCD_Data(){ //constructor, initializes the FLIP variable for use in toggling the bottom line of the LCD |
O_Thom | 5:f87129ac8bf3 | 32 | flip = 1; |
O_Thom | 6:b7f6e0c0f646 | 33 | temp = 0; |
O_Thom | 6:b7f6e0c0f646 | 34 | pressure = 0; |
O_Thom | 6:b7f6e0c0f646 | 35 | fLDR = 0; |
O_Thom | 5:f87129ac8bf3 | 36 | } |
O_Thom | 10:08c366434f2b | 37 | |
O_Thom | 6:b7f6e0c0f646 | 38 | 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 | 39 | { |
O_Thom | 6:b7f6e0c0f646 | 40 | update_temp(msg.temp); // Include message class passing of data |
O_Thom | 6:b7f6e0c0f646 | 41 | update_pressure(msg.pressure); |
O_Thom | 6:b7f6e0c0f646 | 42 | update_LDR(msg.ldr); |
O_Thom | 5:f87129ac8bf3 | 43 | } |
O_Thom | 5:f87129ac8bf3 | 44 | void display_LCD() //updates the current LCD display with the new sensor information |
O_Thom | 5:f87129ac8bf3 | 45 | { |
O_Thom | 5:f87129ac8bf3 | 46 | lcd.cls(); //clear current LCD display |
O_Thom | 5:f87129ac8bf3 | 47 | lcd.printf("%4.2fC", temp); //print temperature to the top line of LCD, 2dp celcius |
O_Thom | 5:f87129ac8bf3 | 48 | switch(flip){ |
O_Thom | 5:f87129ac8bf3 | 49 | case 1: |
O_Thom | 5:f87129ac8bf3 | 50 | lcd.printf("\n%4.2f mbar", pressure); //print pressure to bottom line of LCD, 2dp mbar |
O_Thom | 6:b7f6e0c0f646 | 51 | flip = 2; |
O_Thom | 6:b7f6e0c0f646 | 52 | break; |
O_Thom | 6:b7f6e0c0f646 | 53 | case 2: |
O_Thom | 6:b7f6e0c0f646 | 54 | lcd.printf("\n%4.2f Lux", fLDR); //print pressure to bottom line of LCD, 2dp mbar |
O_Thom | 6:b7f6e0c0f646 | 55 | flip = 1; |
O_Thom | 6:b7f6e0c0f646 | 56 | break; |
O_Thom | 6:b7f6e0c0f646 | 57 | default: |
O_Thom | 5:f87129ac8bf3 | 58 | printf("Error in LCD flip function"); |
O_Thom | 5:f87129ac8bf3 | 59 | break; |
O_Thom | 5:f87129ac8bf3 | 60 | } |
O_Thom | 9:654e14de9d74 | 61 | } |
O_Thom | 6:b7f6e0c0f646 | 62 | }; |
O_Thom | 10:08c366434f2b | 63 | #endif |
O_Thom | 10:08c366434f2b | 64 | |
O_Thom | 10:08c366434f2b | 65 | // Create an instance |
O_Thom | 5:f87129ac8bf3 | 66 | LCD_Data m_oDisplay; |