OS 5.4 30th March 2017

Dependencies:   LPS25H hts221

Files at this revision

API Documentation at this revision

Comitter:
noutram
Date:
Wed Apr 12 13:45:28 2017 +0000
Parent:
34:62aae7d507e2
Commit message:
Fixed by noutram

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Apr 05 11:00:20 2017 +0000
+++ b/main.cpp	Wed Apr 12 13:45:28 2017 +0000
@@ -1,132 +1,62 @@
 #include "mbed.h"
 #include "rtos.h"
-#include "string.h"
-#include <stdio.h>
-#include <ctype.h>
- #include "hts221.h"
+#include "hts221.h"
 #include "LPS25H.h"
 
-#define SWITCH1_RELEASE 1
- 
-void thread1();
- 
+
 DigitalOut myled(LED1);
 I2C i2c2(I2C_SDA, I2C_SCL);
-LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR);
-HTS221 measurer(I2C_SDA, I2C_SCL);
-DigitalIn  onBoardSwitch(USER_BUTTON);
- 
+
+float tempCelsius = 25.50;
+float humi = 55;
+int humiMax = 100; 
+char cmd=0;
+uint32_t seconds = 0, minutes=0, hours=0; 
 
-//Threads
-Thread *t1;
- 
-//Class type
-class Measure {
-public:    
-    float temperature;    
-    float humidity;
-    float pressure;
-    
-    //Constructor
-    Measure(float f, float h, float p) {
-        temperature = f;
-        humidity = h;
-        pressure = p;    
-    }
-};
- 
-//Mail queue
-Mail<Measure, 16> mail_box;
- 
- 
-// Call this on precise intervals
-void adcISR() {
- 
-    
-    //Read sample - make a copy
-    float temperature = 0 , humidity = 0,pressure = 0;
-    
-    measurer.ReadTempHumi(&temperature,&humidity);
-    barometer.get();
-    pressure = barometer.pressure();
-    
-    //Allocate a block from the memory pool
-    Measure *measure = mail_box.alloc();
-    if (measure == NULL) {
-        //Out of memory
-        printf("Out of memory\n\r");
-        return;   
-    }
-    
-    //Fill in the data
-    measure->temperature = temperature;
-    measure->humidity = humidity;
-    measure->pressure = pressure;
-   // printf("%4.2fC %3.1f%% %6.1f \r\n", measure->temperature, measure->humidity,measure->pressure);
-    
-    //Write to queue
-    osStatus stat = mail_box.put(measure);    //Note we are sending the "pointer"
+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());
     
-    //Check if succesful
-    if (stat == osErrorResource) {
-        printf("queue->put() Error code: %4Xh, Resource not available\r\n", stat);   
-        mail_box.free(measure);
-        return;
+  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
+      }
     }
-    
-}
- 
-//Normal priority thread (consumer)
-void thread1() 
-{      
+  }
+  
+
+
+/*#include "mbed.h"
+
+DigitalOut led1(LED1);
+
+// main() runs in its own thread in the OS
+int main() {
     while (true) {
-        //Block on the queue
-        osEvent evt = mail_box.get();
-        
-        //Check status
-        if (evt.status == osEventMail) {
-            Measure *measure = (Measure*)evt.value.p;  //This is the pointer (address)
-            //Make a copy
-            printf("Consumer: %4.2fC |  %3.1f%% |  %6.1f \r\n", measure->temperature, measure->humidity,measure->pressure);
-            Measure msr(measure->temperature, measure->humidity,measure->pressure);
-            //We are done with this, so give back the memory to the pool
-            mail_box.free(measure);
-            
-            //Echo to the terminal
-            
-        } else {
-            printf("ERROR: %x\n\r", evt.status);   
-        }  
-        
-    } //end while
+        led1 = !led1;
+        wait(0.5);
+    }
 }
- 
- 
-// Main thread
-int main() {
-           
-    measurer.init();
-    measurer.calib();
-    //Start message
-    printf("Welcome\n");           
-   
-    //Hook up timer interrupt   
-    Ticker timer; 
-    timer.attach(&adcISR, 5);
-               
-    //Threads
-    t1 = new Thread();
-    t1->start(thread1); 
-    
-    printf("Main Thread\n");
-    while(1) 
-    {
-      Thread::wait(3000);
-        float tempCelsius,humi;
-        measurer.ReadTempHumi(&tempCelsius, &humi);
-        barometer.get();
-        printf("Main ThreaD: %4.2fC %3.1f%% %6.1f \r\n", tempCelsius, humi,barometer.pressure());
-
-      }
-}
- 
\ No newline at end of file
+*/