JY901.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #ifndef JY901_h
  2. #define JY901_h
  3. #define SAVE 0x00
  4. #define CALSW 0x01
  5. #define RSW 0x02
  6. #define RRATE 0x03
  7. #define BAUD 0x04
  8. #define AXOFFSET 0x05
  9. #define AYOFFSET 0x06
  10. #define AZOFFSET 0x07
  11. #define GXOFFSET 0x08
  12. #define GYOFFSET 0x09
  13. #define GZOFFSET 0x0a
  14. #define HXOFFSET 0x0b
  15. #define HYOFFSET 0x0c
  16. #define HZOFFSET 0x0d
  17. #define D0MODE 0x0e
  18. #define D1MODE 0x0f
  19. #define D2MODE 0x10
  20. #define D3MODE 0x11
  21. #define D0PWMH 0x12
  22. #define D1PWMH 0x13
  23. #define D2PWMH 0x14
  24. #define D3PWMH 0x15
  25. #define D0PWMT 0x16
  26. #define D1PWMT 0x17
  27. #define D2PWMT 0x18
  28. #define D3PWMT 0x19
  29. #define IICADDR 0x1a
  30. #define LEDOFF 0x1b
  31. #define GPSBAUD 0x1c
  32. #define YYMM 0x30
  33. #define DDHH 0x31
  34. #define MMSS 0x32
  35. #define MS 0x33
  36. #define AX 0x34
  37. #define AY 0x35
  38. #define AZ 0x36
  39. #define GX 0x37
  40. #define GY 0x38
  41. #define GZ 0x39
  42. #define HX 0x3a
  43. #define HY 0x3b
  44. #define HZ 0x3c
  45. #define Roll 0x3d
  46. #define Pitch 0x3e
  47. #define Yaw 0x3f
  48. #define TEMP 0x40
  49. #define D0Status 0x41
  50. #define D1Status 0x42
  51. #define D2Status 0x43
  52. #define D3Status 0x44
  53. #define PressureL 0x45
  54. #define PressureH 0x46
  55. #define HeightL 0x47
  56. #define HeightH 0x48
  57. #define LonL 0x49
  58. #define LonH 0x4a
  59. #define LatL 0x4b
  60. #define LatH 0x4c
  61. #define GPSHeight 0x4d
  62. #define GPSYAW 0x4e
  63. #define GPSVL 0x4f
  64. #define GPSVH 0x50
  65. #define DIO_MODE_AIN 0
  66. #define DIO_MODE_DIN 1
  67. #define DIO_MODE_DOH 2
  68. #define DIO_MODE_DOL 3
  69. #define DIO_MODE_DOPWM 4
  70. #define DIO_MODE_GPS 5
  71. struct STime
  72. {
  73. unsigned char ucYear;
  74. unsigned char ucMonth;
  75. unsigned char ucDay;
  76. unsigned char ucHour;
  77. unsigned char ucMinute;
  78. unsigned char ucSecond;
  79. unsigned short usMiliSecond;
  80. };
  81. struct SAcc
  82. {
  83. short a[3];
  84. short T;
  85. };
  86. struct SGyro
  87. {
  88. short w[3];
  89. short T;
  90. };
  91. struct SAngle
  92. {
  93. short Angle[3];
  94. short T;
  95. };
  96. struct SMag
  97. {
  98. short h[3];
  99. short T;
  100. };
  101. struct SDStatus
  102. {
  103. short sDStatus[4];
  104. };
  105. struct SPress
  106. {
  107. long lPressure;
  108. long lAltitude;
  109. };
  110. struct SLonLat
  111. {
  112. long lLon;
  113. long lLat;
  114. };
  115. struct SGPSV
  116. {
  117. short sGPSHeight;
  118. short sGPSYaw;
  119. long lGPSVelocity;
  120. };
  121. struct SQuater
  122. {
  123. short q0;
  124. short q1;
  125. short q2;
  126. short q3;
  127. };
  128. struct SSN
  129. {
  130. short sSVNum;
  131. short sPDOP;
  132. short sHDOP;
  133. short sVDOP;
  134. };
  135. class CJY901
  136. {
  137. public:
  138. struct STime stcTime;
  139. struct SAcc stcAcc;
  140. struct SGyro stcGyro;
  141. struct SAngle stcAngle;
  142. struct SMag stcMag;
  143. struct SDStatus stcDStatus;
  144. struct SPress stcPress;
  145. struct SLonLat stcLonLat;
  146. struct SGPSV stcGPSV;
  147. struct SQuater stcQuater;
  148. struct SSN stcSN;
  149. CJY901 ();
  150. void StartIIC();
  151. void StartIIC(unsigned char ucAddr);
  152. void CopeSerialData(unsigned char ucData);
  153. short ReadWord(unsigned char ucAddr);
  154. void WriteWord(unsigned char ucAddr,short sData);
  155. void ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[]);
  156. void GetTime();
  157. void GetAcc();
  158. void GetGyro();
  159. void GetAngle();
  160. void GetMag();
  161. void GetPress();
  162. void GetDStatus();
  163. void GetLonLat();
  164. void GetGPSV();
  165. private:
  166. unsigned char ucDevAddr;
  167. void readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest);
  168. void writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite);
  169. };
  170. extern CJY901 JY901;
  171. #include <Wire.h>
  172. #endif