Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __MSANG_H__
00013 #define __MSANG_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #pragma systemFile
00036
00037 #ifndef __COMMON_H__
00038 #include "common.h"
00039 #endif
00040
00041 #define MSANG_I2C_ADDR 0x30
00042 #define MSANG_CMD_REG 0x41
00043 #define MSANG_OFFSET 0x42
00044
00045
00046 #define MSANG_ANG 0x00
00047 #define MSANG_RAW 0x04
00048 #define MSANG_RPM 0x08
00049
00050
00051 #define MSANG_CMD_RST_ANG 0x72
00052
00053 int MSANGreadAngle(tSensors link);
00054 int MSANGreadRPM(tSensors link);
00055 int MSANGreadRaw(tSensors link);
00056 bool MSANGresetAngle(tSensors link);
00057
00058 tByteArray MSANG_I2CRequest;
00059 tByteArray MSANG_I2CReply;
00060
00061
00062
00063
00064
00065
00066
00067 int MSANGreadAngle(tSensors link) {
00068 memset(MSANG_I2CRequest, 0, sizeof(tByteArray));
00069
00070 MSANG_I2CRequest[0] = 2;
00071 MSANG_I2CRequest[1] = MSANG_I2C_ADDR;
00072 MSANG_I2CRequest[2] = MSANG_OFFSET + MSANG_ANG;
00073
00074 if (!writeI2C(link, MSANG_I2CRequest, MSANG_I2CReply, 4))
00075 return -1;
00076
00077 return MSANG_I2CReply[0] + (MSANG_I2CReply[1] << 8) + (MSANG_I2CReply[2] << 16) + (MSANG_I2CReply[3] << 24);
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 int MSANGreadRaw(tSensors link) {
00087 memset(MSANG_I2CRequest, 0, sizeof(tByteArray));
00088
00089 MSANG_I2CRequest[0] = 2;
00090 MSANG_I2CRequest[1] = MSANG_I2C_ADDR;
00091 MSANG_I2CRequest[2] = MSANG_OFFSET + MSANG_RAW;
00092
00093 if (!writeI2C(link, MSANG_I2CRequest, MSANG_I2CReply, 4))
00094 return -1;
00095
00096 return MSANG_I2CReply[0] + (MSANG_I2CReply[1] << 8) + (MSANG_I2CReply[2] << 16) + (MSANG_I2CReply[3] << 24);
00097 }
00098
00099
00100
00101
00102
00103
00104
00105 int MSANGreadRPM(tSensors link) {
00106 memset(MSANG_I2CRequest, 0, sizeof(tByteArray));
00107
00108 MSANG_I2CRequest[0] = 2;
00109 MSANG_I2CRequest[1] = MSANG_I2C_ADDR;
00110 MSANG_I2CRequest[2] = MSANG_OFFSET + MSANG_RPM;
00111
00112 if (!writeI2C(link, MSANG_I2CRequest, MSANG_I2CReply, 2))
00113 return -1;
00114
00115 return (MSANG_I2CReply[1] << 8) + MSANG_I2CReply[0];
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 bool MSANGresetAngle(tSensors link) {
00125 memset(MSANG_I2CRequest, 0, sizeof(tByteArray));
00126
00127 MSANG_I2CRequest[0] = 3;
00128 MSANG_I2CRequest[1] = MSANG_I2C_ADDR;
00129 MSANG_I2CRequest[2] = MSANG_CMD_REG;
00130 MSANG_I2CRequest[3] = MSANG_CMD_RST_ANG;
00131
00132 return writeI2C(link, MSANG_I2CRequest);
00133 }
00134
00135
00136 #endif // __MSANG_H__
00137
00138
00139
00140
00141
00142