123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /*
- * SPDX-FileCopyrightText: 2022 Helmut Pozimski <helmut@pozimski.eu>
- *
- * SPDX-License-Identifier: GPL-2.0-only
- */
- #include <time.h>
- #include <freertos/FreeRTOS.h>
- #include <freertos/event_groups.h>
- #include <driver/gpio.h>
- #include <nvs_flash.h>
- #include <esp_log.h>
- #include <esp_wifi.h>
- #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);
- }
|