terry LAI / Mbed 2 deprecated ESDC2014-pwm

Dependencies:   mbed

Fork of ESDC2014 by terry LAI

compass.h

Committer:
terryLAI
Date:
2014-07-04
Revision:
4:a377ecb9364f
Parent:
3:4306d042af6f

File content as of revision 4:a377ecb9364f:

#ifndef _COMPASS_H
#define _COMPASS_H

#include "mbed.h"
#include "define.h"
#include "math.h"


#define RUN_MSB     0xC7
#define RUN_LSB     0x10
#define ACK_RUN_MSB     0xC7
#define ACK_RUN_LSB     0x10

#define STOP_MSB    0xC6
#define STOP_LSB    0x10
#define ACK_STOP_MSB    0xD6
#define ACK_STOP_LSB    0x01

#define RESUME_MSB      0xD1
#define RESUME_LSB      0x10
#define ACK_RESUME_MSB      0xD1
#define ACK_RESUME_LSB      0x10

#define RST_MSB     0xC2
#define RST_LSB     0x10    

#define DECLINATIONANGLE  -0.0457

#define DATA_BUFFER_SIZE 256

class Compass
{
public:
    Compass(MySerial _compassSerial);
    ~Compass();
    void putToBuffer(uint8_t _x);
    void clearBuffer();
    int read();

private:
    MySerial* _compassSerial;
    MySerial* temp;
    uint8_t* buffer;
    uint8_t _MSB;
    uint8_t _LSB;

    uint8_t _in;
    uint8_t _out;
    
    uint32_t add;

    uint16_t _degree;
    
    void write2Bytes(char msb, char lsb);
    void run();
    void stop();
    void resume();
    void reset();
};

#endif