Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __HTAC_H__
00013 #define __HTAC_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
00042
00043
00044
00045
00046 #pragma systemFile
00047
00048 #ifndef __COMMON_H__
00049 #include "common.h"
00050 #endif
00051
00052 #define HTAC_I2C_ADDR 0x02
00053 #define HTAC_OFFSET 0x42
00054 #define HTAC_X_UP 0x00
00055 #define HTAC_Y_UP 0x01
00056 #define HTAC_Z_UP 0x02
00057 #define HTAC_X_LOW 0x03
00058 #define HTAC_Y_LOW 0x04
00059 #define HTAC_Z_LOW 0x05
00060
00061 bool HTACreadAllAxes(tSensors link, int &x, int &y, int &z);
00062
00063 #ifdef __HTSMUX_SUPPORT__
00064 bool HTACreadAllAxes(tMUXSensor muxsensor, int &x, int &y, int &z);
00065
00066 tConfigParams HTAC_config = {HTSMUX_CHAN_I2C, 6, 0x02, 0x42};
00067 #endif
00068
00069 tByteArray HTAC_I2CRequest;
00070 tByteArray HTAC_I2CReply;
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 bool HTACreadAllAxes(tSensors link, int &x, int &y, int &z) {
00081 memset(HTAC_I2CRequest, 0, sizeof(tByteArray));
00082
00083 HTAC_I2CRequest[0] = 2;
00084 HTAC_I2CRequest[1] = HTAC_I2C_ADDR;
00085 HTAC_I2CRequest[2] = HTAC_OFFSET + HTAC_X_UP;
00086
00087 if (!writeI2C(link, HTAC_I2CRequest, HTAC_I2CReply, 6))
00088 return false;
00089
00090
00091
00092
00093 x = (HTAC_I2CReply[0] > 127) ? (HTAC_I2CReply[0] - 256) * 4 + HTAC_I2CReply[3]
00094 : HTAC_I2CReply[0] * 4 + HTAC_I2CReply[3];
00095
00096 y = (HTAC_I2CReply[1] > 127) ? (HTAC_I2CReply[1] - 256) * 4 + HTAC_I2CReply[4]
00097 : HTAC_I2CReply[1] * 4 + HTAC_I2CReply[4];
00098
00099 z = (HTAC_I2CReply[2] > 127) ? (HTAC_I2CReply[2] - 256) * 4 + HTAC_I2CReply[5]
00100 : HTAC_I2CReply[2] * 4 + HTAC_I2CReply[5];
00101
00102 return true;
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 #ifdef __HTSMUX_SUPPORT__
00115 bool HTACreadAllAxes(tMUXSensor muxsensor, int &x, int &y, int &z) {
00116 memset(HTAC_I2CReply, 0, sizeof(tByteArray));
00117
00118 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00119 HTSMUXconfigChannel(muxsensor, HTAC_config);
00120
00121 if (!HTSMUXreadPort(muxsensor, HTAC_I2CReply, 6, HTAC_X_UP)) {
00122 return false;
00123 }
00124
00125
00126
00127
00128 x = (HTAC_I2CReply[0] > 127) ? (HTAC_I2CReply[0] - 256) * 4 + HTAC_I2CReply[3]
00129 : HTAC_I2CReply[0] * 4 + HTAC_I2CReply[3];
00130
00131 y = (HTAC_I2CReply[1] > 127) ? (HTAC_I2CReply[1] - 256) * 4 + HTAC_I2CReply[4]
00132 : HTAC_I2CReply[1] * 4 + HTAC_I2CReply[4];
00133
00134 z = (HTAC_I2CReply[2] > 127) ? (HTAC_I2CReply[2] - 256) * 4 + HTAC_I2CReply[5]
00135 : HTAC_I2CReply[2] * 4 + HTAC_I2CReply[5];
00136
00137 return true;
00138 }
00139 #endif // __HTSMUX_SUPPORT__
00140
00141 #endif // __HTAC_H__
00142
00143
00144
00145
00146
00147