From 4913c714195b6544e7a850f238d8642733b7a641 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 28 Apr 2020 00:44:21 +0200 Subject: [PATCH] Updates for stmf407vg --- src/hasp_config.cpp | 46 ++++++++++++++++++++++++++++++++----------- src/hasp_dispatch.cpp | 28 +++++++++++++++----------- src/hasp_oobe.cpp | 2 ++ src/hasp_ota.cpp | 4 +++- src/hasp_ota.h | 3 +++ src/hasp_telnet.cpp | 1 - src/hasp_tft.cpp | 9 +++++++-- src/hasp_wifi.cpp | 16 ++++++--------- 8 files changed, 71 insertions(+), 38 deletions(-) diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index 69649c0c..86fec041 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -1,18 +1,9 @@ #include "Arduino.h" #include "ArduinoJson.h" #include "ArduinoLog.h" -#include // Include the SPIFFS library -#include "EEPROM.h" - -#if defined(ARDUINO_ARCH_ESP32) -#include "SPIFFS.h" -#endif #include "hasp_config.h" #include "hasp_debug.h" -#include "hasp_http.h" -#include "hasp_wifi.h" -#include "hasp_mdns.h" #include "hasp_gui.h" #include "hasp_ota.h" #include "hasp_spiffs.h" @@ -21,9 +12,21 @@ #include "hasp.h" #include "hasp_conf.h" -#if HASP_USE_MQTT -#include "hasp_mqtt.h" + +#if HASP_USE_SPIFFS>0 +#include // Include the SPIFFS library +#if defined(ARDUINO_ARCH_ESP32) +#include "SPIFFS.h" #endif +#endif +#if HASP_USE_EEPROM>0 +#include "EEPROM.h" +#endif + +#ifndef FPSTR +#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer)) +#endif + void confDebugSet(const char * name) { @@ -75,8 +78,10 @@ void configStartDebug(bool setupdebug, String & configFile) if(setupdebug) { debugStart(); // Debug started, now we can use it; HASP header sent Log.notice(F("FILE: [SUCCESS] SPI flash FS mounted")); +#if HASP_USE_SPIFFS>0 spiffsInfo(); spiffsList(); +#endif } Log.notice(F("CONF: Loading %s"), configFile.c_str()); } @@ -86,6 +91,8 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false) String configFile((char *)0); configFile.reserve(128); configFile = String(FPSTR(HASP_CONFIG_FILE)); + +#if HASP_USE_SPIFFS>0 File file = SPIFFS.open(configFile, "r"); if(file) { @@ -119,6 +126,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false) return; } } +#endif // File does not exist or error reading file if(setupdebug) { @@ -131,6 +139,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false) void configBackupToEeprom() { +#if HASP_USE_SPIFFS>0 String configFile((char *)0); configFile.reserve(128); configFile = String(FPSTR(HASP_CONFIG_FILE)); @@ -154,10 +163,12 @@ void configBackupToEeprom() Log.verbose(F("CONF: Written %u to EEPROM"), index); } +#endif } void configWriteConfig() { +#if HASP_USE_SPIFFS>0 String configFile((char *)0); configFile.reserve(128); configFile = String(FPSTR(HASP_CONFIG_FILE)); @@ -264,16 +275,26 @@ void configWriteConfig() } else { Log.notice(F("CONF: Configuration was not changed")); } +#endif } void configSetup() { +#if HASP_USE_SPIFFS>0 if(!SPIFFS.begin()) { - Log.error(F("FILE: SPI flash init failed. Unable to mount FS: Using default settings...")); +#endif + +#if HASP_USE_SPIFFS>0 } else { +#endif DynamicJsonDocument settings(1024 + 128); + Serial.print(__FILE__); + Serial.println(__LINE__); configGetConfig(settings, true); + + Log.error(F("FILE: SPI flash init failed. Unable to mount FS: Using default settings...")); +#if HASP_USE_SPIFFS>0 Log.verbose(F("Loading debug settings")); debugSetConfig(settings[F("debug")]); Log.verbose(F("Loading GUI settings")); @@ -304,6 +325,7 @@ void configSetup() #endif } Log.notice(F("User configuration loaded")); +#endif } void configOutput(const JsonObject & settings) diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp index d44f81bc..bed14991 100644 --- a/src/hasp_dispatch.cpp +++ b/src/hasp_dispatch.cpp @@ -6,17 +6,11 @@ #include "hasp_dispatch.h" #include "hasp_config.h" #include "hasp_debug.h" -#include "hasp_http.h" -#include "hasp_mdns.h" -#include "hasp_wifi.h" #include "hasp_gui.h" -#include "hasp_ota.h" +#include "hasp_hal.h" #include "hasp.h" #include "hasp_conf.h" -#if HASP_USE_MQTT -#include "hasp_mqtt.h" -#endif inline void dispatchPrintln(String header, String & data) { @@ -272,42 +266,50 @@ void dispatchJsonl(char * payload) void dispatchIdle(const char * state) { -#if HASP_USE_MQTT +#if HASP_USE_MQTT>0 mqtt_send_state(F("idle"), state); +#else + Log.notice(F("OUT: idle = %s"), state); #endif } void dispatchReboot(bool saveConfig) { if(saveConfig) configWriteConfig(); -#if HASP_USE_MQTT +#if HASP_USE_MQTT>0 mqttStop(); // Stop the MQTT Client first #endif debugStop(); +#if HASP_USE_WIFI>0 wifiStop(); +#endif Log.verbose(F("-------------------------------------")); Log.notice(F("STOP: Properly Rebooting the MCU now!")); Serial.flush(); - ESP.restart(); + //halRestart(); } void dispatch_button(uint8_t id, const char * event) { -#if HASP_USE_MQTT +#if HASP_USE_MQTT > 0 mqtt_send_input(id, event); #endif } void dispatchWebUpdate(const char * espOtaUrl) { +#if HASP_USE_OTA > 0 Log.verbose(F("FWUP: Checking for updates at URL: %s"), espOtaUrl); otaHttpUpdate(espOtaUrl); +#endif } void IRAM_ATTR dispatch_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data) { -#if HASP_USE_MQTT +#if HASP_USE_MQTT > 0 mqtt_send_obj_attribute_str(pageid, btnid, attribute, data); +#else + Log.notice(F("OUT: json = {\"p[%u].b[%u].%s\":\"%s\"}"), pageid, btnid, attribute, data); #endif } @@ -397,6 +399,8 @@ void dispatchConfig(const char * topic, const char * payload) size_t size = serializeJson(doc, buffer, sizeof(buffer)); #if HASP_USE_MQTT mqtt_send_state(F("config"), buffer); +#else + Log.notice(F("OUT: config %s = %s"),topic,buffer); #endif } } diff --git a/src/hasp_oobe.cpp b/src/hasp_oobe.cpp index 7ebc92a0..7f91127e 100644 --- a/src/hasp_oobe.cpp +++ b/src/hasp_oobe.cpp @@ -298,6 +298,7 @@ void oobeSetup() char ssid[32]; char pass[32]; +#if HASP_USE_WIFI>0 if(wifiShowAP(ssid, pass)) { guiSetDim(100); oobeSetupQR(ssid, pass); @@ -314,4 +315,5 @@ void oobeSetup() Log.verbose(F("OOBE: Already calibrated")); } } +#endif } \ No newline at end of file diff --git a/src/hasp_ota.cpp b/src/hasp_ota.cpp index efae40e8..188fbcc0 100644 --- a/src/hasp_ota.cpp +++ b/src/hasp_ota.cpp @@ -1,3 +1,4 @@ +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) #include #include #include "ArduinoJson.h" @@ -184,4 +185,5 @@ void otaHttpUpdate(const char * espOtaUrl) #endif mdnsStart(); // nextionSendCmd("page " + String(nextionActivePage)); -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/hasp_ota.h b/src/hasp_ota.h index 3004691a..e30d1a36 100644 --- a/src/hasp_ota.h +++ b/src/hasp_ota.h @@ -1,3 +1,5 @@ +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) + #ifndef HASP_OTA_H #define HASP_OTA_H @@ -8,4 +10,5 @@ void otaLoop(void); void otaEverySecond(void); void otaHttpUpdate(const char * espOtaUrl); +#endif #endif \ No newline at end of file diff --git a/src/hasp_telnet.cpp b/src/hasp_telnet.cpp index cb5136bd..b59c2096 100644 --- a/src/hasp_telnet.cpp +++ b/src/hasp_telnet.cpp @@ -5,7 +5,6 @@ #include "ArduinoJson.h" #include "ArduinoLog.h" -#include "hasp_http.h" #include "hasp_debug.h" #include "hasp_config.h" #include "hasp_dispatch.h" diff --git a/src/hasp_tft.cpp b/src/hasp_tft.cpp index cf44ff89..b8f07ed0 100644 --- a/src/hasp_tft.cpp +++ b/src/hasp_tft.cpp @@ -82,8 +82,13 @@ void tftShowConfig(TFT_eSPI & tft) tft.getSetup(tftSetup); Log.verbose(F("TFT: TFT_eSPI : v%s"), tftSetup.version.c_str()); +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_32) Log.verbose(F("TFT: Processor : ESP%x"), tftSetup.esp); Log.verbose(F("TFT: CPU freq. : %i MHz"), ESP.getCpuFreqMHz()); +#else + Log.verbose(F("TFT: Processor : STM%x"), tftSetup.esp); + Log.verbose(F("TFT: CPU freq. : %i MHz"), F_CPU/1000/1000); +#endif #if defined(ARDUINO_ARCH_ESP8266) Log.verbose(F("TFT: Voltage : %2.2f V"), ESP.getVcc() / 918.0); // 918 empirically determined @@ -164,8 +169,8 @@ void tftShowConfig(TFT_eSPI & tft) // Get pin name for ESP8266 int8_t getPinName(int8_t pin) { -// For ESP32 pin labels on boards use the GPIO number -#if defined(ARDUINO_ARCH_ESP32) +// For ESP32 and STM32 pin labels on boards use the GPIO number +#ifndef ARDUINO_ARCH_ESP8266 return pin; #endif diff --git a/src/hasp_wifi.cpp b/src/hasp_wifi.cpp index 70725e9a..ecde60b0 100644 --- a/src/hasp_wifi.cpp +++ b/src/hasp_wifi.cpp @@ -4,23 +4,17 @@ #include "hasp_conf.h" -#include "hasp_wifi.h" -#include "hasp_http.h" -#include "hasp_mdns.h" +#if HASP_USE_WIFI>0 + #include "hasp_debug.h" #include "hasp_config.h" #include "hasp_dispatch.h" #include "hasp_gui.h" #include "hasp.h" -#include "hasp_conf.h" -#if HASP_USE_MQTT -#include "hasp_mqtt.h" -#endif - #if defined(ARDUINO_ARCH_ESP32) #include -#else +#elif defined(ARDUINO_ARCH_ESP8266) #include static WiFiEventHandler gotIpEventHandler, disconnectedEventHandler; @@ -261,4 +255,6 @@ void wifiStop() WiFi.disconnect(); WiFi.mode(WIFI_OFF); Log.warning(F("WIFI: Stopped")); -} \ No newline at end of file +} + +#endif \ No newline at end of file