00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __HTIRS2_H__
00013 #define __HTIRS2_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #pragma systemFile
00042
00043 #ifndef __COMMON_H__
00044 #include "common.h"
00045 #endif
00046
00047 #define HTIRS2_I2C_ADDR 0x10
00048 #define HTIRS2_DSP_MODE 0x41
00049 #define HTIRS2_OFFSET 0x42
00050 #define HTIRS2_DC_DIR 0x00
00051 #define HTIRS2_DC_SSTR1 0x01
00052 #define HTIRS2_DC_SSTR2 0x02
00053 #define HTIRS2_DC_SSTR3 0x03
00054 #define HTIRS2_DC_SSTR4 0x04
00055 #define HTIRS2_DC_SSTR5 0x05
00056 #define HTIRS2_DC_SAVG 0x06
00057 #define HTIRS2_AC_DIR 0x07
00058 #define HTIRS2_AC_SSTR1 0x08
00059 #define HTIRS2_AC_SSTR2 0x09
00060 #define HTIRS2_AC_SSTR3 0x0A
00061 #define HTIRS2_AC_SSTR4 0x0B
00062 #define HTIRS2_AC_SSTR5 0x0C
00063
00064
00065
00066 typedef enum {
00067 DSP_1200 = 0,
00068 DSP_600 = 1
00069 } tHTIRS2DSPMode;
00070
00071
00072 int HTIRS2readDCDir(tSensors link);
00073 bool HTIRS2readAllDCStrength(tSensors link, int &dcS1, int &dcS2, int &dcS3, int &dcS4, int &dcS5);
00074 int HTIRS2readDCAverage(tSensors link);
00075
00076 bool HTIRS2setDSPMode(tSensors link, tHTIRS2DSPMode mode);
00077 int HTIRS2readACDir(tSensors link);
00078 bool HTIRS2readAllACStrength(tSensors link, int &acS1, int &acS2, int &acS3, int &acS4, int &acS5);
00079
00080 #ifdef __HTSMUX_SUPPORT__
00081
00082 int HTIRS2readDCDir(tMUXSensor muxsensor);
00083 bool HTIRS2readAllDCStrength(tMUXSensor muxsensor, int &dcS1, int &dcS2, int &dcS3, int &dcS4, int &dcS5);
00084 int HTIRS2readDCAverage(tMUXSensor muxsensor);
00085
00086 int HTIRS2readACDir(tMUXSensor muxsensor);
00087 bool HTIRS2readAllACStrength(tMUXSensor muxsensor, int &acS1, int &acS2, int &acS3, int &acS4, int &acS5);
00088
00089 tConfigParams HTIRS2_config = {HTSMUX_CHAN_I2C, 13, 0x10, 0x42};
00090 #endif // __HTSMUX_SUPPORT__
00091
00092 tByteArray HTIRS2_I2CRequest;
00093 tByteArray HTIRS2_I2CReply;
00094
00095
00096
00097
00098
00099
00100
00101
00102 int HTIRS2readDCDir(tSensors link) {
00103 memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00104
00105 HTIRS2_I2CRequest[0] = 2;
00106 HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR;
00107 HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_DC_DIR;
00108
00109 if (!writeI2C(link, HTIRS2_I2CRequest, 1))
00110 return -1;
00111
00112 if (!readI2C(link, HTIRS2_I2CReply, 1))
00113 return -1;
00114
00115 return HTIRS2_I2CReply[0];
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 #ifdef __HTSMUX_SUPPORT__
00125 int HTIRS2readDCDir(tMUXSensor muxsensor) {
00126 memset(HTIRS2_I2CReply, 0, sizeof(tByteArray));
00127
00128 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00129 HTSMUXconfigChannel(muxsensor, HTIRS2_config);
00130
00131 if (!HTSMUXreadPort(muxsensor, HTIRS2_I2CReply, 1, HTIRS2_DC_DIR)) {
00132 return -1;
00133 }
00134
00135 return HTIRS2_I2CReply[0];
00136 }
00137 #endif // __HTSMUX_SUPPORT__
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 bool HTIRS2readAllDCStrength(tSensors link, int &dcS1, int &dcS2, int &dcS3, int &dcS4, int &dcS5) {
00151 memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00152
00153 HTIRS2_I2CRequest[0] = 2;
00154 HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR;
00155 HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_DC_SSTR1;
00156
00157 if (!writeI2C(link, HTIRS2_I2CRequest, 5))
00158 return false;
00159
00160 if (!readI2C(link, HTIRS2_I2CReply, 5))
00161 return false;
00162
00163 dcS1 = HTIRS2_I2CReply[0];
00164 dcS2 = HTIRS2_I2CReply[1];
00165 dcS3 = HTIRS2_I2CReply[2];
00166 dcS4 = HTIRS2_I2CReply[3];
00167 dcS5 = HTIRS2_I2CReply[4];
00168
00169 return true;
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 #ifdef __HTSMUX_SUPPORT__
00184 bool HTIRS2readAllDCStrength(tMUXSensor muxsensor, int &dcS1, int &dcS2, int &dcS3, int &dcS4, int &dcS5) {
00185 memset(HTIRS2_I2CReply, 0, sizeof(tByteArray));
00186
00187 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00188 HTSMUXconfigChannel(muxsensor, HTIRS2_config);
00189
00190 if (!HTSMUXreadPort(muxsensor, HTIRS2_I2CReply, 5, HTIRS2_DC_SSTR1)) {
00191 return false;
00192 }
00193
00194 dcS1 = HTIRS2_I2CReply[0];
00195 dcS2 = HTIRS2_I2CReply[1];
00196 dcS3 = HTIRS2_I2CReply[2];
00197 dcS4 = HTIRS2_I2CReply[3];
00198 dcS5 = HTIRS2_I2CReply[4];
00199
00200 return true;
00201 }
00202 #endif // __HTSMUX_SUPPORT__
00203
00204
00205
00206
00207
00208
00209
00210 int HTIRS2readDCAverage(tSensors link) {
00211 memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00212
00213 HTIRS2_I2CRequest[0] = 2;
00214 HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR;
00215 HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_DC_SAVG;
00216
00217 if (!writeI2C(link, HTIRS2_I2CRequest, 1))
00218 return -1;
00219
00220 if (!readI2C(link, HTIRS2_I2CReply, 1))
00221 return -1;
00222
00223 return HTIRS2_I2CReply[0];
00224 }
00225
00226
00227
00228
00229
00230
00231
00232 #ifdef __HTSMUX_SUPPORT__
00233 int HTIRS2readDCAverage(tMUXSensor muxsensor) {
00234 memset(HTIRS2_I2CReply, 0, sizeof(tByteArray));
00235
00236 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00237 HTSMUXconfigChannel(muxsensor, HTIRS2_config);
00238
00239 if (!HTSMUXreadPort(muxsensor, HTIRS2_I2CReply, 1, HTIRS2_DC_SAVG)) {
00240 return -1;
00241 }
00242
00243 return HTIRS2_I2CReply[0];
00244 }
00245 #endif // __HTSMUX_SUPPORT__
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 bool HTIRS2setDSPMode(tSensors link, tHTIRS2DSPMode mode) {
00261 memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00262
00263 HTIRS2_I2CRequest[0] = 3;
00264 HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR;
00265 HTIRS2_I2CRequest[2] = HTIRS2_DSP_MODE;
00266 HTIRS2_I2CRequest[3] = (ubyte)mode;
00267
00268 return writeI2C(link, HTIRS2_I2CRequest, 0);
00269 }
00270
00271
00272
00273
00274
00275
00276 int HTIRS2readACDir(tSensors link) {
00277 memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00278
00279 HTIRS2_I2CRequest[0] = 2;
00280 HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR;
00281 HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_AC_DIR;
00282
00283 if (!writeI2C(link, HTIRS2_I2CRequest, 1))
00284 return -1;
00285
00286 if (!readI2C(link, HTIRS2_I2CReply, 1))
00287 return -1;
00288
00289 return HTIRS2_I2CReply[0];
00290 }
00291
00292
00293
00294
00295
00296
00297
00298 #ifdef __HTSMUX_SUPPORT__
00299 int HTIRS2readACDir(tMUXSensor muxsensor) {
00300 memset(HTIRS2_I2CReply, 0, sizeof(tByteArray));
00301
00302 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00303 HTSMUXconfigChannel(muxsensor, HTIRS2_config);
00304
00305 if (!HTSMUXreadPort(muxsensor, HTIRS2_I2CReply, 1, HTIRS2_AC_DIR)) {
00306 return -1;
00307 }
00308
00309 return HTIRS2_I2CReply[0];
00310 }
00311 #endif // __HTSMUX_SUPPORT__
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 bool HTIRS2readAllACStrength(tSensors link, int &acS1, int &acS2, int &acS3, int &acS4, int &acS5) {
00325 memset(HTIRS2_I2CRequest, 0, sizeof(tByteArray));
00326
00327 HTIRS2_I2CRequest[0] = 2;
00328 HTIRS2_I2CRequest[1] = HTIRS2_I2C_ADDR;
00329 HTIRS2_I2CRequest[2] = HTIRS2_OFFSET + HTIRS2_AC_SSTR1;
00330
00331 if (!writeI2C(link, HTIRS2_I2CRequest, 5))
00332 return false;
00333
00334 if (!readI2C(link, HTIRS2_I2CReply, 5))
00335 return false;
00336
00337 acS1 = HTIRS2_I2CReply[0];
00338 acS2 = HTIRS2_I2CReply[1];
00339 acS3 = HTIRS2_I2CReply[2];
00340 acS4 = HTIRS2_I2CReply[3];
00341 acS5 = HTIRS2_I2CReply[4];
00342
00343 return true;
00344 }
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 #ifdef __HTSMUX_SUPPORT__
00358 bool HTIRS2readAllACStrength(tMUXSensor muxsensor, int &acS1, int &acS2, int &acS3, int &acS4, int &acS5) {
00359 memset(HTIRS2_I2CReply, 0, sizeof(tByteArray));
00360
00361 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00362 HTSMUXconfigChannel(muxsensor, HTIRS2_config);
00363
00364 if (!HTSMUXreadPort(muxsensor, HTIRS2_I2CReply, 5, HTIRS2_AC_SSTR1)) {
00365 return false;
00366 }
00367
00368 acS1 = HTIRS2_I2CReply[0];
00369 acS2 = HTIRS2_I2CReply[1];
00370 acS3 = HTIRS2_I2CReply[2];
00371 acS4 = HTIRS2_I2CReply[3];
00372 acS5 = HTIRS2_I2CReply[4];
00373
00374 return true;
00375 }
00376 #endif // __HTSMUX_SUPPORT__
00377
00378 #endif // __HTIRS2_H__
00379
00380
00381
00382
00383
00384