Add mgos_barometer API

This commit is contained in:
Pim van Pelt
2018-04-21 15:17:24 +02:00
parent acec109ae8
commit 89ec34dc1d
7 changed files with 324 additions and 1 deletions

View File

@ -23,6 +23,7 @@
#include "mgos_ccs811.h"
#include "mgos_mpu9250.h"
#include "mgos_imu.h"
#include "mgos_barometer.h"
#include <fcntl.h>
#include <sys/ioctl.h>
@ -154,6 +155,22 @@ bool do_mpu9250(struct mgos_mpu9250 *sensor) {
return true;
}
bool do_baro(struct mgos_barometer *sensor) {
float pressure, temperature;
if (!sensor)
return false;
if (mgos_barometer_get_pressure(sensor, &pressure)) {
LOG(LL_INFO, ("Pressure %.2fPa", pressure));
}
if (mgos_barometer_get_temperature(sensor, &temperature)) {
LOG(LL_INFO, ("Temperature %.2fC", temperature));
}
return true;
}
int main() {
struct mgos_i2c * i2c;
struct mgos_si7021 * si7021;
@ -162,6 +179,7 @@ int main() {
struct mgos_mcp9808 *mcp9808;
struct mgos_ccs811 * ccs811;
struct mgos_mpu9250 *mpu9250;
struct mgos_barometer *baro;
if (!mgos_i2c_open(I2CBUSNR)) {
LOG(LL_ERROR, ("Cannot open I2C bus %u", I2CBUSNR));
@ -187,6 +205,7 @@ int main() {
* LOG(LL_ERROR, ("Cannot create CCS811 device"));
*/
/*
if (!(mpu9250 = mgos_mpu9250_create(i2c, 0x68))) {
LOG(LL_ERROR, ("Cannot create MPU9250 device"));
} else {
@ -195,6 +214,10 @@ int main() {
mgos_mpu9250_set_magnetometer_scale(mpu9250, SCALE_14_BITS);
mgos_mpu9250_set_magnetometer_speed(mpu9250, MAG_100_HZ);
}
*/
if (!(baro=mgos_barometer_create_i2c(i2c, 0x60, BARO_MPL115))) {
LOG(LL_ERROR, ("Cannot create MPL115 barometer"));
}
for (;;) {
/*
@ -203,8 +226,9 @@ int main() {
* do_htu21df(htu21df);
* do_mcp9808(mcp9808);
* do_ccs811(ccs811);
* do_mpu9250(mpu9250);
*/
do_mpu9250(mpu9250);
do_baro(baro);
sleep(1);
}
@ -214,6 +238,7 @@ int main() {
mgos_mcp9808_destroy(&mcp9808);
mgos_ccs811_destroy(&ccs811);
mgos_mpu9250_destroy(&mpu9250);
mgos_barometer_destroy(&baro);
return 0;
}