Updates for stmf407vg

This commit is contained in:
fvanroie 2020-04-28 00:44:21 +02:00
parent 161ce4d81e
commit 4913c71419
8 changed files with 71 additions and 38 deletions

View File

@ -1,18 +1,9 @@
#include "Arduino.h"
#include "ArduinoJson.h"
#include "ArduinoLog.h"
#include <FS.h> // 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 <FS.h> // 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<const __FlashStringHelper *>(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)

View File

@ -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
}
}

View File

@ -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
}

View File

@ -1,3 +1,4 @@
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#include <Arduino.h>
#include <ArduinoOTA.h>
#include "ArduinoJson.h"
@ -184,4 +185,5 @@ void otaHttpUpdate(const char * espOtaUrl)
#endif
mdnsStart();
// nextionSendCmd("page " + String(nextionActivePage));
}
}
#endif

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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 <Wifi.h>
#else
#elif defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
static WiFiEventHandler gotIpEventHandler, disconnectedEventHandler;
@ -261,4 +255,6 @@ void wifiStop()
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
Log.warning(F("WIFI: Stopped"));
}
}
#endif