main/brewboard.c

changeset 0
b74b0e4902c3
child 1
ad2c8b13eb88
equal deleted inserted replaced
-1:000000000000 0:b74b0e4902c3
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
22
23 int Main_Screen = MAIN_MODE_UNKNOWN;
24 int Old_Screen = MAIN_MODE_UNKNOWN;
25 bool System_TimeOk = false;
26
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;
40 sprintf(temp, "BrewBoard %s", VERSION);
41 TFT_print(temp, CENTER, 4);
42
43 TFT_setFont(DEJAVU18_FONT, NULL);
44 _fg = TFT_CYAN;
45 TFT_print("Mount /spiffs ", 0, LASTY+tempy);
46 ESP_LOGI(TAG, "Initializing SPIFFS");
47
48 esp_vfs_spiffs_conf_t conf = {
49 .base_path = "/spiffs",
50 .partition_label = NULL,
51 .max_files = 5,
52 .format_if_mount_failed = true
53 };
54
55 // Use settings defined above to initialize and mount SPIFFS filesystem.
56 // Note: esp_vfs_spiffs_register is an all-in-one convenience function.
57 esp_err_t ret = esp_vfs_spiffs_register(&conf);
58
59 if (ret != ESP_OK) {
60 if (ret == ESP_FAIL) {
61 ESP_LOGE(TAG, "Failed to mount or format filesystem");
62 } else if (ret == ESP_ERR_NOT_FOUND) {
63 ESP_LOGE(TAG, "Failed to find SPIFFS partition");
64 } else {
65 ESP_LOGE(TAG, "Failed to initialize SPIFFS (%d)", ret);
66 }
67 _fg = TFT_RED;
68 TFT_print("error\r\n", LASTX, LASTY);
69 return; // Stop application.
70 }
71
72 size_t total = 0, used = 0;
73 ret = esp_spiffs_info(NULL, &total, &used);
74 if (ret != ESP_OK) {
75 ESP_LOGE(TAG, "Failed to get SPIFFS partition information");
76 _fg = TFT_RED;
77 TFT_print("error\r\n", LASTX, LASTY);
78 return; // Stop application.
79 } else {
80 ESP_LOGI(TAG, "Partition size: %d, used: %d - %d%%", total, used, (used * 100) / total);
81 }
82 TFT_print("Ok\r\n", LASTX, LASTY);
83
84 // Just to debug, list the /spiffs filesystem.
85 #if 1
86 DIR *dir = opendir("/spiffs");
87 struct dirent* de = readdir(dir);
88 while (de) {
89 if (de->d_type == DT_REG) {
90 printf("F ");
91 }
92 if (de->d_type == DT_DIR) {
93 printf("D ");
94 }
95 printf("%s\n", de->d_name);
96 de = readdir(dir);
97 }
98 closedir(dir);
99 #endif
100
101 /*
102 * Read or create configuration
103 */
104 TFT_print("Ophalen configuratie ", LASTX, LASTY);
105 read_config();
106 read_equipment(config.EquipmentRec);
107 read_runtime();
108 // unlink("/spiffs/etc/recipe.conf");
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);
130 xTaskCreate(&task_sound, "task_sound", 3072, NULL,15, &xTaskSound);
131 xTaskCreate(&task_sdcard, "task_sdcard", 8192, NULL,10, &xTaskSDcard);
132 /* disable the default wifi logging */
133 esp_log_level_set("wifi", ESP_LOG_NONE);
134 xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi);
135 // Task for MQTT
136 TFT_print(" Ok\r\nConnecting ", LASTX, LASTY);
137
138 int wait = 20;
139 while (wait) {
140 vTaskDelay(500 / portTICK_PERIOD_MS);
141 TFT_print(".", LASTX, LASTY);
142 if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) {
143 if (wifi_state->STA_connected == true)
144 wait = 0;
145 else
146 wait--;
147 xSemaphoreGive(xSemaphoreWiFi);
148 }
149 }
150
151 Main_Screen = MAIN_MODE_FREE;
152 TFT_print(" Ok\r\n", LASTX, LASTY);
153 SoundPlay(SOUND_StartUp);
154
155 /* Do not write to the TFT during VNC startup to avoid race conditions */
156 VncStartup();
157 start_http_websocket();
158 vTaskDelay(1000 / portTICK_PERIOD_MS);
159
160 /*
161 * A small useless delay
162 */
163 vTaskDelay(1000 / portTICK_PERIOD_MS);
164
165 // static char cBuffer[ 1024 ];
166
167 /*
168 * Main application loop.
169 */
170 while (1) {
171 vTaskDelay(20000 / portTICK_PERIOD_MS);
172
173 // vTaskList( cBuffer );
174 // printf("Name State Prio Stack Num\n");
175 // printf("--------------- ------- ------- ------- -------\n");
176 // printf("%s\n", cBuffer);
177 }
178 // Not reached.
179 }
180

mercurial