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

hitechnic-irseeker-v2.h

Go to the documentation of this file.
00001 /*!@addtogroup HiTechnic
00002  * @{
00003  * @defgroup htirs2 IR Seeker V2
00004  * HiTechnic IR Seeker V2
00005  * @{
00006  */
00007 
00008 /*
00009  * $Id: hitechnic-irseeker-v2.h 133 2013-03-10 15:15:38Z xander $
00010  */
00011 
00012 #ifndef __HTIRS2_H__
00013 #define __HTIRS2_H__
00014 /** \file hitechnic-irseeker-v2.h
00015  * \brief HiTechnic IR Seeker V2 driver
00016  *
00017  * hitechnic-irseeker-v2.h provides an API for the HiTechnic IR Seeker V2.
00018  *
00019  * Changelog:
00020  * - 0.1: Initial release
00021  * - 0.2: Added SMUX functions
00022  * - 0.3: All functions using tIntArray are now pass by reference.<br>
00023  *        HTIRS2_SMUXData removed
00024  * - 0.4: Removed all calls to ubyteToInt()<br>
00025  *        Replaced all functions that used SPORT/MPORT macros
00026  * - 0.5: Driver renamed to HTIRS2
00027  *
00028  * Credits:
00029  * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
00030  *
00031  * License: You may use this code as you wish, provided you give credit where its due.
00032  *
00033  * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. 
00034 
00035  * \author Xander Soldaat (mightor_at_gmail.com)
00036  * \date 06 April 2010
00037  * \version 0.5
00038  * \example hitechnic-irseeker-v2-test1.c
00039  * \example hitechnic-irseeker-v2-enhanced-test1.c
00040  * \example hitechnic-irseeker-v2-SMUX-test1.c
00041  * \example hitechnic-irseeker-v2-enhanced-SMUX-test1.c
00042  */
00043 
00044 #pragma systemFile
00045 
00046 #ifndef __COMMON_H__
00047 #include "common.h"
00048 #endif
00049 
00050 #define HTIRS2_I2C_ADDR    0x10      /*!< IR Seeker I2C device address */
00051 #define HTIRS2_DSP_MODE    0x41      /*!< AC DSP mode - 0 = 1200Hz, 1 = 600Hz */
00052 #define HTIRS2_OFFSET      0x42      /*!< Offset for data registers */
00053 #define HTIRS2_DC_DIR      0x00      /*!< DC Direction data */
00054 #define HTIRS2_DC_SSTR1    0x01      /*!< DC Sensor 0 signal strength above average */
00055 #define HTIRS2_DC_SSTR2    0x02      /*!< DC Sensor 1 signal strength above average */
00056 #define HTIRS2_DC_SSTR3    0x03      /*!< DC Sensor 2 signal strength above average */
00057 #define HTIRS2_DC_SSTR4    0x04      /*!< DC Sensor 3 signal strength above average */
00058 #define HTIRS2_DC_SSTR5    0x05      /*!< DC Sensor 4 signal strength above average */
00059 #define HTIRS2_DC_SAVG     0x06      /*!< DC sensor signal strength average */
00060 #define HTIRS2_AC_DIR      0x07      /*!< DC Direction data */
00061 #define HTIRS2_AC_SSTR1    0x08      /*!< AC Sensor 0 signal strength above average */
00062 #define HTIRS2_AC_SSTR2    0x09      /*!< AC Sensor 1 signal strength above average */
00063 #define HTIRS2_AC_SSTR3    0x0A      /*!< AC Sensor 2 signal strength above average */
00064 #define HTIRS2_AC_SSTR4    0x0B      /*!< AC Sensor 3 signal strength above average */
00065 #define HTIRS2_AC_SSTR5    0x0C      /*!< AC Sensor 4 signal strength above average */
00066 
00067 
00068 /*!< AC DSP modes */
00069 typedef enum {
00070   DSP_1200 = 0,
00071   DSP_600 = 1
00072 } tHTIRS2DSPMode;
00073 
00074 // ---------------------------- DC Signal processing -----------------------------
00075 int HTIRS2readDCDir(tSensors link);
00076 bool HTIRS2readAllDCStrength(tSensors link, int &dcS1, int &dcS2, int &dcS3, int &dcS4, int &dcS5);
00077 int HTIRS2readDCAverage(tSensors link);
00078 // ---------------------------- AC Signal processing -----------------------------
00079 bool HTIRS2setDSPMode(tSensors link, tHTIRS2DSPMode mode);
00080 int HTIRS2readACDir(tSensors link);
00081 bool HTIRS2readAllACStrength(tSensors link, int &acS1, int &acS2, int &acS3, int &acS4, int &acS5);
00082 
00083 bool HTIRS2readEnhanced(tSensors  link, int &dir, int &strength);
00084 
00085 #ifdef __HTSMUX_SUPPORT__
00086 // ---------------------------- DC Signal processing -----------------------------
00087 int HTIRS2readDCDir(tMUXSensor muxsensor);
00088 bool HTIRS2readAllDCStrength(tMUXSensor muxsensor, int &dcS1, int &dcS2, int &dcS3, int &dcS4, int &dcS5);
00089 int HTIRS2readDCAverage(tMUXSensor muxsensor);
00090 // ---------------------------- AC Signal processing -----------------------------
00091 int HTIRS2readACDir(tMUXSensor muxsensor);
00092 bool HTIRS2readAllACStrength(tMUXSensor muxsensor, int &acS1, int &acS2, int &acS3, int &acS4, int &acS5);
00093 
00094 bool HTIRS2readEnhanced(tMUXSensor muxsensor, int &dir, int &strength);
00095 
00096 tConfigParams HTIRS2_config = {HTSMUX_CHAN_I2C, 13, 0x10, 0x42}; /*!< Array to hold SMUX config data for sensor */
00097 #endif // __HTSMUX_SUPPORT__
00098 
00099 tByteArray HTIRS2_I2CRequest;    /*!< Array to hold I2C command data */
00100 tByteArray HTIRS2_I2CReply;      /*!< Array to hold I2C reply data */
00101 
00102 // ---------------------------- DC Signal processing -----------------------------
00103 
00104 /**
00105  * Read the value of the DC Direction data register and return it.
00106  * @param link the HTIRS2 port number
00107  * @return value of 0-9, the direction index of the detected IR signal or -1 if an error occurred.
00108  */
00109 int HTIRS2readDCDir(tSensors link) {
00110   memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00111 
00112   HTIRS2_I2CRequest[0] = 2;              // Message size
00113   HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR; // I2C Address
00114   HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_DC_DIR;  // Start direction register
00115 
00116   if (!writeI2C(link, HTIRS2_I2CRequest, HTIRS2_I2CReply, 1))
00117     return -1;
00118 
00119   return HTIRS2_I2CReply[0];
00120 }
00121 
00122 
00123 /**
00124  * Read the value of the DC Direction data register and return it.
00125  * @param muxsensor the SMUX sensor port number
00126  * @return value of 0-9, the direction index of the detected IR signal or -1 if an error occurred.
00127  */
00128 #ifdef __HTSMUX_SUPPORT__
00129 int HTIRS2readDCDir(tMUXSensor muxsensor) {
00130         memset(HTIRS2_I2CReply, 0, sizeof(tByteArray));
00131 
00132   if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00133     HTSMUXconfigChannel(muxsensor, HTIRS2_config);
00134 
00135   if (!HTSMUXreadPort(muxsensor, HTIRS2_I2CReply, 1, HTIRS2_DC_DIR)) {
00136     return -1;
00137   }
00138 
00139   return HTIRS2_I2CReply[0];
00140 }
00141 #endif // __HTSMUX_SUPPORT__
00142 
00143 
00144 /**
00145  * Read the value of the all of the internal DC sensors above average.
00146  * @param link the HTIRS2 port number
00147  * @param dcS1 data from internal sensor nr 1
00148  * @param dcS2 data from internal sensor nr 2
00149  * @param dcS3 data from internal sensor nr 3
00150  * @param dcS4 data from internal sensor nr 4
00151  * @param dcS5 data from internal sensor nr 5
00152  * @return true if no error occured, false if it did
00153  */
00154 bool HTIRS2readAllDCStrength(tSensors link, int &dcS1, int &dcS2, int &dcS3, int &dcS4, int &dcS5) {
00155   memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00156 
00157   HTIRS2_I2CRequest[0] = 2;                      // Message size
00158   HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR;         // I2C Address
00159   HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_DC_SSTR1;         // Sensor 0 signal strength
00160 
00161   if (!writeI2C(link, HTIRS2_I2CRequest, HTIRS2_I2CReply, 5))
00162     return false;
00163 
00164   //if (!readI2C(link, HTIRS2_I2CReply, 5))
00165   //  return false;
00166 
00167   dcS1 = HTIRS2_I2CReply[0];
00168   dcS2 = HTIRS2_I2CReply[1];
00169   dcS3 = HTIRS2_I2CReply[2];
00170   dcS4 = HTIRS2_I2CReply[3];
00171   dcS5 = HTIRS2_I2CReply[4];
00172 
00173   return true;
00174 }
00175 
00176 
00177 /**
00178  * Read the value of the all of the internal DC sensors above average.
00179  * @param muxsensor the SMUX sensor port number
00180  * @param dcS1 data from internal sensor nr 1
00181  * @param dcS2 data from internal sensor nr 2
00182  * @param dcS3 data from internal sensor nr 3
00183  * @param dcS4 data from internal sensor nr 4
00184  * @param dcS5 data from internal sensor nr 5
00185  * @return true if no error occured, false if it did
00186  */
00187 #ifdef __HTSMUX_SUPPORT__
00188 bool HTIRS2readAllDCStrength(tMUXSensor muxsensor, int &dcS1, int &dcS2, int &dcS3, int &dcS4, int &dcS5) {
00189   memset(HTIRS2_I2CReply, 0, sizeof(tByteArray));
00190 
00191   if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00192     HTSMUXconfigChannel(muxsensor, HTIRS2_config);
00193 
00194   if (!HTSMUXreadPort(muxsensor, HTIRS2_I2CReply, 5, HTIRS2_DC_SSTR1)) {
00195     return false;
00196   }
00197 
00198   dcS1 = HTIRS2_I2CReply[0];
00199   dcS2 = HTIRS2_I2CReply[1];
00200   dcS3 = HTIRS2_I2CReply[2];
00201   dcS4 = HTIRS2_I2CReply[3];
00202   dcS5 = HTIRS2_I2CReply[4];
00203 
00204   return true;
00205 }
00206 #endif // __HTSMUX_SUPPORT__
00207 
00208 
00209 /**
00210  * Read the value of the average data register and return it.
00211  * @param link the HTIRS2 port number
00212  * @return value of 0-9, the direction index of the detected IR signal or -1 if an error occurred.
00213  */
00214 int HTIRS2readDCAverage(tSensors link) {
00215   memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00216 
00217   HTIRS2_I2CRequest[0] = 2;              // Message size
00218   HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR; // I2C Address
00219   HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_DC_SAVG;  // DC sensor signal strength average
00220 
00221   if (!writeI2C(link, HTIRS2_I2CRequest, HTIRS2_I2CReply, 1))
00222     return -1;
00223 
00224   return HTIRS2_I2CReply[0];
00225 }
00226 
00227 
00228 /**
00229  * Read the value of the average data register and return it.
00230  * @param muxsensor the SMUX sensor port number
00231  * @return value of 0-9, the direction index of the detected IR signal or -1 if an error occurred.
00232  */
00233 #ifdef __HTSMUX_SUPPORT__
00234 int HTIRS2readDCAverage(tMUXSensor muxsensor) {
00235   memset(HTIRS2_I2CReply, 0, sizeof(tByteArray));
00236 
00237   if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00238     HTSMUXconfigChannel(muxsensor, HTIRS2_config);
00239 
00240   if (!HTSMUXreadPort(muxsensor, HTIRS2_I2CReply, 1, HTIRS2_DC_SAVG)) {
00241     return -1;
00242   }
00243 
00244   return HTIRS2_I2CReply[0];
00245 }
00246 #endif // __HTSMUX_SUPPORT__
00247 
00248 
00249 // ---------------------------- AC Signal processing -----------------------------
00250 
00251 /**
00252  * Set the DSP mode of the AC carrier wave detector.
00253  *
00254  * Mode is one of:
00255  * -DSP_1200
00256  * -DSP_600
00257  * @param link the HTIRS2 port number
00258  * @param mode the frequency that should be detected
00259  * @return true if no error occured, false if it did
00260  */
00261 bool HTIRS2setDSPMode(tSensors link, tHTIRS2DSPMode mode) {
00262   memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00263 
00264   HTIRS2_I2CRequest[0] = 3;              // Message size
00265   HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR; // I2C Address
00266   HTIRS2_I2CRequest[2] = HTIRS2_DSP_MODE; // Start direction register
00267   HTIRS2_I2CRequest[3] = (ubyte)mode;
00268 
00269   return writeI2C(link, HTIRS2_I2CRequest);
00270 }
00271 
00272 /**
00273  * Read the value of the AC Direction data register and return it.
00274  * @param link the HTIRS2 port number
00275  * @return value of 0-9, the direction index of the detected IR signal or -1 if an error occurred.
00276  */
00277 int HTIRS2readACDir(tSensors link) {
00278   memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00279 
00280   HTIRS2_I2CRequest[0] = 2;              // Message size
00281   HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR; // I2C Address
00282   HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_AC_DIR;      // Start direction register
00283 
00284   if (!writeI2C(link, HTIRS2_I2CRequest, HTIRS2_I2CReply, 1))
00285     return -1;
00286 
00287   return HTIRS2_I2CReply[0];
00288 }
00289 
00290 
00291 /**
00292  * Read the value of the AC Direction data register and return it.
00293  * @param muxsensor the SMUX sensor port number
00294  * @return value of 0-9, the direction index of the detected IR signal or -1 if an error occurred.
00295  */
00296 #ifdef __HTSMUX_SUPPORT__
00297 int HTIRS2readACDir(tMUXSensor muxsensor) {
00298   memset(HTIRS2_I2CReply, 0, sizeof(tByteArray));
00299 
00300   if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00301     HTSMUXconfigChannel(muxsensor, HTIRS2_config);
00302 
00303   if (!HTSMUXreadPort(muxsensor, HTIRS2_I2CReply, 1, HTIRS2_AC_DIR)) {
00304     return -1;
00305   }
00306 
00307   return HTIRS2_I2CReply[0];
00308 }
00309 #endif // __HTSMUX_SUPPORT__
00310 
00311 
00312 /**
00313  * Read the value of the all of the internal AC sensors and copy into specified buffer.
00314  * @param link the HTIRS2 port number
00315  * @param acS1 data from internal sensor nr 1
00316  * @param acS2 data from internal sensor nr 2
00317  * @param acS3 data from internal sensor nr 3
00318  * @param acS4 data from internal sensor nr 4
00319  * @param acS5 data from internal sensor nr 5
00320  * @return true if no error occured, false if it did
00321  */
00322 bool HTIRS2readAllACStrength(tSensors link, int &acS1, int &acS2, int &acS3, int &acS4, int &acS5) {
00323   memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00324 
00325   HTIRS2_I2CRequest[0] = 2;                      // Message size
00326   HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR;         // I2C Address
00327   HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_AC_SSTR1;         // Sensor 0 signal strength
00328 
00329   if (!writeI2C(link, HTIRS2_I2CRequest, HTIRS2_I2CReply, 5))
00330     return false;
00331 
00332   acS1 = HTIRS2_I2CReply[0];
00333   acS2 = HTIRS2_I2CReply[1];
00334   acS3 = HTIRS2_I2CReply[2];
00335   acS4 = HTIRS2_I2CReply[3];
00336   acS5 = HTIRS2_I2CReply[4];
00337 
00338   return true;
00339 }
00340 
00341 
00342 /**
00343  * Read the value of the all of the internal AC sensors and copy into specified buffer.
00344  * @param muxsensor the SMUX sensor port number
00345  * @param acS1 data from internal sensor nr 1
00346  * @param acS2 data from internal sensor nr 2
00347  * @param acS3 data from internal sensor nr 3
00348  * @param acS4 data from internal sensor nr 4
00349  * @param acS5 data from internal sensor nr 5
00350  * @return true if no error occured, false if it did
00351  */
00352 #ifdef __HTSMUX_SUPPORT__
00353 bool HTIRS2readAllACStrength(tMUXSensor muxsensor, int &acS1, int &acS2, int &acS3, int &acS4, int &acS5) {
00354   memset(HTIRS2_I2CReply, 0, sizeof(tByteArray));
00355 
00356   if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00357     HTSMUXconfigChannel(muxsensor, HTIRS2_config);
00358 
00359   if (!HTSMUXreadPort(muxsensor, HTIRS2_I2CReply, 5, HTIRS2_AC_SSTR1)) {
00360     return false;
00361   }
00362 
00363   acS1 = HTIRS2_I2CReply[0];
00364   acS2 = HTIRS2_I2CReply[1];
00365   acS3 = HTIRS2_I2CReply[2];
00366   acS4 = HTIRS2_I2CReply[3];
00367   acS5 = HTIRS2_I2CReply[4];
00368 
00369   return true;
00370 }
00371 #endif // __HTSMUX_SUPPORT__
00372 
00373 
00374 /**
00375  * This function calculates the strength and direction based on both the DC and AC
00376  * signal strengths.
00377  * @param link the HTIRS2 port number
00378  * @param dir direction where the ball is detected, value of 0-9 (0 when no ball is detected)
00379  * @param strength the strength (and distance) of the ball's IR signal
00380  * @return true if no error occured, false if it did
00381  */
00382 bool HTIRS2readEnhanced(tSensors  link, int &dir, int &strength)
00383 {
00384   ubyte iMax = 0;
00385   long dcSigSum = 0;
00386 
00387   // Read DC mode
00388   memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00389 
00390   HTIRS2_I2CRequest[0] = 2;                                 // Message size
00391   HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR;                   // I2C Address
00392   HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_DC_SSTR1;   // Sensor 0 signal strength
00393 
00394   if (!writeI2C(link, HTIRS2_I2CRequest, HTIRS2_I2CReply, 6))
00395     return false;
00396 
00397   // Find the max DC sig strength
00398   for (int i = 1; i < 5; i++)
00399   {
00400     if (HTIRS2_I2CReply[i] > HTIRS2_I2CReply[iMax])
00401     {
00402       iMax = i;
00403     }
00404   }
00405 
00406   // Calc base DC direction value
00407   dir = iMax * 2 + 1;
00408   // Set base dcStrength based on max signal and average
00409   dcSigSum = HTIRS2_I2CReply[iMax] + HTIRS2_I2CReply[5];
00410 
00411   // Check signal strength of neighbouring sensor elements
00412   if ((iMax > 0) && (HTIRS2_I2CReply[iMax - 1] > (ubyte)(HTIRS2_I2CReply[iMax] / 2)))
00413   {
00414       dir--;
00415       dcSigSum += HTIRS2_I2CReply[iMax - 1];
00416   }
00417 
00418   if ((iMax < 4) && (HTIRS2_I2CReply[iMax + 1] > (ubyte)(HTIRS2_I2CReply[iMax] / 2)))
00419   {
00420       dir++;
00421       dcSigSum += HTIRS2_I2CReply[iMax + 1];
00422   }
00423 
00424   // Make DC strength compatible with AC strength.
00425   // use: sqrt(dcSigSum*500)
00426   strength = sqrt(dcSigSum * 500);
00427 
00428   // Decide if using AC strength
00429   if (strength <= 200)
00430   {
00431     writeDebugStreamLine("switching to AC");
00432     // Use AC Dir
00433     HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_AC_DIR; // Recycle rest of cmdBuf
00434 
00435           if (!writeI2C(link, HTIRS2_I2CRequest, HTIRS2_I2CReply, 6))
00436             return false;
00437 
00438     dir = HTIRS2_I2CReply[0];
00439 
00440     // Sum the sensor elements to get strength
00441     if (dir > 0)
00442     {
00443       strength = HTIRS2_I2CReply[1] + HTIRS2_I2CReply[2] +
00444                  HTIRS2_I2CReply[3] + HTIRS2_I2CReply[4] +
00445                  HTIRS2_I2CReply[5];
00446     }
00447   }
00448   return true;
00449 }
00450 
00451 /**
00452  * This function calculates the strength and direction based on both the DC and AC
00453  * signal strengths.
00454  * @param muxsensor the SMUX sensor port number
00455  * @param dir direction where the ball is detected, value of 0-9 (0 when no ball is detected)
00456  * @param strength the strength (and distance) of the ball's IR signal
00457  * @return true if no error occured, false if it did
00458  */
00459 #ifdef __HTSMUX_SUPPORT__
00460 bool HTIRS2readEnhanced(tMUXSensor muxsensor, int &dir, int &strength)
00461 {
00462   ubyte iMax = 0;
00463   long dcSigSum = 0;
00464 
00465   memset(HTIRS2_I2CReply, 0, sizeof(tByteArray));
00466 
00467   if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00468     HTSMUXconfigChannel(muxsensor, HTIRS2_config);
00469 
00470   if (!HTSMUXreadPort(muxsensor, HTIRS2_I2CReply, 13, HTIRS2_DC_DIR)) {
00471     return false;
00472   }
00473 
00474   // Find the max DC sig strength
00475   for (int i = 1; i < 5; i++)
00476   {
00477     if (HTIRS2_I2CReply[HTIRS2_DC_SSTR1+i] > HTIRS2_I2CReply[HTIRS2_DC_SSTR1+iMax])
00478     {
00479       iMax = i;
00480     }
00481   }
00482 
00483   // Calc base DC direction value
00484   dir = iMax * 2 + 1;
00485   // Set base dcStrength based on max signal and average
00486   dcSigSum = HTIRS2_I2CReply[HTIRS2_DC_SSTR1+iMax] + HTIRS2_I2CReply[HTIRS2_DC_SSTR1+5];
00487 
00488   // Check signal strength of neighbouring sensor elements
00489   if ((iMax > 0) && (HTIRS2_I2CReply[HTIRS2_DC_SSTR1+iMax - 1] > (ubyte)(HTIRS2_I2CReply[HTIRS2_DC_SSTR1+iMax] / 2)))
00490   {
00491       dir--;
00492       dcSigSum += HTIRS2_I2CReply[HTIRS2_DC_SSTR1+iMax - 1];
00493   }
00494 
00495   if ((iMax < 4) && (HTIRS2_I2CReply[HTIRS2_DC_SSTR1+iMax + 1] > (ubyte)(HTIRS2_I2CReply[HTIRS2_DC_SSTR1+iMax] / 2)))
00496   {
00497       dir++;
00498       dcSigSum += HTIRS2_I2CReply[HTIRS2_DC_SSTR1+iMax + 1];
00499   }
00500 
00501   // Make DC strength compatible with AC strength.
00502   // use: sqrt(dcSigSum*500)
00503   strength = sqrt(dcSigSum * 500);
00504 
00505   // Decide if using AC strength
00506   if (strength <= 200)
00507   {
00508     writeDebugStreamLine("switching to AC");
00509     // Use AC Dir
00510     dir = HTIRS2_I2CReply[HTIRS2_AC_DIR];
00511 
00512     // Sum the sensor elements to get strength
00513     if (dir > 0)
00514     {
00515       strength = HTIRS2_I2CReply[HTIRS2_AC_SSTR1] + HTIRS2_I2CReply[HTIRS2_AC_SSTR2] +
00516                  HTIRS2_I2CReply[HTIRS2_AC_SSTR3] + HTIRS2_I2CReply[HTIRS2_AC_SSTR4] +
00517                  HTIRS2_I2CReply[HTIRS2_AC_SSTR5];
00518     }
00519   }
00520   return true;
00521 }
00522 #endif // __HTSMUX_SUPPORT__
00523 
00524 #endif // __HTIRS2_H__
00525 
00526 /*
00527  * $Id: hitechnic-irseeker-v2.h 133 2013-03-10 15:15:38Z xander $
00528  */
00529 /* @} */
00530 /* @} */