main.cpp
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <nvs_flash.h>
#include "display.h"
#include "https_request.h"
#include "stock.h"
#include "wifi.h"
//#include "esp_heap_trace.h"
//static heap_trace_record_t trace_record[200];
esp_err_t init_nvs() {
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
return ret;
}
void init() {
ESP_ERROR_CHECK(init_display());
ESP_ERROR_CHECK(init_nvs());
ESP_ERROR_CHECK(init_wifi());
ESP_ERROR_CHECK(init_https());
ESP_ERROR_CHECK(init_stock());
}
extern "C" void app_main() {
// TODO: Get internet with GUEST_WLAN
// TODO: Memory leak
const char* TAG = "app_main";
init();
ESP_LOGI(TAG, "Init finished");
ESP_ERROR_CHECK(connect_wifi(WIFI_SSID, WIFI_PASSWORD));
ESP_LOGI(TAG, "Wifi finished");
xTaskCreate(display_stock_task, "display_stock_task", 1024*4, NULL, configMAX_PRIORITIES-1, NULL);
xTaskCreate(fetch_stock_task, "fetch_stock_task", 1024*4, NULL, configMAX_PRIORITIES-1, NULL);
/*
ESP_ERROR_CHECK(heap_trace_init_standalone(trace_record, 200));
ESP_ERROR_CHECK(heap_trace_start(HEAP_TRACE_LEAKS));
int i = 1;
for(;;) {
ESP_LOGI("mem", "Free heap=%lu", esp_get_free_heap_size());
vTaskDelay(60000 / portTICK_PERIOD_MS);
if(--i == 0) {
ESP_ERROR_CHECK(heap_trace_stop());
heap_trace_dump();
}
}
*/
ESP_LOGI(TAG, "main task finished");
}