This commit is contained in:
2025-04-26 17:09:55 +02:00
parent 5853bf849f
commit cb339e6b66
18 changed files with 270 additions and 111 deletions

View File

@@ -8,14 +8,94 @@
static uint8_t s_led_state = 0;
uint8_t foundDevices[128];
uint8_t prevDevices[128];
static void configure_led(void)
{
gpio_reset_pin(BLINK_GPIO);
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
}
// void update_devices() {
// memcpy(prevDevices, foundDevices, sizeof(prevDevices));
// memset(foundDevices, 0, sizeof(foundDevices));
// for (uint8_t i = 0; i < 128; i++)
// {
// fflush(stdout);
// esp_err_t ret = i2c_master_probe(i2c0_bus_hdl, i, 20);
// if (ret == ESP_OK)
// {
// foundDevices[i] = 1;
// printf("Found device at 0x%02X\n", i);
// }
// }
// }
// void init_connected() {
// for (uint8_t i = 0; i < 128; i++) {
// if (foundDevices[i] != prevDevices[i]) {
// if (foundDevices[i]) {
// switch (i)
// {
// case MCP23018_ADDRESS:
// /* code */
// if (mcp23018_init() == ESP_OK) {
// foundDevices[i] = 2;
// }
// break;
// case INA260_ADDRESS:
// if (ina260_init() == ESP_OK) {
// foundDevices[i] = 2;
// }
// /* code */
// break;
// case CCS811_ADDRESS:
// if (ccs811_init() == ESP_OK) {
// foundDevices[i] = 2;
// }
// /* code */
// break;
// case MPU9250_ADDRESS:
// if (mpu9250_init() == ESP_OK) {
// foundDevices[i] = 2;
// }
// /* code */
// break;
// case BME680_ADDRESS:
// if (bme680b_init() == ESP_OK) {
// foundDevices[i] = 2;
// }
// /* code */
// break;
// default:
// break;
// }
// }
// }
// }
// }
void i2c_sensors_task(void *pvParameters)
{
memset(foundDevices, 0, sizeof(foundDevices));
memset(prevDevices, 0, sizeof(prevDevices));
bme680b_init();
mpu9250_init();
ccs811_init();
ina260_init();
// update_devices();
// init_connected();
// initialize the xLastWakeTime variable with the current time.
const int64_t interval_us = 100000; // 100 ms
int64_t start_time, end_time, elapsed;
@@ -23,11 +103,6 @@ void i2c_sensors_task(void *pvParameters)
//
// initialize i2c device configuration
bme680b_init();
mpu9250_init();
ina260_init();
ccs811_init();
mcp3550_spi_init();
configure_led();
@@ -97,16 +172,20 @@ void i2c_sensors_task(void *pvParameters)
ina260_readParams(&volts, &current, &power);
ina260_printParams(volts, current, power);
float VREFVoltage = volts * 1.25 / 1000; // Mame vobec nieco na VREFE? Na scheme su len medzi sebou prepojene
float VREFVoltage = 2.5;
mics_adc_data_t ADCData = mcp3550_read_all(5.0); // vref = 5.0V
log_mics_adc_values(&ADCData);
mics_adc_data_t ADCData;
memset(&ADCData, 0, sizeof(ADCData));
//mics_adc_data_t ADCData = mcp3550_read_all(VREFVoltage);
ADCData = mcp3550_read_all(VREFVoltage);
//log_mics_adc_values(&ADCData);
log_mics_adc_values(&ADCData);
int32_t nh3val = mcp3550_read(MCP_CS_ADC_NH3);
gpio_set_level(BLINK_GPIO, s_led_state);
ESP_LOGI(TAG_BME, "MICS NH3: %ld -> %fV", nh3val, mcp3550_to_voltage(nh3val, VREFVoltage));
//gpio_set_level(BLINK_GPIO, s_led_state);
mcp23018_set_pin(MCP23018_DEV_HANDLE, MCP_CS_ADC_UVC, s_led_state);
/* Toggle the LED state */
s_led_state = !s_led_state;
end_time = esp_timer_get_time();

View File

@@ -19,6 +19,8 @@
#include "esp_log.h"
extern uint8_t foundDevices[128];
extern uint8_t prevDevices[128];
void i2c_sensors_task(void *pvParameters);