/* * SPDX-FileCopyrightText: 2022 Helmut Pozimski * * SPDX-License-Identifier: GPL-2.0-only */ #include #include #include #include #include #include #include #include "wifi.h" #include "configuration.h" #include "ds3231.h" #include "tm1637.h" #include "time_sync.h" #include "time_display.h" #include "alarm_task.h" #include "api.h" #include "storage.h" static void IRAM_ATTR gpio_interrupt_handler(void *args) { uint8_t* button_pressed_flag = (uint8_t*)args; *button_pressed_flag = 1; } static void init_peripherals(uint8_t* button_pressed_flag) { ESP_ERROR_CHECK(nvs_flash_init()); ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); wifi_init(); wifi_start(); ESP_ERROR_CHECK(storage_init("a1")); ds3231_init(DS3231_SDA_PIN, DS3231_SCL_PIN); tm1637_init(TM1637_CLK_PIN, TM1637_DIO_PIN, true, 1); esp_rom_gpio_pad_select_gpio(BUTTON_INTERRUPT_PIN); gpio_set_direction(BUTTON_INTERRUPT_PIN, GPIO_MODE_INPUT); gpio_pulldown_en(BUTTON_INTERRUPT_PIN); gpio_pullup_dis(BUTTON_INTERRUPT_PIN); gpio_set_intr_type(BUTTON_INTERRUPT_PIN, GPIO_INTR_POSEDGE); gpio_install_isr_service(0); gpio_isr_handler_add(BUTTON_INTERRUPT_PIN, gpio_interrupt_handler, (void*)button_pressed_flag); } void app_main(void) { static httpd_handle_t server; static uint8_t button_pressed_flag = 0; struct tm current_time; init_peripherals(); ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler, &server)); ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, &server)); server = start_webserver(); ds3231_read_date_time(¤t_time); sntp_start(21600); if (current_time.tm_year == 0) { await_sntp_sync(); } xTaskCreate(display_update_task, "display_update_task", 2048, NULL, 7, NULL); xTaskCreate(alarm_task, "alarm_task", 2048, (void*) &button_pressed_flag, 7, NULL); }