|
@@ -1,21 +1,21 @@
|
|
-#include "JY901.h"
|
|
|
|
|
|
+#include "imuData.h"
|
|
#include "string.h"
|
|
#include "string.h"
|
|
|
|
|
|
-CJY901 ::CJY901 ()
|
|
|
|
|
|
+ImuDataClass ::ImuDataClass ()
|
|
{
|
|
{
|
|
ucDevAddr =0x50;
|
|
ucDevAddr =0x50;
|
|
}
|
|
}
|
|
-void CJY901::StartIIC()
|
|
|
|
|
|
+void ImuDataClass::StartIIC()
|
|
{
|
|
{
|
|
ucDevAddr = 0x50;
|
|
ucDevAddr = 0x50;
|
|
Wire.begin();
|
|
Wire.begin();
|
|
}
|
|
}
|
|
-void CJY901::StartIIC(unsigned char ucAddr)
|
|
|
|
|
|
+void ImuDataClass::StartIIC(unsigned char ucAddr)
|
|
{
|
|
{
|
|
ucDevAddr = ucAddr;
|
|
ucDevAddr = ucAddr;
|
|
Wire.begin();
|
|
Wire.begin();
|
|
}
|
|
}
|
|
-void CJY901 ::CopeSerialData(unsigned char ucData)
|
|
|
|
|
|
+void ImuDataClass ::CopeSerialData(unsigned char ucData)
|
|
{
|
|
{
|
|
static unsigned char ucRxBuffer[250];
|
|
static unsigned char ucRxBuffer[250];
|
|
static unsigned char ucRxCnt = 0;
|
|
static unsigned char ucRxCnt = 0;
|
|
@@ -40,12 +40,11 @@ void CJY901 ::CopeSerialData(unsigned char ucData)
|
|
case 0x56: memcpy(&stcPress,&ucRxBuffer[2],8);break;
|
|
case 0x56: memcpy(&stcPress,&ucRxBuffer[2],8);break;
|
|
case 0x57: memcpy(&stcLonLat,&ucRxBuffer[2],8);break;
|
|
case 0x57: memcpy(&stcLonLat,&ucRxBuffer[2],8);break;
|
|
case 0x58: memcpy(&stcGPSV,&ucRxBuffer[2],8);break;
|
|
case 0x58: memcpy(&stcGPSV,&ucRxBuffer[2],8);break;
|
|
- case 0x59: memcpy(&stcQuater,&ucRxBuffer[2],8);break;
|
|
|
|
}
|
|
}
|
|
ucRxCnt=0;
|
|
ucRxCnt=0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-void CJY901::readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest)
|
|
|
|
|
|
+void ImuDataClass::readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest)
|
|
{
|
|
{
|
|
Wire.beginTransmission(deviceAddr);
|
|
Wire.beginTransmission(deviceAddr);
|
|
Wire.write(addressToRead);
|
|
Wire.write(addressToRead);
|
|
@@ -58,7 +57,7 @@ void CJY901::readRegisters(unsigned char deviceAddr,unsigned char addressToRead,
|
|
for(int x = 0 ; x < bytesToRead ; x++)
|
|
for(int x = 0 ; x < bytesToRead ; x++)
|
|
dest[x] = Wire.read();
|
|
dest[x] = Wire.read();
|
|
}
|
|
}
|
|
-void CJY901::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite)
|
|
|
|
|
|
+void ImuDataClass::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite)
|
|
{
|
|
{
|
|
Wire.beginTransmission(deviceAddr);
|
|
Wire.beginTransmission(deviceAddr);
|
|
Wire.write(addressToWrite);
|
|
Wire.write(addressToWrite);
|
|
@@ -67,56 +66,60 @@ void CJY901::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite
|
|
Wire.endTransmission(); //Stop transmitting
|
|
Wire.endTransmission(); //Stop transmitting
|
|
}
|
|
}
|
|
|
|
|
|
-short CJY901::ReadWord(unsigned char ucAddr)
|
|
|
|
|
|
+short ImuDataClass::ReadWord(unsigned char ucAddr)
|
|
{
|
|
{
|
|
short sResult;
|
|
short sResult;
|
|
readRegisters(ucDevAddr, ucAddr, 2, (char *)&sResult);
|
|
readRegisters(ucDevAddr, ucAddr, 2, (char *)&sResult);
|
|
return sResult;
|
|
return sResult;
|
|
}
|
|
}
|
|
-void CJY901::WriteWord(unsigned char ucAddr,short sData)
|
|
|
|
|
|
+void ImuDataClass::WriteWord(unsigned char ucAddr,short sData)
|
|
{
|
|
{
|
|
writeRegister(ucDevAddr, ucAddr, 2, (char *)&sData);
|
|
writeRegister(ucDevAddr, ucAddr, 2, (char *)&sData);
|
|
}
|
|
}
|
|
-void CJY901::ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[])
|
|
|
|
|
|
+void ImuDataClass::ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[])
|
|
{
|
|
{
|
|
readRegisters(ucDevAddr, ucAddr, ucLength, chrData);
|
|
readRegisters(ucDevAddr, ucAddr, ucLength, chrData);
|
|
}
|
|
}
|
|
|
|
|
|
-void CJY901::GetTime()
|
|
|
|
|
|
+void ImuDataClass::GetTime()
|
|
{
|
|
{
|
|
readRegisters(ucDevAddr, 0x30, 8, (char*)&stcTime);
|
|
readRegisters(ucDevAddr, 0x30, 8, (char*)&stcTime);
|
|
}
|
|
}
|
|
-void CJY901::GetAcc()
|
|
|
|
|
|
+void ImuDataClass::GetAcc()
|
|
{
|
|
{
|
|
readRegisters(ucDevAddr, AX, 6, (char *)&stcAcc);
|
|
readRegisters(ucDevAddr, AX, 6, (char *)&stcAcc);
|
|
}
|
|
}
|
|
-void CJY901::GetGyro()
|
|
|
|
|
|
+void ImuDataClass::GetGyro()
|
|
{
|
|
{
|
|
readRegisters(ucDevAddr, GX, 6, (char *)&stcGyro);
|
|
readRegisters(ucDevAddr, GX, 6, (char *)&stcGyro);
|
|
}
|
|
}
|
|
|
|
|
|
-void CJY901::GetAngle()
|
|
|
|
|
|
+void ImuDataClass::GetAngle()
|
|
{
|
|
{
|
|
readRegisters(ucDevAddr, Roll, 6, (char *)&stcAngle);
|
|
readRegisters(ucDevAddr, Roll, 6, (char *)&stcAngle);
|
|
}
|
|
}
|
|
-void CJY901::GetMag()
|
|
|
|
|
|
+void ImuDataClass::GetMag()
|
|
{
|
|
{
|
|
readRegisters(ucDevAddr, HX, 6, (char *)&stcMag);
|
|
readRegisters(ucDevAddr, HX, 6, (char *)&stcMag);
|
|
}
|
|
}
|
|
-void CJY901::GetPress()
|
|
|
|
|
|
+void ImuDataClass::GetPress()
|
|
{
|
|
{
|
|
readRegisters(ucDevAddr, PressureL, 8, (char *)&stcPress);
|
|
readRegisters(ucDevAddr, PressureL, 8, (char *)&stcPress);
|
|
}
|
|
}
|
|
-void CJY901::GetDStatus()
|
|
|
|
|
|
+void ImuDataClass::GetDStatus()
|
|
{
|
|
{
|
|
readRegisters(ucDevAddr, D0Status, 8, (char *)&stcDStatus);
|
|
readRegisters(ucDevAddr, D0Status, 8, (char *)&stcDStatus);
|
|
}
|
|
}
|
|
-void CJY901::GetLonLat()
|
|
|
|
|
|
+void ImuDataClass::GetLonLat()
|
|
{
|
|
{
|
|
readRegisters(ucDevAddr, LonL, 8, (char *)&stcLonLat);
|
|
readRegisters(ucDevAddr, LonL, 8, (char *)&stcLonLat);
|
|
}
|
|
}
|
|
-void CJY901::GetGPSV()
|
|
|
|
|
|
+void ImuDataClass::GetGPSV()
|
|
{
|
|
{
|
|
readRegisters(ucDevAddr, GPSHeight, 8, (char *)&stcGPSV);
|
|
readRegisters(ucDevAddr, GPSHeight, 8, (char *)&stcGPSV);
|
|
}
|
|
}
|
|
-CJY901 JY901 = CJY901();
|
|
|
|
|
|
+void ImuDataClass::GetQuater()
|
|
|
|
+{
|
|
|
|
+ readRegisters(ucDevAddr, QUATER, 8, (char *)&stcQuater);
|
|
|
|
+}
|
|
|
|
+ImuDataClass imuData = ImuDataClass();
|