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