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