Panagiotis Mitseas
/
SOFT253_Assignment_V3
READDELETEALL
Fork of SOFT253_Assignment_V2 by
Diff: main.cpp
- Revision:
- 37:b62b3aa19645
- Parent:
- 36:7426f37f0c96
- Child:
- 38:8b6a6927b4f2
--- a/main.cpp Fri May 12 20:30:29 2017 +0000 +++ b/main.cpp Fri May 12 22:09:40 2017 +0000 @@ -2,9 +2,10 @@ #include "rtos.h" #include "hts221.h" #include "LPS25H.h" + Serial pc(USBTX, USBRX); - +#define NUMTHRDS 2 #define N 10 DigitalOut myled(D7); Ticker t; @@ -18,15 +19,22 @@ float humArray[N]; float pressArray[N]; uint32_t seconds = 0, minutes=0, hours=0; -static float nextTEMPsample, nextHUMsample, nextPRESSsample; + -static int indexOfOldest = (N-1); + LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR); HTS221 humidity(I2C_SDA, I2C_SCL); void adcISR(); +void thread1 (void const *args ); +void threadcomun (void const *args); + +Thread* t1; +Thread* t2; + + @@ -50,14 +58,14 @@ //Thread::wait(1000); } -void thread1 (void const* arg) +void thread1 (void const *args ) { pc.baud(115200); - pc.printf("Temperature,Humidity,Pressure\n\n"); + //pc.printf("Temperature,Humidity,Pressure\n\n"); while(1) { - + cmd=NULL; osEvent evt = mail_box.get(); if (evt.status == osEventMail) { @@ -71,11 +79,7 @@ tempArray[0]= message->tempVal; humArray[0] = message->humVal; pressArray[0]= message->pressVal; - for (unsigned int n=0; n<N; n++) - { - pc.printf("the element of %d is %4.2f\n\r ",n,tempArray[n]); - wait(1.0); - } + // pc.printf("%4.2f,%3.1f,%6.1f\n\r", tempArray[N/2], humArray[N/2], pressArray[N/2]); @@ -83,19 +87,39 @@ } } } + +void threadcomun (void const *args) +{ + pc.baud(115200); + pc.printf("Temperature,Humidity,Pressure\n\n"); + while(cmd==NULL){cmd=getchar();} + if(cmd=='A') + { + for (unsigned int n=0; n<N; n++) + { + pc.printf("the element of %d is %4.2f\n\r ",n,tempArray[n]); + //wait(1.0); + } + } + + } char answer; int main(void) { puts("Loading... \n\n"); - Thread thread(thread1); - t.attach(&adcISR,15); + t1 = new Thread(thread1); + t2 = new Thread(threadcomun); + + + // Thread thread(thread1); + //threadcomun(); + + //Thread thread(threadcomun); + t.attach(&adcISR,1); while(1) { - - - humidity.init(); humidity.calib(); humidity.ReadTempHumi(&tempCelsius, &humi); @@ -106,10 +130,6 @@ Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds! myled = 0; // LED is OFF Thread::wait(100); // 100 ms - - - - } }