00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __HTANG_H__
00013 #define __HTANG_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 #pragma systemFile
00038
00039 #ifndef __COMMON_H__
00040 #include "common.h"
00041 #endif
00042
00043 #define HTANG_I2C_ADDR 0x02
00044 #define HTANG_CMD_REG 0x41
00045 #define HTANG_OFFSET 0x42
00046
00047
00048 #define HTANG_ANG2 0x00
00049 #define HTANG_ANG1 0x01
00050 #define HTANG_ACC_ANG_B4 0x02
00051 #define HTANG_ACC_ANG_B3 0x03
00052 #define HTANG_ACC_ANG_B2 0x04
00053 #define HTANG_ACC_ANG_B1 0x05
00054 #define HTANG_RPM_H 0x06
00055 #define HTANG_RPM_L 0x07
00056
00057
00058 #define HTANG_CMD_MEASURE 0x00
00059 #define HTANG_CMD_RST_ANG 0x43
00060 #define HTANG_CMD_RST_ACC_ANG 0x52
00061
00062 int HTANGreadAngle(tSensors link);
00063 long HTANGreadAccumulatedAngle(tSensors link);
00064 int HTANGreadRPM(tSensors link);
00065 bool HTANGresetAngle(tSensors link);
00066 bool HTANGresetAccumulatedAngle(tSensors link);
00067 bool _HTANGsendCommand(tSensors link, byte command);
00068
00069 #ifdef __HTSMUX_SUPPORT__
00070 int HTANGreadAngle(tMUXSensor muxsensor);
00071 long HTANGreadAccumulatedAngle(tMUXSensor muxsensor);
00072 int HTANGreadRPM(tMUXSensor muxsensor);
00073
00074 tConfigParams HTANG_config = {HTSMUX_CHAN_I2C, 8, 0x02, 0x42};
00075 #endif // __HTSMUX_SUPPORT__
00076
00077 tByteArray HTANG_I2CRequest;
00078 tByteArray HTANG_I2CReply;
00079
00080
00081
00082
00083
00084
00085
00086 int HTANGreadAngle(tSensors link) {
00087 memset(HTANG_I2CRequest, 0, sizeof(tByteArray));
00088
00089 HTANG_I2CRequest[0] = 2;
00090 HTANG_I2CRequest[1] = HTANG_I2C_ADDR;
00091 HTANG_I2CRequest[2] = HTANG_OFFSET + HTANG_ANG2;
00092
00093 if (!writeI2C(link, HTANG_I2CRequest, 2))
00094 return -1;
00095
00096 if (!readI2C(link, HTANG_I2CReply, 2))
00097 return -1;
00098
00099 return HTANG_I2CReply[0] * 2 + HTANG_I2CReply[1];
00100 }
00101
00102
00103
00104
00105
00106
00107
00108 #ifdef __HTSMUX_SUPPORT__
00109 int HTANGreadAngle(tMUXSensor muxsensor) {
00110 memset(HTANG_I2CRequest, 0, sizeof(tByteArray));
00111
00112 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00113 HTSMUXconfigChannel(muxsensor, HTANG_config);
00114
00115 if (!HTSMUXreadPort(muxsensor, HTANG_I2CReply, 2, HTANG_ANG2)) {
00116 return -1;
00117 }
00118
00119 return HTANG_I2CReply[0] * 2 + HTANG_I2CReply[1];
00120 }
00121 #endif // __HTSMUX_SUPPORT__
00122
00123
00124
00125
00126
00127
00128
00129 long HTANGreadAccumulatedAngle(tSensors link) {
00130 memset(HTANG_I2CRequest, 0, sizeof(tByteArray));
00131
00132 HTANG_I2CRequest[0] = 2;
00133 HTANG_I2CRequest[1] = HTANG_I2C_ADDR;
00134 HTANG_I2CRequest[2] = HTANG_OFFSET + HTANG_ACC_ANG_B4;
00135
00136 if (!writeI2C(link, HTANG_I2CRequest, 4))
00137 return -1;
00138
00139 if (!readI2C(link, HTANG_I2CReply, 4))
00140 return -1;
00141
00142 return (HTANG_I2CReply[0] << 24) +
00143 (HTANG_I2CReply[1] << 16) +
00144 (HTANG_I2CReply[2] << 8) +
00145 HTANG_I2CReply[3];
00146 }
00147
00148
00149
00150
00151
00152
00153
00154 #ifdef __HTSMUX_SUPPORT__
00155 long HTANGreadAccumulatedAngle(tMUXSensor muxsensor) {
00156 memset(HTANG_I2CRequest, 0, sizeof(tByteArray));
00157
00158 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00159 HTSMUXconfigChannel(muxsensor, HTANG_config);
00160
00161 if (!HTSMUXreadPort(muxsensor, HTANG_I2CReply, 4, HTANG_ACC_ANG_B4)) {
00162 return -1;
00163 }
00164
00165 return (HTANG_I2CReply[0] << 24) +
00166 (HTANG_I2CReply[1] << 16) +
00167 (HTANG_I2CReply[2] << 8) +
00168 HTANG_I2CReply[3];
00169 }
00170 #endif // __HTSMUX_SUPPORT__
00171
00172
00173
00174
00175
00176
00177
00178 int HTANGreadRPM(tSensors link) {
00179 memset(HTANG_I2CRequest, 0, sizeof(tByteArray));
00180
00181 HTANG_I2CRequest[0] = 2;
00182 HTANG_I2CRequest[1] = HTANG_I2C_ADDR;
00183 HTANG_I2CRequest[2] = HTANG_OFFSET + HTANG_RPM_H;
00184
00185 if (!writeI2C(link, HTANG_I2CRequest, 2))
00186 return -1;
00187
00188 if (!readI2C(link, HTANG_I2CReply, 2))
00189 return -1;
00190
00191 return (HTANG_I2CReply[0] << 8) +
00192 HTANG_I2CReply[1];
00193 }
00194
00195
00196
00197
00198
00199
00200
00201 #ifdef __HTSMUX_SUPPORT__
00202 int HTANGreadRPM(tMUXSensor muxsensor) {
00203 memset(HTANG_I2CRequest, 0, sizeof(tByteArray));
00204
00205 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00206 HTSMUXconfigChannel(muxsensor, HTANG_config);
00207
00208 if (!HTSMUXreadPort(muxsensor, HTANG_I2CReply, 2, HTANG_RPM_H)) {
00209 return -1;
00210 }
00211
00212 return HTANG_I2CReply[0] * 2 + HTANG_I2CReply[1];
00213
00214 return (HTANG_I2CReply[0] << 8) +
00215 HTANG_I2CReply[1];
00216 }
00217 #endif // __HTSMUX_SUPPORT__
00218
00219
00220
00221
00222
00223
00224
00225
00226 bool HTANGresetAngle(tSensors link) {
00227 return _HTANGsendCommand(link, HTANG_CMD_RST_ANG);
00228 }
00229
00230
00231
00232
00233
00234
00235
00236 bool HTANGresetAccumulatedAngle(tSensors link) {
00237 return _HTANGsendCommand(link, HTANG_CMD_RST_ACC_ANG);
00238 }
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 bool _HTANGsendCommand(tSensors link, byte command) {
00250 memset(HTANG_I2CRequest, 0, sizeof(tByteArray));
00251
00252 HTANG_I2CRequest[0] = 3;
00253 HTANG_I2CRequest[1] = HTANG_I2C_ADDR;
00254 HTANG_I2CRequest[2] = HTANG_CMD_REG;
00255 HTANG_I2CRequest[3] = command;
00256
00257 return writeI2C(link, HTANG_I2CRequest, 0);
00258 }
00259
00260
00261 #endif // __HTANG_H__
00262
00263
00264
00265
00266
00267