Thu, 04 Jul 2019 21:48:53 +0200
Version 0.3.4
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; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
46 | TFT_print((char *)"Mount /spiffs ", 0, LASTY+tempy); |
0 | 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; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
69 | TFT_print((char *)"error\r\n", LASTX, LASTY); |
0 | 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; | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
78 | TFT_print((char *)"error\r\n", LASTX, LASTY); |
0 | 79 | return; // Stop application. |
80 | } else { | |
81 | ESP_LOGI(TAG, "Partition size: %d, used: %d - %d%%", total, used, (used * 100) / total); | |
82 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
83 | TFT_print((char *)"Ok\r\n", LASTX, LASTY); |
0 | 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 | */ | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
105 | TFT_print((char *)"Ophalen configuratie ", LASTX, LASTY); |
0 | 106 | read_config(); |
107 | read_equipment(config.EquipmentRec); | |
108 | read_runtime(); | |
109 | read_recipe(config.RecipeRec); | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
110 | TFT_print((char *)"Ok\r\n", LASTX, LASTY); |
0 | 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 | ||
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
125 | TFT_print((char *)"Starten taken ", LASTX, LASTY); |
0 | 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); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
135 | TFT_print((char *)" Ok\r\nConnecting ", LASTX, LASTY); |
0 | 136 | |
137 | int wait = 20; | |
138 | while (wait) { | |
53
cf91a3a20d0d
Version 0.3.2, if WiFi connection is lost or AP is not available at startup, scan form another known AP and connect to that AP.
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
139 | vTaskDelay(750 / portTICK_PERIOD_MS); |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
140 | TFT_print((char *)".", LASTX, LASTY); |
0 | 141 | if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { |
53
cf91a3a20d0d
Version 0.3.2, if WiFi connection is lost or AP is not available at startup, scan form another known AP and connect to that AP.
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
142 | if (wifi_state->STA_connected == true) |
0 | 143 | wait = 0; |
144 | else | |
145 | wait--; | |
146 | xSemaphoreGive(xSemaphoreWiFi); | |
147 | } | |
148 | } | |
54
7b134c27fadb
Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
149 | TFT_print((char *)" Ok\r\n", LASTX, LASTY); |
0 | 150 | SoundPlay(SOUND_StartUp); |
151 | ||
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 |