Fri, 28 Jun 2024 15:33:24 +0200
Fixed changing runtime datarecord size during switching between IDF 4.2 and 5.1. Fixed wiping the /spiffs filesystem. The directory listing from the SD card doesn't overwrite parts of the screen anymore. Solved the slow speed issue with the SD card. Try to force the SD card to operate at 20 MHz. More project settings changed to improve performance and memory usage.
/* BrewVoard */ #include "config.h" static const char *TAG = "brewboard"; static TaskHandle_t xTaskTFT = NULL; static TaskHandle_t xTaskDS18B20 = NULL; static TaskHandle_t xTaskDriver = NULL; static TaskHandle_t xTaskSound = NULL; static TaskHandle_t xTaskSDcard = NULL; static TaskHandle_t xTaskWifi = NULL; extern SemaphoreHandle_t xSemaphoreDS18B20; extern SemaphoreHandle_t xSemaphoreDriver; extern SemaphoreHandle_t xSemaphoreWiFi; extern WIFI_State *wifi_state; extern my_config_t config; int Main_Screen = MAIN_MODE_UNKNOWN; ///< Screen number int Old_Screen = MAIN_MODE_UNKNOWN; ///< Previous screen number int Sub_Screen = 0; ///< Subscreen during mash bool System_TimeOk = false; ///< System time status const esp_app_desc_t *app_desc = NULL; void app_main() { int tempy; char temp[64]; esp_err_t ret; ESP_LOGI(TAG, "Starting"); init_tft_display(); TFT_setFont(DEJAVU24_FONT, NULL); _fg = TFT_YELLOW; tempy = TFT_getfontheight() + 4; app_desc = esp_app_get_description(); sprintf(temp, "BrewBoard %s", app_desc->version); TFT_print(temp, CENTER, 4); /* * Initialize NVS */ 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(); } ESP_ERROR_CHECK(ret); TFT_setFont(DEJAVU18_FONT, NULL); _fg = TFT_CYAN; TFT_print((char *)"Mount /spiffs ", 0, LASTY+tempy); ESP_LOGD(TAG, "Initializing SPIFFS"); esp_vfs_spiffs_conf_t conf = { .base_path = "/spiffs", .partition_label = NULL, .max_files = 5, .format_if_mount_failed = true }; /* * Use settings defined above to initialize and mount SPIFFS filesystem. * Note: esp_vfs_spiffs_register is an all-in-one convenience function. */ ret = esp_vfs_spiffs_register(&conf); if (ret != ESP_OK) { if (ret == ESP_FAIL) { ESP_LOGE(TAG, "Failed to mount or format filesystem"); } else if (ret == ESP_ERR_NOT_FOUND) { ESP_LOGE(TAG, "Failed to find SPIFFS partition"); } else { ESP_LOGE(TAG, "Failed to initialize SPIFFS (%d)", ret); } _fg = TFT_RED; TFT_print((char *)"error\r\n", LASTX, LASTY); return; // Stop application. } size_t total = 0, used = 0; ret = esp_spiffs_info(NULL, &total, &used); if (ret != ESP_OK) { ESP_LOGE(TAG, "Failed to get SPIFFS partition information"); _fg = TFT_RED; TFT_print((char *)"error\r\n", LASTX, LASTY); return; // Stop application. } else { ESP_LOGI(TAG, "Partition size: %d, used: %d - %d%%", total, used, (used * 100) / total); } TFT_print((char *)"Ok\r\n", LASTX, LASTY); // Just to debug, list the /spiffs filesystem. #if 0 DIR *dir = opendir("/spiffs"); struct stat st; char strftime_buf[64], filename[280]; struct dirent* de = readdir(dir); while (de) { snprintf(filename, 279, "/spiffs/%s", de->d_name); if (stat(filename, &st) == 0) { strftime(strftime_buf, sizeof(strftime_buf), "%a, %d %b %Y %T %z", localtime(&(st.st_mtime))); printf("%5ld %s %s\n", st.st_size, strftime_buf, filename); } else { printf("%d %s\n", stat(filename, &st), de->d_name); } de = readdir(dir); } closedir(dir); #endif /* * Read or create configuration */ TFT_print((char *)"Ophalen configuratie ", LASTX, LASTY); read_config(); read_equipment(config.EquipmentRec); read_runtime(); read_recipe(config.RecipeRec); TFT_print((char *)"Ok\r\n", LASTX, LASTY); // Set the Touchscreen calibration/ TS_set_calibration(config.ts_xleft, config.ts_xright, config.ts_ytop, config.ts_ybottom); /* * TZ names don't work, so set the TZ the hard way. * This is the setting for Europe/Amsterdam. */ setenv("TZ", "CET-01CEST-02,M3.4.0,M10.4.0", 1); tzset(); xSemaphoreDS18B20 = xSemaphoreCreateMutex(); xSemaphoreDriver = xSemaphoreCreateMutex(); TFT_print((char *)"Starten taken ", LASTX, LASTY); xTaskCreate(&task_tft, "task_tft", 6144, NULL, 4, &xTaskTFT); vTaskDelay(400 / portTICK_PERIOD_MS); xTaskCreate(&task_ds18b20, "task_ds18b20", 2560, NULL, 8, &xTaskDS18B20); xTaskCreate(&task_driver, "task_driver", 2560, NULL, 8, &xTaskDriver); xTaskCreate(&task_sound, "task_sound", 2048, NULL,15, &xTaskSound); xTaskCreate(&task_sdcard, "task_sdcard", 8192, NULL,10, &xTaskSDcard); /* lower the wifi logging level */ esp_log_level_set("wifi", ESP_LOG_ERROR); esp_log_level_set("wifi_init", ESP_LOG_ERROR); xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi); TFT_print((char *)" Ok\r\nConnecting ", LASTX, LASTY); int wait = 20; while (wait) { vTaskDelay(750 / portTICK_PERIOD_MS); TFT_print((char *)".", LASTX, LASTY); if (xSemaphoreTake(xSemaphoreWiFi, 25) == pdTRUE) { if (wifi_state->STA_connected == true) wait = 0; else wait--; xSemaphoreGive(xSemaphoreWiFi); } } TFT_print((char *)" Ok\r\n", LASTX, LASTY); SoundPlay(SOUND_StartUp); start_http_websocket(); vTaskDelay(1000 / portTICK_PERIOD_MS); Main_Screen = MAIN_MODE_FREE; /* * Main application loop. */ while (1) { vTaskDelay(20000 / portTICK_PERIOD_MS); } // Not reached. }