diff --git a/lcd_config.ini b/lcd_config.ini index dcbd3ebb..0e421971 100644 --- a/lcd_config.ini +++ b/lcd_config.ini @@ -8,7 +8,7 @@ lolin24 = -D ILI9341_DRIVER=1 -D TFT_WIDTH=240 -D TFT_HEIGHT=320 - -D TFT_ROTATION=2 ; 0=0, 1=90, 2=180 or 3=270 degree + -D TFT_ROTATION=0 ; 0=0, 1=90, 2=180 or 3=270 degree -D SPI_FREQUENCY=40000000 -D SPI_TOUCH_FREQUENCY=2500000 -D SPI_READ_FREQUENCY=20000000 diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index 2def1d73..cf07995e 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -392,4 +392,28 @@ void configOutput(const JsonObject & settings) if(password.length() > 2) output.replace(password, passmask); Log.trace(F("CONF: %s"), output.c_str()); +} + +bool configClear() +{ +#if defined(STM32F4xx) + Log.verbose(F("CONF: Clearing EEPROM")); + char buffer[1024 + 128]; + memset(buffer, 1 ,sizeof(buffer)); + if(sizeof(buffer) > 0) { + uint16_t i; + for(i = 0; i < sizeof(buffer); i++) eeprom_buffered_write_byte(i, buffer[i]); + eeprom_buffered_write_byte(i, 0); + eeprom_buffer_flush(); + Log.verbose(F("CONF: [SUCCESS] Cleared EEPROM")); + return true; + } else { + Log.error(F("CONF: Failed to clear to EEPROM")); + return false; + } +#elif HASP_USE_SPIFFS > 0 + return SPIFFS.format(); +#else + return false; +#endif } \ No newline at end of file diff --git a/src/hasp_config.h b/src/hasp_config.h index ee425190..cb447c23 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -43,5 +43,6 @@ void configOutput(const JsonObject & settings); bool configSet(int8_t & value, const JsonVariant & setting, const char * name); bool configSet(uint8_t & value, const JsonVariant & setting, const char * name); bool configSet(uint16_t & value, const JsonVariant & setting, const char * name); +bool configClear(); #endif \ No newline at end of file diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp index cec24e28..94e5ae53 100644 --- a/src/hasp_dispatch.cpp +++ b/src/hasp_dispatch.cpp @@ -119,6 +119,9 @@ void dispatchAttribute(String strTopic, const char * payload) } else if(strTopic == F("update")) { dispatchWebUpdate(payload); + } else if(strTopic == F("clearconfig")) { + configClear(); + } else if(strTopic == F("setupap")) { // haspDisplayAP(String(F("HASP-ABC123")).c_str(), String(F("haspadmin")).c_str()); diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp index d5d018ba..16667ad2 100644 --- a/src/hasp_http.cpp +++ b/src/hasp_http.cpp @@ -1555,15 +1555,13 @@ void httpHandleResetConfig() httpMessage += F("
"); if(resetConfirmed) { // User has confirmed, so reset everything -#if HASP_USE_SPIFFS > 0 - bool formatted = SPIFFS.format(); + bool formatted = configClear(); if(formatted) { httpMessage += F("Resetting all saved settings and restarting device into WiFi AP mode"); } else { httpMessage += F("Failed to format the internal flash partition"); resetConfirmed = false; } -#endif } else { httpMessage += F("

Warning

This process will reset all settings to the default values. The internal flash " diff --git a/src/hasp_wifi.cpp b/src/hasp_wifi.cpp index 00df9802..b173f8ba 100644 --- a/src/hasp_wifi.cpp +++ b/src/hasp_wifi.cpp @@ -23,7 +23,7 @@ static WiFiEventHandler gotIpEventHandler, disconnectedEventHandler; // #include // #include "WiFiSpi.h" // extern WiFiSpiClass WiFi; -SPIClass spi2(ESPSPI_MOSI, ESPSPI_MISO, ESPSPI_SCLK); // SPI port where esp is connected +SPIClass espSPI(ESPSPI_MOSI, ESPSPI_MISO, ESPSPI_SCLK); // SPI port where esp is connected #endif //#include "DNSserver.h" @@ -165,7 +165,7 @@ void wifiSetup() // // Initialize the WifiSpi library - WiFiSpi.init(ESPSPI_CS, 8000000, &spi2); + WiFiSpi.init(ESPSPI_CS, 8000000, &espSPI); // check for the presence of the shield: if (WiFiSpi.status() == WL_NO_SHIELD) { @@ -181,12 +181,14 @@ void wifiSetup() } // attempt to connect to Wifi network - int status = WL_IDLE_STATUS; // the Wifi radio's status - + // int status = WL_IDLE_STATUS; // the Wifi radio's status + if(!wifiShowAP()) { // while (status != WL_CONNECTED) { Log.notice(F("WIFI: Connecting to : %s"), wifiSsid); // Connect to WPA/WPA2 network - status = WiFi.begin(wifiSsid, wifiPassword); + // status = WiFi.begin(wifiSsid, wifiPassword); + WiFi.begin(wifiSsid, wifiPassword); + } // } #else @@ -214,7 +216,9 @@ void wifiSetup() bool wifiEvery5Seconds() { #if defined(STM32F4xx) - if(WiFi.status() == WL_CONNECTED) { + if(wifiShowAP()) { // no ssid is set yet wait for user on-screen input + return false; + } else if(WiFi.status() == WL_CONNECTED) { #else if(WiFi.getMode() != WIFI_STA) { return false;