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: BME280 BMP280 TextLCD
Diff: main.cpp
- Revision:
- 37:7c4d7f206039
- Parent:
- 36:a0098306fc58
- Child:
- 38:8d86e0d8a816
--- a/main.cpp Sun Jan 07 16:17:24 2018 +0000
+++ b/main.cpp Sun Jan 07 19:21:11 2018 +0000
@@ -1,7 +1,7 @@
/*
ELEC 351 Group T
Team Members : Christopher Hills, Thomas Morris
-Current Verision 17
+Current Verision 18
Overiew: Working Tasks 1,2,3,5,6,7,8,9,10,11,12,13
Last Revision: Added Mail Box to serial
@@ -20,7 +20,7 @@
while(1)
{
Thread::wait(5000);//Waits 5 seconds
- cout << "In Network Thread" << endl;
+ if(Log_Value==1){cout << "In Network Thread" << endl;} //Log this
time_t Time = Data_Active.get_time();
tm* Time_Pointer = localtime(&Time);
@@ -42,10 +42,12 @@
void LCD_Write_Year()
{
Time_Lock_Main.lock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Year Time lock taken"<<endl;}
time_t Time = time(NULL);
tm* Time_Pointer = localtime(&Time);
int Years = 1900 + Time_Pointer->tm_year;
Time_Lock_Main.unlock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Year Time lock released"<<endl;}
stringstream ss;
ss << Years;
string Year_String = ss.str();
@@ -58,10 +60,12 @@
void LCD_Write_Month()
{
Time_Lock_Main.lock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Month Time lock taken"<<endl;}
time_t Time = time(NULL);
tm* Time_Pointer = localtime(&Time);
int Months = 1 + Time_Pointer->tm_mon;
Time_Lock_Main.unlock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Month Time lock released"<<endl;}
stringstream ss;
ss << Months;
string Month_String = ss.str();
@@ -73,10 +77,12 @@
void LCD_Write_Day()
{
Time_Lock_Main.lock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Day Time lock taken"<<endl;}
time_t Time = time(NULL);
tm* Time_Pointer = localtime(&Time);
int Days = Time_Pointer->tm_mday;
Time_Lock_Main.unlock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Day Time lock released"<<endl;}
stringstream ss;
ss << Days;
string Day_String = ss.str();
@@ -90,10 +96,12 @@
void LCD_Write_Hour()
{
Time_Lock_Main.lock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Hour Time lock taken"<<endl;}
time_t Time = time(NULL);
tm* Time_Pointer = localtime(&Time);
int Hours = Time_Pointer->tm_hour;
Time_Lock_Main.unlock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Hour Time lock released"<<endl;}
stringstream ss;
ss << Hours;
string Hour_String = ss.str();
@@ -105,10 +113,12 @@
void LCD_Write_Minute()
{
Time_Lock_Main.lock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Minute Time lock taken"<<endl;}
time_t Time = time(NULL);
tm* Time_Pointer = localtime(&Time);
int Minutes = Time_Pointer->tm_min;
Time_Lock_Main.unlock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Minute Time lock released"<<endl;}
stringstream ss;
ss << Minutes;
string Minute_String = ss.str();
@@ -120,10 +130,12 @@
void LCD_Write_Seconds()
{
Time_Lock_Main.lock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Seconds Time lock taken"<<endl;}
time_t Time = time(NULL);
tm* Time_Pointer = localtime(&Time);
int Seconds = Time_Pointer->tm_sec;
Time_Lock_Main.unlock();
+ if(Log_Value == 1){cout<<"In LCD_Write_Seconds Time lock released"<<endl;}
stringstream ss;
ss << Seconds;
string Second_String = ss.str();
@@ -140,10 +152,10 @@
Thread::wait(10);//Dont Delete
if(mode == 0)//Default mode
{
- if(Log_Value == 1){cout << "In mode 0 " << endl;}
+ if(Log_Value == 1){cout << "In mode 0 " << endl;}//Log this
Thread::wait(Default_Mode_Toggle_Time);
-
+ if(Log_Value == 1){cout<<"Writing Data to LCD"<<endl;}
sprintf (LCD_buffer, "%1.1f %1.1f %1.1f",Data_Active.get_temperature(),Data_Active.get_pressure(),Data_Active.get_light());//Used for converting to a sting
LCD.DDRAM_Address(0x00);
@@ -152,7 +164,7 @@
LCD.Write_String(LCD_buffer);
Thread::wait(Default_Mode_Toggle_Time);
-
+ if(Log_Value == 1){cout<<"Writing Time and Date to LCD"<<endl;}
Time_Lock_Main.lock();
time_t Time = Data_Active.get_time();
tm* Time_Pointer = localtime(&Time);
@@ -165,6 +177,7 @@
LCD.DDRAM_Address(0x40);
LCD.Write_String(LCD_buffer);
+ if(Log_Value == 1){cout<<"Checking Switches for next mode"<<endl;}
if(SW1.read() & SW2.read() == 1)
{
mode = 1;
@@ -181,14 +194,16 @@
LCD.DDRAM_Address(0x40);
LCD.Write_String("< >");
Thread::wait(1000);
- if(SW1.read() == 1)
+ if(Log_Value == 1){cout<<"Checking SW1 to go to Date setting"<<endl;}
+ if(SW1.read() == 1 & SW2.read() == 0)
{
- mode = 2;
+ mode = 2;//Date Setting
break;
}
- if(SW2.read() == 1)
+ if(Log_Value == 1){cout<<"Checking SW2 to go to Time setting"<<endl;}
+ if(SW2.read() == 1 & SW1.read() == 0)
{
- mode = 5;
+ mode = 5;//Time Setting
break;
}
}
@@ -201,15 +216,18 @@
{
LCD_Write_Year();
Thread::wait(1000);
+ if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go to Month setting"<<endl;}
if(SW1.read() & SW2.read() == 1)
{
mode = 3;
break;
}
+ if(Log_Value == 1){cout<<"Checking SW1 to add Year"<<endl;}
if(SW1.read() == 1 & SW2.read() == 0)
{
Add_Year();
}
+ if(Log_Value == 1){cout<<"Checking SW2 to subtract Year"<<endl;}
else if(SW2.read() == 1 & SW1.read() == 0)
{
Subtract_Year();
@@ -225,15 +243,18 @@
{
LCD_Write_Month();
Thread::wait(1000);
+ if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go to Day setting"<<endl;}
if(SW1.read() & SW2.read() == 1)
{
mode = 4;
break;
- }
+ }
+ if(Log_Value == 1){cout<<"Checking SW1 to add Month"<<endl;}
if(SW1.read() == 1 & SW2.read() == 0)
{
Add_Month();
}
+ if(Log_Value == 1){cout<<"Checking SW2 to subtract Month"<<endl;}
else if(SW2.read() == 1 & SW1.read() == 0)
{
Subtract_Month();
@@ -249,15 +270,18 @@
{
LCD_Write_Day();
Thread::wait(1000);
+ if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Default setting"<<endl;}
if(SW1.read() & SW2.read() == 1)
{
mode = 0;
break;
}
+ if(Log_Value == 1){cout<<"Checking SW1 to add Day"<<endl;}
if(SW1.read() == 1 & SW2.read() == 0)
{
Add_Day();
}
+ if(Log_Value == 1){cout<<"Checking SW2 to subtract Day"<<endl;}
else if(SW2.read() == 1 & SW1.read() == 0)
{
Subtract_Day();
@@ -272,15 +296,18 @@
{
LCD_Write_Hour();
Thread::wait(1000);
+ if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Minute setting"<<endl;}
if(SW1.read() & SW2.read() == 1)
{
mode = 6;
break;
- }
+ }
+ if(Log_Value == 1){cout<<"Checking SW1 to add Hour"<<endl;}
if(SW1.read() == 1 & SW2.read() == 0)
{
Add_Hour();
}
+ if(Log_Value == 1){cout<<"Checking SW2 to subtract Hour"<<endl;}
else if(SW2.read() == 1 & SW1.read() == 0)
{
Subtract_Hour();
@@ -295,15 +322,18 @@
{
LCD_Write_Minute();
Thread::wait(1000);
+ if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Seconds setting"<<endl;}
if(SW1.read() & SW2.read() == 1)
{
mode = 7;
break;
}
+ if(Log_Value == 1){cout<<"Checking SW1 to add Minute"<<endl;}
if(SW1.read() == 1 & SW2.read() == 0)
{
Add_Minute();
}
+ if(Log_Value == 1){cout<<"Checking SW2 to subtract Minute"<<endl;}
else if(SW2.read() == 1 & SW1.read() == 0)
{
Subtract_Minute();
@@ -318,15 +348,18 @@
{
LCD_Write_Seconds();
Thread::wait(1000);
+ if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Default setting"<<endl;}
if(SW1.read() & SW2.read() == 1)
{
mode = 0;
break;
- }
+ }
+ if(Log_Value == 1){cout<<"Checking SW1 to add Second"<<endl;}
if(SW1.read() == 1 & SW2.read() == 0)
{
Add_Second();
}
+ if(Log_Value == 1){cout<<"Checking SW1 to subtract Second"<<endl;}
else if(SW2.read() == 1 & SW1.read() == 0)
{
Subtract_Second();
@@ -335,17 +368,20 @@
}
else
{
+ if(Log_Value == 1){cout<<"Mode Error occured mode now set to 0"<<endl;}
mode = 0;
}
}
}
void Serial_Commands()//Used for getting input from the user to determine the opperations to perform
{
+
string Serial_Input;
- int A,B,C;
+ int A,B,C;//Place a thread wait here?
while(1) {
+ if(Log_Value == 1){cout<<"In Serial_Commands"<<endl;}
Serial_Input = "Blank";
- cout << "Please type in a command" << endl;
+ cout << "Please type in a command" << endl;//Log this
cin >> Serial_Input >> A >> B >> C;
@@ -364,7 +400,7 @@
{
Sampling_Timer.detach();
Console_Output_Timer.detach();
- for (int x = 0; x < mailsize; x++)
+ for (int x = 0; x < mailsize; x++)//cout deleted or something
{
}
@@ -375,7 +411,7 @@
{
for (int x = 0; x < A; x++)
{
- Serial_Comms_Stealth_Mode();
+ Serial_Comms_Data_Get();
if(Log_Value == 1){cout << "Read " << x << " samples" << endl;}
}
}
@@ -412,7 +448,7 @@
}
else if(Serial_Input == "LOGGING")
{
- Log_Value = A;
+ Log_Value = A;//Look into a nicer way of doing this
}
else if(Serial_Input == "HELP")// Use this to display all of the availble commands
{
@@ -422,18 +458,15 @@
{
Console_Output_Timer.detach(); //Stops Sampling
}
- else if(Serial_Input == "Blank Blank")
- {
- cout << "Blank Blank complete" << endl;
- }
else
{
cout << "Please enter an acceptable command" << endl;
}
}
}
-void Serial_Comms_Stealth_Mode() //Change this name
+void Serial_Comms_Data_Get() //Change this name
{
+ if(Log_Value == 1){cout<<"Getting Data"<<endl;}
time_t Time = Data_Active.get_time();
tm* Time_Pointer = localtime(&Time);
strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string
@@ -448,9 +481,11 @@
}
void Serial_Comms()//Thread for Serial Communications
{
- while(1) {
+ while(1)
+ {
Thread::signal_wait(SerialCommsTime);//Stupid 0 Bug
- Serial_Comms_Stealth_Mode();
+ Serial_Comms_Data_Get();
+ if(Log_Value == 1){cout<<"In Serial Comms"<<endl;}
}
}
@@ -463,7 +498,7 @@
while(1)
{
Thread::signal_wait(SamplingTime); //Set the time between samples
-
+ if(Log_Value == 1){cout<<"Sample Time"<<endl;}
Data_Active.set_temperature(sensor.getTemperature()); //Read Temperature
Data_Active.set_pressure(sensor.getPressure()); //Read Pressure
Data_Active.set_light(adcIn.read()); //Read Light
@@ -476,15 +511,12 @@
Red_led.Toggle();
t1.signal_set(NotSamplingTime);
+ if(Log_Value == 1){cout<<"New Sample avaliable"<<endl;}
}
}
int main()
{
- //Greeting
- pc.printf("Test Start");
- pc.printf("\n\r");
-
- set_time(1512940530); //Set RTC time to December 10 2017
+ set_time(1515352584); //Set RTC time to December 10 2017
pc.baud(9600); //Sets the Serial Comms Baud Rate
@@ -508,9 +540,18 @@
if (fp == NULL) {
error("Could not open file for write\n");
LCD.Display_Clear();
- LCD.Write_String("CANNOT OPEN FILE\n\n");//Change me
+ LCD.Write_String("CANNOT OPEN FILE");
errorCode(FATAL);
}
+ int network_temp;
+ network_temp = Network_Init();
+ if(network_temp == 1)//Sets up the network and checks if the network cable is not pluged in
+ {
+ error("Could not access network");
+ LCD.Display_Clear();
+ LCD.Write_String("Could not access network");
+ errorCode(FATAL);
+ }
//Last message before sampling begins
LCD.Display_Clear();
LCD.Write_String("READY PLAYER");
@@ -518,7 +559,6 @@
LCD.Write_String(" One ");
LCD.DDRAM_Address(0x00);
- Network_Init();//Sets up the network
Sample_Rate = TimerInterval;
//Run interrupt
Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);