You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.5 KiB
133 lines
3.5 KiB
/* Hello World Example
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <web/websrv.h>
|
|
#include <esp_wifi.h>
|
|
#include <esp_log.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_system.h"
|
|
#include "esp_spi_flash.h"
|
|
#include "graphics/nokia.h"
|
|
#include "knob.h"
|
|
#include "gui.h"
|
|
#include "analog.h"
|
|
#include "utils.h"
|
|
#include "esp_event_loop.h"
|
|
#include "nvs_flash.h"
|
|
#include "firehazard.h"
|
|
|
|
/**
|
|
* Application event handler
|
|
*
|
|
* @param ctx - ignored, context passed to esp_event_loop_init()
|
|
* @param event
|
|
* @return success
|
|
*/
|
|
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
|
{
|
|
switch (event->event_id) {
|
|
case SYSTEM_EVENT_STA_START:
|
|
try_reconn_if_have_wifi_creds();
|
|
break;
|
|
|
|
case SYSTEM_EVENT_STA_CONNECTED:
|
|
// we should get an IP address soon
|
|
break;
|
|
|
|
case SYSTEM_EVENT_STA_GOT_IP:
|
|
// xEventGroupSetBits(g_wifi_event_group, EG_WIFI_CONNECTED_BIT);
|
|
break;
|
|
|
|
case SYSTEM_EVENT_STA_DISCONNECTED:
|
|
// xEventGroupClearBits(g_wifi_event_group, EG_WIFI_CONNECTED_BIT);
|
|
try_reconn_if_have_wifi_creds();
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// dhcp_watchdog_notify(dhcp_wd, event->event_id);
|
|
|
|
return ESP_OK;
|
|
}
|
|
|
|
|
|
/**
|
|
* Initialize WiFi in station mode, try to connect if settings are stored.
|
|
* Set up WiFi event group & start related tasks
|
|
*/
|
|
static void initialise_wifi(void)
|
|
{
|
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
|
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH));
|
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
|
|
|
ESP_ERROR_CHECK(esp_wifi_start());
|
|
}
|
|
|
|
|
|
void __attribute__((noreturn)) app_main()
|
|
{
|
|
// Initialize NVS
|
|
esp_err_t err = nvs_flash_init();
|
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
// NVS partition was truncated and needs to be erased
|
|
// Retry nvs_flash_init
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
err = nvs_flash_init();
|
|
}
|
|
ESP_ERROR_CHECK( err );
|
|
|
|
|
|
//ESP_ERROR_CHECK(esp_register_shutdown_handler(cspemu_run_shutdown_handlers));
|
|
|
|
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
|
|
|
gpio_config_t output = {
|
|
.pin_bit_mask = (1<<22),
|
|
.mode = GPIO_MODE_OUTPUT
|
|
};
|
|
gpio_config(&output);
|
|
|
|
tcpip_adapter_init();
|
|
initialise_wifi();
|
|
|
|
#if 0
|
|
// TODO add proper join procedure
|
|
const char *ssid = "Chlivek_2.4G";
|
|
const char *pass = "slepice123";
|
|
wifi_config_t wifi_config = {};
|
|
strncpy((char*) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
|
|
if (pass) {
|
|
strncpy((char*) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
|
|
}
|
|
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
|
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
|
|
ESP_ERROR_CHECK( esp_wifi_disconnect() );
|
|
ESP_ERROR_CHECK( esp_wifi_connect() );
|
|
#endif
|
|
|
|
gui_init();
|
|
knob_init();
|
|
analog_init();
|
|
|
|
try_reconn_if_have_wifi_creds();
|
|
websrv_init();
|
|
fire_init();
|
|
|
|
bool level = 0;
|
|
while (1) {
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
gpio_set_level(22, level);
|
|
level ^= 1;
|
|
}
|
|
}
|
|
|