34 lines
1008 B
C
34 lines
1008 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <bmp280.h>
|
|
#include "ygg_bmp280.h"
|
|
|
|
extern float last_temperature;
|
|
|
|
void ygg_bmp280_init(bmp280_t *dev) {
|
|
bmp280_params_t params;
|
|
bmp280_init_default_params(¶ms);
|
|
memset(dev, 0, sizeof(bmp280_t));
|
|
|
|
ESP_ERROR_CHECK(bmp280_init_desc(dev, BMP280_I2C_ADDRESS_0, 0, I2C_MASTER_SDA, I2C_MASTER_SCL));
|
|
ESP_ERROR_CHECK(bmp280_init(dev, ¶ms));
|
|
|
|
bool bme280p = dev->id == BME280_CHIP_ID;
|
|
printf("BMP280: found %s\n", bme280p ? "BME280" : "BMP280");
|
|
}
|
|
|
|
void ygg_bmp280_read_sensor(bmp280_t *dev) {
|
|
float pressure, temperature, humidity;
|
|
bool bme280p = dev->id == BME280_CHIP_ID;
|
|
|
|
if (bmp280_read_float(dev, &temperature, &pressure, &humidity) != ESP_OK)
|
|
printf("Temperature/pressure reading failed\n");
|
|
|
|
last_temperature = temperature;
|
|
printf("Pressure: %.2f Pa, Temperature: %.2f C", pressure, temperature);
|
|
if (bme280p)
|
|
printf(", Humidity: %.2f\n", humidity);
|
|
else
|
|
printf("\n");
|
|
}
|