Skip to content
Snippets Groups Projects
Commit bc5e0322 authored by fxk8y's avatar fxk8y :spider:
Browse files

adding basic code / bme280 lib

parent bd744ef8
No related branches found
No related tags found
No related merge requests found
...@@ -20,3 +20,6 @@ ...@@ -20,3 +20,6 @@
[submodule "components/ESP32-Digital-RGB-LED-Drivers"] [submodule "components/ESP32-Digital-RGB-LED-Drivers"]
path = components/ESP32-Digital-RGB-LED-Drivers path = components/ESP32-Digital-RGB-LED-Drivers
url = git@git.services.c3pb.de:c3pb/ESP32-Digital-RGB-LED-Drivers.git url = git@git.services.c3pb.de:c3pb/ESP32-Digital-RGB-LED-Drivers.git
[submodule "components/esp32-bme280"]
path = components/esp32-bme280
url = git@git.services.c3pb.de:c3pb/esp32-bme280.git
esp32-bme280 @ 12ce1eee
Subproject commit 12ce1eee7a3bfa1746f1f4e7a78a034fc1b67d33
CXXFLAGS += -std=c++17 CXXFLAGS += -std=c++17
COMPONENT_SRCDIRS := . device peripherals COMPONENT_SRCDIRS := . device peripherals peripherals/sensors
COMPONENT_ADD_INCLUDEDIRS := . COMPONENT_ADD_INCLUDEDIRS := .
\ No newline at end of file
#include "bme280.h"
static bool measured_started = false;
typedef struct {
std::string topic;
BME280 bme280;
qthing::bme280_measure_callback_t callback;
} bme280_config_t;
static bme280_config_t cfg;
#include "esp_log.h"
static void measured(void *ignored) {
while (true) {
bme280_reading_data data = cfg.bme280.readSensorData();
ESP_LOGE("BME280", "Temperature: %.2f°C, Humidity: %.2f%%, Pressure: %.2fPa\n",
(double) data.temperature,
(double) data.humidity,
(double) data.pressure
);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
namespace qthing {
void add_bme280(gpio_num_t sda, gpio_num_t scl, std::string topic, qthing::bme280_measure_callback_t callback, uint8_t address) {
BME280 bme280 = BME280(address);
bme280.setDebug(false);
bme280.init(sda, scl);
cfg = {
topic,
bme280,
callback
};
if (!measured_started) {
measured_started = true;
xTaskCreate(measured, "bme280_measured", 10000, NULL, 1, NULL);
}
}
}
# pragma once
#include <qthing.h>
#include <string>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "BME280.h"
...@@ -94,6 +94,18 @@ namespace qthing { ...@@ -94,6 +94,18 @@ namespace qthing {
void add_ledstrip(gpio_num_t gpio, uint16_t num_leds, qthing::led_strip_types_t led_type); void add_ledstrip(gpio_num_t gpio, uint16_t num_leds, qthing::led_strip_types_t led_type);
void set_color_handler(led_color_handler_t led_color_handler); void set_color_handler(led_color_handler_t led_color_handler);
void set_led_strip_fps(uint8_t fps); void set_led_strip_fps(uint8_t fps);
// BME280
typedef struct {
float temperature;
float humidity;
float pressure;
} bme280_data_t;
typedef std::function<void(bme280_data_t)> bme280_measure_callback_t;
void add_bme280(gpio_num_t sda, gpio_num_t scl, std::string topic, qthing::bme280_measure_callback_t callback, uint8_t address = 0x76);
} }
// utility // utility
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment