JY901.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 QUATER 0x51
  66. #define DIO_MODE_AIN 0
  67. #define DIO_MODE_DIN 1
  68. #define DIO_MODE_DOH 2
  69. #define DIO_MODE_DOL 3
  70. #define DIO_MODE_DOPWM 4
  71. #define DIO_MODE_GPS 5
  72. struct STime
  73. {
  74. unsigned char ucYear;
  75. unsigned char ucMonth;
  76. unsigned char ucDay;
  77. unsigned char ucHour;
  78. unsigned char ucMinute;
  79. unsigned char ucSecond;
  80. unsigned short usMiliSecond;
  81. };
  82. struct SAcc
  83. {
  84. short a[3];
  85. short T;
  86. };
  87. struct SGyro
  88. {
  89. short w[3];
  90. short T;
  91. };
  92. struct SAngle
  93. {
  94. short Angle[3];
  95. short T;
  96. };
  97. struct SMag
  98. {
  99. short h[3];
  100. short T;
  101. };
  102. struct SDStatus
  103. {
  104. short sDStatus[4];
  105. };
  106. struct SPress
  107. {
  108. long lPressure;
  109. long lAltitude;
  110. };
  111. struct SLonLat
  112. {
  113. long lLon;
  114. long lLat;
  115. };
  116. struct SGPSV
  117. {
  118. short sGPSHeight;
  119. short sGPSYaw;
  120. long lGPSVelocity;
  121. };
  122. struct SQuater
  123. {
  124. short q[4];
  125. short T;
  126. };
  127. class CJY901
  128. {
  129. public:
  130. struct STime stcTime;
  131. struct SAcc stcAcc;
  132. struct SGyro stcGyro;
  133. struct SAngle stcAngle;
  134. struct SMag stcMag;
  135. struct SDStatus stcDStatus;
  136. struct SPress stcPress;
  137. struct SLonLat stcLonLat;
  138. struct SGPSV stcGPSV;
  139. struct SQuater stcQuater;
  140. CJY901 ();
  141. void StartIIC();
  142. void StartIIC(unsigned char ucAddr);
  143. void CopeSerialData(unsigned char ucData);
  144. short ReadWord(unsigned char ucAddr);
  145. void WriteWord(unsigned char ucAddr,short sData);
  146. void ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[]);
  147. void GetTime();
  148. void GetAcc();
  149. void GetGyro();
  150. void GetAngle();
  151. void GetMag();
  152. void GetPress();
  153. void GetDStatus();
  154. void GetLonLat();
  155. void GetGPSV();
  156. void GetQuater();
  157. private:
  158. unsigned char ucDevAddr;
  159. void readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest);
  160. void writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite);
  161. };
  162. extern CJY901 JY901;
  163. #include <Wire.h>
  164. #endif