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 watchdog_RTOS BME280 ntp-client
LCD.hpp
- Committer:
- O_Thom
- Date:
- 2019-01-02
- Revision:
- 20:2ce28a5032d5
- Parent:
- 19:c3b396b65f2a
File content as of revision 20:2ce28a5032d5:
#ifndef _LCD_
#define _LCD_
#include "mbed.h"
#include "messageStruct.hpp"
#include "sample_hardware.hpp"
#include "Network.hpp"
#include <stdio.h>
#include <string.h>
Mail<time_and_date,5> Serial2LCD; // Serial -> LCD Mailbox 5 Elements Wide Time&Date
class LCD_Data
{
friend class Network;
private: //private variables can only be changed via functions in this class
float temp; //current temperature of sensor, updated every 15 seconds
float pressure; //current pressure of sensor, updated every 15 seconds
float fLDR; //current light level from LDR, updated every 15 seconds
int flip;
string day;
string month;
string date;
string time;
string year;
private:
struct tm Time_Date; //decale instance Time_Date of structure tm which is defined by mbed / C
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 LCD_Queue; //create an event queue for main
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);
void getSerial2LCD() // Queue Consumer
{
if (!Serial2LCD.empty())
{
osEvent evt = Serial2LCD.get();
switch (evt.status)
{
case osEventMail:
//Normal status
time_and_date *time_copy = (time_and_date*)evt.value.p;
time = time_copy->current_time; // Update the internal clock
Serial2Net.free(time_copy); // Free up the space in the memory Pool
default:
//All other errors (see cmsis_os.h for meaning of error code)
//printf("Serial2Net->get() returned %02x status\n\r", evt.status);
}
}
}
LCD_Data(){ //constructor, initializes the FLIP variable for use in toggling the bottom line of the LCD
flip = 1;
temp = 0;
pressure = 0;
fLDR = 0;
}
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 display_LCD() //updates the current LCD display with the new sensor information
{
lcd.cls(); //clear current LCD display
lcd.printf("%4.2fC", temp); //print temperature to the top line of LCD, 2dp celcius
switch(flip){
case 1:
lcd.printf("\n%4.2f mbar", pressure); //print pressure to bottom line of LCD, 2dp mbar
flip = 2;
break;
case 2:
lcd.printf("\n%4.2f Lux", fLDR); //print pressure to bottom line of LCD, 2dp mbar
flip = 1;
break;
case 3: //only ever called when the interupt button is pressed to update time
lcd.printf("\nTime updated"); //informs the user the current time has been set
printf("Current time is %s\r\n", ctime(×tamp)); //prints current time and date in human readable time to terminal
flip = 1;
break;
default:
printf("Error in LCD flip function");
break;
}
}
time_and_date update_time_date (){
timestamp = ntp.get_timestamp(); //reads the current time from a local NTP server in UNIX format
string current_time = ctime(×tamp); //converts time to human readable format string
day.assign(current_time, 0, 3); //extract only day from current_time string
month.assign(current_time, 4, 3); //extract only month from ""
date.assign(current_time, 9, 1); //extract only date from ""
time.assign(current_time, 11, 8); //extract only time from ""
year.assign(current_time, 20, 4); //extract only year from ""
//printf("current day is: %s\n", day);
// printf("current year is: %s\n", year);
// printf("current time is: %s\n", time);
// printf("current date is: %s\n", date);
// printf("current month is: %s\n", month);
m_oNet.Network_Queue.call(&m_oNet, &Network::update_Time, current_time);
time_and_date Timemsg; // Define instance of message structure
Timemsg.day = day;
Timemsg.month = month;
Timemsg.date = date;
Timemsg.time = time;
Timemsg.year = year;
Timemsg.current_time = current_time;
flip = 3; //will tell the user that the time has been updated on next FLIP instance with the LCD
return Timemsg; //swap this for a function that sends the structure to ollie?
}
}; //end of LCD class
// Define the member object for the LCD
LCD_Data m_oDisplay;
#endif