00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __HTPB_H__
00012 #define __HTPB_H__
00013
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
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #pragma systemFile
00060
00061 #ifndef __COMMON_H__
00062 #include "common.h"
00063 #endif
00064
00065 #define HTPB_I2C_ADDR 0x02
00066 #define HTPB_OFFSET 0x42
00067 #define HTPB_A0_U 0x00
00068 #define HTPB_A0_L 0x01
00069 #define HTPB_DIGIN 0x0A
00070 #define HTPB_DIGOUT 0x0B
00071 #define HTPB_DIGCTRL 0x0C
00072 #define HTPB_SRATE 0x0D
00073
00074 tByteArray HTPB_I2CRequest;
00075 tByteArray HTPB_I2CReply;
00076
00077 ubyte HTPBreadIO(tSensors link, ubyte mask);
00078 bool HTPBwriteIO(tSensors link, ubyte mask);
00079 bool HTPBsetupIO(tSensors link, ubyte mask);
00080 int HTPBreadADC(tSensors link, byte channel, byte width);
00081 bool HTPBreadAllADC(tSensors link, int &adch0, int &adch1, int &adch2, int &adch3, int &adch4, byte width);
00082 bool HTPBsetSamplingTime(tSensors link, byte interval);
00083
00084 #ifdef __HTSMUX_SUPPORT__
00085 ubyte HTPBreadIO(tMUXSensor muxsensor, ubyte mask);
00086 int HTPBreadADC(tMUXSensor muxsensor, byte channel, byte width);
00087 bool HTPBreadAllADC(tMUXSensor muxsensor, int &adch0, int &adch1, int &adch2, int &adch3, int &adch4, byte width);
00088
00089 tConfigParams HTPB_config = {HTSMUX_CHAN_I2C + HTSMUX_CHAN_9V, 14, 0x02, 0x42};
00090 #endif // __HTSMUX_SUPPORT__
00091
00092
00093
00094
00095
00096
00097 ubyte HTPBreadIO(tSensors link, ubyte mask) {
00098 memset(HTPB_I2CRequest, 0, sizeof(tByteArray));
00099
00100 HTPB_I2CRequest[0] = 2;
00101 HTPB_I2CRequest[1] = HTPB_I2C_ADDR;
00102 HTPB_I2CRequest[2] = HTPB_OFFSET + HTPB_DIGIN;
00103
00104 writeI2C(link, HTPB_I2CRequest, HTPB_I2CReply, 1);
00105
00106 return HTPB_I2CReply[0] & mask;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115 #ifdef __HTSMUX_SUPPORT__
00116 ubyte HTPBreadIO(tMUXSensor muxsensor, ubyte mask) {
00117 memset(HTPB_I2CReply, 0, sizeof(tByteArray));
00118
00119 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00120 HTSMUXconfigChannel(muxsensor, HTPB_config);
00121
00122 if (!HTSMUXreadPort(muxsensor, HTPB_I2CReply, 1, HTPB_DIGIN))
00123 return 0;
00124
00125 return HTPB_I2CReply[0] & mask;
00126 }
00127 #endif // __HTSMUX_SUPPORT__
00128
00129
00130
00131
00132
00133
00134
00135
00136 bool HTPBwriteIO(tSensors link, ubyte mask) {
00137 memset(HTPB_I2CRequest, 0, sizeof(tByteArray));
00138
00139 HTPB_I2CRequest[0] = 3;
00140 HTPB_I2CRequest[1] = HTPB_I2C_ADDR;
00141 HTPB_I2CRequest[2] = HTPB_OFFSET + HTPB_DIGOUT;
00142 HTPB_I2CRequest[3] = mask;
00143
00144
00145 return writeI2C(link, HTPB_I2CRequest);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155 bool HTPBsetupIO(tSensors link, ubyte mask) {
00156 memset(HTPB_I2CRequest, 0, sizeof(tByteArray));
00157
00158 HTPB_I2CRequest[0] = 3;
00159 HTPB_I2CRequest[1] = HTPB_I2C_ADDR;
00160 HTPB_I2CRequest[2] = HTPB_OFFSET + HTPB_DIGCTRL;
00161 HTPB_I2CRequest[3] = mask;
00162
00163 return writeI2C(link, HTPB_I2CRequest);
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 int HTPBreadADC(tSensors link, byte channel, byte width) {
00175 memset(HTPB_I2CRequest, 0, sizeof(tByteArray));
00176
00177 int _adcVal = 0;
00178 HTPB_I2CRequest[0] = 2;
00179 HTPB_I2CRequest[1] = HTPB_I2C_ADDR;
00180 HTPB_I2CRequest[2] = HTPB_OFFSET + HTPB_A0_U + (channel * 2);
00181
00182 if (!writeI2C(link, HTPB_I2CRequest, HTPB_I2CReply, 2))
00183 return -1;
00184
00185
00186
00187
00188
00189
00190 if (width == 8)
00191 _adcVal = HTPB_I2CReply[0];
00192 else
00193 _adcVal = (HTPB_I2CReply[0] * 4) + HTPB_I2CReply[1];
00194
00195 return _adcVal;
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 #ifdef __HTSMUX_SUPPORT__
00207 int HTPBreadADC(tMUXSensor muxsensor, byte channel, byte width) {
00208 int _adcVal = 0;
00209 memset(HTPB_I2CReply, 0, sizeof(tByteArray));
00210
00211 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00212 HTSMUXconfigChannel(muxsensor, HTPB_config);
00213
00214 if (!HTSMUXreadPort(muxsensor, HTPB_I2CReply, 2, HTPB_A0_U + (channel * 2)))
00215 return -1;
00216
00217
00218
00219
00220
00221
00222 if (width == 8)
00223 _adcVal = HTPB_I2CReply[0];
00224 else
00225 _adcVal = (HTPB_I2CReply[0] * 4) + HTPB_I2CReply[1];
00226
00227 return _adcVal;
00228 }
00229 #endif // __HTSMUX_SUPPORT__
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 bool HTPBreadAllADC(tSensors link, int &adch0, int &adch1, int &adch2, int &adch3, int &adch4, byte width) {
00244 memset(HTPB_I2CRequest, 0, sizeof(tByteArray));
00245
00246 HTPB_I2CRequest[0] = 2;
00247 HTPB_I2CRequest[1] = HTPB_I2C_ADDR;
00248 HTPB_I2CRequest[2] = HTPB_OFFSET + HTPB_A0_U;
00249
00250 if (!writeI2C(link, HTPB_I2CRequest, HTPB_I2CReply, 10))
00251 return false;
00252
00253
00254
00255
00256
00257
00258 if (width == 8) {
00259 adch0 = (int)HTPB_I2CReply[0];
00260 adch1 = (int)HTPB_I2CReply[2];
00261 adch2 = (int)HTPB_I2CReply[4];
00262 adch3 = (int)HTPB_I2CReply[6];
00263 adch4 = (int)HTPB_I2CReply[8];
00264 } else {
00265 adch0 = ((int)HTPB_I2CReply[0] << 2) + (int)HTPB_I2CReply[1];
00266 adch1 = ((int)HTPB_I2CReply[2] << 2) + (int)HTPB_I2CReply[3];
00267 adch2 = ((int)HTPB_I2CReply[4] << 2) + (int)HTPB_I2CReply[5];
00268 adch3 = ((int)HTPB_I2CReply[6] << 2) + (int)HTPB_I2CReply[7];
00269 adch4 = ((int)HTPB_I2CReply[8] << 2) + (int)HTPB_I2CReply[9];
00270 }
00271 return true;
00272 }
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 #ifdef __HTSMUX_SUPPORT__
00287 bool HTPBreadAllADC(tMUXSensor muxsensor, int &adch0, int &adch1, int &adch2, int &adch3, int &adch4, byte width) {
00288 memset(HTPB_I2CReply, 0, sizeof(tByteArray));
00289
00290 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00291 HTSMUXconfigChannel(muxsensor, HTPB_config);
00292
00293 if (!HTSMUXreadPort(muxsensor, HTPB_I2CReply, 10, HTPB_A0_U))
00294 return false;
00295
00296
00297
00298
00299
00300
00301 if (width == 8) {
00302 adch0 = (int)HTPB_I2CReply[0];
00303 adch1 = (int)HTPB_I2CReply[2];
00304 adch2 = (int)HTPB_I2CReply[4];
00305 adch3 = (int)HTPB_I2CReply[6];
00306 adch4 = (int)HTPB_I2CReply[8];
00307 } else {
00308 adch0 = ((int)HTPB_I2CReply[0] << 2) + (int)HTPB_I2CReply[1];
00309 adch1 = ((int)HTPB_I2CReply[2] << 2) + (int)HTPB_I2CReply[3];
00310 adch2 = ((int)HTPB_I2CReply[4] << 2) + (int)HTPB_I2CReply[5];
00311 adch3 = ((int)HTPB_I2CReply[6] << 2) + (int)HTPB_I2CReply[7];
00312 adch4 = ((int)HTPB_I2CReply[8] << 2) + (int)HTPB_I2CReply[9];
00313 }
00314 return true;
00315 }
00316 #endif // __HTSMUX_SUPPORT__
00317
00318
00319
00320
00321
00322
00323
00324
00325 bool HTPBsetSamplingTime(tSensors link, byte interval) {
00326 memset(HTPB_I2CRequest, 0, sizeof(tByteArray));
00327
00328
00329 if (interval < 4) interval = 4;
00330 if (interval > 100) interval = 100;
00331
00332 HTPB_I2CRequest[0] = 3;
00333 HTPB_I2CRequest[1] = HTPB_I2C_ADDR;
00334 HTPB_I2CRequest[2] = HTPB_OFFSET + HTPB_A0_U;
00335 HTPB_I2CRequest[3] = interval;
00336
00337
00338 if (interval < 4) HTPB_I2CRequest[3] = 4;
00339 if (interval > 100) HTPB_I2CRequest[3] = 100;
00340
00341 if (!writeI2C(link, HTPB_I2CRequest))
00342 return false;
00343
00344 return true;
00345 }
00346
00347 #endif // __HTPB_H__
00348
00349
00350
00351
00352
00353