Manuel Caballero / BM1383AGLV

Files at this revision

API Documentation at this revision

Comitter:
mcm
Date:
Wed Oct 30 20:18:40 2019 +0000
Parent:
3:24c3e7a9db4e
Commit message:
An example about how to use this driver was added in the header file.

Changed in this revision

BM1383AGLV.h Show annotated file Show diff for this revision Revisions of this file
--- a/BM1383AGLV.h	Wed Oct 30 20:13:53 2019 +0000
+++ b/BM1383AGLV.h	Wed Oct 30 20:18:40 2019 +0000
@@ -22,7 +22,109 @@
 /**
     Example:
 @code
+#include "mbed.h"
+#include "BM1383AGLV.h"
 
+BM1383AGLV myBM1383AGLV ( I2C_SDA, I2C_SCL, BM1383AGLV::BM1383AGLV_ADDRESS, 400000 );
+Serial pc               ( USBTX, USBRX );
+
+DigitalOut  myled   ( LED1 );
+Ticker      newReading;
+
+
+//@brief Variables.
+uint32_t    myState = 0;
+
+//@brief   FUNCTION PROTOTYPES
+void    changeDATA     ( void );
+
+
+//@brief FUNCTION FOR APPLICATION MAIN ENTRY.
+int main()
+{
+    BM1383AGLV::BM1383AGLV_data_t   myBM1383AGLV_Data;
+    BM1383AGLV::BM1383AGLV_status_t aux;
+
+    pc.baud ( 115200 );
+
+    myled   =   1;
+    wait(3);
+    myled   =   0;
+
+    // Get device IDs
+    aux  =   myBM1383AGLV.BM1383AGLV_GetDeviceID ( &myBM1383AGLV_Data );
+    pc.printf( "Device ID1: %x | ID2: %x\r\n", myBM1383AGLV_Data.id1, myBM1383AGLV_Data.id2 );
+
+    // Configure the device: 1 sample | DRDY pin disabled | One-shot mode
+    myBM1383AGLV_Data.ave_num    =   BM1383AGLV::MODE_CONTROL_AVE_NUM_SINGLE;
+    myBM1383AGLV_Data.dren       =   BM1383AGLV::MODE_CONTROL_DREN_DRDY_DISABLE;
+
+    // Measurement control block is ACTIVE  
+    myBM1383AGLV_Data.rstb   =   BM1383AGLV::RESET_RSTB_ACTIVE;
+    aux  =   myBM1383AGLV.BM1383AGLV_SetSoftReset ( myBM1383AGLV_Data );
+
+    // Device in Active mode     
+    myBM1383AGLV_Data.pwr_down   =   BM1383AGLV::POWER_DOWN_PWR_DOWN_ACTIVE;
+    aux  =   myBM1383AGLV.BM1383AGLV_SetPowerDown ( myBM1383AGLV_Data );
+
+
+    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 ) {
+            // Trigegr a new sample 
+            myBM1383AGLV_Data.mode       =   BM1383AGLV::MODE_CONTROL_MODE_ONE_SHOT;
+            aux  =   myBM1383AGLV.BM1383AGLV_SetModeControl ( myBM1383AGLV_Data );
+
+            // Wait until the conversion is finished    
+            do {
+                aux      =   myBM1383AGLV.BM1383AGLV_GetStatus ( &myBM1383AGLV_Data );
+            } while( ( myBM1383AGLV_Data.rd_drdy & BM1383AGLV::STATUS_RD_DRDY_MASK ) == BM1383AGLV::STATUS_RD_DRDY_DATA_MEASURING );   // [TODO] Dangerous!!! The uC may get stuck here if something goes wrong!
+            // [WORKAROUND] Insert a counter.
+
+            // Get pressure 
+            aux  =   myBM1383AGLV.BM1383AGLV_GetPressure ( &myBM1383AGLV_Data );
+
+            // Get temperature   
+            aux  =   myBM1383AGLV.BM1383AGLV_GetTemperature ( &myBM1383AGLV_Data );
+
+            // Transmit result over the UART
+            pc.printf( "P: %0.2f hPa | T: %0.2f C\r\n", myBM1383AGLV_Data.pressure, myBM1383AGLV_Data.temperature );
+
+            myState  =   0;                                                     // Reset the variable
+        }
+
+        myled = 0;
+    }
+}
+
+
+// @brief       changeDATA ( void  )
+//
+// @details     It changes myState variable
+//
+// @param[in]    N/A
+//
+// @param[out]   N/A.
+//
+//
+// @return       N/A..
+//
+//
+// @author      Manuel Caballero
+// @date        02/October/2019
+// @version     02/October/2019   The ORIGIN
+// @pre         N/A
+// @warning     N/A.
+void changeDATA ( void )
+{
+    myState = 1;
+}
 @endcode
 */