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