Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __MSAC_H__
00013 #define __MSAC_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 #pragma systemFile
00039
00040 #ifndef __COMMON_H__
00041 #include "common.h"
00042 #endif
00043
00044 #define MSAC_I2C_ADDR 0x02
00045
00046 #define MSAC_CMD 0x41
00047
00048 #define MSAC_X_TILT 0x42
00049 #define MSAC_Y_TILT 0x43
00050 #define MSAC_Z_TILT 0x44
00051
00052 #define MSAC_X_ACCEL 0x45
00053 #define MSAC_Y_ACCEL 0x47
00054 #define MSAC_Z_ACCEL 0x49
00055
00056 #define MSAC_RANGE_2_5 1
00057 #define MSAC_RANGE_3_3 2
00058 #define MSAC_RANGE_6_7 3
00059 #define MSAC_RANGE_10 4
00060
00061 bool MSACreadTilt(tSensors link, int &x_tilt, int &y_tilt, int &z_tilt);
00062 bool MSACreadAccel(tSensors link, int &x_accel, int &y_accel, int &z_accel);
00063 bool MSACsendCmd(tSensors link, byte command);
00064 bool MSACsetRange(tSensors link, int range);
00065
00066 tByteArray MSAC_I2CRequest;
00067 tByteArray MSAC_I2CReply;
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 bool MSACreadTilt(tSensors link, int &x_tilt, int &y_tilt, int &z_tilt) {
00079 memset(MSAC_I2CRequest, 0, sizeof(tByteArray));
00080
00081 MSAC_I2CRequest[0] = 2;
00082 MSAC_I2CRequest[1] = MSAC_I2C_ADDR;
00083 MSAC_I2CRequest[2] = MSAC_X_TILT;
00084
00085 if (!writeI2C(link, MSAC_I2CRequest, MSAC_I2CReply, 3))
00086 return false;
00087
00088 x_tilt = MSAC_I2CReply[0] - 128;
00089 y_tilt = MSAC_I2CReply[1] - 128;
00090 z_tilt = MSAC_I2CReply[2] - 128;
00091
00092 return true;
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 bool MSACreadAccel(tSensors link, int &x_accel, int &y_accel, int &z_accel) {
00105 memset(MSAC_I2CRequest, 0, sizeof(tByteArray));
00106
00107 MSAC_I2CRequest[0] = 2;
00108 MSAC_I2CRequest[1] = MSAC_I2C_ADDR;
00109 MSAC_I2CRequest[2] = MSAC_X_ACCEL;
00110
00111 if (!writeI2C(link, MSAC_I2CRequest, MSAC_I2CReply, 6))
00112 return false;
00113
00114
00115 x_accel = MSAC_I2CReply[0] + (MSAC_I2CReply[1] << 8);
00116 y_accel = MSAC_I2CReply[2] + (MSAC_I2CReply[3] << 8);
00117 z_accel = MSAC_I2CReply[4] + (MSAC_I2CReply[5] << 8);
00118 return true;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128 bool MSACsendCmd(tSensors link, byte command) {
00129 memset(MSAC_I2CRequest, 0, sizeof(tByteArray));
00130
00131 MSAC_I2CRequest[0] = 3;
00132 MSAC_I2CRequest[1] = MSAC_I2C_ADDR;
00133 MSAC_I2CRequest[2] = MSAC_CMD;
00134 MSAC_I2CRequest[3] = command;
00135
00136 return writeI2C(link, MSAC_I2CRequest);
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146 bool MSACsetRange(tSensors link, int range) {
00147 byte command = 0;
00148
00149 switch (range) {
00150 case 1: command = '1'; break;
00151 case 2: command = '2'; break;
00152 case 3: command = '3'; break;
00153 case 4: command = '4'; break;
00154 default: return false; break;
00155 }
00156 return MSACsendCmd(link, command);
00157 }
00158
00159 #endif //__MSAC_H__
00160
00161
00162
00163
00164
00165