|
|
|
#include <sdkconfig.h>
|
|
|
|
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <console/console_ioimpl.h>
|
|
|
|
|
|
|
|
#include "esp_wifi.h"
|
|
|
|
#include "esp_event.h"
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include "esp_system.h"
|
|
|
|
#include "nvs_flash.h"
|
|
|
|
|
|
|
|
#include "driver/adc.h"
|
|
|
|
#include "application.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
#include "console/console_server.h"
|
|
|
|
|
|
|
|
#include "wifi_conn.h"
|
|
|
|
|
|
|
|
#include "console/register_cmds.h"
|
|
|
|
#include "mbiface.h"
|
|
|
|
#include "actuators.h"
|
|
|
|
#include "fancontrol.h"
|
|
|
|
#include "onewires.h"
|
|
|
|
|
|
|
|
static const char *TAG = "main";
|
|
|
|
|
|
|
|
void app_main(void) {
|
|
|
|
ESP_ERROR_CHECK(nvs_flash_init());
|
|
|
|
ESP_ERROR_CHECK(esp_register_shutdown_handler(cspemu_run_shutdown_handlers));
|
|
|
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
|
|
|
|
|
|
|
settings_init();
|
|
|
|
settings_load();
|
|
|
|
|
|
|
|
// do it ASAP so the fan maybe doesn't have time to start
|
|
|
|
onewires_setup();
|
|
|
|
act_init();
|
|
|
|
fancontrol_init();
|
|
|
|
|
|
|
|
// Start IDF service for pin change interrupts
|
|
|
|
ESP_ERROR_CHECK(gpio_install_isr_service(0));
|
|
|
|
|
|
|
|
ESP_LOGD(TAG, "initing netif");
|
|
|
|
ESP_ERROR_CHECK(esp_netif_init());
|
|
|
|
if (gSettings.wifi_enabled && (gSettings.sta_enabled || gSettings.ap_enabled)) {
|
|
|
|
initialise_wifi();
|
|
|
|
g_State.wifi_inited = true;
|
|
|
|
} else {
|
|
|
|
// initialise the bare minimum so wifi config can be changed
|
|
|
|
ESP_LOGD(TAG, "initing wifi");
|
|
|
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
|
|
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
|
|
|
|
|
|
|
ESP_LOGD(TAG, "set storage, set sta");
|
|
|
|
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH));
|
|
|
|
g_State.wifi_inited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
console_init(NULL);
|
|
|
|
register_console_commands();
|
|
|
|
|
|
|
|
console_setup_uart_stdio();
|
|
|
|
ESP_ERROR_CHECK(console_start_stdio(NULL, NULL));
|
|
|
|
|
|
|
|
mbiface_setup();
|
|
|
|
|
|
|
|
telnetsrv_start(CONSOLE_TELNET_PORT);
|
|
|
|
ESP_LOGI(TAG, "Startup finished, free heap = %u, cmds %"PRIu32, esp_get_free_heap_size(), console_count_commands());
|
|
|
|
}
|