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:
- 10:46946784326d
- Parent:
- 8:0e4481b64353
- Child:
- 11:e7b5ed6cd3cf
--- a/main.cpp Wed Dec 20 13:01:36 2017 +0000
+++ b/main.cpp Wed Dec 20 14:32:40 2017 +0000
@@ -57,6 +57,7 @@
double temp = 0;
double pressure = 0;
double lux = 0;
+string buffer_time = 0;
char buffer[32];
@@ -66,7 +67,7 @@
int mode = 0;
-
+Mail<DATA, 120> mail_box; //Mail Queue, Type DATA, Capacity 120, name mail_box
void Network()
{
@@ -153,30 +154,58 @@
pc.printf("Hello World \n");
while(1)
{
+ osEvent evt = mail_box.get(); //Get the latest entry from "mail_box"
+
+ if (evt.status == osEventMail){
+ DATA *Rec_Data = (DATA*)evt.value.p;
+ pc.printf("Time = %d\t", Rec_Data->get_time()); //Print Time
+ pc.printf("Temperature = %f", Rec_Data->get_temperature()); //Print Temperature
+ pc.printf("Pressure = %f", Rec_Data->get_pressure()); //Print Pressure
+ pc.printf("Light = %f", Rec_Data->get_light()); //Print Light
+ }
+
pc.printf("Test\n");//Use this Line to output a string to Putty
Green_led.Toggle();
Thread::wait(1000);
}
}
-void Sample_signal_set()//Sets the Signal for when to sample the sensors
+void Sample_signal_set() //Sets the Signal for when to sample the sensors
{
- t1.signal_set(SamplingTime);
+ t1.signal_set(SamplingTime); //Set the sampling thread signal high
}
+
void Sample()//Samples the hardware and prints the result to the LCD
{
while(1)
{
- Thread::signal_wait(SamplingTime);
+ Thread::signal_wait(SamplingTime); //Set the time between samples
+
+ temp = sensor.getTemperature(); //Read Temperature
+ pressure = sensor.getPressure(); //Read Pressure
+ lux = adcIn.read(); //Read Light
+ buffer_time = buffer; //Read Time
- //Read environmental sensors
+ DATA *Send_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data
- temp = sensor.getTemperature();
- pressure = sensor.getPressure();
- lux = adcIn.read();
-
-
+ if (Send_Data == NULL){ //If Data is empty
+ //pc.printf("Out of memory\n\r"); //Print out of memory warning
+ return;
+ }
+
+ Send_Data->set_time(buffer_time); //Pass in Time
+ Send_Data->set_temperature(temp); //Pass in Temp
+ Send_Data->set_pressure(pressure); //Pass in Pres
+ Send_Data->set_light(lux); //Pass in Light
+
+ osStatus stat = mail_box.put(Send_Data); //Puts "Send_Data" into the mailbox
+
+ if (stat == osErrorResource){ //If mailbox overfills
+ //pc.printf("queue->put() Error code: %4Xh, Resource not available\r\n", stat); //Print error message
+ mail_box.free(Send_Data); //Free the mail box
+ return;
+ }
Red_led.Toggle();
t1.signal_set(NotSamplingTime);
}
@@ -186,10 +215,10 @@
{
//Greeting
printf("Testing\n\n");
- set_time(1512940530); // Set RTC time to December 10 2017
- pc.baud(9600);//Sets the Serial Comms Baud Rate
+ set_time(1512940530); //Set RTC time to December 10 2017
+ pc.baud(9600); //Sets the Serial Comms Baud Rate
- post();//Power on Self Test
+ post(); //Power on Self Test
//Initialise the SD card (this needs to move)
if ( sd.init() != 0) {