soft253

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

Files at this revision

API Documentation at this revision

Comitter:
akovaci
Date:
Fri May 12 20:30:29 2017 +0000
Parent:
35:af125862c33e
Commit message:
soft253

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Apr 12 13:45:28 2017 +0000
+++ b/main.cpp	Fri May 12 20:30:29 2017 +0000
@@ -2,61 +2,125 @@
 #include "rtos.h"
 #include "hts221.h"
 #include "LPS25H.h"
+Serial pc(USBTX, USBRX);
 
 
-DigitalOut myled(LED1);
+#define N 10
+DigitalOut myled(D7);
+Ticker t;
 I2C i2c2(I2C_SDA, I2C_SCL);
 
 float tempCelsius = 25.50;
 float humi = 55;
 int humiMax = 100; 
 char cmd=0;
+float tempArray[N];
+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);
 
 
-int main()
-  {
-  humidity.init();
-  humidity.calib();
-  printf("SOFT253 simple Temperature Humidity and Pressure Sensor Monitor\n\r");
-  printf("Using the X-NUCLEO-IKS01A1 shield and MBED Libraries\n\r");
-    //printf("%#x\n\r",barometer.read_id());
+void adcISR();
+
+
+
+typedef struct {
+      
+      float tempVal ;
+      float humVal;
+      float pressVal;
+    }message_t;
     
-  while(1) 
+Mail<message_t, 10> mail_box;
+
+void adcISR()
+{
+       message_t *message = mail_box.alloc();
+       message->tempVal = tempCelsius;
+       message->humVal = humi;
+       message->pressVal = barometer.pressure();
+       myled=1;
+       mail_box.put(message);
+       //Thread::wait(1000);
+       
+}
+void thread1 (void const* arg)
+{
+         
+         pc.baud(115200);
+         pc.printf("Temperature,Humidity,Pressure\n\n");
+   while(1) 
+   {  
+        
+         osEvent evt = mail_box.get();
+        if (evt.status == osEventMail) 
+        { 
+            for (unsigned int n=(N-1); n>0; n--) 
+           { 
+             tempArray[n]= tempArray[n-1];
+             humArray[n]= humArray[n-1];
+             pressArray[n]= pressArray[n-1];
+           }
+             message_t *message = (message_t*)evt.value.p;
+             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]);
+             
+             mail_box.free(message); 
+       }
+    }    
+}
+ char answer;
+int main(void)
+  { 
+  
+    puts("Loading... \n\n");
+    Thread thread(thread1);
+    t.attach(&adcISR,15);
+    
+    while(1) 
     {
-      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(cmd=='A'){
-        humidity.ReadTempHumi(&tempCelsius, &humi);
-        printf("%4.2fC %3.1f%%", tempCelsius, humi);
-        barometer.get();
-        printf(" %6.1f %4.1f\r\n", 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
-      }
+       
+      
+           
+       humidity.init();
+       humidity.calib();
+       humidity.ReadTempHumi(&tempCelsius, &humi);
+       barometer.get();
+       barometer.pressure();
+       barometer.temperature();
+       sleep();
+       Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds! 
+       myled = 0; // LED is OFF
+       Thread::wait(100); // 100 ms
+        
+       
+      
+     
     }
+      
   }
   
 
 
-/*#include "mbed.h"
+
 
-DigitalOut led1(LED1);
+
 
-// main() runs in its own thread in the OS
-int main() {
-    while (true) {
-        led1 = !led1;
-        wait(0.5);
-    }
-}
-*/
+
+
+
+