Central Applications - Mbed Code repo / Mbed OS MAX30205_Demo

Dependencies:   MAX30205 max32630fthr

Fork of MAX30205_Demo by Corey Harris

Revision:
4:7865b145ff3c
Parent:
3:4a8ab8ffd52d
Child:
5:fb64c72bb867
--- a/main.cpp	Mon Aug 21 14:57:25 2017 +0000
+++ b/main.cpp	Tue Aug 22 21:54:03 2017 +0000
@@ -18,11 +18,10 @@
     
     I2C i2cBus(I2C1_SDA, I2C1_SCL);     // I2C bus, P3_4 = SDA, P3_5 = SCL   
     
-    MAX30205 * temp_sensor;
-    temp_sensor = new MAX30205(i2cBus, 0x48);
-    int rc = temp_sensor_config(*temp_sensor);  // Configure the temp. sensor
+    MAX30205 temp_sensor(i2cBus, 0x48);         // New MAX30205 on i2cBus
+    int rc = temp_sensor_config(temp_sensor);   // Configure sensor, return 0 on success
     
-    Timer temp_sensor_sampleTimer;      // Create temp. sesnor sample timer 
+    Timer temp_sensor_sampleTimer;      // Create temp. sensor sample timer 
     temp_sensor_sampleTimer.start();    // Start the timer
     
     MAX30205::Configuration_u temp_cfg;
@@ -33,8 +32,8 @@
         
         if( rc == 0 ) {
         
-            /* Start a new temperature conversion */
-            if ( temp_sensor_sampleTimer.read() > 1.0 && !temp_conversion_flag && rc == 0) {
+            // Start a new temperature conversion 
+            if ( ( temp_sensor_sampleTimer.read() > 1.0f ) && !temp_conversion_flag && ( rc == 0 ) ) {
                 
                 temp_cfg.bits.one_shot = 1;
                 rc = temp_sensor->writeConfiguration(temp_cfg);     // Send one-shot cmd to begin conversion  
@@ -42,8 +41,8 @@
                 
             } 
             
-            /* Read the completed temperature conversion */
-            if ( temp_sensor_sampleTimer.read() > 1.05 && temp_conversion_flag && rc == 0){
+            // Read the completed temperature conversion 
+            if ( ( temp_sensor_sampleTimer.read() > 1.05f ) && temp_conversion_flag && ( rc == 0 ) ){
                 
                 temp_conversion_flag = 0;                                   // Lower flag when conversion has completed
                 rc = temp_sensor->readTemperature(rawTemperatureRead);      // Read the temperature data
@@ -55,13 +54,16 @@
             }
         
         }else{
+            
             pc.printf("Something went wrong, check the I2C bus and power connections... \r\n");
             bLed = LED_OFF;
             gLed = LED_OFF;
+            
             while(1){
                 rLed = !rLed;
                 wait(0.5);   
             }
+            
         }
     }
 }