54 lines
1.9 KiB
C
Executable File
54 lines
1.9 KiB
C
Executable File
#include <stdio.h>
|
|
#include <inttypes.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_check.h"
|
|
#include "wifi-connect.h"
|
|
#include "lvgl_st7735s_use.h"
|
|
#include "i2c_master_messager.h"
|
|
|
|
#define BOTANY_I2C_PORT I2C_NUM_0
|
|
#define BOTANY_I2C_SCL_GPIO GPIO_NUM_5
|
|
#define BOTANY_I2C_SDA_GPIO GPIO_NUM_4
|
|
#define BOTANY_READ_PERIOD_MS 1000
|
|
|
|
void app_main(void)
|
|
{
|
|
//初始化 Wi-Fi 配网组件,支持长按按键进入配网
|
|
ESP_ERROR_CHECK(wifi_connect_init());
|
|
printf("设备启动完成:长按按键进入配网模式,手机连接 ESP32-* 后访问 http://192.168.4.1\n");
|
|
|
|
// 启动 LVGL 演示程序,显示简单的界面
|
|
ESP_ERROR_CHECK(start_lvgl_demo());
|
|
|
|
i2c_master_messager_config_t i2c_cfg = {
|
|
.i2c_port = BOTANY_I2C_PORT,
|
|
.scl_io_num = BOTANY_I2C_SCL_GPIO,
|
|
.sda_io_num = BOTANY_I2C_SDA_GPIO,
|
|
.read_period_ms = BOTANY_READ_PERIOD_MS,
|
|
.bh1750_addr = 0x23,
|
|
.bh1750_mode = BH1750_CONTINUE_1LX_RES,
|
|
};
|
|
|
|
ESP_ERROR_CHECK(i2c_master_messager_init(&i2c_cfg));
|
|
ESP_ERROR_CHECK(i2c_master_messager_start());
|
|
|
|
for (;;)
|
|
{
|
|
i2c_master_messager_data_t sensor_data = {0};
|
|
if (i2c_master_messager_get_data(&sensor_data) == ESP_OK && sensor_data.bh1750.valid) {
|
|
char text[32] = {0};
|
|
snprintf(text, sizeof(text), "Light: %.1f lx", sensor_data.bh1750.lux);
|
|
ESP_ERROR_CHECK(lvgl_st7735s_set_center_text(text));
|
|
printf("[BH1750] lux=%.2f update_ms=%" PRId64 "\n",
|
|
sensor_data.bh1750.lux,
|
|
sensor_data.bh1750.last_update_ms);
|
|
} else {
|
|
ESP_ERROR_CHECK(lvgl_st7735s_set_center_text("Light: waiting..."));
|
|
printf("[BH1750] waiting data, err=0x%x\n", sensor_data.bh1750.last_error);
|
|
}
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
}
|
|
}
|