Tony YI
/
ESDC2014
123123123123123123123123123
Diff: compass.h
- Revision:
- 1:cbec1283a16a
- Parent:
- 0:3417ca0a36c0
- Child:
- 2:442902ec3aa1
--- a/compass.h Tue Jul 01 10:59:33 2014 +0000 +++ b/compass.h Thu Jul 03 03:56:29 2014 +0000 @@ -1,54 +1,58 @@ -#ifndef HMC5883L_H -#define HMC5883L_H +#ifndef COMPASS_H +#define COMPASS_H #include "mbed.h" +#include "define.h" -#define HMC5883L_IDENT_A 0x0A // In this case the identification register A is used to identify the devide. ASCII value H -#define HMC5883L_I2C 0x1E // 7-bit address. 0x3C write, 0x3D read. -#define HMC5883L_I2C_WRITE 0x3C // Same as (& 0xFE), ensure that the MSB bit is being set to zero (RW=0 -> Writing) -#define HMC5883L_I2C_READ 0x3D // Same as (| 0x01), ensure that the MSB bit is being set to one (RW=1 -> Reading) +#define RUN_MSB 0xC7 +#define RUN_LSB 0x10 + +#define STOP_MSB 0xC6 +#define STOP_LSB 0x10 + +#define RESUME_MSB 0xD1 +#define RESUME_LSB 0x10 -#define HMC5883L_CONFIG_A 0x00 -#define HMC5883L_CONFIG_B 0x01 -#define HMC5883L_MODE 0x02 -#define HMC5883L_STATUS 0x09 +#define RST_MSB 0xC2 +#define RST_LSB 0x10 -#define HMC5883L_X_MSB 0x03 -#define HMC5883L_X_LSB 0x04 -#define HMC5883L_Z_MSB 0x05 -#define HMC5883L_Z_LSB 0x06 -#define HMC5883L_Y_MSB 0x07 -#define HMC5883L_Y_LSB 0x08 -#define PI 3.14159265 -#define SDA p9 -#define SCL p10 +#define RESUME_MSB 0xD1 +#define RESUME_LSB 0x10 + +#define COMPASS_TX p9 +#define COMPASS_RX p10 + + #define DECLINATIONANGLE -0.0457 #define OFFSET 0 #include <math.h> -class HMC5883L +class COMPASS { public: - HMC5883L(PinName sda, PinName scl); - float getMx(); - float getMy(); - float getMz(); + COMPASS(PinName TX, PinName RX); + uint16_t Read(); + - void setDeclination(float declinationAngle); - void setOffset(int offset); +private: + + MySerial *serial; + char buffer[2]; + uint16_t degree; - unsigned short get_degree(); -private: - void Write(char reg_address, char data); - char Read(char data); - void MultiByteRead(char address, char* output, int size); - I2C i2c; + void init(); + void run(); + void stop(); + void resume(); + void reset(); + void write2Bytes(char msb, char lsb); + float declinationAngle; int offset; }; -#endif /* HMC5883L_H */ \ No newline at end of file +#endif /* COMPASS_H */ \ No newline at end of file