#include "ambient_light.c" #include "driver/i2c.h" #include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "light.c" #include "mqtt.c" #include "sdkconfig.h" #include "wifi.c" #define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */ #define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */ #define I2C_MASTER_SDA_IO CONFIG_I2C_SDA #define I2C_MASTER_SCL_IO CONFIG_I2C_SCL #define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */ #define I2C_MASTER_NUM CONFIG_I2C_NUM #include "embedded_display.c" #include "temperature.c" void init_i2c() { int i2c_master_port = I2C_MASTER_NUM; i2c_config_t conf = { .mode = I2C_MODE_MASTER, .sda_io_num = I2C_MASTER_SDA_IO, .scl_io_num = I2C_MASTER_SCL_IO, .sda_pullup_en = GPIO_PULLUP_ENABLE, .scl_pullup_en = GPIO_PULLUP_ENABLE, .master.clk_speed = I2C_MASTER_FREQ_HZ, }; i2c_param_config(i2c_master_port, &conf); ESP_LOGI("I2C", "Enabling I2C"); ESP_ERROR_CHECK(i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0)); ESP_LOGI("SCR", "I2C initialized successfully"); } static const char *TAG = "DisplayAmbientLight"; void app_main(void) { light_init_strip(); init_i2c(); init_display(); display_print8_str(0, 0, "Ambient Light"); ambient_light_init(); ambient_light_auto_fetch(); auto_fetch_temperature(); init_ui(); xTaskCreate(publish_ui_input, "ui_input_event", 2048, NULL, 10, NULL); vTaskDelay(pdMS_TO_TICKS(10)); light_play(light_mode_connection_wifi); if (connect_wifi()) { light_play(light_mode_idle); } vTaskDelay(pdMS_TO_TICKS(1000)); mqtt_app_start(); if (waiting_for_mqtt_connected()) { light_play(light_mode_mqtt_connected); } if (waiting_for_desktop_online()) { light_play(light_mode_desktop_online); } while (waiting_and_get_colors()) { light_play_colors(NUMBER_OF_LEDS * 3, mqtt_colors_buffer); } }