test
Dependencies: CheckRTC LPS25H hts221
Fork of ELEC350-extended-referral2 by
Diff: main.cpp
- Revision:
- 40:426cd176ce80
- Parent:
- 39:504f5dc30a33
- Child:
- 41:ce3d6fb38d3b
--- a/main.cpp Wed Nov 15 11:43:05 2017 +0000 +++ b/main.cpp Thu Nov 16 01:06:41 2017 +0000 @@ -2,6 +2,7 @@ #include "rtos.h" #include "hts221.h" #include "LPS25H.h" +#include <sstream> //#include "CheckRTC.h" @@ -11,7 +12,7 @@ float tempCelsius = 25.50; float humi = 55; int humiMax = 100; -char cmd=0; +char buffer_str=0; uint32_t seconds = 0, minutes=0, hours=0; Ticker t; volatile static unsigned short sample16 = 0; @@ -19,70 +20,57 @@ int count = 0; char *buf; size_t sz; - +typedef struct { + float temp; + float press; + float humid; +} measurement; +measurement buffer [120]; LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR); HTS221 humidity(I2C_SDA, I2C_SCL); - - - - +void function1(); +void function2(); +void function3(); -int main() -{ - pc.baud(9600); //sets baud rate to 9600 - time_t seconds = time(NULL); - char time [32]; - char date [32]; - strftime(time, 32, "%H:%M:%S %p", localtime(&seconds)); - strftime(date, 32, "%Y/%m/%d %a", localtime(&seconds)); - humidity.init(); - humidity.calib(); - //t.attach(doSample1Hz, 1.0); - printf("press T to set time and date \n\r"); - printf("press S to start sampling\n\r"); - printf("press D to delete sensor data\n\r"); - printf("Press A to read all sensor data\n\r"); - printf("Press R to read sensor data in memory\n\r"); +Thread t1; +Thread t2; +Thread t3; +Thread t4; - - - - - while(1) { +osThreadId idMain; +osThreadId id1; - cmd=NULL; - while(cmd==NULL) { - cmd=getchar(); - } - if(cmd=='?') { - printf("SOFT253 simple Temperature Humidity and Pressure Sensor Monitor\n\r"); - printf("Using the X-NUCLEO-IKS01A1 shield and MBED Libraries\n\r"); - } -/*--------------If 'A' is pressed then all sensor data is diplayed---------------------*/ - if(cmd=='A') { - humidity.ReadTempHumi(&tempCelsius, &humi); // reads temperature and humity levels - barometer.get(); // gets barometer readings - // displays all the variables of time, date, temperature, humidity and all the barometric readings to the serial - printf("%s, %s, %4.2fC , %3.1f%%, %6.1f, %4.1f\n\r", time, date, tempCelsius, humi, barometer.pressure(), barometer.temperature()); - myled = 1; // LED is ON - Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds! - myled = 0; // LED is OFF - Thread::wait(100); // 100 ms - } - /*-------------- if 'T' is pressed then the time and date are set to the UTC below------------------------*/ - if(cmd=='T') { - set_time(1508268288); - printf("time and date updated to %s %s\n\r", time, date); - myled = 1; - Thread::wait(200); - myled = 0; - Thread::wait(100); - } -/*-------------if 's' is pressed, 5 sample of data are taken and stored to the RAM every second-------------------------*/ - if(cmd=='S') { - for (count = 0; count < 5; count++){ +void function1() +{ + char buffer [128]; + scanf("%127s", buffer); + string buffer_str(buffer); + + /*--------------If 'A' is pressed then all sensor data is diplayed---------------------*/ + if(buffer_str=="READALL") { + humidity.ReadTempHumi(&tempCelsius, &humi); // reads temperature and humity levels + barometer.get(); // gets barometer readings + // displays all the variables of time, date, temperature, humidity and all the barometric readings to the serial + printf("%s, %s, %4.2fC , %3.1f%%, %6.1f, %4.1f\n\r", time, date, tempCelsius, humi, barometer.pressure(), barometer.temperature()); + myled = 1; // LED is ON + Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds! + myled = 0; // LED is OFF + Thread::wait(100); // 100 ms + } + /*-------------- if 'T' is pressed then the time and date are set to the UTC below------------------------*/ + if(buffer_str=="SETTIME") { + set_time(1508268288); + printf("time and date updated to %s %s\n\r", time, date); + myled = 1; + Thread::wait(200); + myled = 0; + Thread::wait(100); + } + /*-------------if 's' is pressed, 5 sample of data are taken and stored to the RAM every second-------------------------*/ + if(buffer_str=="SETT") { + for (count = 0; count < 5; count++) { sz = snprintf(NULL, 0,"%s, %s, %4.2fC , %3.1f%%, %6.1f, %4.1f\n\r", time, date, tempCelsius, humi, barometer.pressure(), barometer.temperature()); buf = (char *)malloc(sz + 1); snprintf(buf, sz + 1, "%s, %s, %4.2fC , %3.1f%%, %6.1f, %4.1f\n\r", time, date, tempCelsius, humi, barometer.pressure(), barometer.temperature()); @@ -93,22 +81,54 @@ myled = 0; Thread::wait(100); wait(1); - } - if(cmd=='R'){ + } + if(buffer_str=="READ") { printf("%s\n\r", buf); myled = 1; Thread::wait(200); myled = 0; Thread::wait (100); - } } } +} + +int main() +{ + pc.baud(9600); //sets baud rate to 9600 + idMain = osThreadGetId(); + t1.start(function1); + id1 = t1.gettid(); + + time_t seconds = time(NULL); + char time [32]; + char date [32]; + strftime(time, 32, "%H:%M:%S %p", localtime(&seconds)); + strftime(date, 32, "%Y/%m/%d %a", localtime(&seconds)); + humidity.init(); + humidity.calib(); + printf("Type SETTIME to set time and date [enter] \n\r"); + printf("Type SETT to start sampling [ENTER]\n\r"); + printf("Type DELETEALL to delete sensor data [enter]\n\r"); + printf("Type READALL [enter]\n\r"); + printf("Type READ to read sensor data in memory [ENTER]\n\r"); + + + + + + while(1) { + char buffer [128]; + scanf("%127s", buffer); + string buffer_str(buffer); + + + if(buffer_str=="?") { + printf("SOFT253 simple Temperature Humidity and Pressure Sensor Monitor\n\r"); + printf("Using the X-NUCLEO-IKS01A1 shield and MBED Libraries\n\r"); + } + + + } + } -void doSample1Hz() -{ - //sz = snprintf(NULL, 0,"%s, %s, %4.2fC , %3.1f%%, %6.1f, %4.1f\n\r", time, date, tempCelsius, humi, barometer.pressure(), barometer.temperature()); - //buf = (char *)malloc(sz + 1); - //snprintf(buf, sz + 1, "%s, %s, %4.2fC , %3.1f%%, %6.1f, %4.1f\n\r", time, date, tempCelsius, humi, barometer.pressure(), barometer.temperature()); - -}