Mindstorms 3rd Party ROBOTC Drivers RobotC
[Home] [Download] [Submit a bug/suggestion] [ROBOTC Forums] [Blog] [Support this project]

dexterind-thermalir.h

Go to the documentation of this file.
00001 /*!@addtogroup Dexter_Industries
00002  * @{
00003  * @defgroup TIR Thermal Infrared Sensor
00004  * Dexter Industries Thermal Infrared Sensor
00005  * @{
00006  */
00007 
00008 /*
00009  * $Id: dexterind-thermalir.h 133 2013-03-10 15:15:38Z xander $
00010  */
00011 
00012 #ifndef __TIR_H__
00013 #define __TIR_H__
00014 /** \file dexterind-thermalir.h
00015  * \brief Dexter Industries Thermal Infrared Sensor driver
00016  *
00017  * TIR2-driver.h provides an API for the Dexter Industries Thermal Infrared Sensor driver.
00018  *
00019  * Changelog:
00020  * - 0.1: Initial release
00021  *
00022  * Credits:
00023  * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
00024  *
00025  * License: You may use this code as you wish, provided you give credit where its due.
00026  *
00027  * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. 
00028 
00029  * \author Xander Soldaat (xander_at_botbench.com)
00030  * \date 10 June 2011
00031  * \version 0.1
00032  * \example dexterind-thermalir-test1.c
00033  * \example dexterind-thermalir-test2.c
00034  */
00035 
00036 #pragma systemFile
00037 
00038 #ifndef __COMMON_H__
00039 #include "common.h"
00040 #endif
00041 
00042 #define TIR_I2C_ADDR        0x0E      /*!< TIR I2C device address */
00043 #define TIR_AMBIENT         0x00      /*!< Thermal Infrared number */
00044 #define TIR_OBJECT          0x01      /*!< Red reading */
00045 #define TIR_SET_EMISSIVITY  0x02      /*!< Green reading */
00046 #define TIR_GET_EMISSIVITY  0x03
00047 #define TIR_CHK_EMISSIVITY  0x04
00048 #define TIR_RESET           0x05
00049 
00050 // Source http://www.rwc.uc.edu/koehler/biophys/8d.html
00051 #define TIR_EM_SKIN_LIGHT   5660
00052 #define TIR_EM_SKIN_DARK    8380
00053 #define TIR_EM_GLASS        9200
00054 #define TIR_EM_CANDLE_SOOT  9500
00055 
00056 #define tempFactor 0.02
00057 
00058 
00059 float TIRreadAmbientTemp(tSensors link);
00060 float TIRreadObjectTemp(tSensors link);
00061 bool TIRsetEmissivity(tSensors link, int emissivity);
00062 bool TIRresetSensor(tSensors link);
00063 
00064 tByteArray TIR_I2CRequest;           /*!< Array to hold I2C command data */
00065 tByteArray TIR_I2CReply;             /*!< Array to hold I2C reply data */
00066 
00067 /**
00068  * Measure the ambient temperature
00069  * @param link the TIR port number
00070  * @return the ambient temperature
00071  */
00072 float TIRreadAmbientTemp(tSensors link) {
00073   float tempData;
00074 
00075   memset(TIR_I2CRequest, 0, sizeof(tByteArray));
00076 
00077   TIR_I2CRequest[0] = 2;            // Message size
00078   TIR_I2CRequest[1] = TIR_I2C_ADDR; // I2C Address
00079   TIR_I2CRequest[2] = TIR_AMBIENT;  // Start colour number register
00080 
00081   if (!writeI2C(link, TIR_I2CRequest, TIR_I2CReply, 2))
00082     return 0;
00083 
00084   wait1Msec(1);
00085 
00086   tempData = (float)(((TIR_I2CReply[1]) << 8) + TIR_I2CReply[0]);
00087   tempData = (tempData * tempFactor) - 0.01;      // Convert to celsius
00088   return tempData - 273.15;            // Convert from Kelvin to Celsius
00089 }
00090 
00091 /**
00092  * Measure the object temperature
00093  * @param link the TIR port number
00094  * @return The object temperature
00095  */
00096 float TIRreadObjectTemp(tSensors link) {
00097   float tempData;
00098 
00099   memset(TIR_I2CRequest, 0, sizeof(tByteArray));
00100 
00101   TIR_I2CRequest[0] = 2;            // Message size
00102   TIR_I2CRequest[1] = TIR_I2C_ADDR; // I2C Address
00103   TIR_I2CRequest[2] = TIR_OBJECT;  // Start colour number register
00104 
00105   if (!writeI2C(link, TIR_I2CRequest, TIR_I2CReply, 2))
00106     return 0;
00107 
00108   wait1Msec(1);
00109   tempData = (float)(((TIR_I2CReply[1]) << 8) + TIR_I2CReply[0]);
00110   tempData = (tempData * tempFactor) - 0.01;      // Convert to celsius
00111   return tempData - 273.15;            // Convert from Kelvin to Celsius
00112 }
00113 
00114 
00115 /**
00116  * Read the current emissivity
00117  * @param link the TIR port number
00118  * @return The current emissivity
00119  */
00120 long TIRreadEmissivity(tSensors link) {
00121   memset(TIR_I2CRequest, 0, sizeof(tByteArray));
00122 
00123   TIR_I2CRequest[0] = 2;            // Message size
00124   TIR_I2CRequest[1] = TIR_I2C_ADDR; // I2C Address
00125   TIR_I2CRequest[2] = TIR_GET_EMISSIVITY;
00126 
00127   if (!writeI2C(link, TIR_I2CRequest, TIR_I2CReply, 2))
00128     return 0;
00129 
00130   return (long)TIR_I2CReply[0] + ((long)TIR_I2CReply[1] << 8);
00131 }
00132 
00133 
00134 /**
00135  * Check the emissivity
00136  * @param link the TIR port number
00137  * @return The current emissivity
00138  */
00139 long TIRcheckEmissivity(tSensors link) {
00140   memset(TIR_I2CRequest, 0, sizeof(tByteArray));
00141 
00142   TIR_I2CRequest[0] = 2;            // Message size
00143   TIR_I2CRequest[1] = TIR_I2C_ADDR; // I2C Address
00144   TIR_I2CRequest[2] = TIR_CHK_EMISSIVITY;
00145 
00146   if (!writeI2C(link, TIR_I2CRequest, TIR_I2CReply, 2))
00147     return 0;
00148 
00149   return TIR_I2CReply[0] + (TIR_I2CReply[1] << 8);
00150 }
00151 
00152 
00153 /**
00154  * Set the current emissivity
00155  * @param link the TIR port number
00156  * @param emissivity the emissivity of the object that is to be measured
00157  * @return true if no error occured, false if it did
00158  */
00159 bool TIRsetEmissivity(tSensors link, int emissivity) {
00160   memset(TIR_I2CRequest, 0, sizeof(tByteArray));
00161 
00162   TIR_I2CRequest[0] = 4;            // Message size
00163   TIR_I2CRequest[1] = TIR_I2C_ADDR; // I2C Address
00164   TIR_I2CRequest[2] = TIR_SET_EMISSIVITY;  // Start colour number register
00165   TIR_I2CRequest[4] = (emissivity >> 8) & 0xFF;    // High Byte
00166   TIR_I2CRequest[3] = emissivity & 0xFF; // Low Byte.
00167 
00168   return writeI2C(link, TIR_I2CRequest);
00169 }
00170 
00171 
00172 /**
00173  * Reset the sensor
00174  * @param link the TIR port number
00175  * @return true if no error occured, false if it did
00176  */
00177 bool TIRresetSensor(tSensors link) {
00178   memset(TIR_I2CRequest, 0, sizeof(tByteArray));
00179 
00180   TIR_I2CRequest[0] = 2;            // Message size
00181   TIR_I2CRequest[1] = TIR_I2C_ADDR; // I2C Address
00182   TIR_I2CRequest[2] = TIR_RESET;  // Start colour number register
00183 
00184   return writeI2C(link, TIR_I2CRequest);
00185 }
00186 
00187 #endif // __TIR_H__
00188 
00189 
00190 /*
00191  * $Id: dexterind-thermalir.h 133 2013-03-10 15:15:38Z xander $
00192  */
00193 /* @} */
00194 /* @} */