unfinished

Dependents:   WRS_mechanamu_test WRS2019_master mbed_2018 mbed_2019_rx3 ... more

Committer:
sgrsn
Date:
Sat Apr 28 03:58:17 2018 +0000
Revision:
3:b0aecd9a3cc9
Parent:
2:5af50b300137
Child:
4:cd62e2d69f62
...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sgrsn 0:6ff4cad60b67 1 #ifndef MBED_JY901_H
sgrsn 0:6ff4cad60b67 2 #define MBED_JY901_H
sgrsn 0:6ff4cad60b67 3
sgrsn 0:6ff4cad60b67 4 #include "mbed.h"
sgrsn 0:6ff4cad60b67 5
sgrsn 2:5af50b300137 6 /*example*************************************
sgrsn 3:b0aecd9a3cc9 7 #include "mbed.h"
sgrsn 3:b0aecd9a3cc9 8 #include "JY901.h"
sgrsn 3:b0aecd9a3cc9 9
sgrsn 2:5af50b300137 10 JY901 i2c(dp5, dp27);
sgrsn 2:5af50b300137 11
sgrsn 2:5af50b300137 12 int main()
sgrsn 2:5af50b300137 13 {
sgrsn 2:5af50b300137 14 float angle = 0;
sgrsn 2:5af50b300137 15 i2c.calibrateAll(5000);
sgrsn 2:5af50b300137 16 while(1)
sgrsn 2:5af50b300137 17 {
sgrsn 2:5af50b300137 18 angle = i2c.getZaxisAngle();
sgrsn 2:5af50b300137 19 printf("%f\r\n", angle);
sgrsn 2:5af50b300137 20 }
sgrsn 2:5af50b300137 21 }
sgrsn 2:5af50b300137 22 **********************************************/
sgrsn 2:5af50b300137 23
sgrsn 0:6ff4cad60b67 24 #define IICADDR 0xa0 // IIC address
sgrsn 0:6ff4cad60b67 25 #define g 9.8 // Acceleration of gravity
sgrsn 0:6ff4cad60b67 26
sgrsn 0:6ff4cad60b67 27 #define SAVE 0x00 // Save
sgrsn 0:6ff4cad60b67 28 #define CALSW 0x01 // Calibration
sgrsn 0:6ff4cad60b67 29 #define RSW 0x02 // Return data content
sgrsn 0:6ff4cad60b67 30 #define RATE 0x03 // Return data Speed
sgrsn 0:6ff4cad60b67 31 #define BAUD 0x04 // Baud rate
sgrsn 0:6ff4cad60b67 32 #define AXOFFSET 0x05 // X axis Acceleration bias
sgrsn 0:6ff4cad60b67 33 #define AYOFFSET 0x06 // Y axis Acceleration bias
sgrsn 0:6ff4cad60b67 34 #define AZOFFSET 0x07 // Z axis Acceleration bias
sgrsn 0:6ff4cad60b67 35 #define GXOFFSET 0x08 // X axis angular velocity bias
sgrsn 0:6ff4cad60b67 36 #define GYOFFSET 0x09 // Y axis angular velocity bias
sgrsn 0:6ff4cad60b67 37 #define GZOFFSET 0x0a // Z axis angular velocity bias
sgrsn 0:6ff4cad60b67 38 #define HXOFFSET 0x0b // X axis Magnetic bias
sgrsn 0:6ff4cad60b67 39 #define HYOFFSET 0x0c // Y axis Magnetic bias
sgrsn 0:6ff4cad60b67 40 #define HZOFFSET 0x0d // Z axis Magnetic bias
sgrsn 0:6ff4cad60b67 41 #define D0MODE 0x0e // D0 mode
sgrsn 0:6ff4cad60b67 42 #define D1MODE 0x0f // D1 mode
sgrsn 0:6ff4cad60b67 43 #define D2MODE 0x10 // D2 mode
sgrsn 0:6ff4cad60b67 44 #define D3MODE 0x11 // D3 mode
sgrsn 0:6ff4cad60b67 45 #define D0PWMH 0x12 // D0PWM High-level width
sgrsn 0:6ff4cad60b67 46 #define D1PWMH 0x13 // D1PWM High-level width
sgrsn 0:6ff4cad60b67 47 #define D2PWMH 0x14 // D2PWM High-level width
sgrsn 0:6ff4cad60b67 48 #define D3PWMH 0x15 // D3PWM High-level width
sgrsn 0:6ff4cad60b67 49 #define D0PWMT 0x16 // D0PWM Period
sgrsn 0:6ff4cad60b67 50 #define D1PWMT 0x17 // D1PWM Period
sgrsn 0:6ff4cad60b67 51 #define D2PWMT 0x18 // D2PWM Period
sgrsn 0:6ff4cad60b67 52 #define D3PWMT 0x19 // D3PWM Period
sgrsn 0:6ff4cad60b67 53 #define LEDOFF 0x1b // Turn off LED
sgrsn 0:6ff4cad60b67 54 #define GPSBAUD 0x1c // GPS baud rate
sgrsn 0:6ff4cad60b67 55
sgrsn 0:6ff4cad60b67 56 #define YYMM 0x30 // Year、Month
sgrsn 0:6ff4cad60b67 57 #define DDHH 0x31 // Day、Hour
sgrsn 0:6ff4cad60b67 58 #define MMSS 0x32 // Minute、Second
sgrsn 0:6ff4cad60b67 59 #define MS 0x33 // Millisecond
sgrsn 0:6ff4cad60b67 60 #define AX 0x34 // X axis Acceleration
sgrsn 0:6ff4cad60b67 61 #define AY 0x35 // Y axis Acceleration
sgrsn 0:6ff4cad60b67 62 #define AZ 0x36 // Z axis Acceleration
sgrsn 0:6ff4cad60b67 63 #define GX 0x37 // X axis angular velocity
sgrsn 0:6ff4cad60b67 64 #define GY 0x38 // Y axis angular velocity
sgrsn 0:6ff4cad60b67 65 #define GZ 0x39 // Z axis angular velocity
sgrsn 0:6ff4cad60b67 66 #define HX 0x3a // X axis Magnetic
sgrsn 0:6ff4cad60b67 67 #define HY 0x3b // Y axis Magnetic
sgrsn 0:6ff4cad60b67 68 #define HZ 0x3c // Z axis Magnetic
sgrsn 0:6ff4cad60b67 69 #define Roll 0x3d // X axis Angle
sgrsn 0:6ff4cad60b67 70 #define Pitch 0x3e // Y axis Angle
sgrsn 0:6ff4cad60b67 71 #define Yaw 0x3f // Z axis Angle
sgrsn 0:6ff4cad60b67 72 #define TEMP 0x40 // Temperature
sgrsn 0:6ff4cad60b67 73 #define D0Status 0x41 // D0Status
sgrsn 0:6ff4cad60b67 74 #define D1Status 0x42 // D1Status
sgrsn 0:6ff4cad60b67 75 #define D2Status 0x43 // D2Status
sgrsn 0:6ff4cad60b67 76 #define D3Status 0x44 // D3Status
sgrsn 0:6ff4cad60b67 77 #define PressureL 0x45 // Pressure Low Byte
sgrsn 0:6ff4cad60b67 78 #define PressureH 0x46 // Pressure High Byte
sgrsn 0:6ff4cad60b67 79 #define HeightL 0x47 // Height Low Byte
sgrsn 0:6ff4cad60b67 80 #define HeightH 0x48 // Height High Byte
sgrsn 0:6ff4cad60b67 81 #define LonL 0x49 // Longitude Low Byte
sgrsn 0:6ff4cad60b67 82 #define LonH 0x4a // Longitude High Byte
sgrsn 0:6ff4cad60b67 83 #define LatL 0x4b // Latitude Low Byte
sgrsn 0:6ff4cad60b67 84 #define LatH 0x4c // Latitude High Byte
sgrsn 0:6ff4cad60b67 85 #define GPSHeight 0x4d // GPS Height
sgrsn 0:6ff4cad60b67 86 #define GPSYaw 0x4e // GPS Yaw
sgrsn 0:6ff4cad60b67 87 #define GPSVL 0x4f // GPS speed Low byte
sgrsn 0:6ff4cad60b67 88 #define GPSVH 0x50 // GPS speed High byte
sgrsn 0:6ff4cad60b67 89 #define Q0 0x51 // Quaternion Q0
sgrsn 0:6ff4cad60b67 90 #define Q1 0x52 // Quaternion Q1
sgrsn 0:6ff4cad60b67 91 #define Q2 0x53 // Quaternion Q2
sgrsn 0:6ff4cad60b67 92 #define Q3 0x54 // Quaternion Q3
sgrsn 0:6ff4cad60b67 93
sgrsn 0:6ff4cad60b67 94 class JY901 : public I2C
sgrsn 0:6ff4cad60b67 95 {
sgrsn 0:6ff4cad60b67 96 public:
sgrsn 0:6ff4cad60b67 97 JY901(PinName sda, PinName scl);
sgrsn 0:6ff4cad60b67 98
sgrsn 1:6bcbd18a719a 99 void calibrateGyroAccel();
sgrsn 1:6bcbd18a719a 100 void calibrateMagnetic();
sgrsn 1:6bcbd18a719a 101 void calibrateHeight();
sgrsn 1:6bcbd18a719a 102 void endCalibrate();
sgrsn 1:6bcbd18a719a 103 void calibrateAll(int time_ms);
sgrsn 0:6ff4cad60b67 104 int getYear();
sgrsn 0:6ff4cad60b67 105 int getMonth();
sgrsn 0:6ff4cad60b67 106 int getDay();
sgrsn 0:6ff4cad60b67 107 int getHour();
sgrsn 0:6ff4cad60b67 108 int getMinute();
sgrsn 0:6ff4cad60b67 109 int getSecond();
sgrsn 0:6ff4cad60b67 110 int getMillisecond();
sgrsn 0:6ff4cad60b67 111 float getXaxisAcceleration();
sgrsn 0:6ff4cad60b67 112 float getYaxisAcceleration();
sgrsn 0:6ff4cad60b67 113 float getZaxisAcceleration();
sgrsn 0:6ff4cad60b67 114 float getXaxisAngularVelocity();
sgrsn 0:6ff4cad60b67 115 float getYaxisAngularVelocity();
sgrsn 0:6ff4cad60b67 116 float getZaxisAngularVelocity();
sgrsn 0:6ff4cad60b67 117 float getXaxisMagnetic();
sgrsn 0:6ff4cad60b67 118 float getYaxisMagnetic();
sgrsn 0:6ff4cad60b67 119 float getZaxisMagnetic();
sgrsn 0:6ff4cad60b67 120 float getXaxisAngle();
sgrsn 0:6ff4cad60b67 121 float getYaxisAngle();
sgrsn 0:6ff4cad60b67 122 float getZaxisAngle();
sgrsn 0:6ff4cad60b67 123 float getTemperature();
sgrsn 0:6ff4cad60b67 124 float getD0Status();
sgrsn 0:6ff4cad60b67 125 float getD1Status();
sgrsn 0:6ff4cad60b67 126 float getD2Status();
sgrsn 0:6ff4cad60b67 127 float getD3Status();
sgrsn 0:6ff4cad60b67 128
sgrsn 0:6ff4cad60b67 129 /*dnt use I correct someday*********/
sgrsn 0:6ff4cad60b67 130 float getPressure();
sgrsn 0:6ff4cad60b67 131 float getHeight();
sgrsn 0:6ff4cad60b67 132 float getLongitude();
sgrsn 0:6ff4cad60b67 133 float getLatitude();
sgrsn 0:6ff4cad60b67 134 float getGPSHeight();
sgrsn 0:6ff4cad60b67 135 float getGPSYaw();
sgrsn 0:6ff4cad60b67 136 float getGPSspeed();
sgrsn 0:6ff4cad60b67 137 /*************************************/
sgrsn 0:6ff4cad60b67 138
sgrsn 0:6ff4cad60b67 139 private:
sgrsn 0:6ff4cad60b67 140 char *getdata(char registar);
sgrsn 0:6ff4cad60b67 141 };
sgrsn 0:6ff4cad60b67 142
sgrsn 0:6ff4cad60b67 143 #endif