Sat, 27 Oct 2018 16:18:31 +0200
Screen startup a bit later. Decreased task sound stack size.
0 | 1 | /* BrewVoard |
2 | ||
3 | */ | |
4 | ||
5 | #include "config.h" | |
6 | ||
7 | ||
8 | static const char *TAG = "brewboard"; | |
9 | ||
10 | static TaskHandle_t xTaskTFT = NULL; | |
11 | static TaskHandle_t xTaskDS18B20 = NULL; | |
12 | static TaskHandle_t xTaskDriver = NULL; | |
13 | static TaskHandle_t xTaskSound = NULL; | |
14 | static TaskHandle_t xTaskSDcard = NULL; | |
15 | static TaskHandle_t xTaskWifi = NULL; | |
16 | ||
17 | extern SemaphoreHandle_t xSemaphoreDS18B20; | |
18 | extern SemaphoreHandle_t xSemaphoreDriver; | |
19 | extern SemaphoreHandle_t xSemaphoreWiFi; | |
20 | extern WIFI_State *wifi_state; | |
21 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
22 | int Main_Screen = MAIN_MODE_UNKNOWN; ///< Screen number |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
23 | int Old_Screen = MAIN_MODE_UNKNOWN; ///< Previous screen number |
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
24 | bool System_TimeOk = false; ///< System time status |
0 | 25 | |
26 | ||
27 | ||
28 | void app_main() | |
29 | { | |
30 | int tempy; | |
31 | char temp[64]; | |
32 | ||
33 | ESP_LOGI(TAG, "Starting"); | |
34 | init_tft_display(); | |
35 | ||
36 | TFT_setFont(DEJAVU24_FONT, NULL); | |
37 | _fg = TFT_YELLOW; | |
38 | tempy = TFT_getfontheight() + 4; | |
39 | sprintf(temp, "BrewBoard %s", VERSION); | |
40 | TFT_print(temp, CENTER, 4); | |
41 | ||
42 | TFT_setFont(DEJAVU18_FONT, NULL); | |
43 | _fg = TFT_CYAN; | |
44 | TFT_print("Mount /spiffs ", 0, LASTY+tempy); | |
45 | ESP_LOGI(TAG, "Initializing SPIFFS"); | |
46 | ||
47 | esp_vfs_spiffs_conf_t conf = { | |
48 | .base_path = "/spiffs", | |
49 | .partition_label = NULL, | |
50 | .max_files = 5, | |
51 | .format_if_mount_failed = true | |
52 | }; | |
53 | ||
54 | // Use settings defined above to initialize and mount SPIFFS filesystem. | |
55 | // Note: esp_vfs_spiffs_register is an all-in-one convenience function. | |
56 | esp_err_t ret = esp_vfs_spiffs_register(&conf); | |
57 | ||
58 | if (ret != ESP_OK) { | |
59 | if (ret == ESP_FAIL) { | |
60 | ESP_LOGE(TAG, "Failed to mount or format filesystem"); | |
61 | } else if (ret == ESP_ERR_NOT_FOUND) { | |
62 | ESP_LOGE(TAG, "Failed to find SPIFFS partition"); | |
63 | } else { | |
64 | ESP_LOGE(TAG, "Failed to initialize SPIFFS (%d)", ret); | |
65 | } | |
66 | _fg = TFT_RED; | |
67 | TFT_print("error\r\n", LASTX, LASTY); | |
68 | return; // Stop application. | |
69 | } | |
70 | ||
71 | size_t total = 0, used = 0; | |
72 | ret = esp_spiffs_info(NULL, &total, &used); | |
73 | if (ret != ESP_OK) { | |
74 | ESP_LOGE(TAG, "Failed to get SPIFFS partition information"); | |
75 | _fg = TFT_RED; | |
76 | TFT_print("error\r\n", LASTX, LASTY); | |
77 | return; // Stop application. | |
78 | } else { | |
79 | ESP_LOGI(TAG, "Partition size: %d, used: %d - %d%%", total, used, (used * 100) / total); | |
80 | } | |
81 | TFT_print("Ok\r\n", LASTX, LASTY); | |
82 | ||
83 | // Just to debug, list the /spiffs filesystem. | |
22
90f22a101fc6
Boot now checks got IP status before installing the http and vnc servers.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
84 | #if 0 |
0 | 85 | DIR *dir = opendir("/spiffs"); |
86 | struct dirent* de = readdir(dir); | |
87 | while (de) { | |
88 | if (de->d_type == DT_REG) { | |
89 | printf("F "); | |
90 | } | |
91 | if (de->d_type == DT_DIR) { | |
92 | printf("D "); | |
93 | } | |
94 | printf("%s\n", de->d_name); | |
95 | de = readdir(dir); | |
96 | } | |
97 | closedir(dir); | |
98 | #endif | |
99 | ||
100 | /* | |
101 | * Read or create configuration | |
102 | */ | |
103 | TFT_print("Ophalen configuratie ", LASTX, LASTY); | |
104 | read_config(); | |
105 | read_equipment(config.EquipmentRec); | |
106 | read_runtime(); | |
107 | read_recipe(config.RecipeRec); | |
108 | TFT_print("Ok\r\n", LASTX, LASTY); | |
109 | ||
110 | // Set the Touchscreen calibration/ | |
111 | TS_set_calibration(config.ts_xleft, config.ts_xright, config.ts_ytop, config.ts_ybottom); | |
112 | ||
113 | /* | |
114 | * TZ names don't work, so set the TZ the hard way. | |
115 | * This is the setting for Europe/Amsterdam. | |
116 | */ | |
117 | setenv("TZ", "CET-01CEST-02,M3.4.0,M10.4.0", 1); | |
118 | tzset(); | |
119 | ||
120 | xSemaphoreDS18B20 = xSemaphoreCreateMutex(); | |
121 | xSemaphoreDriver = xSemaphoreCreateMutex(); | |
122 | ||
123 | TFT_print("Starten taken ", LASTX, LASTY); | |
124 | xTaskCreate(&task_tft, "task_tft", 6144, NULL, 4, &xTaskTFT); | |
125 | vTaskDelay(400 / portTICK_PERIOD_MS); | |
126 | xTaskCreate(&task_ds18b20, "task_ds18b20", 2560, NULL, 8, &xTaskDS18B20); | |
127 | xTaskCreate(&task_driver, "task_driver", 2560, NULL, 8, &xTaskDriver); | |
23
0a1c1a8324a3
Screen startup a bit later. Decreased task sound stack size.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
128 | xTaskCreate(&task_sound, "task_sound", 2048, NULL,15, &xTaskSound); |
0 | 129 | xTaskCreate(&task_sdcard, "task_sdcard", 8192, NULL,10, &xTaskSDcard); |
6
e84200edc852
Updated esp-ide. Removed VNC server corre encoding because no clients would use it. Enabled WiFi error logmessages. Write runtime record is now debug logging. Removed recipe.Record number, not usefull and was wrong too. Removed console print of json log data.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
130 | /* lower the wifi logging level */ |
e84200edc852
Updated esp-ide. Removed VNC server corre encoding because no clients would use it. Enabled WiFi error logmessages. Write runtime record is now debug logging. Removed recipe.Record number, not usefull and was wrong too. Removed console print of json log data.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
131 | esp_log_level_set("wifi", ESP_LOG_ERROR); |
0 | 132 | xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi); |
133 | TFT_print(" Ok\r\nConnecting ", LASTX, LASTY); | |
134 | ||
135 | int wait = 20; | |
136 | while (wait) { | |
137 | vTaskDelay(500 / portTICK_PERIOD_MS); | |
138 | TFT_print(".", LASTX, LASTY); | |
139 | if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { | |
22
90f22a101fc6
Boot now checks got IP status before installing the http and vnc servers.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
140 | if (wifi_state->STA_online == true) |
0 | 141 | wait = 0; |
142 | else | |
143 | wait--; | |
144 | xSemaphoreGive(xSemaphoreWiFi); | |
145 | } | |
146 | } | |
147 | TFT_print(" Ok\r\n", LASTX, LASTY); | |
148 | SoundPlay(SOUND_StartUp); | |
149 | ||
150 | /* Do not write to the TFT during VNC startup to avoid race conditions */ | |
151 | VncStartup(); | |
152 | start_http_websocket(); | |
153 | vTaskDelay(1000 / portTICK_PERIOD_MS); | |
23
0a1c1a8324a3
Screen startup a bit later. Decreased task sound stack size.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
154 | Main_Screen = MAIN_MODE_FREE; |
0 | 155 | |
156 | // static char cBuffer[ 1024 ]; | |
157 | ||
158 | /* | |
159 | * Main application loop. | |
160 | */ | |
161 | while (1) { | |
162 | vTaskDelay(20000 / portTICK_PERIOD_MS); | |
163 | ||
164 | // vTaskList( cBuffer ); | |
165 | // printf("Name State Prio Stack Num\n"); | |
166 | // printf("--------------- ------- ------- ------- -------\n"); | |
167 | // printf("%s\n", cBuffer); | |
168 | } | |
169 | // Not reached. | |
170 | } | |
171 |