Steve Martin / libdev_si7210

si7210.h

Committer:
ninensei
Date:
2017-09-12
Revision:
0:ee9d6b55bf85
Child:
1:8cb452601311

File content as of revision 0:ee9d6b55bf85:

#include "mbed.h"

#ifndef SI7210_H
#define SI7210_H

#define SI7210_BASE_ADDR_7BIT   0x30

typedef struct {
    float       mag_T;
    float       temp_C;
} si7210_measurements_t;

class SI7210 {
 public:
    /**
    * Constructor
    *
    * @param i2c I2C class servicing the strip
    */
    SI7210(I2C * i2c, uint8_t addr_7bit) : _i2c(i2c) {
        _addr_8bit = ((addr_7bit & 0x3) + SI7210_BASE_ADDR_7BIT) << 1;
    }
    
    /**
    * Read temperature and humidity
    *
    * @param data points to struct to store measurements in.  Stucture is
    *      valid only when function returns success indication.
    *
    * @returns true (success) or false (failure)
    */
    bool read(si7210_measurements_t * data);

 protected:
 
    /**
    * I2C read/write helper function
    *
    * @param address is the register to read/write
    * @param buff holds the data to write and recieves the data to read
    * @param writeSize is the number of bytes to write to register
    * @param readSize is the number of bytes to retrieve from device
    *
    * @returns true (success) or false (failure)
    */
    bool _i2c_transfer(int address, void * buff, size_t writeSize, size_t readSize);
    
    /**
    * 
    bool _validate(void)
    */

    int     _addr_8bit;
    I2C    *_i2c;
};

#endif //SI7210_H