Single and Dual Zone Infra Red Thermometer

Revision:
4:c5344a5f3266
Parent:
2:1d6817048eb1
--- a/MLX90614.cpp	Tue Dec 26 11:07:58 2017 +0000
+++ b/MLX90614.cpp	Tue Dec 26 11:14:36 2017 +0000
@@ -599,6 +599,122 @@
 
 
 /**
+ * @brief       MLX90614_GetTemperatureSource ( MLX90614_vector_data_t* )
+ *
+ * @details     It gets the temperature source.
+ *
+ * @param[in]    NaN
+ *
+ * @param[out]   myTempSource:      Temperature source.
+ *
+ *
+ * @return       Status of MLX90614_GetTemperatureSource.
+ *
+ *
+ * @author      Manuel Caballero
+ * @date        26/December/2017
+ * @version     26/December/2017     The ORIGIN
+ * @pre         NaN.
+ * @warning     NaN.
+ */
+MLX90614::MLX90614_status_t  MLX90614::MLX90614_GetTemperatureSource ( MLX90614_vector_data_t* myTempSource )
+{
+    char         cmd[]       =   { MLX90614_CONFIG_REGISTER_1, 0, 0 };
+    uint32_t     aux         =   0;
+
+
+    // It gets the temperature source
+    aux      =   _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true );
+    aux      =   _i2c.read  ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
+
+
+    myTempSource->TempSource   =   ( MLX90614_configregister1_temp_t )( cmd[0] & CONFIGREG1_TEMP_MASK );
+    myTempSource->PEC          =   cmd[2];
+
+
+
+
+    if ( aux == I2C_SUCCESS )
+        return   MLX90614_SUCCESS;
+    else
+        return   MLX90614_FAILURE;
+}
+
+
+/**
+ * @brief       MLX90614_SetTemperatureSource ( I2C_parameters_t , MLX90614_configregister1_temp_t )
+ *
+ * @details     It sets the temperature source.
+ *
+ * @param[in]    myTempSource:      Temperature source.
+ *
+ * @param[out]   NaN.
+ *
+ *
+ * @return       Status of MLX90614_SetTemperatureSource.
+ *
+ *
+ * @author      Manuel Caballero
+ * @date        26/December/2017
+ * @version     26/December/2017     The ORIGIN
+ * @pre         NaN.
+ * @warning     NaN.
+ */
+MLX90614::MLX90614_status_t  MLX90614::MLX90614_SetTemperatureSource ( MLX90614_configregister1_temp_t myTempSource )
+{
+    char         cmd[]       =   { MLX90614_CONFIG_REGISTER_1, 0, 0 };
+    uint32_t     aux         =   0;
+    uint32_t     ii          =   0;
+
+
+    // It gets the IIR
+    aux      =   _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true );
+    aux      =   _i2c.read  ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
+
+    // Erase EEPROM
+    cmd[2]   =   cmd[1];                                                       // MSB
+    cmd[1]   =   ( cmd[0] & ~CONFIGREG1_TEMP_MASK );                           // LSB
+    cmd[0]   =   MLX90614_CONFIG_REGISTER_1;                                   // Command
+    aux      =   _i2c.write ( _MLX90614_Addr, &cmd[0], 3, false );
+
+    // It takes EEPROM about 5ms to write/read
+    do
+    {
+        cmd[0]   =   MLX90614_FLAGS;
+        aux      =   _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true );
+        aux      =   _i2c.read  ( _MLX90614_Addr, &cmd[0], 3 );
+        ii++;                                                                                 // Increase the timeout
+    }
+    while ( ( ( cmd[0] & FLAG_EEBUSY_HIGH ) == FLAG_EEBUSY_HIGH ) && ( ii < MLX90614_TIMEOUT ) );
+
+
+    // If TIMEOUT, exit with failure.
+    if ( ii >= MLX90614_TIMEOUT )
+        return MLX90614_FAILURE;
+    else
+    {
+        // It gets the IIR
+        aux      =   _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true );
+        aux      =   _i2c.read  ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) );
+
+        // Update the new value
+        cmd[2]   =   cmd[1];                                                       // MSB
+        cmd[1]   =   ( ( cmd[0] & ~CONFIGREG1_TEMP_MASK ) | myTempSource );        // LSB
+        cmd[0]   =   MLX90614_CONFIG_REGISTER_1;                                   // Command
+        aux      =   _i2c.write ( _MLX90614_Addr, &cmd[0], 2, false );
+    }
+
+
+
+
+    if ( aux == I2C_SUCCESS )
+        return   MLX90614_SUCCESS;
+    else
+        return   MLX90614_FAILURE;
+}
+
+
+/**
  * @brief       MLX90614_GetFLAGS ( MLX90614_vector_data_t* )
  *
  * @details     It gets the flags.