BM1383AGLV sensor library
Dependents: simple-sensor-client rohm-SensorShield-example
BM1383AGLV.h
00001 /* Copyright (c) 2015 ARM Ltd., MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 * 00018 * 00019 * BM1383AGLV Pressure sensor library 00020 * 00021 * @author Toyomasa Watarai 00022 * @version 1.0 00023 * @date 30-December-2015 00024 * 00025 * Library for "BM1383AGLV Pressure sensor library" 00026 * http://www.rohm.com/web/eu/news-detail?news-title=2014-12-11_ad_pressure&defaultGroupId=false 00027 * 00028 */ 00029 00030 #ifndef BM1383AGLV_H 00031 #define BM1383AGLV_H 00032 00033 #include "mbed.h" 00034 00035 #define BM1383AGLV_DEFAULT_SLAVE_ADDRESS (0x5D << 1) 00036 #define BM1383AGLV_ID1_VAL (0xE0) 00037 #define BM1383AGLV_ID2_VAL (0x32) 00038 #define BM1383AGLV_ID1 (0x0F) 00039 #define BM1383AGLV_ID2 (0x10) 00040 #define BM1383AGLV_POWER_DOWN (0x12) 00041 #define BM1383AGLV_RESET (0x13) 00042 #define BM1383AGLV_MODE_CONTROL (0x14) 00043 #define BM1383AGLV_STATUS (0x19) 00044 #define BM1383AGLV_PRESSURE_MSB (0x1A) 00045 #define BM1383AGLV_PRESSURE_LSB (0x1B) 00046 #define BM1383AGLV_PRESSURE_XLSB (0x1C) 00047 #define BM1383AGLV_TEMPERATURE_MSB (0x1D) 00048 #define BM1383AGLV_TEMPERATURE_LSB (0x1E) 00049 00050 #define BM1383AGLV_WAIT_READY_STATUS 0 00051 00052 #ifdef _DEBUG 00053 extern Serial pc; 00054 #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__) 00055 #else 00056 #define DEBUG_PRINT(...) 00057 #endif 00058 00059 /** 00060 * BM1383AGLV pressure sensor example 00061 * 00062 * @code 00063 * BM1383AGLV sensor(I2C_SDA, I2C_SCL); 00064 * Serial pc(USBTX, USBRX); 00065 * 00066 * int main() { 00067 * pc.printf("\nBM1383AGLV Pressure sensor library test program.\n"); 00068 * 00069 * while(1) { 00070 * pc.printf("pressure=%7.2f, temperature=%5.3f\n", sensor.getPressure(), sensor.getTemperature()); 00071 * wait(0.5); 00072 * } 00073 * } 00074 * @endcode 00075 */ 00076 class BM1383AGLV 00077 { 00078 public: 00079 /** 00080 * BM1383AGLV constructor 00081 * 00082 * @param sda SDA pin 00083 * @param sdl SCL pin 00084 * @param addr slave address of the I2C peripheral (default: 0xBA) 00085 */ 00086 BM1383AGLV(PinName sda, PinName scl, int addr = BM1383AGLV_DEFAULT_SLAVE_ADDRESS); 00087 00088 /** 00089 * Create a BM1383AGLV instance which is connected to specified I2C pins 00090 * with specified address 00091 * 00092 * @param i2c_obj I2C object (instance) 00093 * @param addr slave address of the I2C-bus peripheral (default: 0xBA) 00094 */ 00095 BM1383AGLV(I2C &i2c_obj, int addr = BM1383AGLV_DEFAULT_SLAVE_ADDRESS); 00096 00097 /** 00098 * BM1383AGLV destructor 00099 */ 00100 ~BM1383AGLV(); 00101 00102 /** Initializa BM1383AGLV sensor 00103 * 00104 * Configure sensor setting 00105 * 00106 */ 00107 void initialize(void); 00108 00109 /** 00110 * Get pressure 00111 * 00112 * @returns pressure 00113 */ 00114 float getPressure(); 00115 00116 /** 00117 * Get temerature 00118 * 00119 * @returns temperature 00120 */ 00121 float getTemperature(); 00122 00123 private: 00124 I2C *i2c_p; 00125 I2C &i2c; 00126 int m_addr; 00127 uint8_t m_buf[3]; 00128 void readRegs(int addr, uint8_t * data, int len); 00129 void writeRegs(uint8_t * data, int len); 00130 00131 }; 00132 00133 #endif
Generated on Tue Jul 12 2022 18:57:04 by 1.7.2