#include #include #include #include #include #include "system.h" #include "wifi.h" #include "web.h" #include "mqtt.h" #include "ntp.h" #include "lux.h" #include #include "rboot-api.h" #define LED_PIN 2 #define SWITCH_PIN 2 #define vTaskDelayMs(ms) vTaskDelay((ms)/portTICK_PERIOD_MS) const gpio_inttype_t int_type = GPIO_INTTYPE_EDGE_NEG; time_t day_seconds(); void gpio_intr_handler(uint8_t gpio_num); void manual_switch(void); _Noreturn void buttonIntTask(void *pvParameters) { printf("Waiting for button press interrupt on gpio %d...\r\n", SWITCH_PIN); QueueHandle_t *tsqueue = (QueueHandle_t *) pvParameters; gpio_set_interrupt(SWITCH_PIN, int_type, gpio_intr_handler); uint32_t last = 0; while (1) { uint32_t button_ts; xQueueReceive(*tsqueue, &button_ts, portMAX_DELAY); button_ts *= portTICK_PERIOD_MS; if(last < button_ts-200) { manual_switch(); //printf("Button interrupt fired at %dms\r\n", button_ts); last = button_ts; } } } static QueueHandle_t tsqueue; void gpio_intr_handler(uint8_t gpio_num) { uint32_t now = xTaskGetTickCountFromISR(); xQueueSendToBackFromISR(tsqueue, &now, NULL); } void register_app(void); void user_init(void) { uart_set_baud(0, 115200); printf("SDK version: %s\n", sdk_system_get_sdk_version()); sdk_wifi_set_sleep_type(WIFI_SLEEP_MODEM); system_init_config(); wifi_available_semaphore = xSemaphoreCreateBinary(); wan_available_semaphore = xSemaphoreCreateBinary(); time_available_semaphore = xSemaphoreCreateBinary(); //gpio_enable(SWITCH_PIN, GPIO_INPUT); tsqueue = xQueueCreate(2, sizeof(uint32_t)); xTaskCreate(wifi_task, "wifi_task", 1024, NULL, 1, NULL); xTaskCreate(&httpd_task, "httpd_task", 2048, NULL, 2, NULL); //xTaskCreate(&lux_task, "lux_task", 512, NULL, 1, NULL); xTaskCreate(&sntp_task, "sntp_task", 512, NULL, 1, NULL); //xTaskCreate(buttonIntTask, "buttonIntTask", 256, &tsqueue, 2, NULL); register_app(); gpio_enable(LED_PIN, GPIO_OUTPUT); gpio_write(LED_PIN, true); /* rboot_config conf = rboot_get_config(); printf("\r\n\r\nOTA Basic demo.\r\nCurrently running on flash slot %d / %d.\r\n\r\n", conf.current_rom, conf.count); printf("Image addresses in flash:\r\n"); for (int i = 0; i < conf.count; i++) { printf("%c%d: offset 0x%08x\r\n", i == conf.current_rom ? '*' : ' ', i, conf.roms[i]); } printf("profit!\n"); */ }