From c4efb1f6ee862589dd8d0b6cb9904fd77d657fd0 Mon Sep 17 00:00:00 2001 From: Cellie Date: Sun, 9 Feb 2020 16:03:35 +0100 Subject: [PATCH] Better FFat detection and formatting code. See #39 and #40. Adafruit_ILI9341 to 1.5.7 Adafruit_GFX to 1.7.5 --- aquacontrol32.ino | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/aquacontrol32.ino b/aquacontrol32.ino index 250e0ec..fe04681 100644 --- a/aquacontrol32.ino +++ b/aquacontrol32.ino @@ -7,8 +7,8 @@ #include /* should be installed together with ESP32 Arduino install */ #include /* should be installed together with ESP32 Arduino install */ #include /* should be installed together with ESP32 Arduino install */ -#include /* Install 1.5.1 via 'Manage Libraries' in Arduino IDE */ -#include /* Install 1.6.1 via 'Manage Libraries' in Arduino IDE */ +#include /* Install 1.5.4 via 'Manage Libraries' in Arduino IDE */ +#include /* Install 1.7.5 via 'Manage Libraries' in Arduino IDE */ #include /* Install 4.0.0 via 'Manage Libraries' in Arduino IDE -> https://github.com/ThingPulse/esp8266-oled-ssd1306 */ #include /* Install 1.3 via 'Manage Libraries' in Arduino IDE */ #include /* Reports as 1.0.3 https://github.com/me-no-dev/AsyncTCP */ @@ -333,8 +333,26 @@ void setup() 1); /* Core where the task should run */ } - /* format fatfs on first boot */ - if ( !preferences.getString("firstrun", "true" ).equals( "false" ) ) { + /* check if a ffat partition is defined and halt the system if it is not defined*/ + if (!esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, "ffat")) { + ESP_LOGI( TAG, "No FFat partition defined. Halting.\nCheck 'Tools>Partition Scheme' in the Arduino IDE and select a FFat partition." ); + const char * noffatStr = "No FFat found..."; + if ( xTftTaskHandle ) { + tft.println( noffatStr ); + } + if ( xOledTaskHandle ) { + OLED.drawString( 64, 20, noffatStr ); + OLED.display(); + } + while (true) delay(1000); /* system is halted */ + } + + /* partition is defined - try to mount it */ + if ( FFat.begin() ) + ESP_LOGI( TAG, "FFat mounted." ); + + /* partition is present, but does not mount so now we just format it */ + else { const char * formatStr = "Formatting..."; if ( xTftTaskHandle ) { tft.println( formatStr ); @@ -343,20 +361,14 @@ void setup() OLED.drawString( 64, 20, formatStr ); OLED.display(); } - ESP_LOGI( TAG, "%s", formatStr ); - - if ( FFat.format( true, (char*)"ffat" ) ) - preferences.putString( "firstrun", "false" ); // and set token - else - ESP_LOGI( TAG, "Could not format FFat." ); + FFat.format( true, (char*)"ffat" ); + if (!FFat.begin()) { + ESP_LOGI( TAG, "FFat not mounted after formatting. Halting." ); + while (true) delay(1000); /* system is halted */; + } } - if ( FFat.begin() ) - ESP_LOGI( TAG, "FFat mounted." ); - else - ESP_LOGI( TAG, "Could not mount FFat." ); - if ( xOledTaskHandle ) { OLED.drawString( 64, 40, "Connecting..." ); OLED.display();