Library to work with the MS5611 pressure sensors. Forked from the MS5607 library
Dependents: MS5611Example Atlas HC-06_MPU9250_F303K_Stream
Fork of MS5607 by
Diff: MS5607I2C.h
- Revision:
- 1:847720b736ea
- Parent:
- 0:5760862143d1
diff -r 5760862143d1 -r 847720b736ea MS5607I2C.h --- a/MS5607I2C.h Tue Jul 03 08:57:57 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* -Copyright (c) 2012, Senio Networks, Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef MS5607_I2C_H -#define MS5607_I2C_H - -#include "MS5607Base.h" - -class MS5607I2C : public MS5607Base { -public: - MS5607I2C(PinName sda, PinName scl, int csb = 0) : i2c(sda, scl), i2cAddr(csb ? 0xEC : 0xEE) { - init(); - } - -private: - I2C i2c; - int i2cAddr; - - virtual void writeCommand(int command, int ms = 0) { - char buf[1] = {command}; - i2c.write(i2cAddr, buf, 1); - if (ms) wait_ms(ms); - } - - virtual int readPROM(int address) { - char buf[2] = {PROM_READ | (address << 1), 0}; - - if (i2c.write(i2cAddr, buf, 1) == 0 && - i2c.read(i2cAddr, buf, 2) == 0) - return buf[0] << 8 | buf[1]; - - return -1; - } - - virtual int readADC(int command) { - char cmd[] = {ADC_CONV | command}; - - if (i2c.write(i2cAddr, cmd, sizeof(cmd)) == 0) { - static int duration[] = {500, 1100, 2100, 4100, 8220}; - wait_us(duration[(command & 0x0F) >> 1]); - cmd[0] = ADC_READ; - char buf[3]; - if (i2c.write(i2cAddr, cmd, sizeof(cmd)) == 0 && - i2c.read(i2cAddr, buf, sizeof(buf)) == 0) - return buf[0] << 16 | buf[1] << 8 | buf[2]; - } - - return -1; - } -}; - -#endif \ No newline at end of file