2021-08-08 20:59:15 +00:00
|
|
|
#include <esp8266.h>
|
|
|
|
#include <esp/uart.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <FreeRTOS.h>
|
|
|
|
#include <task.h>
|
|
|
|
|
2021-07-09 19:35:41 +00:00
|
|
|
#include "system.h"
|
2021-07-02 16:45:29 +00:00
|
|
|
#include "wifi.h"
|
|
|
|
#include "web.h"
|
|
|
|
#include "mqtt.h"
|
2021-11-16 19:19:02 +00:00
|
|
|
#include "ntp.h"
|
2021-07-02 16:45:29 +00:00
|
|
|
#include "lux.h"
|
2021-06-19 14:42:38 +00:00
|
|
|
|
2021-07-09 19:42:44 +00:00
|
|
|
#include <espressif/esp_common.h>
|
2021-06-19 14:42:38 +00:00
|
|
|
|
2021-07-23 22:40:45 +00:00
|
|
|
#include "rboot-api.h"
|
|
|
|
|
2021-08-08 20:59:15 +00:00
|
|
|
#define LED_PIN 2
|
|
|
|
#define SWITCH_PIN 2
|
|
|
|
|
|
|
|
|
2021-11-03 18:14:18 +00:00
|
|
|
#define vTaskDelayMs(ms) vTaskDelay((ms)/portTICK_PERIOD_MS)
|
2021-08-08 20:59:15 +00:00
|
|
|
|
|
|
|
const gpio_inttype_t int_type = GPIO_INTTYPE_EDGE_NEG;
|
|
|
|
|
2021-11-03 18:14:18 +00:00
|
|
|
time_t day_seconds();
|
2021-08-08 20:59:15 +00:00
|
|
|
|
|
|
|
void gpio_intr_handler(uint8_t gpio_num);
|
|
|
|
|
|
|
|
void manual_switch(void);
|
|
|
|
|
2021-11-17 23:09:40 +00:00
|
|
|
_Noreturn void buttonIntTask(void *pvParameters) {
|
2021-08-08 20:59:15 +00:00
|
|
|
printf("Waiting for button press interrupt on gpio %d...\r\n", SWITCH_PIN);
|
2021-11-17 23:09:40 +00:00
|
|
|
QueueHandle_t *tsqueue = (QueueHandle_t *) pvParameters;
|
2021-08-08 20:59:15 +00:00
|
|
|
gpio_set_interrupt(SWITCH_PIN, int_type, gpio_intr_handler);
|
|
|
|
|
|
|
|
uint32_t last = 0;
|
2021-11-17 23:09:40 +00:00
|
|
|
while (1) {
|
2021-08-08 20:59:15 +00:00
|
|
|
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);
|
|
|
|
|
2021-11-03 18:14:18 +00:00
|
|
|
void user_init(void) {
|
2021-08-08 20:59:15 +00:00
|
|
|
uart_set_baud(0, 115200);
|
2021-11-03 18:14:18 +00:00
|
|
|
printf("SDK version: %s\n", sdk_system_get_sdk_version());
|
2021-08-08 20:59:15 +00:00
|
|
|
|
2021-11-03 18:14:18 +00:00
|
|
|
sdk_wifi_set_sleep_type(WIFI_SLEEP_MODEM);
|
2021-08-08 20:59:15 +00:00
|
|
|
|
2021-11-03 18:14:18 +00:00
|
|
|
system_init_config();
|
2021-08-08 20:59:15 +00:00
|
|
|
|
2021-11-03 18:14:18 +00:00
|
|
|
wifi_available_semaphore = xSemaphoreCreateBinary();
|
2021-11-16 19:19:02 +00:00
|
|
|
wan_available_semaphore = xSemaphoreCreateBinary();
|
2021-11-03 18:14:18 +00:00
|
|
|
time_available_semaphore = xSemaphoreCreateBinary();
|
2021-08-08 20:59:15 +00:00
|
|
|
|
2021-11-16 19:19:02 +00:00
|
|
|
//gpio_enable(SWITCH_PIN, GPIO_INPUT);
|
2021-08-08 20:59:15 +00:00
|
|
|
|
|
|
|
tsqueue = xQueueCreate(2, sizeof(uint32_t));
|
|
|
|
|
2021-11-03 18:14:18 +00:00
|
|
|
xTaskCreate(wifi_task, "wifi_task", 1024, NULL, 1, NULL);
|
2021-06-19 14:42:38 +00:00
|
|
|
|
2021-11-16 19:19:02 +00:00
|
|
|
xTaskCreate(&httpd_task, "httpd_task", 2048, NULL, 2, NULL);
|
2021-07-09 19:42:44 +00:00
|
|
|
|
2021-11-16 19:19:02 +00:00
|
|
|
xTaskCreate(&lux_task, "lux_task", 512, NULL, 1, NULL);
|
2021-07-18 22:18:16 +00:00
|
|
|
|
2021-11-16 19:19:02 +00:00
|
|
|
xTaskCreate(&sntp_task, "sntp_task", 512, NULL, 1, NULL);
|
2021-07-09 19:42:44 +00:00
|
|
|
|
2021-11-03 18:14:18 +00:00
|
|
|
//xTaskCreate(buttonIntTask, "buttonIntTask", 256, &tsqueue, 2, NULL);
|
2021-07-19 20:31:30 +00:00
|
|
|
|
2021-11-03 18:14:18 +00:00
|
|
|
register_app();
|
2021-07-23 22:40:45 +00:00
|
|
|
|
2021-11-03 18:14:18 +00:00
|
|
|
gpio_enable(LED_PIN, GPIO_OUTPUT);
|
|
|
|
gpio_write(LED_PIN, true);
|
2021-11-16 19:19:02 +00:00
|
|
|
|
|
|
|
/*
|
2021-07-23 22:40:45 +00:00
|
|
|
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");
|
2021-11-03 18:14:18 +00:00
|
|
|
for (int i = 0; i < conf.count; i++) {
|
|
|
|
printf("%c%d: offset 0x%08x\r\n", i == conf.current_rom ? '*' : ' ', i, conf.roms[i]);
|
2021-07-23 22:40:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("profit!\n");
|
2021-11-16 19:19:02 +00:00
|
|
|
*/
|
2021-06-19 14:42:38 +00:00
|
|
|
}
|