LPS331 library
See https://developer.mbed.org/users/yasuyuki/notebook/LPS331/
Revision 1:f70e671b008f, committed 2014-10-10
- Comitter:
- yasuyuki
- Date:
- Fri Oct 10 04:37:48 2014 +0000
- Parent:
- 0:ef4f624dc3ec
- Commit message:
- H last
Changed in this revision
diff -r ef4f624dc3ec -r f70e671b008f LPS331.cpp --- a/LPS331.cpp Sat Oct 04 12:02:25 2014 +0000 +++ b/LPS331.cpp Fri Oct 10 04:37:48 2014 +0000 @@ -39,22 +39,41 @@ long LPS331::value() { - // get press_high - get(LPS331_PRESS_OUT_H); - //press=buf[0]*0x10000; - press.byte.UB=buf[0]; + // XL first and H last + // get press_xl + get(LPS331_PRESS_POUT_XL_REH); + press.byte.LB=buf[0]; // get tpress_low get(LPS331_PRESS_OUT_L); - //press+=buf[0]*0x100; press.byte.HB=buf[0]; - // get press_xl - get(LPS331_PRESS_POUT_XL_REH); - //press+=buf[0]; - press.byte.LB=buf[0]; + // get press_high + get(LPS331_PRESS_OUT_H); + press.byte.UB=buf[0]; return press.Val; - + + // hPa = press.Val / 4096 + // Pa = press.Val / 40.96 } + +short LPS331::temperature() +{ + + // L first and H last + // get tpress_low + get(LPS331_TEMP_OUT_L); + temp.byte.LB=buf[0]; + // get press_high + get(LPS331_TEMP_OUT_H); + temp.byte.HB=buf[0]; + return temp.S; + + // C = 42.5 + temp.S / 480 + // range:0 to 80C + // accuracy:+-2C +} + + void LPS331::init() { // Power ON Cycle=1Hz @@ -62,3 +81,4 @@ } +
diff -r ef4f624dc3ec -r f70e671b008f LPS331.h --- a/LPS331.h Sat Oct 04 12:02:25 2014 +0000 +++ b/LPS331.h Fri Oct 10 04:37:48 2014 +0000 @@ -44,12 +44,14 @@ void put(unsigned char a, unsigned char b); void get(unsigned char a); long value(); + short temperature(); protected: I2C _i2c; DWORD_VAL press; + WORD_VAL temp; char buf[2]; };
diff -r ef4f624dc3ec -r f70e671b008f typedef.h --- a/typedef.h Sat Oct 04 12:02:25 2014 +0000 +++ b/typedef.h Fri Oct 10 04:37:48 2014 +0000 @@ -19,6 +19,7 @@ { WORD Val; BYTE v[2]; + short S; struct { BYTE LB;