Fri, 17 May 2019 15:39:05 +0200
Fixed css path in chart.html. Show errors in console when writing logfiles.json. Upgraded esp-idf.
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 |
42 | 24 | int Sub_Screen = 0; ///< Subscreen during mash |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
25 | bool System_TimeOk = false; ///< System time status |
39
e5900c9b9a7b
Use PROJECT_VER for version number. Updated README and info screen.
Michiel Broek <mbroek@mbse.eu>
parents:
38
diff
changeset
|
26 | const esp_app_desc_t *app_desc = NULL; |
0 | 27 | |
28 | ||
29 | void app_main() | |
30 | { | |
31 | int tempy; | |
32 | char temp[64]; | |
33 | ||
34 | ESP_LOGI(TAG, "Starting"); | |
35 | init_tft_display(); | |
36 | ||
37 | TFT_setFont(DEJAVU24_FONT, NULL); | |
38 | _fg = TFT_YELLOW; | |
39 | tempy = TFT_getfontheight() + 4; | |
39
e5900c9b9a7b
Use PROJECT_VER for version number. Updated README and info screen.
Michiel Broek <mbroek@mbse.eu>
parents:
38
diff
changeset
|
40 | app_desc = esp_ota_get_app_description(); |
e5900c9b9a7b
Use PROJECT_VER for version number. Updated README and info screen.
Michiel Broek <mbroek@mbse.eu>
parents:
38
diff
changeset
|
41 | sprintf(temp, "BrewBoard %s", app_desc->version); |
0 | 42 | TFT_print(temp, CENTER, 4); |
43 | ||
44 | TFT_setFont(DEJAVU18_FONT, NULL); | |
45 | _fg = TFT_CYAN; | |
46 | TFT_print("Mount /spiffs ", 0, LASTY+tempy); | |
47 | ESP_LOGI(TAG, "Initializing SPIFFS"); | |
48 | ||
49 | esp_vfs_spiffs_conf_t conf = { | |
50 | .base_path = "/spiffs", | |
51 | .partition_label = NULL, | |
52 | .max_files = 5, | |
53 | .format_if_mount_failed = true | |
54 | }; | |
55 | ||
56 | // Use settings defined above to initialize and mount SPIFFS filesystem. | |
57 | // Note: esp_vfs_spiffs_register is an all-in-one convenience function. | |
58 | esp_err_t ret = esp_vfs_spiffs_register(&conf); | |
59 | ||
60 | if (ret != ESP_OK) { | |
61 | if (ret == ESP_FAIL) { | |
62 | ESP_LOGE(TAG, "Failed to mount or format filesystem"); | |
63 | } else if (ret == ESP_ERR_NOT_FOUND) { | |
64 | ESP_LOGE(TAG, "Failed to find SPIFFS partition"); | |
65 | } else { | |
66 | ESP_LOGE(TAG, "Failed to initialize SPIFFS (%d)", ret); | |
67 | } | |
68 | _fg = TFT_RED; | |
69 | TFT_print("error\r\n", LASTX, LASTY); | |
70 | return; // Stop application. | |
71 | } | |
72 | ||
73 | size_t total = 0, used = 0; | |
74 | ret = esp_spiffs_info(NULL, &total, &used); | |
75 | if (ret != ESP_OK) { | |
76 | ESP_LOGE(TAG, "Failed to get SPIFFS partition information"); | |
77 | _fg = TFT_RED; | |
78 | TFT_print("error\r\n", LASTX, LASTY); | |
79 | return; // Stop application. | |
80 | } else { | |
81 | ESP_LOGI(TAG, "Partition size: %d, used: %d - %d%%", total, used, (used * 100) / total); | |
82 | } | |
83 | TFT_print("Ok\r\n", LASTX, LASTY); | |
84 | ||
85 | // Just to debug, list the /spiffs filesystem. | |
47
2aab3b5af4b5
Fixed css path in chart.html. Show errors in console when writing logfiles.json. Upgraded esp-idf.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
86 | #if 1 |
0 | 87 | DIR *dir = opendir("/spiffs"); |
88 | struct dirent* de = readdir(dir); | |
89 | while (de) { | |
90 | if (de->d_type == DT_REG) { | |
91 | printf("F "); | |
92 | } | |
93 | if (de->d_type == DT_DIR) { | |
94 | printf("D "); | |
95 | } | |
96 | printf("%s\n", de->d_name); | |
97 | de = readdir(dir); | |
98 | } | |
99 | closedir(dir); | |
100 | #endif | |
101 | ||
102 | /* | |
103 | * Read or create configuration | |
104 | */ | |
105 | TFT_print("Ophalen configuratie ", LASTX, LASTY); | |
106 | read_config(); | |
107 | read_equipment(config.EquipmentRec); | |
108 | read_runtime(); | |
109 | read_recipe(config.RecipeRec); | |
110 | TFT_print("Ok\r\n", LASTX, LASTY); | |
111 | ||
112 | // Set the Touchscreen calibration/ | |
113 | TS_set_calibration(config.ts_xleft, config.ts_xright, config.ts_ytop, config.ts_ybottom); | |
114 | ||
115 | /* | |
116 | * TZ names don't work, so set the TZ the hard way. | |
117 | * This is the setting for Europe/Amsterdam. | |
118 | */ | |
119 | setenv("TZ", "CET-01CEST-02,M3.4.0,M10.4.0", 1); | |
120 | tzset(); | |
121 | ||
122 | xSemaphoreDS18B20 = xSemaphoreCreateMutex(); | |
123 | xSemaphoreDriver = xSemaphoreCreateMutex(); | |
124 | ||
125 | TFT_print("Starten taken ", LASTX, LASTY); | |
126 | xTaskCreate(&task_tft, "task_tft", 6144, NULL, 4, &xTaskTFT); | |
127 | vTaskDelay(400 / portTICK_PERIOD_MS); | |
128 | xTaskCreate(&task_ds18b20, "task_ds18b20", 2560, NULL, 8, &xTaskDS18B20); | |
129 | 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
|
130 | xTaskCreate(&task_sound, "task_sound", 2048, NULL,15, &xTaskSound); |
0 | 131 | 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
|
132 | /* 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
|
133 | esp_log_level_set("wifi", ESP_LOG_ERROR); |
0 | 134 | xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi); |
135 | TFT_print(" Ok\r\nConnecting ", LASTX, LASTY); | |
136 | ||
137 | int wait = 20; | |
138 | while (wait) { | |
139 | vTaskDelay(500 / portTICK_PERIOD_MS); | |
140 | TFT_print(".", LASTX, LASTY); | |
141 | 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
|
142 | if (wifi_state->STA_online == true) |
0 | 143 | wait = 0; |
144 | else | |
145 | wait--; | |
146 | xSemaphoreGive(xSemaphoreWiFi); | |
147 | } | |
148 | } | |
149 | TFT_print(" Ok\r\n", LASTX, LASTY); | |
150 | SoundPlay(SOUND_StartUp); | |
151 | ||
152 | /* Do not write to the TFT during VNC startup to avoid race conditions */ | |
38
537ffe280775
Removed the noVNC code and web pages.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
153 | // VncStartup(); |
0 | 154 | start_http_websocket(); |
155 | 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
|
156 | Main_Screen = MAIN_MODE_FREE; |
0 | 157 | |
158 | // static char cBuffer[ 1024 ]; | |
159 | ||
160 | /* | |
161 | * Main application loop. | |
162 | */ | |
163 | while (1) { | |
164 | vTaskDelay(20000 / portTICK_PERIOD_MS); | |
165 | ||
166 | // vTaskList( cBuffer ); | |
167 | // printf("Name State Prio Stack Num\n"); | |
168 | // printf("--------------- ------- ------- ------- -------\n"); | |
169 | // printf("%s\n", cBuffer); | |
170 | } | |
171 | // Not reached. | |
172 | } | |
173 |