board/main/main.c

71 lines
2.0 KiB
C
Raw Normal View History

#include "ambient_light.c"
#include "driver/i2c.h"
2022-11-12 22:33:03 +08:00
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
2022-11-13 17:05:41 +08:00
#include "light.c"
#include "mqtt.c"
2022-11-12 22:33:03 +08:00
#include "sdkconfig.h"
2022-11-12 22:42:03 +08:00
#include "wifi.c"
2022-11-12 22:33:03 +08:00
#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";
2022-11-12 22:33:03 +08:00
void app_main(void) {
2022-11-13 17:05:41 +08:00
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);
2022-11-13 17:05:41 +08:00
vTaskDelay(pdMS_TO_TICKS(10));
light_play(light_mode_connection_wifi);
if (connect_wifi()) {
light_play(light_mode_idle);
2022-11-12 22:33:03 +08:00
}
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);
}
2022-11-22 20:08:11 +08:00
while (waiting_and_get_colors()) {
light_play_colors(NUMBER_OF_LEDS * 3, mqtt_colors_buffer);
}
2022-11-12 22:33:03 +08:00
}