Indoor Air Quality Sensor Module

Dependents:   Sensor_iAQ_core Sensor_iAQ_sgp30_bme_si7051 POCBreath_V2_smd_commercial

Files at this revision

API Documentation at this revision

Comitter:
mcm
Date:
Mon Jun 11 12:31:22 2018 +0000
Parent:
2:cddf1d41f9b0
Commit message:
The driver was completed and tested ( using a NUCLEO-L152RE board ), it works as expected.

Changed in this revision

iAQ_Core.cpp Show annotated file Show diff for this revision Revisions of this file
iAQ_Core.h Show annotated file Show diff for this revision Revisions of this file
diff -r cddf1d41f9b0 -r 53c56ce59c29 iAQ_Core.cpp
--- a/iAQ_Core.cpp	Fri Jun 08 15:59:01 2018 +0000
+++ b/iAQ_Core.cpp	Mon Jun 11 12:31:22 2018 +0000
@@ -32,7 +32,7 @@
 
 
 /**
- * @brief       iAQ_Core_GetNewReading ( iAQ_Core_vector_data_t* )
+ * @brief       iAQ_Core_GetNewReading ( iAQ_Core_data_t* )
  *
  * @details     It performs a new parameters reading from the sensor.
  *
@@ -50,7 +50,7 @@
  * @pre         Measurement interval ( continuous ): 1s | Measurement interval ( pulsed ): Max. 11s.
  * @warning     First functional reading after start up is 5 minutes.
  */
-iAQ_Core::iAQ_Core_status_t  iAQ_Core::iAQ_Core_GetNewReading ( iAQ_Core_vector_data_t* myData )
+iAQ_Core::iAQ_Core_status_t  iAQ_Core::iAQ_Core_GetNewReading ( iAQ_Core_data_t* myData )
 {
     char     cmd[9]    =   { 0 };
     uint32_t aux       =   0;
diff -r cddf1d41f9b0 -r 53c56ce59c29 iAQ_Core.h
--- a/iAQ_Core.h	Fri Jun 08 15:59:01 2018 +0000
+++ b/iAQ_Core.h	Mon Jun 11 12:31:22 2018 +0000
@@ -22,7 +22,72 @@
 /**
     Example:
 @code
-[todo]
+#include "mbed.h"
+#include "iAQ_Core.h"
+
+iAQ_Core myiAQ_Core ( I2C_SDA, I2C_SCL, iAQ_Core::iAQ_Core_ADDRESS );
+Serial pc           ( USBTX, USBRX );
+
+DigitalOut  myled       ( LED1 );
+Ticker      newReading;
+
+iAQ_Core::iAQ_Core_status_t  aux;
+iAQ_Core::iAQ_Core_data_t    myiAQ_Core_data;
+uint32_t                     myState = 0;
+
+
+void changeDATA ( void )
+{
+    myState = 1;
+}
+
+
+int main()
+{
+    uint32_t myWarmUpCounter  =   0;
+
+
+    pc.baud ( 115200 );
+
+    myled   =   1;
+    wait(3);
+    myled   =   0;
+
+
+    // iAQ-Core warm up is at least 5 minutes ( 300 * 1s ) or when the sensor is ready
+    do
+    {
+      aux      =   myiAQ_Core.iAQ_Core_GetNewReading ( &myiAQ_Core_data );
+      wait(1);
+      myWarmUpCounter++;
+    } while( ( myWarmUpCounter < 300 ) && ( myiAQ_Core_data.status == iAQ_Core::iAQ_Core_STATUS_RUNIN ) );
+
+
+    newReading.attach( &changeDATA, 1 );                                        // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
+
+    // Let the callbacks take care of everything
+    while(1)
+    {
+      sleep();
+
+      myled = 1;
+
+      if ( myState == 1 ) {
+        // New reading
+        do {
+            aux      =   myiAQ_Core.iAQ_Core_GetNewReading (  &myiAQ_Core_data );
+            wait_ms(1);
+        } while( myiAQ_Core_data.status != iAQ_Core::iAQ_Core_STATUS_OK );          // [TODO] Dangerous!!! The uC may get stuck here if something goes wrong!
+                                                                                    // [WORKAROUND] Insert a counter.
+
+        // Send data through the UART
+        pc.printf( "Pred: %d | Tvoc: %d | Resistance: %d\r\n", myiAQ_Core_data.pred, myiAQ_Core_data.Tvoc, myiAQ_Core_data.resistance );
+        myState  =   0;                                                             // Reset the variable
+      }
+
+      myled = 0;
+    }
+}
 @endcode
 */
 
@@ -58,14 +123,14 @@
 
 
 
-#ifndef iAQ_Core_VECTOR_STRUCT_H
-#define iAQ_Core_VECTOR_STRUCT_H
+#ifndef iAQ_Core_STRUCT_H
+#define iAQ_Core_STRUCT_H
     typedef struct {
         uint16_t                pred;               /*!<  Prediction (CO2 eq. ppm),  Typical Value: 450                     */
         iAQ_Core_status_flag_t  status;             /*!<  Status,                    Typical Value: 0                       */
         int32_t                 resistance;         /*!<  Sensor resistance [Ohm],   Typical Value: 256431                  */
         uint16_t                Tvoc;               /*!<  Prediction (TVOC eq. ppb), Typical Value: 125                     */
-    } iAQ_Core_vector_data_t;
+    } iAQ_Core_data_t;
 #endif
 
 
@@ -96,7 +161,7 @@
 
     /** It performs a new parameters reading from the sensor.
       */
-    iAQ_Core_status_t iAQ_Core_GetNewReading     ( iAQ_Core_vector_data_t* myData );
+    iAQ_Core_status_t iAQ_Core_GetNewReading     ( iAQ_Core_data_t* myData );