From 554849714d73bb799549cd2c532c4c156003e84f Mon Sep 17 00:00:00 2001
From: arovak
Date: Thu, 30 Apr 2020 15:03:59 +0200
Subject: [PATCH 01/56] Initital Tasmotaslave support
---
include/hasp_conf.h | 4 ++
src/hasp_debug.cpp | 6 +-
src/hasp_dispatch.cpp | 53 +++++++++------
src/hasp_gpio.cpp | 4 ++
src/hasp_gui.cpp | 8 ++-
src/hasp_slave.cpp | 147 ++++++++++++++++++++++++++++++++++++++++++
src/hasp_slave.h | 20 ++++++
src/main.cpp | 8 +++
8 files changed, 227 insertions(+), 23 deletions(-)
create mode 100644 src/hasp_slave.cpp
create mode 100644 src/hasp_slave.h
diff --git a/include/hasp_conf.h b/include/hasp_conf.h
index a14b936f..96b88a60 100644
--- a/include/hasp_conf.h
+++ b/include/hasp_conf.h
@@ -85,6 +85,10 @@
#include "hasp_ota.h"
#endif
+#if HASP_USE_TASMOTA_SLAVE>0
+#include "hasp_slave.h"
+#endif
+
#endif
#ifndef FPSTR
diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp
index 854b9db4..2dae3a19 100644
--- a/src/hasp_debug.cpp
+++ b/src/hasp_debug.cpp
@@ -331,8 +331,10 @@ void debugPreSetup(JsonObject settings)
if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */
#ifdef STM32_CORE_VERSION_MAJOR
- Serial.setRx(PA3); // User Serial2
- Serial.setTx(PA2);
+ #ifndef STM32_SERIAL1 // Define what Serial port to use for log output
+ Serial.setRx(PA3); // User Serial2
+ Serial.setTx(PA2);
+ #endif
#endif
Serial.begin(baudrate); /* prepare for possible serial debug */
delay(10);
diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp
index bed14991..b605825e 100644
--- a/src/hasp_dispatch.cpp
+++ b/src/hasp_dispatch.cpp
@@ -51,6 +51,8 @@ void dispatchOutput(int output, bool state)
#if defined(ARDUINO_ARCH_ESP32)
ledcWrite(99, state ? 1023 : 0); // ledChannel and value
+#elif defined(STM32_CORE_VERSION)
+ digitalWrite(HASP_OUTPUT_PIN, state);
#else
analogWrite(pin, state ? 1023 : 0);
#endif
@@ -95,12 +97,6 @@ void dispatchAttribute(String strTopic, const char * payload)
{
if(strTopic.startsWith("p[")) {
dispatchButtonAttribute(strTopic, payload);
- } else if(strTopic.startsWith(F("output"))) {
-#if defined(ARDUINO_ARCH_ESP8266)
- uint8_t state = isON(payload) ? HIGH : LOW;
- digitalWrite(D1, state);
-#endif
-
} else if(strTopic == F("page")) {
dispatchPage(payload);
@@ -138,9 +134,12 @@ void dispatchPage(String strPageid)
String strPage((char *)0);
strPage.reserve(128);
strPage = haspGetPage();
-#if HASP_USE_MQTT
+#if HASP_USE_MQTT > 0
mqtt_send_state(F("page"), strPage.c_str());
#endif
+#if HASP_USE_TASMOTA_SLAVE > 0
+ slave_send_state(F("page"), strPage.c_str());
+#endif
}
void dispatchClearPage(String strPageid)
@@ -160,11 +159,16 @@ void dispatchDim(String strDimLevel)
if(strDimLevel.length() != 0) guiSetDim(strDimLevel.toInt());
dispatchPrintln(F("DIM"), strDimLevel);
-#if HASP_USE_MQTT
+#if HASP_USE_MQTT > 0
char buffer[8];
itoa(guiGetDim(), buffer, DEC);
mqtt_send_state(F("dim"), buffer);
#endif
+#if HASP_USE_TASMOTA_SLAVE > 0
+ char buffer[8];
+ itoa(guiGetDim(), buffer, DEC);
+ slave_send_state(F("dim"), buffer);
+#endif
}
void dispatchBacklight(String strPayload)
@@ -177,9 +181,13 @@ void dispatchBacklight(String strPayload)
// Return the current state
strPayload = getOnOff(guiGetBacklight());
-#if HASP_USE_MQTT
+#if HASP_USE_MQTT > 0
mqtt_send_state(F("light"), strPayload.c_str());
#endif
+#if HASP_USE_TASMOTA_SLAVE > 0
+ slave_send_state(F("light"), strPayload.c_str());
+#endif
+
}
void dispatchCommand(String cmnd)
@@ -266,8 +274,10 @@ void dispatchJsonl(char * payload)
void dispatchIdle(const char * state)
{
-#if HASP_USE_MQTT>0
+#if HASP_USE_MQTT > 0
mqtt_send_state(F("idle"), state);
+#elif HASP_USE_TASMOTA_SLAVE > 0
+ slave_send_state(F("idle"), state);
#else
Log.notice(F("OUT: idle = %s"), state);
#endif
@@ -276,11 +286,11 @@ void dispatchIdle(const char * state)
void dispatchReboot(bool saveConfig)
{
if(saveConfig) configWriteConfig();
-#if HASP_USE_MQTT>0
+#if HASP_USE_MQTT > 0
mqttStop(); // Stop the MQTT Client first
#endif
debugStop();
-#if HASP_USE_WIFI>0
+#if HASP_USE_WIFI > 0
wifiStop();
#endif
Log.verbose(F("-------------------------------------"));
@@ -294,6 +304,9 @@ void dispatch_button(uint8_t id, const char * event)
#if HASP_USE_MQTT > 0
mqtt_send_input(id, event);
#endif
+#if HASP_USE_TASMOTA_SLAVE
+ slave_send_input(id, event);
+#endif
}
void dispatchWebUpdate(const char * espOtaUrl)
@@ -308,6 +321,8 @@ void IRAM_ATTR dispatch_obj_attribute_str(uint8_t pageid, uint8_t btnid, const c
{
#if HASP_USE_MQTT > 0
mqtt_send_obj_attribute_str(pageid, btnid, attribute, data);
+#elif HASP_USE_TASMOTA_SLAVE > 0
+ slave_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
@@ -356,14 +371,14 @@ void dispatchConfig(const char * topic, const char * payload)
haspGetConfig(settings);
}
-#if HASP_USE_WIFI
+#if HASP_USE_WIFI > 0
else if(strcmp_P(topic, PSTR("wifi")) == 0) {
if(update)
wifiSetConfig(settings);
else
wifiGetConfig(settings);
}
-#if HASP_USE_MQTT
+#if HASP_USE_MQTT > 0
else if(strcmp_P(topic, PSTR("mqtt")) == 0) {
if(update)
mqttSetConfig(settings);
@@ -371,11 +386,11 @@ void dispatchConfig(const char * topic, const char * payload)
mqttGetConfig(settings);
}
#endif
-#if HASP_USE_TELNET
+#if HASP_USE_TELNET > 0
// else if(strcmp_P(topic, PSTR("telnet")) == 0)
// telnetGetConfig(settings[F("telnet")]);
#endif
-#if HASP_USE_MDNS
+#if HASP_USE_MDNS > 0
else if(strcmp_P(topic, PSTR("mdns")) == 0) {
if(update)
mdnsSetConfig(settings);
@@ -383,7 +398,7 @@ void dispatchConfig(const char * topic, const char * payload)
mdnsGetConfig(settings);
}
#endif
-#if HASP_USE_HTTP
+#if HASP_USE_HTTP > 0
else if(strcmp_P(topic, PSTR("http")) == 0) {
if(update)
httpSetConfig(settings);
@@ -397,8 +412,10 @@ void dispatchConfig(const char * topic, const char * payload)
if(!update) {
settings.remove(F("pass")); // hide password in output
size_t size = serializeJson(doc, buffer, sizeof(buffer));
-#if HASP_USE_MQTT
+#if HASP_USE_MQTT > 0
mqtt_send_state(F("config"), buffer);
+#elif HASP_USE_TASMOTA > 0
+ slave_send_state(F("config"), buffer);
#else
Log.notice(F("OUT: config %s = %s"),topic,buffer);
#endif
diff --git a/src/hasp_gpio.cpp b/src/hasp_gpio.cpp
index 1ab5cefb..4094d7e6 100644
--- a/src/hasp_gpio.cpp
+++ b/src/hasp_gpio.cpp
@@ -7,4 +7,8 @@ void gpioSetup()
pinMode(D1, OUTPUT);
pinMode(D2, INPUT_PULLUP);
#endif
+#if defined(STM32_CORE_VERSION)
+ pinMode(HASP_OUTPUT_PIN, OUTPUT);
+ pinMode(HASP_INPUT_PIN, INPUT_PULLUP);
+#endif
}
\ No newline at end of file
diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp
index 021b890a..3232e7c3 100644
--- a/src/hasp_gui.cpp
+++ b/src/hasp_gui.cpp
@@ -925,6 +925,7 @@ bool guiGetConfig(const JsonObject & settings)
v.set(calData[i]);
} else {
changed = true;
+ tft.setTouch(calData);
}
i++;
}
@@ -935,6 +936,8 @@ bool guiGetConfig(const JsonObject & settings)
for(uint8_t i = 0; i < 5; i++) {
array.add(calData[i]);
}
+ changed = true;
+ tft.setTouch(calData);
}
if(changed) configOutput(settings);
@@ -983,14 +986,13 @@ bool guiSetConfig(const JsonObject & settings)
}
if(calData[0] != 0 || calData[1] != 65535 || calData[2] != 0 || calData[3] != 65535) {
- Log.trace(F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3],
- calData[4]);
+ Log.trace(F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3],calData[4]);
oobeSetAutoCalibrate(false);
} else {
Log.notice(F("First Touch Calibration enabled"));
oobeSetAutoCalibrate(true);
}
-
+ if (status) tft.setTouch(calData);
changed |= status;
}
diff --git a/src/hasp_slave.cpp b/src/hasp_slave.cpp
new file mode 100644
index 00000000..0fc479ef
--- /dev/null
+++ b/src/hasp_slave.cpp
@@ -0,0 +1,147 @@
+/*********************
+ * INCLUDES
+ *********************/
+#include "hasp_slave.h"
+#include
+#include "ArduinoJson.h"
+#include "ArduinoLog.h"
+#include "hasp_dispatch.h"
+#include "hasp_gui.h"
+#include "tasmotaSlave.h"
+
+// set RX and TX pins
+HardwareSerial Serial2(PD6, PD5);
+TasmotaSlave slave(&Serial2);
+
+#define slaveNodeTopic "hasp/"
+
+unsigned long updateLedTimer = 0; // timer in msec for tele mqtt send
+unsigned long updatLedPeriod = 1000; // timer in msec for tele mqtt send
+
+bool ledstate = false;
+
+
+void IRAM_ATTR slave_send_state(const __FlashStringHelper * subtopic, const char * payload)
+{
+ // page = 0
+ // p[0].b[0].attr = abc
+ // dim = 100
+ // idle = 0/1
+ // light = 0/1
+ // brightness = 100
+
+ char cBuffer[strlen(payload) + 64];
+ memset(cBuffer, 0 ,sizeof(cBuffer));
+ snprintf(cBuffer, sizeof(cBuffer), PSTR("publish %sstate/%s %s"), slaveNodeTopic ,subtopic, payload);
+ slave.ExecuteCommand((char*)cBuffer);
+
+ // Log after char buffers are cleared
+ Log.notice(F("TAS PUB: %sstate/%S = %s"), slaveNodeTopic, subtopic, payload);
+}
+
+void IRAM_ATTR slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data)
+{
+ char cBuffer[192];
+ memset(cBuffer, 0 ,sizeof(cBuffer));
+ snprintf_P(cBuffer, sizeof(cBuffer), PSTR("publish %sstate/json {\"p[%u].b[%u].%s\":\"%s\"}"), slaveNodeTopic, pageid, btnid, attribute, data);
+ slave.ExecuteCommand((char*)cBuffer);
+ // Log after char buffers are cleared
+ Log.notice(F("TAS PUB: %sstate/json = {\"p[%u].b[%u].%s\":\"%s\"}"), slaveNodeTopic, pageid, btnid, attribute, data);
+}
+
+void slave_send_input(uint8_t id, const char * payload)
+{
+ // Log.trace(F("MQTT TST: %sstate/input%u = %s"), mqttNodeTopic, id, payload); // to be removed
+
+ char cBuffer[strlen(payload) + 64];
+ memset(cBuffer, 0 ,sizeof(cBuffer));
+ snprintf_P(cBuffer, sizeof(cBuffer), PSTR("publish %sstate/input%u %s"), slaveNodeTopic, id, payload);
+ slave.ExecuteCommand((char*)cBuffer);
+
+ // Log after char buffers are cleared
+ Log.notice(F("TAS PUB: %sstate/input%u = %s"), slaveNodeTopic, id, payload);
+}
+
+// void slave_send_statusupdate()
+// { // Periodically publish a JSON string indicating system status
+// char data[3 * 128];
+// {
+// char buffer[128];
+// snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
+// haspGetVersion().c_str(), long(millis() / 1000));
+// strcat(buffer, data);
+// snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","),
+// ESP.getFreeHeap(), halGetHeapFragmentation(), halGetCoreVersion().c_str());
+// strcat(data, buffer);
+// snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u}"),
+// haspGetPage(), (HASP_NUM_PAGES));
+// strcat(data, buffer);
+// snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"),
+// tftDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT));
+// strcat(data, buffer);
+// }
+// slave_send_state(F("statusupdate"), data);
+// debugLastMillis = millis();
+// }
+
+void TASMO_DATA_RECEIVE(char *data)
+{
+ Log.verbose(F("TAS: Slave IN [%s]"), data);
+
+ char slvCmd[20],slvVal[60];
+ memset(slvCmd, 0 ,sizeof(slvCmd));
+ memset(slvVal, 0 ,sizeof(slvVal));
+ sscanf(data,"%s %s", slvCmd, slvVal);
+
+ Log.verbose(F("TAS: Cmd[%s] Val[%s]"), slvCmd, slvVal);
+
+ if (!strcmp(slvCmd, "calData")){
+ if (strlen(slvVal) != 0) {
+ char cBuffer[strlen(slvVal) + 24];
+ memset(cBuffer, 0 ,sizeof(cBuffer));
+ snprintf_P(cBuffer, sizeof(cBuffer), PSTR("{'calibration':[%s]}"), slvVal);
+ dispatchConfig("gui",cBuffer);
+ } else {
+ dispatchConfig("gui","");
+ }
+ } else if (!strcmp(slvCmd, "jsonl")) {
+ dispatchJsonl(slvVal);
+ } else {
+ char cBuffer[strlen(data)+1];
+ snprintf_P(cBuffer, sizeof(cBuffer), PSTR("%s=%s"), slvCmd, slvVal);
+ dispatchCommand(cBuffer);
+ }
+}
+
+void TASMO_EVERY_SECOND(void)
+{
+ if (ledstate) {
+ ledstate = false;
+ digitalWrite(HASP_OUTPUT_PIN, 1);
+ // Log.verbose(F("LED OFF"));
+ } else {
+ ledstate = true;
+ digitalWrite(HASP_OUTPUT_PIN, 0);
+ // Log.verbose(F("LED ON"));
+ }
+}
+
+void slaveSetup()
+{
+ Serial2.begin(HASP_SLAVE_SPEED);
+ // slave.attach_FUNC_EVERY_SECOND(TASMO_EVERY_SECOND);
+ slave.attach_FUNC_COMMAND_SEND(TASMO_DATA_RECEIVE);
+
+ Log.notice(F("TAS: HASP SLAVE LOADED"));
+}
+
+void slaveLoop(void)
+{
+ slave.loop();
+ // demo code to run the led without tasmota
+ // if ((millis() - updateLedTimer) >= updatLedPeriod) {
+ // updateLedTimer = millis();
+ // TASMO_EVERY_SECOND();
+ // }
+
+}
\ No newline at end of file
diff --git a/src/hasp_slave.h b/src/hasp_slave.h
new file mode 100644
index 00000000..89db9964
--- /dev/null
+++ b/src/hasp_slave.h
@@ -0,0 +1,20 @@
+#ifndef HASP_SLAVE_H
+#define HASP_SLAVE_H
+
+#include "ArduinoJson.h"
+
+#define HASP_SLAVE_SPEED 38400
+
+void TASMO_EVERY_SECOND(void);
+void TASMO_DATA_RECEIVE(char *data);
+void IRAM_ATTR slave_send_state(const __FlashStringHelper * subtopic, const char * payload);
+void IRAM_ATTR slave_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data);
+void slave_send_input(uint8_t id, const char * payload);
+void slave_send_statusupdate();
+
+
+void slaveSetup();
+void slaveLoop(void);
+
+
+#endif
\ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 5bb44c72..020416c5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -80,6 +80,10 @@ void setup()
buttonSetup();
#endif
+#if HASP_USE_TASMOTA_SLAVE
+ slaveSetup();
+#endif
+
mainLastLoopTime = millis() - 1000; // reset loop counter
}
@@ -132,6 +136,10 @@ void loop()
#endif // WIFI
+#if HASP_USE_TASMOTA_SLAVE
+ slaveLoop();
+#endif // TASMOTASLAVE
+
// Every Second Loop
if(millis() - mainLastLoopTime >= 1000) {
/* Run Every Second */
From 7e826979828d30b8dc90eef78f791db7125b76ff Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Thu, 30 Apr 2020 17:30:17 +0200
Subject: [PATCH 02/56] Add DMA define
---
src/hasp_gui.cpp | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp
index 021b890a..d590718f 100644
--- a/src/hasp_gui.cpp
+++ b/src/hasp_gui.cpp
@@ -628,6 +628,13 @@ void guiSetup()
{
/* TFT init */
tft.begin();
+
+#ifdef USE_DMA_TO_TFT
+// DMA - should work with STM32F2xx/F4xx/F7xx processors
+// NOTE: >>>>>> DMA IS FOR SPI DISPLAYS ONLY <<<<<<
+tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767)
+#endif
+
tft.setRotation(guiRotation); /* 1/3=Landscape or 0/2=Portrait orientation */
#if TOUCH_DRIVER == 0
tft.setTouch(calData);
@@ -673,8 +680,13 @@ void guiSetup()
lv_fs_if_init(); // auxilary file system drivers
#endif
- /* Dump TFT Cofiguration */
+ /* Dump TFT Configuration */
tftSetup(tft);
+#ifdef USE_DMA_TO_TFT
+ Log.verbose(F("TFT: DMA : ENABELD"));
+#else
+ Log.verbose(F("TFT: DMA : DISABELD"));
+#endif
/* Load User Settings */
// guiSetConfig(settings);
@@ -814,7 +826,7 @@ void IRAM_ATTR guiLoop()
#ifdef STM32_CORE_VERSION_MAJOR
tick.update();
- while(Serial.available()) {
+ while(Serial.available()) {
char ch = Serial.read();
Serial.print(ch);
if (ch == 13 ||ch == 10) {
@@ -991,6 +1003,7 @@ bool guiSetConfig(const JsonObject & settings)
oobeSetAutoCalibrate(true);
}
+ if (status) tft.setTouch(calData);
changed |= status;
}
From f9d14e7fba2702a5faf2b54f174a9c54ca94428c Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Thu, 30 Apr 2020 17:30:51 +0200
Subject: [PATCH 03/56] Update debug for STM32
---
src/hasp_debug.cpp | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp
index 854b9db4..9a7192ba 100644
--- a/src/hasp_debug.cpp
+++ b/src/hasp_debug.cpp
@@ -15,7 +15,7 @@
#endif
#include "hasp_hal.h"
-#if HASP_USE_MQTT>0
+#if HASP_USE_MQTT > 0
#include "hasp_mqtt.h"
#endif
@@ -73,7 +73,7 @@ Syslog * syslog;
// Serial Settings
uint16_t debugSerialBaud = SERIAL_SPEED / 10; // Multiplied by 10
bool debugSerialStarted = false;
-bool debugAnsiCodes = true;
+bool debugAnsiCodes = true;
//#define TERM_COLOR_Black "\u001b[30m"
#define TERM_COLOR_GRAY "\e[37m"
@@ -94,7 +94,8 @@ String debugHaspHeader()
{
String header((char *)0);
header.reserve(256);
- header = F(" _____ _____ _____ _____\r\n"
+ if(debugAnsiCodes) header += TERM_COLOR_YELLOW;
+ header += F(" _____ _____ _____ _____\r\n"
" | | | _ | __| _ |\r\n"
" | | |__ | __|\r\n"
" |__|__|__|__|_____|__|\r\n"
@@ -216,21 +217,23 @@ static void debugPrintTimestamp(int level, Print * _logOutput)
time_t rawtime;
struct tm * timeinfo;
- //time(&rawtime);
- //timeinfo = localtime(&rawtime);
+ // time(&rawtime);
+ // timeinfo = localtime(&rawtime);
// strftime(buffer, sizeof(buffer), "%b %d %H:%M:%S.", timeinfo);
// Serial.println(buffer);
debugSendAnsiCode(F(TERM_COLOR_CYAN), _logOutput);
- /* if(timeinfo->tm_year >= 120) {
- char buffer[64];
- strftime(buffer, sizeof(buffer), "[%b %d %H:%M:%S.", timeinfo); // Literal String
- _logOutput->print(buffer);
- _logOutput->printf(PSTR("%03lu]"), millis() % 1000);
- } else */ {
- _logOutput->printf(PSTR("[%20.3f]"), (float)millis() / 1000);
+ /* if(timeinfo->tm_year >= 120) {
+ char buffer[64];
+ strftime(buffer, sizeof(buffer), "[%b %d %H:%M:%S.", timeinfo); // Literal String
+ _logOutput->print(buffer);
+ _logOutput->printf(PSTR("%03lu]"), millis() % 1000);
+ } else */
+ {
+ //_logOutput->printf(PSTR("[%20.3f]"), (float)millis() / 1000);
+ _logOutput->printf(PSTR("[%20d]"), millis() );
}
}
@@ -328,15 +331,15 @@ void debugPreSetup(JsonObject settings)
uint32_t baudrate = settings[FPSTR(F_CONFIG_BAUD)].as() * 10;
if(baudrate == 0) baudrate = SERIAL_SPEED;
- if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */
+ if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */
#ifdef STM32_CORE_VERSION_MAJOR
- Serial.setRx(PA3); // User Serial2
- Serial.setTx(PA2);
+ // Serial.setRx(PA3); // User Serial2
+ // Serial.setTx(PA2);
#endif
Serial.begin(baudrate); /* prepare for possible serial debug */
delay(10);
- Log.registerOutput(0, &Serial, LOG_LEVEL_VERBOSE, true);
+ Log.registerOutput(0, &Serial, LOG_LEVEL_VERBOSE, true);
debugSerialStarted = true;
Serial.println();
Log.trace(("Serial started at %u baud"), baudrate);
From cd91930104f51d9c6edd42b20c7326765ad45685 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Thu, 30 Apr 2020 17:31:07 +0200
Subject: [PATCH 04/56] Update debug for STM32
---
lib/ArduinoLog/ArduinoLog.h | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/lib/ArduinoLog/ArduinoLog.h b/lib/ArduinoLog/ArduinoLog.h
index 645d4f74..d0f9f3d9 100644
--- a/lib/ArduinoLog/ArduinoLog.h
+++ b/lib/ArduinoLog/ArduinoLog.h
@@ -285,19 +285,15 @@ class Logging {
if(_logOutput[i] == NULL || level>_level[i]) continue;
if(_prefix != NULL) {
- // _prefix(level, _logOutput[i]);
+ _prefix(level, _logOutput[i]);
}
va_list args;
va_start(args, msg);
-#ifdef STM32_CORE_VERSION_MAJOR
- print(_logOutput[i], msg, args);
- Serial.println();
-#else
- print(_logOutput[i], msg, args);
-#endif
+ print(_logOutput[i], msg, args);
+
if(_suffix != NULL) {
- // _suffix(level, _logOutput[i]);
+ _suffix(level, _logOutput[i]);
}
}
From 814006aad88e761686b1c520623e075061e08ac0 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Thu, 30 Apr 2020 17:31:36 +0200
Subject: [PATCH 05/56] Code cleanup
---
src/hasp_config.cpp | 5 -----
1 file changed, 5 deletions(-)
diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp
index 86fec041..8e4a0ada 100644
--- a/src/hasp_config.cpp
+++ b/src/hasp_config.cpp
@@ -23,11 +23,6 @@
#include "EEPROM.h"
#endif
-#ifndef FPSTR
-#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer))
-#endif
-
-
void confDebugSet(const char * name)
{
/*char buffer[128];
From 6e4fa9ee974622e15be383e8a1b5cafb105054a1 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Thu, 30 Apr 2020 17:32:09 +0200
Subject: [PATCH 06/56] Code cleanup
---
src/hasp_dispatch.cpp | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp
index bed14991..d4965ce2 100644
--- a/src/hasp_dispatch.cpp
+++ b/src/hasp_dispatch.cpp
@@ -48,11 +48,15 @@ void dispatchOutput(int output, bool state)
int pin = 0;
if(pin >= 0) {
+ Log.notice(F("PIN OUTPUT STATE %d"),state);
#if defined(ARDUINO_ARCH_ESP32)
ledcWrite(99, state ? 1023 : 0); // ledChannel and value
-#else
+#elif defined(ARDUINO_ARCH_ESP8266)
analogWrite(pin, state ? 1023 : 0);
+#else
+ pinMode (PE0, OUTPUT);
+ digitalWrite(PE0, state ? 1 : 0);
#endif
}
}
@@ -95,11 +99,6 @@ void dispatchAttribute(String strTopic, const char * payload)
{
if(strTopic.startsWith("p[")) {
dispatchButtonAttribute(strTopic, payload);
- } else if(strTopic.startsWith(F("output"))) {
-#if defined(ARDUINO_ARCH_ESP8266)
- uint8_t state = isON(payload) ? HIGH : LOW;
- digitalWrite(D1, state);
-#endif
} else if(strTopic == F("page")) {
dispatchPage(payload);
@@ -184,7 +183,7 @@ void dispatchBacklight(String strPayload)
void dispatchCommand(String cmnd)
{
- // dispatchPrintln(F("CMND"), cmnd);
+ dispatchPrintln(F("CMND"), cmnd);
if(cmnd.startsWith(F("page "))) {
cmnd = cmnd.substring(5, cmnd.length());
@@ -293,6 +292,8 @@ void dispatch_button(uint8_t id, const char * event)
{
#if HASP_USE_MQTT > 0
mqtt_send_input(id, event);
+#else
+ Log.notice(F("OUT: input%d = %s"), id, event);
#endif
}
From 3296b5005bce761a3de1d139ee19375666c0a24b Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Thu, 30 Apr 2020 17:32:30 +0200
Subject: [PATCH 07/56] Test support for STM32
---
src/hasp_button.cpp | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/src/hasp_button.cpp b/src/hasp_button.cpp
index 400a0b84..b30efe74 100644
--- a/src/hasp_button.cpp
+++ b/src/hasp_button.cpp
@@ -36,17 +36,13 @@ static void button_event_cb(AceButton * button, uint8_t eventType, uint8_t butto
memcpy_P(buffer, PSTR("UP"), sizeof(buffer));
break;
}
+ Log.verbose(F("BTNS: setup(): ready"));
+
dispatch_button(button->getId(), buffer);
}
void buttonSetup(void)
{
- // button[0] = new Button(2);
- button[1] = new AceButton(3, HIGH, 1);
- button[2] = new AceButton(4, HIGH, 2);
-
- Log.verbose(F("BTNS: setup(): ready"));
-
ButtonConfig * buttonConfig = ButtonConfig::getSystemButtonConfig();
buttonConfig->setEventHandler(button_event_cb);
@@ -63,6 +59,25 @@ void buttonSetup(void)
buttonConfig->setLongPressDelay(LV_INDEV_DEF_LONG_PRESS_TIME);
buttonConfig->setRepeatPressDelay(LV_INDEV_DEF_LONG_PRESS_TIME);
buttonConfig->setRepeatPressInterval(LV_INDEV_DEF_LONG_PRESS_REP_TIME);
+
+ // button[0] = new Button(2);
+#if defined(ARDUINO_ARCH_ESP8266)
+ button[1] = new AceButton(3, HIGH, 1);
+#else
+ //button[1] = new AceButton(3, HIGH, 1);
+#endif
+ pinMode (PC13, INPUT_PULLUP);
+ button[0] = new AceButton(buttonConfig, PC13, HIGH, 0);
+
+ pinMode (PA0, INPUT_PULLUP);
+ button[1] = new AceButton(buttonConfig, PA0, HIGH, 1);
+
+ pinMode (PD15, INPUT);
+ button[2] = new AceButton(buttonConfig, PD15, HIGH, 2);
+
+ Log.verbose(F("BTNS: setup(): ready"));
+
+
}
void IRAM_ATTR buttonLoop(void)
From 9ab641b9efea14724a36c2355872f51ad51c3ab9 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Thu, 30 Apr 2020 17:32:39 +0200
Subject: [PATCH 08/56] Add logging
---
lib/lv_fs_if/lv_fs_spiffs.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/lv_fs_if/lv_fs_spiffs.cpp b/lib/lv_fs_if/lv_fs_spiffs.cpp
index 49acb1ce..aad335bd 100644
--- a/lib/lv_fs_if/lv_fs_spiffs.cpp
+++ b/lib/lv_fs_if/lv_fs_spiffs.cpp
@@ -150,7 +150,7 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path,
Log.verbose(F("LVFS: %d"), __LINE__);
lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p; /*Just avoid the confusing casings*/
// Log.verbose(F("LVFS: Copying %s"), f.name());
- Log.verbose(F("LVFS: %d"), __LINE__);
+ Log.verbose(F("LVFS: %d - %x - %d"), __LINE__, fp, sizeof(lv_spiffs_file_t));
if (fp != NULL) (*fp) = file;
// memcpy(fp,&file,sizeof(lv_spiffs_file_t));
Log.verbose(F("LVFS: %d"), __LINE__);
From 60e40f876702811c7d839dcdc2eaa1cc44548907 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Thu, 30 Apr 2020 17:38:05 +0200
Subject: [PATCH 09/56] Update lvgl
---
lib/lvgl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/lvgl b/lib/lvgl
index 85f281bd..549c75c0 160000
--- a/lib/lvgl
+++ b/lib/lvgl
@@ -1 +1 @@
-Subproject commit 85f281bd3b4a6cb60381ff3d8a73534748e7d079
+Subproject commit 549c75c07fbabc5c6799ef5d676875eadd5874e6
From c15af62a46f3f9b102a5e429066b097cec3a6d6e Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Thu, 30 Apr 2020 17:42:44 +0200
Subject: [PATCH 10/56] Fix merge issue
---
platformio.ini | 4 +++-
src/hasp_dispatch.cpp | 5 +----
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/platformio.ini b/platformio.ini
index 81b7f8d9..3c9bec90 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -88,6 +88,7 @@ esp32_flags=
stm32_flags=
${env.build_flags}
-D IRAM_ATTR= ; No IRAM_ATTR available on STM32
+ -D STM32
; -- By default there are no ${override.build_flags} set
; -- to use it, copy platformio_override.ini from the template
@@ -144,7 +145,8 @@ build_flags =
-D TFT_BCKL=-1 ;None, configurable via web UI (e.g. 2 for D4)
-D TOUCH_CS=PC4 ;NC
-D TFT_RST=-1 ;D4
- -D STM32
+ -D HASP_OUTPUT_PIN=PA1 ; User LED D2 on DevEBox board
+ -D HASP_INPUT_PIN=PA0 ; User Button K1 on DevEBox board
lib_deps =
${env.lib_deps}
diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp
index a93a485e..43156964 100644
--- a/src/hasp_dispatch.cpp
+++ b/src/hasp_dispatch.cpp
@@ -98,10 +98,7 @@ void dispatchAttribute(String strTopic, const char * payload)
{
if(strTopic.startsWith("p[")) {
dispatchButtonAttribute(strTopic, payload);
-<<<<<<< HEAD
-
-=======
->>>>>>> 408b27b8155bd5f1c11900503df88956925fa6bd
+
} else if(strTopic == F("page")) {
dispatchPage(payload);
From bbb45057153d808cd9dade224cb24df6e37e3ab2 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Fri, 1 May 2020 21:57:55 +0200
Subject: [PATCH 11/56] Code clean-up
---
src/hasp.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/hasp.h b/src/hasp.h
index c9dbbab9..beda81e2 100644
--- a/src/hasp.h
+++ b/src/hasp.h
@@ -81,8 +81,6 @@ void hasp_send_obj_attribute_int(lv_obj_t * obj, const char * attribute, int32_t
void hasp_send_obj_attribute_color(lv_obj_t * obj, const char * attribute, lv_color_t color);
void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char * attr, const char * payload);
-void haspSendCmd(String nextionCmd);
-void haspParseJson(String & strPayload);
void haspNewObject(const JsonObject & config, uint8_t & saved_page_id);
void haspReconnect(void);
From d669e47704b72d4060a57a9da422b13b8c31e74f Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Fri, 1 May 2020 21:58:10 +0200
Subject: [PATCH 12/56] Code clean-up
---
src/hasp_gui.cpp | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp
index 337f8761..06c21d2e 100644
--- a/src/hasp_gui.cpp
+++ b/src/hasp_gui.cpp
@@ -306,14 +306,6 @@ static void IRAM_ATTR lv_tick_handler(void)
lv_tick_inc(guiTickPeriod);
}
-#ifdef STM32_CORE_VERSION
-void Update_IT_callback(void)
-{
- Serial.print("?");
- lv_tick_inc(guiTickPeriod);
-}
-#endif
-
/* Reading input device (simulated encoder here) */
/*bool read_encoder(lv_indev_drv_t * indev, lv_indev_data_t * data)
{
@@ -823,7 +815,7 @@ tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767
void IRAM_ATTR guiLoop()
{
-#ifdef STM32_CORE_VERSION_MAJOR
+#if defined(STM32F4xx)
tick.update();
while(Serial.available()) {
From 1a456481469ae507b6fdccfa23b4a8c331d5e4fc Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Fri, 1 May 2020 21:58:45 +0200
Subject: [PATCH 13/56] Code clean-up
---
src/hasp_eeprom.cpp | 46 +++++++--------------------------------------
1 file changed, 7 insertions(+), 39 deletions(-)
diff --git a/src/hasp_eeprom.cpp b/src/hasp_eeprom.cpp
index 1aed0979..ddc3d8d8 100644
--- a/src/hasp_eeprom.cpp
+++ b/src/hasp_eeprom.cpp
@@ -1,49 +1,17 @@
#include
#include "EEPROM.h"
-#include "hasp_debug.h"
-
-void eepromWrite(char addr, std::string & data);
-std::string eepromRead(char addr);
-
void eepromSetup()
{
+
+#if defined(STM32Fxx)
+ eeprom_buffer_fill();
+#endif
+
+ // ESP8266 // Don't start at boot, only at write
// EEPROM.begin(1024);
// debugPrintln("EEPROM: Started Eeprom");
}
void eepromLoop()
-{}
-
-void eepromUpdate(uint16_t addr, char ch)
-{
- if(EEPROM.read(addr) != ch) {
- EEPROM.write(addr, ch);
- }
-}
-
-void eepromWrite(uint16_t addr, std::string & data)
-{
- int count = data.length();
- for(int i = 0; i < count; i++) {
- eepromUpdate(addr + i, data[i]);
- }
- eepromUpdate(addr + count, '\0');
- // EEPROM.commit();
-}
-
-std::string eepromRead(uint16_t addr)
-{
- char data[1024]; // Max 1024 Bytes
- int len = 0;
- unsigned char k;
- k = EEPROM.read(addr);
- while(k != '\0' && len < 1023) // Read until null character
- {
- k = EEPROM.read(addr + len);
- if((uint8_t(k) < 32) || (uint8_t(k) > 127)) break; // check for printable ascii, includes '\0'
- data[len] = k;
- len++;
- }
- return std::string(data);
-}
\ No newline at end of file
+{}
\ No newline at end of file
From 7650a2ed811271d464aaba3a3a34851e97675120 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 00:15:54 +0200
Subject: [PATCH 14/56] Move from button to gpio
---
src/hasp_button.cpp | 90 -----------------------
src/hasp_button.h | 10 ---
src/hasp_gpio.cpp | 170 +++++++++++++++++++++++++++++++++++++++++---
src/hasp_gpio.h | 24 ++++++-
4 files changed, 184 insertions(+), 110 deletions(-)
delete mode 100644 src/hasp_button.cpp
delete mode 100644 src/hasp_button.h
diff --git a/src/hasp_button.cpp b/src/hasp_button.cpp
deleted file mode 100644
index b30efe74..00000000
--- a/src/hasp_button.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-#include "Arduino.h"
-#include "ArduinoLog.h"
-#include "AceButton.h"
-
-#include "hasp_conf.h"
-#include "lv_conf.h"
-
-#include "hasp_mqtt.h" // testing memory consumption
-#include "hasp_button.h"
-#include "hasp_dispatch.h"
-
-using namespace ace_button;
-static AceButton * button[HASP_NUM_INPUTS]; // Connect your button between pin 2 and GND
-
-static void button_event_cb(AceButton * button, uint8_t eventType, uint8_t buttonState)
-{
- char buffer[8];
- switch(eventType) {
- case 0: // AceButton::kEventPressed:
- memcpy_P(buffer, PSTR("DOWN"), sizeof(buffer));
- break;
- case 2: // AceButton::kEventClicked:
- memcpy_P(buffer, PSTR("SHORT"), sizeof(buffer));
- break;
- // case AceButton::kEventDoubleClicked:
- // memcpy_P(buffer, PSTR("DOUBLE"), sizeof(buffer));
- // break;
- case 4: // AceButton::kEventLongPressed:
- memcpy_P(buffer, PSTR("LONG"), sizeof(buffer));
- break;
- case 5: // AceButton::kEventRepeatPressed:
- return; // Fix needed for switches
- memcpy_P(buffer, PSTR("HOLD"), sizeof(buffer));
- break;
- case 1: // AceButton::kEventReleased:
- memcpy_P(buffer, PSTR("UP"), sizeof(buffer));
- break;
- }
- Log.verbose(F("BTNS: setup(): ready"));
-
- dispatch_button(button->getId(), buffer);
-}
-
-void buttonSetup(void)
-{
- ButtonConfig * buttonConfig = ButtonConfig::getSystemButtonConfig();
- buttonConfig->setEventHandler(button_event_cb);
-
- // Features
- buttonConfig->setFeature(ButtonConfig::kFeatureClick);
- buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
- buttonConfig->setFeature(ButtonConfig::kFeatureRepeatPress);
- // buttonConfig->setFeature(ButtonConfig::kFeatureDoubleClick);
- // buttonConfig->setFeature(ButtonConfig::kFeatureSuppressClickBeforeDoubleClick);
-
- // Delays
- buttonConfig->setClickDelay(LV_INDEV_DEF_LONG_PRESS_TIME);
- buttonConfig->setDoubleClickDelay(LV_INDEV_DEF_LONG_PRESS_TIME);
- buttonConfig->setLongPressDelay(LV_INDEV_DEF_LONG_PRESS_TIME);
- buttonConfig->setRepeatPressDelay(LV_INDEV_DEF_LONG_PRESS_TIME);
- buttonConfig->setRepeatPressInterval(LV_INDEV_DEF_LONG_PRESS_REP_TIME);
-
- // button[0] = new Button(2);
-#if defined(ARDUINO_ARCH_ESP8266)
- button[1] = new AceButton(3, HIGH, 1);
-#else
- //button[1] = new AceButton(3, HIGH, 1);
-#endif
- pinMode (PC13, INPUT_PULLUP);
- button[0] = new AceButton(buttonConfig, PC13, HIGH, 0);
-
- pinMode (PA0, INPUT_PULLUP);
- button[1] = new AceButton(buttonConfig, PA0, HIGH, 1);
-
- pinMode (PD15, INPUT);
- button[2] = new AceButton(buttonConfig, PD15, HIGH, 2);
-
- Log.verbose(F("BTNS: setup(): ready"));
-
-
-}
-
-void IRAM_ATTR buttonLoop(void)
-{
- // Should be called every 4-5ms or faster, for the default debouncing time
- // of ~20ms.
- for(uint8_t i = 0; i < HASP_NUM_INPUTS; i++) {
- if(button[i]) button[i]->check();
- }
-}
diff --git a/src/hasp_button.h b/src/hasp_button.h
deleted file mode 100644
index e19bb556..00000000
--- a/src/hasp_button.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#if HASP_USE_BUTTON
-
-#ifndef HASP_BUTTON_H
-#define HASP_BUTTON_H
-
-void buttonSetup(void);
-void IRAM_ATTR buttonLoop(void);
-
-#endif
-#endif
diff --git a/src/hasp_gpio.cpp b/src/hasp_gpio.cpp
index 4094d7e6..cf3ceee9 100644
--- a/src/hasp_gpio.cpp
+++ b/src/hasp_gpio.cpp
@@ -1,14 +1,166 @@
-#include
-#include "ArduinoJson.h"
+#include "Arduino.h"
+#include "ArduinoLog.h"
+
+#include "AceButton.h"
+#include "lv_conf.h" // For timing defines
+
+#include "hasp_conf.h"
+#include "hasp_gpio.h"
+#include "hasp_dispatch.h"
+
+#define HASP_NUM_GPIO_CONFIG 5
+
+uint8_t gpioUsedInputCount = 0;
+uint16_t gpioConfig[HASP_NUM_GPIO_CONFIG];
+
+using namespace ace_button;
+static AceButton * button[HASP_NUM_INPUTS];
+
+static void gpio_event_cb(AceButton * button, uint8_t eventType, uint8_t buttonState)
+{
+ char buffer[16];
+ switch(eventType) {
+ case 0: // AceButton::kEventPressed:
+ memcpy_P(buffer, PSTR("DOWN"), sizeof(buffer));
+ break;
+ case 2: // AceButton::kEventClicked:
+ memcpy_P(buffer, PSTR("SHORT"), sizeof(buffer));
+ break;
+ case AceButton::kEventDoubleClicked:
+ memcpy_P(buffer, PSTR("DOUBLE"), sizeof(buffer));
+ break;
+ case 4: // AceButton::kEventLongPressed:
+ memcpy_P(buffer, PSTR("LONG"), sizeof(buffer));
+ break;
+ case 5: // AceButton::kEventRepeatPressed:
+ // return; // Fix needed for switches
+ memcpy_P(buffer, PSTR("HOLD"), sizeof(buffer));
+ break;
+ case 1: // AceButton::kEventReleased:
+ memcpy_P(buffer, PSTR("UP"), sizeof(buffer));
+ break;
+ default:
+ memcpy_P(buffer, PSTR("UNKNOWN"), sizeof(buffer));
+ }
+ dispatch_button(button->getId(), buffer);
+}
+
+void aceButtonSetup(void)
+{
+ ButtonConfig * buttonConfig = ButtonConfig::getSystemButtonConfig();
+ buttonConfig->setEventHandler(gpio_event_cb);
+
+ // Features
+ buttonConfig->setFeature(ButtonConfig::kFeatureClick);
+ buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
+ buttonConfig->setFeature(ButtonConfig::kFeatureRepeatPress);
+ // buttonConfig->setFeature(ButtonConfig::kFeatureDoubleClick);
+ // buttonConfig->setFeature(ButtonConfig::kFeatureSuppressClickBeforeDoubleClick);
+
+ // Delays
+ buttonConfig->setClickDelay(LV_INDEV_DEF_LONG_PRESS_TIME);
+ buttonConfig->setDoubleClickDelay(LV_INDEV_DEF_LONG_PRESS_TIME);
+ buttonConfig->setLongPressDelay(LV_INDEV_DEF_LONG_PRESS_TIME);
+ buttonConfig->setRepeatPressDelay(LV_INDEV_DEF_LONG_PRESS_TIME);
+ buttonConfig->setRepeatPressInterval(LV_INDEV_DEF_LONG_PRESS_REP_TIME);
+}
+
+void IRAM_ATTR gpioLoop(void)
+{
+ // Should be called every 4-5ms or faster, for the default debouncing time of ~20ms.
+ for(uint8_t i = 0; i < gpioUsedInputCount; i++) {
+ if(button[i]) button[i]->check();
+ }
+}
+
+void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8_t channel)
+{
+ uint8_t i;
+ for(i = 0; i < HASP_NUM_INPUTS; i++) {
+
+ if(!button[i]) {
+ button[i] = new AceButton(pin, default_state, channel);
+
+ if(button[i]) {
+ pinMode(pin, input_mode);
+
+ ButtonConfig * buttonConfig = button[i]->getButtonConfig();
+ buttonConfig->setEventHandler(gpio_event_cb);
+ buttonConfig->setFeature(ButtonConfig::kFeatureClick);
+ buttonConfig->setFeature(ButtonConfig::kFeatureDoubleClick);
+ buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
+ buttonConfig->setFeature(ButtonConfig::kFeatureRepeatPress);
+ buttonConfig->setFeature(ButtonConfig::kFeatureSuppressClickBeforeDoubleClick);
+
+ Log.verbose(F("GPIO: Button%d created on pin %d (channel %d) mode %d default %d"), i, pin, channel, input_mode,default_state);
+ gpioUsedInputCount = i + 1;
+ return;
+ }
+ }
+ }
+ Log.error(F("GPIO: Failed to create Button%d pin %d (channel %d). All %d slots available are in use!"), i, pin,
+ channel, HASP_NUM_INPUTS);
+}
void gpioSetup()
{
-#if defined(ARDUINO_ARCH_ESP8266)
- pinMode(D1, OUTPUT);
- pinMode(D2, INPUT_PULLUP);
-#endif
-#if defined(STM32_CORE_VERSION)
- pinMode(HASP_OUTPUT_PIN, OUTPUT);
- pinMode(HASP_INPUT_PIN, INPUT_PULLUP);
+ aceButtonSetup();
+
+ //gpioConfig[0] = PD15 * 256 + 5 + (INPUT << 3);
+
+ for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
+ uint8_t pin = (gpioConfig[i] >> 8) & 0xFF;
+ uint8_t channel = gpioConfig[i] & 0b111; // 3bit
+ uint8_t input_mode = (gpioConfig[i] >> 3) & 0b11; // 2bit gpio mode
+ uint8_t gpiotype = (gpioConfig[i] >> 5) & 0b111; // 3bit
+ uint8_t default_state = gpioConfig[i] & 0b1; // 1bit: 0=LOW, 1=HIGH
+
+ switch(input_mode) {
+ case 1:
+ input_mode = OUTPUT;
+ break;
+ case 2:
+ input_mode = INPUT_PULLUP;
+ break;
+ case 3:
+ input_mode = INPUT_PULLDOWN;
+ break;
+ default:
+ input_mode = INPUT;
+ }
+
+ switch(gpiotype) {
+ case HASP_GPIO_SWITCH:
+ case HASP_GPIO_BUTTON:
+ gpioAddButton(pin, input_mode, default_state, channel);
+ break;
+
+ case HASP_GPIO_RELAY:
+ pinMode(pin, OUTPUT);
+ break;
+
+ // case HASP_GPIO_LED:
+ case HASP_GPIO_PWM:
+ case HASP_GPIO_BACKLIGHT:
+ pinMode(pin, OUTPUT);
+#if defined(ARDUINO_ARCH_ESP32)
+ // configure LED PWM functionalitites
+ ledcSetup(channel, 20000, 10);
+ // attach the channel to the GPIO to be controlled
+ ledcAttachPin(pin, channel);
#endif
+ break;
+ }
+ }
+
+ /*
+ #if defined(ARDUINO_ARCH_ESP8266)
+ pinMode(D1, OUTPUT);
+ pinMode(D2, INPUT_PULLUP);
+ #endif
+ #if defined(STM32F4xx)
+ pinMode(HASP_OUTPUT_PIN, OUTPUT);
+ pinMode(HASP_INPUT_PIN, INPUT);
+ #endif
+ */
}
\ No newline at end of file
diff --git a/src/hasp_gpio.h b/src/hasp_gpio.h
index 075f3a12..9a5c3b91 100644
--- a/src/hasp_gpio.h
+++ b/src/hasp_gpio.h
@@ -1,3 +1,25 @@
+#ifndef HASP_GPIO_H
+#define HASP_GPIO_H
+
#include "ArduinoJson.h"
-void gpioSetup();
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void gpioSetup(void);
+void IRAM_ATTR gpioLoop(void);
+
+enum lv_hasp_gpio_type_t {
+ HASP_GPIO_SWITCH = 0,
+ HASP_GPIO_BUTTON = 1,
+ HASP_GPIO_RELAY = 2,
+ HASP_GPIO_PWM = 3,
+ HASP_GPIO_BACKLIGHT = 4,
+};
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
\ No newline at end of file
From 80b1c0e6fa45470770d8aad04fa3746526efee51 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 00:16:17 +0200
Subject: [PATCH 15/56] Move from button to gpio
---
include/hasp_conf.h | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/include/hasp_conf.h b/include/hasp_conf.h
index 96b88a60..14366c88 100644
--- a/include/hasp_conf.h
+++ b/include/hasp_conf.h
@@ -22,10 +22,10 @@
#define HASP_HAS_FILESYSTEM (ARDUINO_ARCH_ESP32>0 || ARDUINO_ARCH_ESP8266>0)
#define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM)
-#define HASP_USE_EEPROM (HASP_HAS_FILESYSTEM)
+#define HASP_USE_EEPROM 1
#define HASP_USE_SDCARD 0
-#define HASP_USE_BUTTON 1
+#define HASP_USE_GPIO 1
#define HASP_USE_QRCODE 1
#define HASP_USE_PNGDECODE 0
@@ -43,7 +43,6 @@
#if HASP_USE_SPIFFS>0
#if defined(ARDUINO_ARCH_ESP32)
#include "SPIFFS.h"
-#include "hasp_eeprom.h"
#endif
#include // Include the SPIFFS library
#include "hasp_spiffs.h"
From 81ad8654565f5fd96b40d4cf2acfcf7157d36fce Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 00:16:40 +0200
Subject: [PATCH 16/56] stm32 memory manager
---
src/hasp_hal.cpp | 140 +++++++++++++++++++++++++++++------------------
1 file changed, 88 insertions(+), 52 deletions(-)
diff --git a/src/hasp_hal.cpp b/src/hasp_hal.cpp
index 83eb07c7..83e7a363 100644
--- a/src/hasp_hal.cpp
+++ b/src/hasp_hal.cpp
@@ -107,56 +107,7 @@ String halGetResetInfo()
#endif
}
- #ifdef __arm__
- // should use uinstd.h to define sbrk but Due causes a conflict
- extern "C" char* sbrk(int incr);
- #else // __ARM__
- extern char *__brkval;
- #endif // __arm__
-
- int freeMemory() {
- char top;
- #ifdef __arm__
- return &top - reinterpret_cast(sbrk(0));
- #elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
- return &top - __brkval;
- #else // __arm__
- return __brkval ? &top - __brkval : &top - __malloc_heap_start;
- #endif // __arm__
- }
-uint8_t halGetHeapFragmentation()
-{
-#if defined(ARDUINO_ARCH_ESP32)
- return (int8_t)(100.00f - (float)ESP.getMaxAllocHeap() * 100.00f / (float)ESP.getFreeHeap());
-#elif defined(ARDUINO_ARCH_ESP8266)
- return ESP.getHeapFragmentation();
-#else
- return 255;
-#endif
-}
-
-size_t halGetMaxFreeBlock()
-{
-#if defined(ARDUINO_ARCH_ESP32)
- return ESP.getMaxAllocHeap();
-#elif defined(ARDUINO_ARCH_ESP8266)
- return ESP.getMaxFreeBlockSize();
-#else
- return freeMemory();
-#endif
-}
-
-size_t halGetFreeHeap(void)
-{
-#if defined(ARDUINO_ARCH_ESP32)
- return ESP.getFreeHeap();
-#elif defined(ARDUINO_ARCH_ESP8266)
- return ESP.getFreeHeap();
-#else
- return 1;
-#endif
-}
String halGetCoreVersion()
{
@@ -193,8 +144,8 @@ String halGetChipModel()
case CHIP_ESP32S2:
model += F("ESP32-S2");
break;
- #endif
- default:
+#endif
+ default:
model = F("Unknown ESP");
}
model += F(" rev");
@@ -202,4 +153,89 @@ String halGetChipModel()
#endif // ESP32
return model;
-}
\ No newline at end of file
+}
+
+
+/*******************************/
+/* Memory Management Functions */
+
+#if defined(STM32F4xx)
+#include // for mallinfo()
+#include // for sbrk()
+
+int freeHighMemory()
+{
+ char top;
+#ifdef __arm__
+ return &top - reinterpret_cast(sbrk(0));
+#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
+ return &top - __brkval;
+#else // __arm__
+ return __brkval ? &top - __brkval : &top - __malloc_heap_start;
+#endif // __arm__
+}
+#endif
+
+/*
+extern char *fake_heap_end; // current heap start
+extern char *fake_heap_start; // current heap end
+
+char* getHeapStart() {
+ return fake_heap_start;
+}
+
+char* getHeapEnd() {
+ return (char*)sbrk(0);
+}
+
+char* getHeapLimit() {
+ return fake_heap_end;
+}
+
+int getMemUsed() { // returns the amount of used memory in bytes
+ struct mallinfo mi = mallinfo();
+ return mi.uordblks;
+}
+
+int getMemFree() { // returns the amount of free memory in bytes
+ struct mallinfo mi = mallinfo();
+ return mi.fordblks + freeHighMemory();
+} */
+
+size_t halGetMaxFreeBlock()
+{
+#if defined(ARDUINO_ARCH_ESP32)
+ return ESP.getMaxAllocHeap();
+#elif defined(ARDUINO_ARCH_ESP8266)
+ return ESP.getMaxFreeBlockSize();
+#else
+ return freeHighMemory();
+#endif
+}
+
+size_t halGetFreeHeap(void)
+{
+#if defined(ARDUINO_ARCH_ESP32)
+ return ESP.getFreeHeap();
+#elif defined(ARDUINO_ARCH_ESP8266)
+ return ESP.getFreeHeap();
+#else
+ struct mallinfo chuncks = mallinfo();
+
+ // fordblks
+ // This is the total size of memory occupied by free (not in use) chunks.
+
+ return chuncks.fordblks + freeHighMemory();
+#endif
+}
+
+uint8_t halGetHeapFragmentation()
+{
+#if defined(ARDUINO_ARCH_ESP32)
+ return (int8_t)(100.00f - (float)ESP.getMaxAllocHeap() * 100.00f / (float)ESP.getFreeHeap());
+#elif defined(ARDUINO_ARCH_ESP8266)
+ return ESP.getHeapFragmentation();
+#else
+ return (int8_t)(100.00f - (float)freeHighMemory() * 100.00f / (float)halGetFreeHeap());
+#endif
+}
From ec37e3d72a8207948ec286f28547a310042159a8 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 00:19:29 +0200
Subject: [PATCH 17/56] Move from button to gpio
---
src/main.cpp | 64 ++++++++++++++++++++++++++++------------------------
1 file changed, 34 insertions(+), 30 deletions(-)
diff --git a/src/main.cpp b/src/main.cpp
index 020416c5..2bb65501 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,12 +1,11 @@
#include "hasp_conf.h" // load first
#include
+#include "hasp_conf.h"
#include "hasp_debug.h"
-#include "hasp_spiffs.h"
#include "hasp_config.h"
#include "hasp_gui.h"
#include "hasp.h"
-#include "hasp_conf.h"
#include "hasp_oobe.h"
#include "hasp_gpio.h"
@@ -23,7 +22,7 @@ void setup()
/* Init Storage */
#if HASP_USE_EEPROM
-// eepromSetup(); // Don't start at boot, only at write
+ eepromSetup(); // Don't start at boot, only at write
#endif
#if HASP_USE_SPIFFS
@@ -44,7 +43,10 @@ void setup()
***************************/
debugSetup();
gpioSetup();
+
+#if HASP_USE_GPIO
guiSetup();
+#endif
#if HASP_USE_WIFI
wifiSetup();
@@ -76,10 +78,6 @@ void setup()
#endif // WIFI
-#if HASP_USE_BUTTON
- buttonSetup();
-#endif
-
#if HASP_USE_TASMOTA_SLAVE
slaveSetup();
#endif
@@ -90,15 +88,21 @@ void setup()
void loop()
{
/* Storage Loops */
+/*
#if HASP_USE_EEPROM
- eepromLoop();
-#endif
- // spiffsLoop();
-#if HASP_USE_SDCARD
- // sdcardLoop();
+ // eepromLoop(); // Not used
#endif
- // configLoop();
+#if HASP_USE_SPIFFS
+ // spiffsLoop(); // Not used
+#endif
+
+#if HASP_USE_SDCARD
+ // sdcardLoop(); // Not used
+#endif
+
+ // configLoop(); // Not used
+*/
/* Graphics Loops */
// tftLoop();
@@ -107,6 +111,10 @@ void loop()
/* Application Loops */
// haspLoop();
+#if HASP_USE_GPIO
+ gpioLoop();
+#endif
+
/* Network Services Loops */
#if HASP_USE_WIFI
@@ -126,10 +134,6 @@ void loop()
mdnsLoop();
#endif // MDNS
-#if HASP_USE_BUTTON
- buttonLoop();
-#endif // BUTTON
-
#if HASP_USE_OTA
otaLoop();
#endif // OTA
@@ -140,7 +144,9 @@ void loop()
slaveLoop();
#endif // TASMOTASLAVE
- // Every Second Loop
+ // digitalWrite(HASP_OUTPUT_PIN, digitalRead(HASP_INPUT_PIN)); // sets the LED to the button's value
+
+ /* Timer Loop */
if(millis() - mainLastLoopTime >= 1000) {
/* Run Every Second */
#if HASP_USE_OTA
@@ -149,27 +155,25 @@ void loop()
debugEverySecond();
/* Run Every 5 Seconds */
- if(mainLoopCounter == 0 || mainLoopCounter == 4) {
+#if HASP_USE_WIFI
+ if(mainLoopCounter == 0 || mainLoopCounter == 5) {
+ isConnected = wifiEvery5Seconds();
#if HASP_USE_HTTP
httpEvery5Seconds();
#endif
-
-#if HASP_USE_WIFI
- isConnected = wifiEvery5Seconds();
-
#if HASP_USE_MQTT
mqttEvery5Seconds(isConnected);
-#endif
-
#endif
}
+#endif // Wifi
- /* Update counters */
+ /* Reset loop counter every 10 seconds */
+ if(mainLoopCounter >= 9) {
+ mainLoopCounter = 0;
+ } else {
+ mainLoopCounter++;
+ }
mainLastLoopTime += 1000;
- mainLoopCounter++;
- if(mainLoopCounter >= 10) {
- mainLoopCounter = 0;
- }
}
delay(3);
From c4d85bf2e4eb175bb0c0ce5649388b694a4195c6 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 00:20:39 +0200
Subject: [PATCH 18/56] Code clean-up
---
src/hasp.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/hasp.h b/src/hasp.h
index beda81e2..169871a9 100644
--- a/src/hasp.h
+++ b/src/hasp.h
@@ -99,10 +99,10 @@ void IRAM_ATTR toggle_event_handler(lv_obj_t * obj, lv_event_t event);
* MACROS
**********************/
-#endif /*LV_USE_DEMO*/
+#endif /*HASP_USE_APP*/
#ifdef __cplusplus
} /* extern "C" */
#endif
-#endif /*DEMO_H*/
+#endif /*HASP_H*/
From d26c0c0200fd91714c947df20409dd41b3c88536 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 00:21:50 +0200
Subject: [PATCH 19/56] Add led brightness
---
src/hasp_attribute.cpp | 56 +++++++++++++++++++++++++-----------------
src/hasp_attribute.h | 1 +
2 files changed, 35 insertions(+), 22 deletions(-)
diff --git a/src/hasp_attribute.cpp b/src/hasp_attribute.cpp
index 43a7aa6f..de69758f 100644
--- a/src/hasp_attribute.cpp
+++ b/src/hasp_attribute.cpp
@@ -84,13 +84,6 @@ static lv_color_t haspPayloadToColor(const char * payload)
case 7:
if(!strcmp_P(payload, PSTR("magenta"))) return haspLogColor(LV_COLOR_MAGENTA);
- /* HEX format #rrggbb or #rrggbbaa */
- int r, g, b, a;
- if(*payload == '#' && sscanf(payload + 1, "%2x%2x%2x%2x", &r, &g, &b, &a) == 4) {
- return haspLogColor(LV_COLOR_MAKE(r, g, b));
- } else if(*payload == '#' && sscanf(payload + 1, "%2x%2x%2x", &r, &g, &b) == 3) {
- return haspLogColor(LV_COLOR_MAKE(r, g, b));
- }
default:
// if(!strcmp_P(payload, PSTR("darkblue"))) return haspLogColor(LV_COLOR_MAKE(0, 51, 102));
// if(!strcmp_P(payload, PSTR("lightblue"))) return haspLogColor(LV_COLOR_MAKE(46, 203,
@@ -98,6 +91,14 @@ static lv_color_t haspPayloadToColor(const char * payload)
break;
}
+ /* HEX format #rrggbb or #rrggbbaa */
+ int r, g, b, a;
+ if(*payload == '#' && sscanf(payload + 1, "%2x%2x%2x%2x", &r, &g, &b, &a) == 4) {
+ return haspLogColor(LV_COLOR_MAKE(r, g, b));
+ } else if(*payload == '#' && sscanf(payload + 1, "%2x%2x%2x", &r, &g, &b) == 3) {
+ return haspLogColor(LV_COLOR_MAKE(r, g, b));
+ }
+
/* 16-bit RGB565 Color Scheme*/
if(only_digits(payload)) {
uint16_t c = atoi(payload);
@@ -582,23 +583,23 @@ static void hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, co
lv_dropdown_set_selected(obj, val);
return;
} else if(check_obj_type(objtype, LV_HASP_LMETER)) {
- lv_linemeter_set_value(obj, intval);
- return;
+ return update ? lv_linemeter_set_value(obj, intval) : hasp_out_int(obj, attr, lv_linemeter_get_value(obj));
} else if(check_obj_type(objtype, LV_HASP_SLIDER)) {
- lv_slider_set_value(obj, intval, LV_ANIM_ON);
- return;
+ return update ? lv_slider_set_value(obj, intval, LV_ANIM_ON)
+ : hasp_out_int(obj, attr, lv_slider_get_value(obj));
} else if(check_obj_type(objtype, LV_HASP_LED)) {
- lv_led_set_bright(obj, (uint8_t)val);
- return;
+ if(update) {
+ return is_true(payload) ? lv_led_on(obj) : lv_led_off(obj);
+ } else {
+ // return hasp_out_int(obj, attr, lv_led_get_state(obj));
+ }
} else if(check_obj_type(objtype, LV_HASP_GAUGE)) {
- lv_gauge_set_value(obj, 0, intval);
- return;
+ return update ? lv_gauge_set_value(obj, 0, intval) : hasp_out_int(obj, attr, lv_gauge_get_value(obj, 0));
} else if(check_obj_type(objtype, LV_HASP_ROLLER)) {
lv_roller_set_selected(obj, val, LV_ANIM_ON);
return;
} else if(check_obj_type(objtype, LV_HASP_BAR)) {
- lv_bar_set_value(obj, intval, LV_ANIM_OFF);
- return;
+ return update ? lv_bar_set_value(obj, intval, LV_ANIM_ON) : hasp_out_int(obj, attr, lv_bar_get_value(obj));
} else if(check_obj_type(objtype, LV_HASP_CPICKER)) {
return update ? (void)lv_cpicker_set_color(obj, haspPayloadToColor(payload))
: hasp_out_color(obj, attr, lv_cpicker_get_color(obj));
@@ -781,6 +782,16 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char
}
break; // not a options object
+ case ATTR_BRIGHTNESS:
+ if(check_obj_type(obj, LV_HASP_LED)) {
+ if(update) {
+ lv_led_set_bright(obj, (uint8_t)val);
+ } else {
+ hasp_out_int(obj, attr, lv_led_get_bright(obj));
+ }
+ return;
+ }
+
// default:
// hasp_local_style_attr(obj, attr, payload, update);
}
@@ -794,9 +805,10 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char
* **************************/
static inline bool is_true(const char * s)
{
- return (!strcmp_P(s, PSTR("true")) || !strcmp_P(s, PSTR("TRUE")) || !strcmp_P(s, PSTR("1")) ||
+ return (!strcmp_P(s, PSTR("true")) || !strcmp_P(s, PSTR("TRUE")) || !strcmp_P(s, PSTR("True")) ||
!strcmp_P(s, PSTR("on")) || !strcmp_P(s, PSTR("ON")) || !strcmp_P(s, PSTR("On")) ||
- !strcmp_P(s, PSTR("yes")) || !strcmp_P(s, PSTR("YES")) || !strcmp_P(s, PSTR("Yes")));
+ !strcmp_P(s, PSTR("yes")) || !strcmp_P(s, PSTR("YES")) || !strcmp_P(s, PSTR("Yes")) ||
+ !strcmp_P(s, PSTR("1")));
}
static inline bool only_digits(const char * s)
@@ -808,17 +820,17 @@ static inline bool only_digits(const char * s)
return strlen(s) == digits;
}
-void hasp_out_int(lv_obj_t * obj, const char * attr, uint32_t val)
+void inline hasp_out_int(lv_obj_t * obj, const char * attr, uint32_t val)
{
hasp_send_obj_attribute_int(obj, attr, val);
}
-void hasp_out_str(lv_obj_t * obj, const char * attr, const char * data)
+void inline hasp_out_str(lv_obj_t * obj, const char * attr, const char * data)
{
hasp_send_obj_attribute_str(obj, attr, data);
}
-void hasp_out_color(lv_obj_t * obj, const char * attr, lv_color_t color)
+void inline hasp_out_color(lv_obj_t * obj, const char * attr, lv_color_t color)
{
hasp_send_obj_attribute_color(obj, attr, color);
}
diff --git a/src/hasp_attribute.h b/src/hasp_attribute.h
index 6171e1e3..e2fc932d 100644
--- a/src/hasp_attribute.h
+++ b/src/hasp_attribute.h
@@ -212,6 +212,7 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t)
#define ATTR_Y 121
#define ATTR_W 119
#define ATTR_H 104
+#define ATTR_BRIGHTNESS 10 // LED
#define ATTR_OPTIONS 29886
#define ATTR_ENABLED 28193
#define ATTR_OPACITY 10155
From bf4c8e975a363952c9091ff1af055fabd6282e37 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 00:22:29 +0200
Subject: [PATCH 20/56] Code clean-up
---
src/hasp_debug.cpp | 6 +++---
src/hasp_dispatch.cpp | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp
index 449c1e3b..8448eb98 100644
--- a/src/hasp_debug.cpp
+++ b/src/hasp_debug.cpp
@@ -232,8 +232,8 @@ static void debugPrintTimestamp(int level, Print * _logOutput)
_logOutput->printf(PSTR("%03lu]"), millis() % 1000);
} else */
{
- //_logOutput->printf(PSTR("[%20.3f]"), (float)millis() / 1000);
- _logOutput->printf(PSTR("[%20d]"), millis() );
+ uint32_t msecs = millis();
+ _logOutput->printf(PSTR("[%16d.%03d]"), msecs/1000, msecs%1000 );
}
}
@@ -333,7 +333,7 @@ void debugPreSetup(JsonObject settings)
if(baudrate == 0) baudrate = SERIAL_SPEED;
if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */
-#ifdef STM32_CORE_VERSION_MAJOR
+#if defined(STM32F4xx)
#ifndef STM32_SERIAL1 // Define what Serial port to use for log output
Serial.setRx(PA3); // User Serial2
Serial.setTx(PA2);
diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp
index 43156964..132966f7 100644
--- a/src/hasp_dispatch.cpp
+++ b/src/hasp_dispatch.cpp
@@ -52,7 +52,7 @@ void dispatchOutput(int output, bool state)
#if defined(ARDUINO_ARCH_ESP32)
ledcWrite(99, state ? 1023 : 0); // ledChannel and value
-#elif defined(STM32_CORE_VERSION)
+#elif defined(STM32F4xx)
digitalWrite(HASP_OUTPUT_PIN, state);
#else
analogWrite(pin, state ? 1023 : 0);
@@ -98,7 +98,7 @@ void dispatchAttribute(String strTopic, const char * payload)
{
if(strTopic.startsWith("p[")) {
dispatchButtonAttribute(strTopic, payload);
-
+
} else if(strTopic == F("page")) {
dispatchPage(payload);
From c1996a5eaffc468257958f1308cc2899e1ca3957 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 00:23:13 +0200
Subject: [PATCH 21/56] Add eeprom support
---
src/hasp_config.cpp | 116 +++++++++++++++++++++++++++++++-------------
1 file changed, 83 insertions(+), 33 deletions(-)
diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp
index 8e4a0ada..3e62e41f 100644
--- a/src/hasp_config.cpp
+++ b/src/hasp_config.cpp
@@ -1,6 +1,7 @@
#include "Arduino.h"
-#include "ArduinoJson.h"
#include "ArduinoLog.h"
+#include "ArduinoJson.h"
+#include "StreamUtils.h"
#include "hasp_config.h"
#include "hasp_debug.h"
@@ -13,13 +14,13 @@
#include "hasp_conf.h"
-#if HASP_USE_SPIFFS>0
+#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
+#if HASP_USE_EEPROM > 0
#include "EEPROM.h"
#endif
@@ -72,13 +73,17 @@ void configStartDebug(bool setupdebug, String & configFile)
{
if(setupdebug) {
debugStart(); // Debug started, now we can use it; HASP header sent
+#if HASP_USE_SPIFFS > 0
Log.notice(F("FILE: [SUCCESS] SPI flash FS mounted"));
-#if HASP_USE_SPIFFS>0
spiffsInfo();
spiffsList();
#endif
}
+#if HASP_USE_SPIFFS > 0
Log.notice(F("CONF: Loading %s"), configFile.c_str());
+#else
+ Log.notice(F("CONF: reading EEPROM"));
+#endif
}
void configGetConfig(JsonDocument & settings, bool setupdebug = false)
@@ -86,9 +91,10 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
String configFile((char *)0);
configFile.reserve(128);
configFile = String(FPSTR(HASP_CONFIG_FILE));
+ DeserializationError error;
-#if HASP_USE_SPIFFS>0
- File file = SPIFFS.open(configFile, "r");
+#if HASP_USE_SPIFFS > 0
+ File file = SPIFFS.open(configFile, "r");
if(file) {
size_t size = file.size();
@@ -97,7 +103,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
return;
}
- DeserializationError error = deserializeJson(settings, file);
+ error = deserializeJson(settings, file);
if(!error) {
file.close();
@@ -121,17 +127,26 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
return;
}
}
+#else
+
+#if HASP_USE_EEPROM > 0
+ EepromStream eepromStream(0, 1024);
+ error = deserializeJson(settings, eepromStream);
+#endif
+
#endif
// File does not exist or error reading file
if(setupdebug) {
debugPreSetup(settings[F("debug")]);
}
-
configStartDebug(setupdebug, configFile);
- Log.error(F("CONF: Failed to load %s"), configFile.c_str());
-}
+#if HASP_USE_SPIFFS > 0
+ Log.error(F("CONF: Failed to load %s"), configFile.c_str());
+#endif
+}
+/*
void configBackupToEeprom()
{
#if HASP_USE_SPIFFS>0
@@ -160,10 +175,9 @@ void configBackupToEeprom()
}
#endif
}
-
+*/
void configWriteConfig()
{
-#if HASP_USE_SPIFFS>0
String configFile((char *)0);
configFile.reserve(128);
configFile = String(FPSTR(HASP_CONFIG_FILE));
@@ -253,6 +267,7 @@ void configWriteConfig()
// changed |= otaGetConfig(settings[F("ota")].as());
if(writefile) {
+#if HASP_USE_SPIFFS > 0
File file = SPIFFS.open(configFile, "w");
if(file) {
Log.notice(F("CONF: Writing %s"), configFile.c_str());
@@ -260,36 +275,70 @@ void configWriteConfig()
file.close();
if(size > 0) {
Log.verbose(F("CONF: [SUCCESS] Saved %s"), configFile.c_str());
- configBackupToEeprom();
- return;
+ // configBackupToEeprom();
+ } else {
+ Log.error(F("CONF: Failed to write %s"), configFile.c_str());
}
+ } else {
+ Log.error(F("CONF: Failed to write %s"), configFile.c_str());
}
+#endif
- Log.error(F("CONF: Failed to write %s"), configFile.c_str());
+ // Method 1
+ // Log.verbose(F("CONF: Writing to EEPROM"));
+ // EepromStream eepromStream(0, 1024);
+ // WriteBufferingStream bufferedWifiClient{eepromStream, 512};
+ // serializeJson(doc, bufferedWifiClient);
+ // bufferedWifiClient.flush(); // <- OPTIONAL
+ // eepromStream.flush(); // (for ESP)
+
+#if defined(STM32F4xx)
+ // Method 2
+ Log.verbose(F("CONF: Writing to EEPROM"));
+ char buffer[1024 + 128];
+ size_t size = serializeJson(doc, buffer, sizeof(buffer));
+ if(size > 0) {
+ uint16_t i;
+ for(i = 0; i < size; i++) eeprom_buffered_write_byte(i, buffer[i]);
+ eeprom_buffered_write_byte(i, 0);
+ eeprom_buffer_flush();
+ Log.verbose(F("CONF: [SUCCESS] Saved EEPROM"));
+ } else {
+ Log.error(F("CONF: Failed to save config to EEPROM"));
+ }
+#endif
} else {
- Log.notice(F("CONF: Configuration was not changed"));
+ Log.notice(F("CONF: Configuration did not change"));
}
-#endif
}
void configSetup()
{
-#if HASP_USE_SPIFFS>0
- if(!SPIFFS.begin()) {
-#endif
-
-#if HASP_USE_SPIFFS>0
- } else {
-#endif
- DynamicJsonDocument settings(1024 + 128);
- Serial.print(__FILE__);
- Serial.println(__LINE__);
+ DynamicJsonDocument settings(1024 + 128);
- configGetConfig(settings, true);
+ for(uint8_t i = 0; i < 2; i++) {
+ Serial.print(__FILE__);
+ Serial.println(__LINE__);
- Log.error(F("FILE: SPI flash init failed. Unable to mount FS: Using default settings..."));
-#if HASP_USE_SPIFFS>0
+ if(i == 0) {
+#if HASP_USE_SPIFFS > 0
+ EepromStream eepromStream(0, 2048);
+ DeserializationError error = deserializeJson(settings, eepromStream);
+#else
+ continue;
+#endif
+ } else {
+#if HASP_USE_SPIFFS > 0
+ if(!SPIFFS.begin()) {
+ Log.error(F("FILE: SPI flash init failed. Unable to mount FS: Using default settings..."));
+ return;
+ }
+#endif
+ configGetConfig(settings, true);
+ }
+
+ //#if HASP_USE_SPIFFS > 0
Log.verbose(F("Loading debug settings"));
debugSetConfig(settings[F("debug")]);
Log.verbose(F("Loading GUI settings"));
@@ -317,10 +366,11 @@ void configSetup()
Log.verbose(F("Loading HTTP settings"));
httpSetConfig(settings[F("http")]);
#endif
-#endif
+#endif // Wifi
+ // }
+ Log.notice(F("User configuration loaded"));
}
- Log.notice(F("User configuration loaded"));
-#endif
+ //#endif
}
void configOutput(const JsonObject & settings)
From 233edece248978e3787f39736c696e6445d2bc92 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 00:53:18 +0200
Subject: [PATCH 22/56] Code clean-up
---
src/hasp_tft.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/hasp_tft.cpp b/src/hasp_tft.cpp
index b8f07ed0..ba8f74f8 100644
--- a/src/hasp_tft.cpp
+++ b/src/hasp_tft.cpp
@@ -98,6 +98,7 @@ void tftShowConfig(TFT_eSPI & tft)
#if defined(ARDUINO_ARCH_ESP8266)
Log.verbose(F("TFT: SPI overlap : %s"), (tftSetup.overlap == 1) ? PSTR("Yes") : PSTR("No"));
#endif
+
if(tftSetup.tft_driver != 0xE9D) // For ePaper displays the size is defined in the sketch
{
Log.verbose(F("TFT: Driver : %s"), tftDriverName().c_str()); // tftSetup.tft_driver);
From 51f34ae3ebaa5c0abeee70dd8e5ded3e547ecb38 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 00:53:59 +0200
Subject: [PATCH 23/56] Add StreamUtils and TasmotaSlave
---
platformio.ini | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/platformio.ini b/platformio.ini
index 3c9bec90..3fe9fa11 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -47,11 +47,13 @@ lib_deps =
;TFT_eSPI@^1.4.20 ; Tft SPI drivers
PubSubClient@^2.7.0 ; MQTT client
ArduinoJson@^6.15.1,>6.15.0 ; needs at least 6.15.0
+ StreamUtils@^1.4.0
Syslog@^2.0.0
AceButton@^1.4.0
;AsyncTCP
;https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip
;https://github.com/me-no-dev/ESPAsyncTCP/archive/master.zip
+ https://github.com/andrethomas/TasmotaSlave.git
lib_ignore =
https://github.com/littlevgl/lvgl.git
@@ -67,6 +69,7 @@ build_flags =
-D SPIFFS_TEMPORAL_FD_CACHE ; speedup opening recent files
-D ARDUINOJSON_DECODE_UNICODE=1 ; for utf-8 symbols
-D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments
+ -D STREAMUTILS_ENABLE_EEPROM=1 ; for STM32, it also supports EEPROM
;-D DISABLE_LOGGING
-I include ; include lv_conf.h and hasp_conf.h
${override.build_flags}
@@ -89,6 +92,7 @@ stm32_flags=
${env.build_flags}
-D IRAM_ATTR= ; No IRAM_ATTR available on STM32
-D STM32
+ -D STREAMUTILS_USE_EEPROM_UPDATE=1 ; update cell only when changed
; -- By default there are no ${override.build_flags} set
; -- to use it, copy platformio_override.ini from the template
@@ -145,8 +149,9 @@ build_flags =
-D TFT_BCKL=-1 ;None, configurable via web UI (e.g. 2 for D4)
-D TOUCH_CS=PC4 ;NC
-D TFT_RST=-1 ;D4
- -D HASP_OUTPUT_PIN=PA1 ; User LED D2 on DevEBox board
- -D HASP_INPUT_PIN=PA0 ; User Button K1 on DevEBox board
+ -D HASP_OUTPUT_PIN=PE0 ; User LED D2 on DevEBox board
+ -D HASP_INPUT_PIN=PD15 ; User Button K1 on DevEBox board
+ -D STM32_SERIAL1 ; Set this option to use Serial1 as default sersial port, leave out if using Serial2
lib_deps =
${env.lib_deps}
From 2785880a094690e3727971e027400b707c42f6bc Mon Sep 17 00:00:00 2001
From: arovak
Date: Sat, 2 May 2020 01:00:24 +0200
Subject: [PATCH 24/56] tasmotaslave impovements
---
lcd_config.ini | 2 +-
src/hasp.cpp | 2 +-
src/hasp_button.cpp | 2 +-
src/hasp_gpio.cpp | 2 +-
src/hasp_slave.cpp | 96 ++++++++++++++++++++++++++-------------------
src/main.cpp | 9 ++---
6 files changed, 63 insertions(+), 50 deletions(-)
diff --git a/lcd_config.ini b/lcd_config.ini
index 0e421971..dcbd3ebb 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=0 ; 0=0, 1=90, 2=180 or 3=270 degree
+ -D TFT_ROTATION=2 ; 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.cpp b/src/hasp.cpp
index cab2eaeb..78c75350 100644
--- a/src/hasp.cpp
+++ b/src/hasp.cpp
@@ -665,7 +665,7 @@ void haspClearPage(uint16_t pageid)
Log.warning(F("HASP: Cannot clear a layer"));
} else {
Log.notice(F("HASP: Clearing page %u"), pageid);
- lv_page_clean(pages[pageid]);
+ lv_obj_clean(pages[pageid]);
}
}
diff --git a/src/hasp_button.cpp b/src/hasp_button.cpp
index 400a0b84..a0aedd5e 100644
--- a/src/hasp_button.cpp
+++ b/src/hasp_button.cpp
@@ -41,7 +41,7 @@ static void button_event_cb(AceButton * button, uint8_t eventType, uint8_t butto
void buttonSetup(void)
{
- // button[0] = new Button(2);
+ button[0] = new AceButton(HASP_INPUT_PIN, LOW, 0);
button[1] = new AceButton(3, HIGH, 1);
button[2] = new AceButton(4, HIGH, 2);
diff --git a/src/hasp_gpio.cpp b/src/hasp_gpio.cpp
index 4094d7e6..d4e29029 100644
--- a/src/hasp_gpio.cpp
+++ b/src/hasp_gpio.cpp
@@ -9,6 +9,6 @@ void gpioSetup()
#endif
#if defined(STM32_CORE_VERSION)
pinMode(HASP_OUTPUT_PIN, OUTPUT);
- pinMode(HASP_INPUT_PIN, INPUT_PULLUP);
+ pinMode(HASP_INPUT_PIN, INPUT_PULLDOWN);
#endif
}
\ No newline at end of file
diff --git a/src/hasp_slave.cpp b/src/hasp_slave.cpp
index 0fc479ef..08e62f6a 100644
--- a/src/hasp_slave.cpp
+++ b/src/hasp_slave.cpp
@@ -7,6 +7,10 @@
#include "ArduinoLog.h"
#include "hasp_dispatch.h"
#include "hasp_gui.h"
+#include "hasp_hal.h"
+#include "hasp_tft.h"
+#include "hasp_config.h"
+#include "hasp.h"
#include "tasmotaSlave.h"
// set RX and TX pins
@@ -62,54 +66,63 @@ void slave_send_input(uint8_t id, const char * payload)
Log.notice(F("TAS PUB: %sstate/input%u = %s"), slaveNodeTopic, id, payload);
}
-// void slave_send_statusupdate()
-// { // Periodically publish a JSON string indicating system status
-// char data[3 * 128];
-// {
-// char buffer[128];
-// snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
-// haspGetVersion().c_str(), long(millis() / 1000));
-// strcat(buffer, data);
-// snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","),
-// ESP.getFreeHeap(), halGetHeapFragmentation(), halGetCoreVersion().c_str());
-// strcat(data, buffer);
-// snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u}"),
-// haspGetPage(), (HASP_NUM_PAGES));
-// strcat(data, buffer);
-// snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"),
-// tftDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT));
-// strcat(data, buffer);
-// }
-// slave_send_state(F("statusupdate"), data);
-// debugLastMillis = millis();
-// }
+void TASMO_TELE_JSON()
+{ // Periodically publish a JSON string indicating system status
+ char data[3 * 128];
+ {
+ char buffer[128];
+ snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
+ haspGetVersion().c_str(), long(millis() / 1000));
+ strcat(buffer, data);
+ snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"),
+ haspGetPage(), (HASP_NUM_PAGES));
+ strcat(data, buffer);
+ snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"),
+ tftDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT));
+ strcat(data, buffer);
+ }
+ slave.sendJSON((char*)data);
+ // slave_send_state(F("statusupdate"), data);
+ // debugLastMillis = millis();
+}
void TASMO_DATA_RECEIVE(char *data)
{
Log.verbose(F("TAS: Slave IN [%s]"), data);
- char slvCmd[20],slvVal[60];
- memset(slvCmd, 0 ,sizeof(slvCmd));
- memset(slvVal, 0 ,sizeof(slvVal));
- sscanf(data,"%s %s", slvCmd, slvVal);
+ char dataType[3];
+ memset(dataType, 0 ,sizeof(dataType));
+ snprintf_P(dataType, sizeof(dataType), data);
+ Log.verbose(F("TAS: dataType [%s]"), dataType);
- Log.verbose(F("TAS: Cmd[%s] Val[%s]"), slvCmd, slvVal);
-
- if (!strcmp(slvCmd, "calData")){
- if (strlen(slvVal) != 0) {
- char cBuffer[strlen(slvVal) + 24];
- memset(cBuffer, 0 ,sizeof(cBuffer));
- snprintf_P(cBuffer, sizeof(cBuffer), PSTR("{'calibration':[%s]}"), slvVal);
- dispatchConfig("gui",cBuffer);
- } else {
- dispatchConfig("gui","");
- }
- } else if (!strcmp(slvCmd, "jsonl")) {
- dispatchJsonl(slvVal);
+ if (!strcmp(dataType, "p[")){ //
+ dispatchCommand(data);
+ } else if (!strcmp(dataType, "[\"")) {
+ dispatchJson(data);
} else {
- char cBuffer[strlen(data)+1];
- snprintf_P(cBuffer, sizeof(cBuffer), PSTR("%s=%s"), slvCmd, slvVal);
- dispatchCommand(cBuffer);
+ char slvCmd[20],slvVal[60];
+ memset(slvCmd, 0 ,sizeof(slvCmd));
+ memset(slvVal, 0 ,sizeof(slvVal));
+ sscanf(data,"%[^=] =%s", slvCmd, slvVal);
+
+ Log.verbose(F("TAS: Cmd[%s] Val[%s]"), slvCmd, slvVal);
+
+ if (!strcmp(slvCmd, "calData")){
+ if (strlen(slvVal) != 0) {
+ char cBuffer[strlen(slvVal) + 24];
+ memset(cBuffer, 0 ,sizeof(cBuffer));
+ snprintf_P(cBuffer, sizeof(cBuffer), PSTR("{'calibration':[%s]}"), slvVal);
+ dispatchConfig("gui",cBuffer);
+ } else {
+ dispatchConfig("gui","");
+ }
+ } else if (!strcmp(slvCmd, "jsonl")) {
+ dispatchJsonl(slvVal);
+ } else if (!strcmp(slvCmd, "clearpage")) {
+ dispatchClearPage(slvVal);
+ } else {
+ dispatchCommand(data);
+ }
}
}
@@ -130,6 +143,7 @@ void slaveSetup()
{
Serial2.begin(HASP_SLAVE_SPEED);
// slave.attach_FUNC_EVERY_SECOND(TASMO_EVERY_SECOND);
+ slave.attach_FUNC_JSON(TASMO_TELE_JSON);
slave.attach_FUNC_COMMAND_SEND(TASMO_DATA_RECEIVE);
Log.notice(F("TAS: HASP SLAVE LOADED"));
diff --git a/src/main.cpp b/src/main.cpp
index 020416c5..79d70c63 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -103,10 +103,13 @@ void loop()
/* Graphics Loops */
// tftLoop();
guiLoop();
-
/* Application Loops */
// haspLoop();
+#if HASP_USE_BUTTON
+ buttonLoop();
+#endif // BUTTON
+
/* Network Services Loops */
#if HASP_USE_WIFI
@@ -126,10 +129,6 @@ void loop()
mdnsLoop();
#endif // MDNS
-#if HASP_USE_BUTTON
- buttonLoop();
-#endif // BUTTON
-
#if HASP_USE_OTA
otaLoop();
#endif // OTA
From 1e25a8e17b162a7ed51ca8fca52c12cec65145d2 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 02:28:01 +0200
Subject: [PATCH 25/56] Update lvgl dev-7.0
---
lib/lvgl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/lvgl b/lib/lvgl
index 549c75c0..1cf1721a 160000
--- a/lib/lvgl
+++ b/lib/lvgl
@@ -1 +1 @@
-Subproject commit 549c75c07fbabc5c6799ef5d676875eadd5874e6
+Subproject commit 1cf1721aa3e693ae37ea1809b7b7656b7c0cf85b
From 01d23a33d44695dd21235c4f41d1e005158a8749 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 03:27:07 +0200
Subject: [PATCH 26/56] Fix halRestart
---
src/hasp_dispatch.cpp | 2 +-
src/hasp_hal.cpp | 18 +++++++++---------
src/hasp_hal.h | 2 +-
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp
index 132966f7..6a23747f 100644
--- a/src/hasp_dispatch.cpp
+++ b/src/hasp_dispatch.cpp
@@ -298,7 +298,7 @@ void dispatchReboot(bool saveConfig)
Log.verbose(F("-------------------------------------"));
Log.notice(F("STOP: Properly Rebooting the MCU now!"));
Serial.flush();
- //halRestart();
+ halRestart();
}
void dispatch_button(uint8_t id, const char * event)
diff --git a/src/hasp_hal.cpp b/src/hasp_hal.cpp
index 83e7a363..672e7ba5 100644
--- a/src/hasp_hal.cpp
+++ b/src/hasp_hal.cpp
@@ -11,15 +11,6 @@
#if defined(ARDUINO_ARCH_ESP32)
#include // needed to get the ResetInfo
-void halRestart(void)
-{
-#if defined(ESP32) || defined(ESP8266)
- ESP.restart();
-#else
- NVIC_SystemReset();
-#endif
-}
-
// Compatibility function for ESP8266 getRestInfo
String esp32ResetReason(uint8_t cpuid)
{
@@ -90,6 +81,15 @@ String esp32ResetReason(uint8_t cpuid)
}
#endif
+void halRestart(void)
+{
+#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
+ ESP.restart();
+#else
+ NVIC_SystemReset();
+#endif
+}
+
String halGetResetInfo()
{
#if defined(ARDUINO_ARCH_ESP32)
diff --git a/src/hasp_hal.h b/src/hasp_hal.h
index 23ac6501..97f85f0a 100644
--- a/src/hasp_hal.h
+++ b/src/hasp_hal.h
@@ -3,12 +3,12 @@
#include
+void halRestart(void);
uint8_t halGetHeapFragmentation(void);
String halGetResetInfo(void);
size_t halGetMaxFreeBlock(void);
size_t halGetFreeHeap(void);
String halGetCoreVersion(void);
String halGetChipModel();
-void halRestart(void);
#endif
\ No newline at end of file
From 857948c8d78c22debffd8e256baf107258770d1a Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 03:27:36 +0200
Subject: [PATCH 27/56] Fix frequency logging
---
src/hasp_tft.cpp | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/hasp_tft.cpp b/src/hasp_tft.cpp
index ba8f74f8..1f246d01 100644
--- a/src/hasp_tft.cpp
+++ b/src/hasp_tft.cpp
@@ -87,7 +87,7 @@ void tftShowConfig(TFT_eSPI & tft)
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);
+ Log.verbose(F("TFT: CPU freq. : %i MHz"), F_CPU / 1000 / 1000);
#endif
#if defined(ARDUINO_ARCH_ESP8266)
@@ -156,14 +156,10 @@ void tftShowConfig(TFT_eSPI & tft)
tftPinInfo(F("TFT_D7"), tftSetup.pin_tft_d7);
if(tftSetup.serial == 1) {
- char buffer[8];
- snprintf_P(buffer, sizeof(buffer), "%4.2f", (float)tftSetup.tft_spi_freq / 10.0f);
- Log.verbose(F("TFT: Display SPI freq. : %s MHz"), buffer);
+ Log.verbose(F("TFT: Display SPI freq. : %d.%d MHz"), tftSetup.tft_spi_freq / 10, tftSetup.tft_spi_freq % 10);
}
if(tftSetup.pin_tch_cs != -1) {
- char buffer[8];
- snprintf_P(buffer, sizeof(buffer), "%4.2f", (float)tftSetup.tch_spi_freq / 10.0f);
- Log.verbose(F("TFT: Touch SPI freq. : %s MHz"), buffer);
+ Log.verbose(F("TFT: Touch SPI freq. : %d.%d MHz"), tftSetup.tch_spi_freq / 10, tftSetup.tch_spi_freq % 10);
}
}
From a47ad914ca29d5b3f2bd3124de215105cf8e1349 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 03:27:53 +0200
Subject: [PATCH 28/56] Code clean-up
---
lib/ArduinoLog/ArduinoLog.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/ArduinoLog/ArduinoLog.cpp b/lib/ArduinoLog/ArduinoLog.cpp
index d9ad7e06..c7265fd0 100644
--- a/lib/ArduinoLog/ArduinoLog.cpp
+++ b/lib/ArduinoLog/ArduinoLog.cpp
@@ -129,7 +129,6 @@ void Logging::print(Print * logOutput, const char * format, va_list args)
++format;
printFormat(logOutput, *format, (va_list *)&args);
} else {
- //_logOutput->print(*format);
logOutput->print(*format);
}
}
From 70daf63ef3d262f31e222009198fc31204ad2272 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 14:49:46 +0200
Subject: [PATCH 29/56] Fiw for ESP8266
---
src/hasp_gpio.cpp | 2 ++
src/hasp_spiffs.cpp | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/hasp_gpio.cpp b/src/hasp_gpio.cpp
index cf3ceee9..77797302 100644
--- a/src/hasp_gpio.cpp
+++ b/src/hasp_gpio.cpp
@@ -122,9 +122,11 @@ void gpioSetup()
case 2:
input_mode = INPUT_PULLUP;
break;
+#ifndef ARDUINO_ARCH_ESP8266
case 3:
input_mode = INPUT_PULLDOWN;
break;
+#endif
default:
input_mode = INPUT;
}
diff --git a/src/hasp_spiffs.cpp b/src/hasp_spiffs.cpp
index fdd64f8a..8522b7f3 100644
--- a/src/hasp_spiffs.cpp
+++ b/src/hasp_spiffs.cpp
@@ -14,7 +14,7 @@
void spiffsInfo()
{ // Get all information of your SPIFFS
-#if defined(ARDUINO_ARCH_ESP8266)
+#if 0
FSInfo fs_info;
SPIFFS.info(fs_info);
From 11e4d77d9f9138b955d6ff8292ff5bda2400c69d Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 15:04:10 +0200
Subject: [PATCH 30/56] Fixed help message
---
platformio_override-template.ini | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/platformio_override-template.ini b/platformio_override-template.ini
index 85445451..92f106ae 100644
--- a/platformio_override-template.ini
+++ b/platformio_override-template.ini
@@ -1,7 +1,7 @@
-; Copy this file and rename it to platform_override.ini
-; ONLY edit platform_override.ini to make local changes to the parameters
+; Copy this file and rename it to platformio_override.ini
+; ONLY edit platformio_override.ini to make local changes to the parameters
;
-; The platform_override.ini file is not overwritten or monitored by git
+; The platformio_override.ini file is not overwritten or monitored by git
[override]
From 0bb0f9875d2153bf721fdb06554ec206de323e4f Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 15:19:16 +0200
Subject: [PATCH 31/56] Fix for ESP8266
---
include/hasp_conf.h | 2 +-
src/hasp_gpio.cpp | 3 ++-
src/hasp_slave.cpp | 10 +++++++---
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/include/hasp_conf.h b/include/hasp_conf.h
index 14366c88..3ba35170 100644
--- a/include/hasp_conf.h
+++ b/include/hasp_conf.h
@@ -48,7 +48,7 @@
#include "hasp_spiffs.h"
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
-//#include "lv_zifont.h"
+#include "lv_zifont.h"
#endif
#endif
diff --git a/src/hasp_gpio.cpp b/src/hasp_gpio.cpp
index 77797302..4975f49d 100644
--- a/src/hasp_gpio.cpp
+++ b/src/hasp_gpio.cpp
@@ -107,6 +107,7 @@ void gpioSetup()
aceButtonSetup();
//gpioConfig[0] = PD15 * 256 + 5 + (INPUT << 3);
+ gpioAddButton(D1, INPUT_PULLUP, HIGH, 1);
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
uint8_t pin = (gpioConfig[i] >> 8) & 0xFF;
@@ -134,7 +135,7 @@ void gpioSetup()
switch(gpiotype) {
case HASP_GPIO_SWITCH:
case HASP_GPIO_BUTTON:
- gpioAddButton(pin, input_mode, default_state, channel);
+ // gpioAddButton(pin, input_mode, default_state, channel);
break;
case HASP_GPIO_RELAY:
diff --git a/src/hasp_slave.cpp b/src/hasp_slave.cpp
index 08e62f6a..0a4eed71 100644
--- a/src/hasp_slave.cpp
+++ b/src/hasp_slave.cpp
@@ -1,6 +1,8 @@
/*********************
* INCLUDES
*********************/
+#if HASP_USE_SLAVE>0
+
#include "hasp_slave.h"
#include
#include "ArduinoJson.h"
@@ -130,11 +132,11 @@ void TASMO_EVERY_SECOND(void)
{
if (ledstate) {
ledstate = false;
- digitalWrite(HASP_OUTPUT_PIN, 1);
+ //digitalWrite(HASP_OUTPUT_PIN, 1);
// Log.verbose(F("LED OFF"));
} else {
ledstate = true;
- digitalWrite(HASP_OUTPUT_PIN, 0);
+ //digitalWrite(HASP_OUTPUT_PIN, 0);
// Log.verbose(F("LED ON"));
}
}
@@ -158,4 +160,6 @@ void slaveLoop(void)
// TASMO_EVERY_SECOND();
// }
-}
\ No newline at end of file
+}
+
+#endif
\ No newline at end of file
From 2936147e50488ab92c95261cd495bcf195b27479 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 15:37:07 +0200
Subject: [PATCH 32/56] Revert led brightness
---
src/hasp_attribute.cpp | 16 +---------------
src/hasp_attribute.h | 1 -
2 files changed, 1 insertion(+), 16 deletions(-)
diff --git a/src/hasp_attribute.cpp b/src/hasp_attribute.cpp
index de69758f..4a110d65 100644
--- a/src/hasp_attribute.cpp
+++ b/src/hasp_attribute.cpp
@@ -588,11 +588,7 @@ static void hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, co
return update ? lv_slider_set_value(obj, intval, LV_ANIM_ON)
: hasp_out_int(obj, attr, lv_slider_get_value(obj));
} else if(check_obj_type(objtype, LV_HASP_LED)) {
- if(update) {
- return is_true(payload) ? lv_led_on(obj) : lv_led_off(obj);
- } else {
- // return hasp_out_int(obj, attr, lv_led_get_state(obj));
- }
+ return update ? lv_led_set_bright(obj, (uint8_t)val) : hasp_out_int(obj, attr, lv_led_get_bright(obj));
} else if(check_obj_type(objtype, LV_HASP_GAUGE)) {
return update ? lv_gauge_set_value(obj, 0, intval) : hasp_out_int(obj, attr, lv_gauge_get_value(obj, 0));
} else if(check_obj_type(objtype, LV_HASP_ROLLER)) {
@@ -782,16 +778,6 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char
}
break; // not a options object
- case ATTR_BRIGHTNESS:
- if(check_obj_type(obj, LV_HASP_LED)) {
- if(update) {
- lv_led_set_bright(obj, (uint8_t)val);
- } else {
- hasp_out_int(obj, attr, lv_led_get_bright(obj));
- }
- return;
- }
-
// default:
// hasp_local_style_attr(obj, attr, payload, update);
}
diff --git a/src/hasp_attribute.h b/src/hasp_attribute.h
index e2fc932d..6171e1e3 100644
--- a/src/hasp_attribute.h
+++ b/src/hasp_attribute.h
@@ -212,7 +212,6 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t)
#define ATTR_Y 121
#define ATTR_W 119
#define ATTR_H 104
-#define ATTR_BRIGHTNESS 10 // LED
#define ATTR_OPTIONS 29886
#define ATTR_ENABLED 28193
#define ATTR_OPACITY 10155
From 9ff231532c44da61e0656b0064610684e53e2160 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 2 May 2020 16:10:02 +0200
Subject: [PATCH 33/56] Add gpio settings
---
src/hasp_dispatch.cpp | 3 +-
src/hasp_gpio.cpp | 11 ++++---
src/hasp_http.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 78 insertions(+), 6 deletions(-)
diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp
index 6a23747f..7255a41c 100644
--- a/src/hasp_dispatch.cpp
+++ b/src/hasp_dispatch.cpp
@@ -55,7 +55,8 @@ void dispatchOutput(int output, bool state)
#elif defined(STM32F4xx)
digitalWrite(HASP_OUTPUT_PIN, state);
#else
- analogWrite(pin, state ? 1023 : 0);
+ digitalWrite(D1, state);
+ // analogWrite(pin, state ? 1023 : 0);
#endif
}
}
diff --git a/src/hasp_gpio.cpp b/src/hasp_gpio.cpp
index 4975f49d..c412482c 100644
--- a/src/hasp_gpio.cpp
+++ b/src/hasp_gpio.cpp
@@ -87,10 +87,10 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8
ButtonConfig * buttonConfig = button[i]->getButtonConfig();
buttonConfig->setEventHandler(gpio_event_cb);
buttonConfig->setFeature(ButtonConfig::kFeatureClick);
- buttonConfig->setFeature(ButtonConfig::kFeatureDoubleClick);
+ buttonConfig->clearFeature(ButtonConfig::kFeatureDoubleClick);
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
- buttonConfig->setFeature(ButtonConfig::kFeatureRepeatPress);
- buttonConfig->setFeature(ButtonConfig::kFeatureSuppressClickBeforeDoubleClick);
+ buttonConfig->clearFeature(ButtonConfig::kFeatureRepeatPress);
+ buttonConfig->clearFeature(ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses
Log.verbose(F("GPIO: Button%d created on pin %d (channel %d) mode %d default %d"), i, pin, channel, input_mode,default_state);
gpioUsedInputCount = i + 1;
@@ -107,7 +107,10 @@ void gpioSetup()
aceButtonSetup();
//gpioConfig[0] = PD15 * 256 + 5 + (INPUT << 3);
- gpioAddButton(D1, INPUT_PULLUP, HIGH, 1);
+#if defined(ARDUINO_ARCH_ESP8266)
+ gpioAddButton(D2, INPUT_PULLUP, HIGH, 1);
+ pinMode(D1, OUTPUT);
+#endif
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
uint8_t pin = (gpioConfig[i] >> 8) & 0xFF;
diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp
index 9bb9c5ab..d6bb718c 100644
--- a/src/hasp_http.cpp
+++ b/src/hasp_http.cpp
@@ -1278,6 +1278,11 @@ void webHandleConfig()
httpMessage +=
F("
");
+#if HASP_USE_GPIO > 0
+ httpMessage +=
+ F("");
+#endif
+
httpMessage +=
F("");
@@ -1489,9 +1494,69 @@ void webHandleHttpConfig()
}
#endif
+////////////////////////////////////////////////////////////////////////////////////////////////////
+void webHandleGpioConfig()
+{ // http://plate01/config/gpio
+ if(!httpIsAuthenticated(F("config/gpio"))) return;
+
+ DynamicJsonDocument settings(256);
+ debugGetConfig(settings.to());
+
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("");
+ httpMessage += httpGetNodename();
+ httpMessage += F("
");
+
+ httpMessage += F("");
+
+ httpMessage +=
+ PSTR("");
+
+ webSendPage(httpGetNodename(), httpMessage.length(), false);
+ webServer.sendContent(httpMessage);
+ httpMessage.clear();
+ webSendFooter();
+}
+
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleDebugConfig()
-{ // http://plate01/config/http
+{ // http://plate01/config/debug
if(!httpIsAuthenticated(F("config/debug"))) return;
DynamicJsonDocument settings(256);
@@ -1851,6 +1916,9 @@ void httpSetup()
#endif
#if HASP_USE_WIFI > 0
webServer.on(F("/config/wifi"), webHandleWifiConfig);
+#endif
+#if HASP_USE_GPIO > 0
+ webServer.on(F("/config/gpio"), webHandleGpioConfig);
#endif
webServer.on(F("/screenshot"), webHandleScreenshot);
webServer.on(F("/saveConfig"), webHandleSaveConfig);
From 3c5babf374836c507528c86f73d476e44569b41c Mon Sep 17 00:00:00 2001
From: arovak
Date: Sat, 2 May 2020 21:44:39 +0200
Subject: [PATCH 34/56] initial ethernet support for STM32F4xx
---
platformio.ini | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/platformio.ini b/platformio.ini
index 3fe9fa11..0a6cfa80 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -152,12 +152,16 @@ build_flags =
-D HASP_OUTPUT_PIN=PE0 ; User LED D2 on DevEBox board
-D HASP_INPUT_PIN=PD15 ; User Button K1 on DevEBox board
-D STM32_SERIAL1 ; Set this option to use Serial1 as default sersial port, leave out if using Serial2
+ -D HAL_ETH_MODULE_ENABLED=1 ; enable ethernet support
+ -D LAN8742A_PHY_ADDRESS=0x01U ; set LAN8720 address
lib_deps =
${env.lib_deps}
Ticker@^3.1.5
- STM32duino LwIP@^2.1.2
- STM32duino STM32Ethernet@^1.0.5
+ ; STM32duino LwIP@^2.1.2
+ ; STM32duino STM32Ethernet@^1.0.5
+ https://github.com/stm32duino/LwIP.git
+ https://github.com/stm32duino/STM32Ethernet.git
src_filter = +<*> -<.git/> -<.svn/> - - - - - +
From 86cfedb06f8bc567d6507f39df0f422d98d7e22f Mon Sep 17 00:00:00 2001
From: arovak
Date: Sat, 2 May 2020 21:45:34 +0200
Subject: [PATCH 35/56] increase tasmotaslave speed
---
src/hasp_slave.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/hasp_slave.h b/src/hasp_slave.h
index 89db9964..772a471c 100644
--- a/src/hasp_slave.h
+++ b/src/hasp_slave.h
@@ -3,7 +3,7 @@
#include "ArduinoJson.h"
-#define HASP_SLAVE_SPEED 38400
+#define HASP_SLAVE_SPEED 57600
void TASMO_EVERY_SECOND(void);
void TASMO_DATA_RECEIVE(char *data);
From ba9a7e204f1e656e53b6e773de8d73c8181417a2 Mon Sep 17 00:00:00 2001
From: arovak
Date: Mon, 4 May 2020 00:37:33 +0200
Subject: [PATCH 36/56] initial ethernet support
---
include/hasp_conf.h | 6 +++++-
include/lv_conf.h | 2 +-
platformio.ini | 48 ++++++++++++++++++++++++++++++++++++++++++-
src/hasp_ethernet.cpp | 33 +++++++++++++++++++++++++++++
src/hasp_ethernet.h | 7 +++++++
src/hasp_slave.cpp | 2 +-
src/main.cpp | 8 ++++++++
7 files changed, 102 insertions(+), 4 deletions(-)
create mode 100644 src/hasp_ethernet.cpp
create mode 100644 src/hasp_ethernet.h
diff --git a/include/hasp_conf.h b/include/hasp_conf.h
index 3ba35170..32ddcfd5 100644
--- a/include/hasp_conf.h
+++ b/include/hasp_conf.h
@@ -48,7 +48,7 @@
#include "hasp_spiffs.h"
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
-#include "lv_zifont.h"
+// #include "lv_zifont.h"
#endif
#endif
@@ -88,6 +88,10 @@
#include "hasp_slave.h"
#endif
+#if HASP_USE_ETHERNET>0
+#include "hasp_ethernet.h"
+#endif
+
#endif
#ifndef FPSTR
diff --git a/include/lv_conf.h b/include/lv_conf.h
index 244aa61a..85829f49 100644
--- a/include/lv_conf.h
+++ b/include/lv_conf.h
@@ -80,7 +80,7 @@ typedef int16_t lv_coord_t;
# define LV_MEM_SIZE (12 * 1024U) // 12KB
#endif
#ifndef LV_MEM_SIZE
-# define LV_MEM_SIZE (64 * 1024U) // 48KB
+# define LV_MEM_SIZE (20 * 1024U) // 48KB
#endif
/* Complier prefix for a big array declaration */
diff --git a/platformio.ini b/platformio.ini
index 0a6cfa80..84f3a1a8 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -153,7 +153,53 @@ build_flags =
-D HASP_INPUT_PIN=PD15 ; User Button K1 on DevEBox board
-D STM32_SERIAL1 ; Set this option to use Serial1 as default sersial port, leave out if using Serial2
-D HAL_ETH_MODULE_ENABLED=1 ; enable ethernet support
- -D LAN8742A_PHY_ADDRESS=0x01U ; set LAN8720 address
+ -D LAN8742A_PHY_ADDRESS=0x01U ; set LAN8720 PHY address
+
+lib_deps =
+ ${env.lib_deps}
+ Ticker@^3.1.5
+ ; STM32duino LwIP@^2.1.2
+ ; STM32duino STM32Ethernet@^1.0.5
+ https://github.com/stm32duino/LwIP.git
+ https://github.com/stm32duino/STM32Ethernet.git
+
+src_filter = +<*> -<.git/> -<.svn/> - - - - - +
+
+;***************************************************
+
+[env:DevEBox_STM32F4xx]
+platform = ststm32
+board = black_f407zg
+board_build.mcu = stm32f407vgt6
+; upload_protocol = dfu
+upload_protocol = stlink
+debug_tool = stlink
+monitor_port = COM19 ; To change the port, use platform_override.ini
+build_flags =
+ ${env.build_flags}
+ ${flags.stm32_flags}
+ -I include/stm32f4
+; -- TFT_eSPI build options ------------------------
+ ${lcd.lolin24}
+ ;-D TFT_MISO=PB4 ;Default
+ ;-D TFT_MOSI=PB5 ;Default
+ ;-D TFT_SCLK=PB3 ;Default
+ -D TFT_CS=PE13 ;D8
+ -D TFT_DC=PE14 ;D3
+ -D TFT_BCKL=-1 ;None, configurable via web UI (e.g. 2 for D4)
+ -D TOUCH_CS=PA6 ;NC
+ -D TFT_RST=-1 ;D4
+ -D STM32
+ -D TFT_SPI3
+ -D USE_DMA_TO_TFT
+ -D HASP_USE_TASMOTA_SLAVE=1
+ -D HASP_OUTPUT_PIN=PA1 ; User LED D2 on DevEBox board
+ -D HASP_INPUT_PIN=PA0 ; User Button K1 on DevEBox board
+ -D STM32_SERIAL1 ; Set this option to use Serial1 as default sersial port, leave out if using Serial2
+ -D HASP_USE_ETHERNET=1
+ -D HAL_ETH_MODULE_ENABLED=1
+ -D LAN8742A_PHY_ADDRESS=0x01U
+ ; -D DP83848_PHY_ADDRESS=0x01U
lib_deps =
${env.lib_deps}
diff --git a/src/hasp_ethernet.cpp b/src/hasp_ethernet.cpp
new file mode 100644
index 00000000..8c30ab9b
--- /dev/null
+++ b/src/hasp_ethernet.cpp
@@ -0,0 +1,33 @@
+#include
+#include "ArduinoJson.h"
+#include "ArduinoLog.h"
+#include "hasp_conf.h"
+
+#if HASP_USE_ETHERNET>0
+
+#include
+#include
+#include
+
+EthernetClient EthClient;
+
+void ethernetSetup()
+{
+ // start Ethernet and UDP
+ Log.notice(F("ETH: Begin Ethernet"));
+
+ if (Ethernet.begin() == 0) {
+ Log.notice(F("ETH: Failed to configure Ethernet using DHCP"));
+ } else {
+ IPAddress ip = Ethernet.localIP();
+ Log.notice(F("ETH: DHCP Success got IP=%d.%d.%d.%d"),ip[0], ip[1], ip[2], ip[3]);
+ }
+}
+
+void ethernetLoop(void)
+{
+ Ethernet.maintain();
+}
+
+
+#endif
\ No newline at end of file
diff --git a/src/hasp_ethernet.h b/src/hasp_ethernet.h
new file mode 100644
index 00000000..0b2b6947
--- /dev/null
+++ b/src/hasp_ethernet.h
@@ -0,0 +1,7 @@
+#ifndef HASP_ETHERNET_H
+#define HASP_ETHERNET_H
+
+void ethernetSetup();
+void ethernetLoop(void);
+
+#endif
\ No newline at end of file
diff --git a/src/hasp_slave.cpp b/src/hasp_slave.cpp
index 0a4eed71..7ae71a3c 100644
--- a/src/hasp_slave.cpp
+++ b/src/hasp_slave.cpp
@@ -1,7 +1,7 @@
/*********************
* INCLUDES
*********************/
-#if HASP_USE_SLAVE>0
+#if HASP_USE_TASMOTA_SLAVE>0
#include "hasp_slave.h"
#include
diff --git a/src/main.cpp b/src/main.cpp
index c4a259d8..eadd500f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -78,6 +78,10 @@ void setup()
#endif // WIFI
+#if HASP_USE_ETHERNET
+ ethernetSetup();
+#endif
+
#if HASP_USE_TASMOTA_SLAVE
slaveSetup();
#endif
@@ -139,6 +143,10 @@ void loop()
#endif // WIFI
+#if HASP_USE_ETHERNET
+ ethernetLoop();
+#endif
+
#if HASP_USE_TASMOTA_SLAVE
slaveLoop();
#endif // TASMOTASLAVE
From b24d8b077ae20c466ce358fd3a65ad63ade1f905 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Mon, 4 May 2020 00:42:01 +0200
Subject: [PATCH 37/56] Move serial input from gui to debug
---
include/hasp_conf.h | 2 +-
src/hasp_debug.cpp | 41 +++++++++++++++++++++++++++++++----------
src/hasp_gui.cpp | 23 +----------------------
src/main.cpp | 1 +
4 files changed, 34 insertions(+), 33 deletions(-)
diff --git a/include/hasp_conf.h b/include/hasp_conf.h
index 3ba35170..14366c88 100644
--- a/include/hasp_conf.h
+++ b/include/hasp_conf.h
@@ -48,7 +48,7 @@
#include "hasp_spiffs.h"
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
-#include "lv_zifont.h"
+//#include "lv_zifont.h"
#endif
#endif
diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp
index 8448eb98..61ccf0cf 100644
--- a/src/hasp_debug.cpp
+++ b/src/hasp_debug.cpp
@@ -71,6 +71,8 @@ Syslog * syslog;
#endif // USE_SYSLOG
// Serial Settings
+uint8_t serialInputIndex = 0; // Empty buffer
+char serialInputBuffer[1024];
uint16_t debugSerialBaud = SERIAL_SPEED / 10; // Multiplied by 10
bool debugSerialStarted = false;
bool debugAnsiCodes = true;
@@ -96,10 +98,10 @@ String debugHaspHeader()
header.reserve(256);
if(debugAnsiCodes) header += TERM_COLOR_YELLOW;
header += F(" _____ _____ _____ _____\r\n"
- " | | | _ | __| _ |\r\n"
- " | | |__ | __|\r\n"
- " |__|__|__|__|_____|__|\r\n"
- " Home Automation Switch Plate\r\n");
+ " | | | _ | __| _ |\r\n"
+ " | | |__ | __|\r\n"
+ " |__|__|__|__|_____|__|\r\n"
+ " Home Automation Switch Plate\r\n");
char buffer[128];
snprintf(buffer, sizeof(buffer), PSTR(" Open Hardware edition v%u.%u.%u\r\n"), HASP_VERSION_MAJOR,
HASP_VERSION_MINOR, HASP_VERSION_REVISION);
@@ -232,8 +234,8 @@ static void debugPrintTimestamp(int level, Print * _logOutput)
_logOutput->printf(PSTR("%03lu]"), millis() % 1000);
} else */
{
- uint32_t msecs = millis();
- _logOutput->printf(PSTR("[%16d.%03d]"), msecs/1000, msecs%1000 );
+ uint32_t msecs = millis();
+ _logOutput->printf(PSTR("[%16d.%03d]"), msecs / 1000, msecs % 1000);
}
}
@@ -334,10 +336,10 @@ void debugPreSetup(JsonObject settings)
if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */
#if defined(STM32F4xx)
- #ifndef STM32_SERIAL1 // Define what Serial port to use for log output
- Serial.setRx(PA3); // User Serial2
+#ifndef STM32_SERIAL1 // Define what Serial port to use for log output
+ Serial.setRx(PA3); // User Serial2
Serial.setTx(PA2);
- #endif
+#endif
#endif
Serial.begin(baudrate); /* prepare for possible serial debug */
delay(10);
@@ -378,7 +380,26 @@ void debugLvgl(lv_log_level_t level, const char * file, uint32_t line, const cha
#endif
void debugLoop()
-{}
+{
+ while(Serial.available()) {
+ char ch = Serial.read();
+ Serial.print(ch);
+ if(ch == 13 || ch == 10) {
+ serialInputBuffer[serialInputIndex] = 0;
+ if(serialInputIndex > 0) dispatchCommand(serialInputBuffer);
+ serialInputIndex = 0;
+ } else {
+ if(serialInputIndex < sizeof(serialInputBuffer) - 1) {
+ serialInputBuffer[serialInputIndex++] = ch;
+ }
+ serialInputBuffer[serialInputIndex] = 0;
+ if(strcmp(serialInputBuffer, "jsonl=") == 0) {
+ dispatchJsonl(Serial);
+ serialInputIndex = 0;
+ }
+ }
+ }
+}
/*void printLocalTime()
{
diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp
index 06c21d2e..76c9d8e6 100644
--- a/src/hasp_gui.cpp
+++ b/src/hasp_gui.cpp
@@ -76,9 +76,6 @@ static uint8_t guiRotation = TFT_ROTATION;
static Ticker tick; /* timer for interrupt handler */
#else
static Ticker tick(lv_tick_handler,guiTickPeriod);
-uint8_t serialInputIndex = 0; // Empty buffer
-char serialInputBuffer[1024];
-
#endif
static TFT_eSPI tft; // = TFT_eSPI(); /* TFT instance */
static uint16_t calData[5] = {0, 65535, 0, 65535, 0};
@@ -817,26 +814,8 @@ void IRAM_ATTR guiLoop()
{
#if defined(STM32F4xx)
tick.update();
-
- while(Serial.available()) {
- char ch = Serial.read();
- Serial.print(ch);
- if (ch == 13 ||ch == 10) {
- serialInputBuffer[serialInputIndex] = 0;
- if (serialInputIndex>0) dispatchCommand(serialInputBuffer);
- serialInputIndex=0;
- }else{
- if(serialInputIndex < sizeof(serialInputBuffer) - 1) {
- serialInputBuffer[serialInputIndex++] = ch;
- }
- serialInputBuffer[serialInputIndex] = 0;
- if (strcmp(serialInputBuffer,"jsonl=")==0){
- dispatchJsonl(Serial);
- serialInputIndex=0;
- }
- }
- }
#endif
+
//lv_tick_handler();
lv_task_handler(); /* let the GUI do its work */
guiCheckSleep();
diff --git a/src/main.cpp b/src/main.cpp
index c4a259d8..041d6aa2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -109,6 +109,7 @@ void loop()
guiLoop();
/* Application Loops */
// haspLoop();
+ debugLoop();
#if HASP_USE_GPIO
gpioLoop();
From d90b57725225517504e9265a27c8d3e25b31e37c Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Mon, 4 May 2020 00:42:47 +0200
Subject: [PATCH 38/56] Initial gpio configuration
---
src/hasp_gpio.cpp | 100 +++++++++++++++++++++++++++++++++++++++++-----
src/hasp_http.cpp | 40 +++++--------------
2 files changed, 100 insertions(+), 40 deletions(-)
diff --git a/src/hasp_gpio.cpp b/src/hasp_gpio.cpp
index c412482c..885278db 100644
--- a/src/hasp_gpio.cpp
+++ b/src/hasp_gpio.cpp
@@ -16,6 +16,46 @@ uint16_t gpioConfig[HASP_NUM_GPIO_CONFIG];
using namespace ace_button;
static AceButton * button[HASP_NUM_INPUTS];
+struct hasp_gpio_config_t {
+ const uint8_t pin;
+ const uint8_t group;
+ const uint8_t io_mode;
+ bool default_state;
+};
+
+// An array of button pins, led pins, and the led states. Cannot be const
+// because ledState is mutable.
+ hasp_gpio_config_t gpioConfig2[HASP_NUM_GPIO_CONFIG] = {
+ {2, 8, INPUT, LOW},
+ {3, 9, OUTPUT, LOW},
+ {4, 10, INPUT, HIGH},
+ {5, 11, OUTPUT, LOW},
+ {6, 12, INPUT, LOW},
+};
+
+#if defined(ARDUINO_ARCH_ESP32)
+class TouchConfig : public ButtonConfig {
+ public:
+ TouchConfig();
+
+ protected:
+ // Number of iterations to sample the capacitive switch. Higher number
+ // provides better smoothing but increases the time taken for a single read.
+ static const uint8_t kSamples = 10;
+
+ // The threshold value which is considered to be a "touch" on the switch.
+ static const long kTouchThreshold = 70;
+
+ int readButton(uint8_t pin) override
+ {
+ // long total = mSensor.capacitiveSensor(kSamples);
+ return (touchRead(pin) > kTouchThreshold) ? LOW : HIGH;
+ }
+};
+
+TouchConfig touchConfig();
+#endif
+
static void gpio_event_cb(AceButton * button, uint8_t eventType, uint8_t buttonState)
{
char buffer[16];
@@ -73,13 +113,16 @@ void IRAM_ATTR gpioLoop(void)
}
}
-void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8_t channel)
+void gpioAddButton( uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8_t channel)
{
+
+
uint8_t i;
for(i = 0; i < HASP_NUM_INPUTS; i++) {
if(!button[i]) {
button[i] = new AceButton(pin, default_state, channel);
+ // button[i]->init(pin, default_state, channel);
if(button[i]) {
pinMode(pin, input_mode);
@@ -90,9 +133,42 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8
buttonConfig->clearFeature(ButtonConfig::kFeatureDoubleClick);
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
buttonConfig->clearFeature(ButtonConfig::kFeatureRepeatPress);
- buttonConfig->clearFeature(ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses
+ buttonConfig->clearFeature(
+ ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses
- Log.verbose(F("GPIO: Button%d created on pin %d (channel %d) mode %d default %d"), i, pin, channel, input_mode,default_state);
+ Log.verbose(F("GPIO: Button%d created on pin %d (channel %d) mode %d default %d"), i, pin, channel,
+ input_mode, default_state);
+ gpioUsedInputCount = i + 1;
+ return;
+ }
+ }
+ }
+ Log.error(F("GPIO: Failed to create Button%d pin %d (channel %d). All %d slots available are in use!"), i, pin,
+ channel, HASP_NUM_INPUTS);
+}
+
+void gpioAddTouchButton( uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8_t channel)
+{
+ uint8_t i;
+ for(i = 0; i < HASP_NUM_INPUTS; i++) {
+
+ if(!button[i]) {
+ button[i] = new AceButton();
+
+ if(button[i]) {
+ pinMode(pin, input_mode);
+
+ ButtonConfig * buttonConfig = button[i]->getButtonConfig();
+ buttonConfig->setEventHandler(gpio_event_cb);
+ buttonConfig->setFeature(ButtonConfig::kFeatureClick);
+ buttonConfig->clearFeature(ButtonConfig::kFeatureDoubleClick);
+ buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
+ buttonConfig->clearFeature(ButtonConfig::kFeatureRepeatPress);
+ buttonConfig->clearFeature(
+ ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses
+
+ Log.verbose(F("GPIO: Button%d created on pin %d (channel %d) mode %d default %d"), i, pin, channel,
+ input_mode, default_state);
gpioUsedInputCount = i + 1;
return;
}
@@ -106,18 +182,24 @@ void gpioSetup()
{
aceButtonSetup();
- //gpioConfig[0] = PD15 * 256 + 5 + (INPUT << 3);
+ // gpioConfig[0] = PD15 * 256 + 5 + (INPUT << 3);
#if defined(ARDUINO_ARCH_ESP8266)
- gpioAddButton(D2, INPUT_PULLUP, HIGH, 1);
+ gpioAddButton( D2, INPUT_PULLUP, HIGH, 1);
+ pinMode(D1, OUTPUT);
+#endif
+
+#if defined(ARDUINO_ARCH_ESP32)
+ gpioAddButton( D2, INPUT, HIGH, 1);
pinMode(D1, OUTPUT);
#endif
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
uint8_t pin = (gpioConfig[i] >> 8) & 0xFF;
- uint8_t channel = gpioConfig[i] & 0b111; // 3bit
+ uint8_t channel = gpioConfig[i] & 0b111; // 3bit
uint8_t input_mode = (gpioConfig[i] >> 3) & 0b11; // 2bit gpio mode
- uint8_t gpiotype = (gpioConfig[i] >> 5) & 0b111; // 3bit
- uint8_t default_state = gpioConfig[i] & 0b1; // 1bit: 0=LOW, 1=HIGH
+ //uint8_t input_mode = gpioConfig[i].io_mode
+ uint8_t gpiotype = (gpioConfig[i] >> 5) & 0b111; // 3bit
+ uint8_t default_state = gpioConfig[i] & 0b1; // 1bit: 0=LOW, 1=HIGH
switch(input_mode) {
case 1:
@@ -138,7 +220,7 @@ void gpioSetup()
switch(gpiotype) {
case HASP_GPIO_SWITCH:
case HASP_GPIO_BUTTON:
- // gpioAddButton(pin, input_mode, default_state, channel);
+ // gpioAddButton(gpioConfig[i].io_mode.pin, input_mode, gpioConfig[i].default_state, gpioConfig[i].group);
break;
case HASP_GPIO_RELAY:
diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp
index d6bb718c..0b35fb4b 100644
--- a/src/hasp_http.cpp
+++ b/src/hasp_http.cpp
@@ -1510,40 +1510,18 @@ void webHandleGpioConfig()
httpMessage += F("");
+// httpMessage += F("");
httpMessage +=
PSTR("");
From 8f71db923ecd0ef957be1fa93014e03a178361ed Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Mon, 4 May 2020 00:43:08 +0200
Subject: [PATCH 39/56] Eeprtom testing
---
src/hasp.cpp | 14 +++++++++++++-
src/hasp_eeprom.cpp | 6 ++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/hasp.cpp b/src/hasp.cpp
index 78c75350..fc983b0c 100644
--- a/src/hasp.cpp
+++ b/src/hasp.cpp
@@ -3,8 +3,9 @@
*********************/
#include "hasp_conf.h"
#include
-#include "ArduinoJson.h"
#include "ArduinoLog.h"
+#include "ArduinoJson.h"
+#include "StreamUtils.h"
#include "lvgl.h"
#include "lv_conf.h"
@@ -24,6 +25,8 @@
#include "hasp_attribute.h"
#include "hasp.h"
+#include "EEPROM.h"
+
//#if LV_USE_HASP
/*********************
@@ -955,6 +958,15 @@ void haspLoadPage(const char * pages)
file.close();
Log.notice(F("HASP: File %s loaded"), pages);
+#else
+
+#if HASP_USE_EEPROM > 0
+ Log.notice(F("HASP: Loading jsonl from EEPROM..."));
+ EepromStream eepromStream(4096, 1024);
+ dispatchJsonl(eepromStream);
+ Log.notice(F("HASP: Loaded jsonl from EEPROM"));
+#endif
+
#endif
}
diff --git a/src/hasp_eeprom.cpp b/src/hasp_eeprom.cpp
index ddc3d8d8..d53963fe 100644
--- a/src/hasp_eeprom.cpp
+++ b/src/hasp_eeprom.cpp
@@ -6,6 +6,12 @@ void eepromSetup()
#if defined(STM32Fxx)
eeprom_buffer_fill();
+ char buffer[] = "{\"objid\":10,\"id\":1,\"page\":0,\"x\":10,\"y\":45,\"w\":220,\"h\":55,\"toggle\":\"TRUE\",\"txt\":\"Toggle Me\"}";
+ uint size = strlen(buffer);
+ uint16_t i;
+ for(i = 0; i < size; i++) eeprom_buffered_write_byte(i+4096, buffer[i]);
+ eeprom_buffered_write_byte(i+4096, 0);
+ // eeprom_buffer_flush();
#endif
// ESP8266 // Don't start at boot, only at write
From cb5225ccf62167f533e5c9dc7e1b6b245d13de26 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Tue, 5 May 2020 15:02:14 +0200
Subject: [PATCH 40/56] Update lvgl from upstream
---
lib/lvgl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/lvgl b/lib/lvgl
index 1cf1721a..21f52a93 160000
--- a/lib/lvgl
+++ b/lib/lvgl
@@ -1 +1 @@
-Subproject commit 1cf1721aa3e693ae37ea1809b7b7656b7c0cf85b
+Subproject commit 21f52a939133d91acc82a3a98767d35de4e2d7a5
From 3d0d3a49b5124d7794c73a87386d7ec121b739d0 Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Wed, 6 May 2020 19:39:03 +0200
Subject: [PATCH 41/56] =?UTF-8?q?Add=20st=C3=B932f4=20http=20and=20mqtt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 1 +
include/hasp_conf.h | 132 ++-
include/stm32f4/hal_conf_custom.h | 13 +
lib/lvgl | 2 +-
platformio.ini | 7 +-
src/hasp_config.cpp | 6 +-
src/hasp_dispatch.cpp | 3 +-
src/hasp_ethernet.cpp | 7 +-
src/hasp_gui.cpp | 98 +-
src/hasp_gui.h | 18 +-
src/hasp_hal.cpp | 112 +-
src/hasp_hal.h | 3 +
src/hasp_http.cpp | 1740 ++++++++++++-----------------
src/hasp_http.h | 2 +
src/hasp_mqtt.cpp | 26 +-
src/hasp_spiffs.cpp | 21 -
src/hasp_spiffs.h | 1 -
src/hasp_telnet.cpp | 79 +-
src/hasp_tft.cpp | 4 +-
src/hasp_wifi.cpp | 16 -
src/main.cpp | 94 +-
21 files changed, 1142 insertions(+), 1243 deletions(-)
create mode 100644 include/stm32f4/hal_conf_custom.h
diff --git a/.gitignore b/.gitignore
index a4938ce5..95b48960 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
.git
.pio
data/*
+src/user_setups/active/*
src/user_config_override.h
platformio_override.ini
diff --git a/include/hasp_conf.h b/include/hasp_conf.h
index 32ddcfd5..ea4bb8d1 100644
--- a/include/hasp_conf.h
+++ b/include/hasp_conf.h
@@ -7,40 +7,82 @@
#define HASP_USE_APP 1
-/* Network */
-#define HASP_HAS_NETWORK (ARDUINO_ARCH_ESP32>0 || ARDUINO_ARCH_ESP8266>0)
+/* Network Services */
+#define HASP_HAS_NETWORK (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0)
+#ifndef HASP_USE_OTA
#define HASP_USE_OTA (HASP_HAS_NETWORK)
-#define HASP_USE_WIFI (HASP_HAS_NETWORK)
-#define HASP_USE_MQTT (HASP_HAS_NETWORK)
-#define HASP_USE_HTTP (HASP_HAS_NETWORK)
-#define HASP_USE_MDNS (HASP_HAS_NETWORK)
-#define HASP_USE_SYSLOG (HASP_HAS_NETWORK)
-#define HASP_USE_TELNET (HASP_HAS_NETWORK)
-
-/* Filesystem */
-#define HASP_HAS_FILESYSTEM (ARDUINO_ARCH_ESP32>0 || ARDUINO_ARCH_ESP8266>0)
-
-#define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM)
-#define HASP_USE_EEPROM 1
-#define HASP_USE_SDCARD 0
-
-#define HASP_USE_GPIO 1
-
-#define HASP_USE_QRCODE 1
-#define HASP_USE_PNGDECODE 0
-
-#define HASP_NUM_INPUTS 3 // Buttons
-#define HASP_NUM_OUTPUTS 3
-
-#if defined(ARDUINO_ARCH_ESP32)
-#define HASP_NUM_PAGES 12
-#else
-#define HASP_NUM_PAGES 4
#endif
+#ifndef HASP_USE_WIFI
+#define HASP_USE_WIFI (HASP_HAS_NETWORK)
+#endif
-#if HASP_USE_SPIFFS>0
+#ifndef HASP_USE_MQTT
+#define HASP_USE_MQTT 1
+#endif
+
+#ifndef HASP_USE_HTTP
+#define HASP_USE_HTTP 1
+#endif
+
+#ifndef HASP_USE_MDNS
+#define HASP_USE_MDNS (HASP_HAS_NETWORK)
+#endif
+
+#ifndef HASP_USE_SYSLOG
+#define HASP_USE_SYSLOG (HASP_HAS_NETWORK)
+#endif
+
+#ifndef HASP_USE_TELNET
+#define HASP_USE_TELNET 0
+#endif
+
+/* Filesystem */
+#define HASP_HAS_FILESYSTEM (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0)
+
+#ifndef HASP_USE_SPIFFS
+#define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM)
+#endif
+
+#ifndef HASP_USE_EEPROM
+#define HASP_USE_EEPROM 1
+#endif
+
+#ifndef HASP_USE_SDCARD
+#define HASP_USE_SDCARD 0
+#endif
+
+#ifndef HASP_USE_GPIO
+#define HASP_USE_GPIO 1
+#endif
+
+#ifndef HASP_USE_QRCODE
+#define HASP_USE_QRCODE 1
+#endif
+
+#ifndef HASP_USE_PNGDECODE
+#define HASP_USE_PNGDECODE 0
+#endif
+
+#ifndef HASP_NUM_INPUTS
+#define HASP_NUM_INPUTS 3 // Buttons
+#endif
+
+#ifndef HASP_NUM_OUTPUTS
+#define HASP_NUM_OUTPUTS 3
+#endif
+
+#ifndef HASP_NUM_PAGES
+#if defined(ARDUINO_ARCH_ESP8266)
+#define HASP_NUM_PAGES 4
+#else
+#define HASP_NUM_PAGES 12
+#endif
+#endif
+
+/* Includes */
+#if HASP_USE_SPIFFS > 0
#if defined(ARDUINO_ARCH_ESP32)
#include "SPIFFS.h"
#endif
@@ -48,52 +90,56 @@
#include "hasp_spiffs.h"
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
-// #include "lv_zifont.h"
-#endif
+#include "lv_zifont.h"
#endif
+#endif // SPIFFS
-#if HASP_USE_EEPROM>0
+#if HASP_USE_EEPROM > 0
#include "hasp_eeprom.h"
#endif
-#if HASP_USE_WIFI>0
+#if HASP_USE_WIFI > 0
#include "hasp_wifi.h"
#endif
-#if HASP_USE_MQTT>0
+#if HASP_USE_MQTT > 0
#include "hasp_mqtt.h"
#endif
-#if HASP_USE_HTTP>0
+#if HASP_USE_HTTP > 0
#include "hasp_http.h"
#endif
-#if HASP_USE_TELNET>0
+#if HASP_USE_TELNET > 0
#include "hasp_telnet.h"
#endif
-#if HASP_USE_MDNS>0
+#if HASP_USE_MDNS > 0
#include "hasp_mdns.h"
#endif
-#if HASP_USE_BUTTON>0
+#if HASP_USE_BUTTON > 0
#include "hasp_button.h"
#endif
-#if HASP_USE_OTA>0
+#if HASP_USE_OTA > 0
#include "hasp_ota.h"
#endif
-#if HASP_USE_TASMOTA_SLAVE>0
+#if HASP_USE_TASMOTA_SLAVE > 0
#include "hasp_slave.h"
#endif
-#if HASP_USE_ETHERNET>0
+#if HASP_USE_ETHERNET > 0
#include "hasp_ethernet.h"
#endif
-#endif
-
#ifndef FPSTR
#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer))
#endif
+
+#ifndef PGM_P
+#define PGM_P const char *
+#endif
+
+#endif // HASP_CONF_H
\ No newline at end of file
diff --git a/include/stm32f4/hal_conf_custom.h b/include/stm32f4/hal_conf_custom.h
new file mode 100644
index 00000000..0febc31b
--- /dev/null
+++ b/include/stm32f4/hal_conf_custom.h
@@ -0,0 +1,13 @@
+/* Include the normal default core configuration */
+#include "stm32f4xx_hal_conf_default.h"
+
+/* Remove the default PHY address */
+#ifdef LAN8742A_PHY_ADDRESS
+#undef LAN8742A_PHY_ADDRESS
+#endif
+
+/* Section 2: PHY configuration section */
+/* Redefine LAN8742A PHY Address*/
+#ifndef LAN8742A_PHY_ADDRESS
+#define LAN8742A_PHY_ADDRESS 0x01U //HASP_PHY_ADDRESS
+#endif
\ No newline at end of file
diff --git a/lib/lvgl b/lib/lvgl
index 21f52a93..5f739643 160000
--- a/lib/lvgl
+++ b/lib/lvgl
@@ -1 +1 @@
-Subproject commit 21f52a939133d91acc82a3a98767d35de4e2d7a5
+Subproject commit 5f739643f4b22254f5742504fcda3b7de50fb88b
diff --git a/platformio.ini b/platformio.ini
index 84f3a1a8..472aea04 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -22,6 +22,8 @@ extra_configs =
default_envs =
; Uncomment the needed environments in platformio_override.ini
; You can also create new environments in in platformio_override.ini
+ DevEBox_STM32F4xx
+ black_f407vg
${override.extra_default_envs}
; -- Location of the configuration files
@@ -93,6 +95,7 @@ stm32_flags=
-D IRAM_ATTR= ; No IRAM_ATTR available on STM32
-D STM32
-D STREAMUTILS_USE_EEPROM_UPDATE=1 ; update cell only when changed
+ -D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
; -- By default there are no ${override.build_flags} set
; -- to use it, copy platformio_override.ini from the template
@@ -196,9 +199,10 @@ build_flags =
-D HASP_OUTPUT_PIN=PA1 ; User LED D2 on DevEBox board
-D HASP_INPUT_PIN=PA0 ; User Button K1 on DevEBox board
-D STM32_SERIAL1 ; Set this option to use Serial1 as default sersial port, leave out if using Serial2
+ -D USE_BUILTIN_ETHERNET=1
-D HASP_USE_ETHERNET=1
-D HAL_ETH_MODULE_ENABLED=1
- -D LAN8742A_PHY_ADDRESS=0x01U
+ ;-D LAN8742A_PHY_ADDRESS=0x01U ; Moved to include\stm32f4\hal_conf_custom.h
; -D DP83848_PHY_ADDRESS=0x01U
lib_deps =
@@ -208,6 +212,7 @@ lib_deps =
; STM32duino STM32Ethernet@^1.0.5
https://github.com/stm32duino/LwIP.git
https://github.com/stm32duino/STM32Ethernet.git
+ EthernetWebServer_STM32
src_filter = +<*> -<.git/> -<.svn/> - - - - - +
diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp
index 3e62e41f..ba6b14cb 100644
--- a/src/hasp_config.cpp
+++ b/src/hasp_config.cpp
@@ -206,6 +206,7 @@ void configWriteConfig()
Log.verbose(F("WIFI: Settings changed"));
writefile = true;
}
+#endif
#if HASP_USE_MQTT
if(settings[F("mqtt")].as().isNull()) settings.createNestedObject(F("mqtt"));
changed = mqttGetConfig(settings[F("mqtt")]);
@@ -240,7 +241,6 @@ void configWriteConfig()
configOutput(settings[F("http")]);
writefile = true;
}
-#endif
#endif
if(settings[F("debug")].as().isNull()) settings.createNestedObject(F("debug"));
@@ -350,6 +350,7 @@ void configSetup()
#if HASP_USE_WIFI
Log.verbose(F("Loading WiFi settings"));
wifiSetConfig(settings[F("wifi")]);
+#endif
#if HASP_USE_MQTT
Log.verbose(F("Loading MQTT settings"));
mqttSetConfig(settings[F("mqtt")]);
@@ -366,8 +367,7 @@ void configSetup()
Log.verbose(F("Loading HTTP settings"));
httpSetConfig(settings[F("http")]);
#endif
-#endif // Wifi
- // }
+ // }
Log.notice(F("User configuration loaded"));
}
//#endif
diff --git a/src/hasp_dispatch.cpp b/src/hasp_dispatch.cpp
index 7255a41c..38a2d271 100644
--- a/src/hasp_dispatch.cpp
+++ b/src/hasp_dispatch.cpp
@@ -161,14 +161,13 @@ void dispatchDim(String strDimLevel)
// Set the current state
if(strDimLevel.length() != 0) guiSetDim(strDimLevel.toInt());
dispatchPrintln(F("DIM"), strDimLevel);
+ char buffer[8];
#if HASP_USE_MQTT > 0
- char buffer[8];
itoa(guiGetDim(), buffer, DEC);
mqtt_send_state(F("dim"), buffer);
#endif
#if HASP_USE_TASMOTA_SLAVE > 0
- char buffer[8];
itoa(guiGetDim(), buffer, DEC);
slave_send_state(F("dim"), buffer);
#endif
diff --git a/src/hasp_ethernet.cpp b/src/hasp_ethernet.cpp
index 8c30ab9b..c61f1f10 100644
--- a/src/hasp_ethernet.cpp
+++ b/src/hasp_ethernet.cpp
@@ -22,11 +22,16 @@ void ethernetSetup()
IPAddress ip = Ethernet.localIP();
Log.notice(F("ETH: DHCP Success got IP=%d.%d.%d.%d"),ip[0], ip[1], ip[2], ip[3]);
}
+
+ uint8_t *mac;
+ mac = Ethernet.MACAddress();
+ Log.notice(F("ETH: MAC Address %x:%x:%x:%x:%x:%x"),*mac,*(mac+1),*(mac+2),*(mac+3),*(mac+4),*(mac+5));
+
}
void ethernetLoop(void)
{
- Ethernet.maintain();
+ Ethernet.maintain();
}
diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp
index 76c9d8e6..917af85a 100644
--- a/src/hasp_gui.cpp
+++ b/src/hasp_gui.cpp
@@ -41,6 +41,11 @@ File pFileOut;
#endif
uint8_t guiSnapshot = 0;
+#if defined(STM32F4xx)
+//#include
+// EthernetWebServer * webClient(0);
+#endif
+
#if defined(ARDUINO_ARCH_ESP8266)
#include
ESP8266WebServer * webClient; // for snatshot
@@ -75,7 +80,7 @@ static uint8_t guiRotation = TFT_ROTATION;
#if ESP32 > 0 || ESP8266 > 0
static Ticker tick; /* timer for interrupt handler */
#else
-static Ticker tick(lv_tick_handler,guiTickPeriod);
+static Ticker tick(lv_tick_handler, guiTickPeriod);
#endif
static TFT_eSPI tft; // = TFT_eSPI(); /* TFT instance */
static uint16_t calData[5] = {0, 65535, 0, 65535, 0};
@@ -171,14 +176,15 @@ static bool guiCheckSleep()
/* Flush VDB bytes to a stream */
static void gui_take_screenshot(uint8_t * data_p, size_t len)
{
-#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
size_t res = 0;
switch(guiSnapshot) {
+#if HASP_USE_SPIFFS > 0
case 1:
res = pFileOut.write(data_p, len);
break;
+#endif
case 2:
- res = webClient->client().write(data_p, len);
+ res = httpClientWrite(data_p, len);
break;
default:
res = 0; // nothing to do
@@ -186,7 +192,6 @@ static void gui_take_screenshot(uint8_t * data_p, size_t len)
if(res != len) {
Log.warning(F("GUI: Pixelbuffer not completely sent"));
}
-#endif
}
/* Experimetnal Display flushing */
@@ -197,7 +202,6 @@ static void IRAM_ATTR tft_espi_flush(lv_disp_drv_t * disp, const lv_area_t * are
/* Update TFT */
tft.startWrite(); /* Start new TFT transaction */
tft.setWindow(area->x1, area->y1, area->x2, area->y2); /* set the working window */
- tft.setSwapBytes(true); /* set endianess */
tft.pushPixels((uint16_t *)color_p, len); /* Write words at once */
tft.endWrite(); /* terminate TFT transaction */
@@ -617,11 +621,12 @@ void guiSetup()
{
/* TFT init */
tft.begin();
+ tft.setSwapBytes(true); /* set endianess */
#ifdef USE_DMA_TO_TFT
-// DMA - should work with STM32F2xx/F4xx/F7xx processors
-// NOTE: >>>>>> DMA IS FOR SPI DISPLAYS ONLY <<<<<<
-tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767)
+ // DMA - should work with STM32F2xx/F4xx/F7xx processors
+ // NOTE: >>>>>> DMA IS FOR SPI DISPLAYS ONLY <<<<<<
+ tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767)
#endif
tft.setRotation(guiRotation); /* 1/3=Landscape or 0/2=Portrait orientation */
@@ -652,10 +657,10 @@ tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767
#else
static lv_disp_buf_t disp_buf;
static lv_color_t guiVdbBuffer1[16 * 512u]; // 16 KBytes
- static lv_color_t guiVdbBuffer2[16 * 512u]; // 16 KBytes
+ // static lv_color_t guiVdbBuffer2[16 * 512u]; // 16 KBytes
guiVDBsize = sizeof(guiVdbBuffer1) / sizeof(guiVdbBuffer1[0]);
- lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize);
- //lv_disp_buf_init(&disp_buf, guiVdbBuffer1, NULL, guiVDBsize);
+ // lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize);
+ lv_disp_buf_init(&disp_buf, guiVdbBuffer1, NULL, guiVDBsize);
#endif
/* Initialize PNG decoder */
@@ -781,27 +786,27 @@ tft.initDMA(); // Initialise the DMA engine (tested with STM32F446 and STM32F767
tick.attach_ms(guiTickPeriod, lv_tick_handler);
#else
-/*
-#if defined(TIM1)
- TIM_TypeDef * Instance = TIM1;
-#else
- TIM_TypeDef * Instance = TIM2;
-#endif
-*/
+ /*
+ #if defined(TIM1)
+ TIM_TypeDef * Instance = TIM1;
+ #else
+ TIM_TypeDef * Instance = TIM2;
+ #endif
+ */
// Instantiate HardwareTimer object. Thanks to 'new' instanciation, HardwareTimer is not destructed when setup()
// function is finished.
- /* static HardwareTimer * MyTim = new HardwareTimer(Instance);
- MyTim->pause();
- MyTim->setPrescaleFactor(1);
- MyTim->setMode(0, TIMER_OUTPUT_COMPARE, NC);
- MyTim->setOverflow(1000 * guiTickPeriod, MICROSEC_FORMAT); // MicroSec
- MyTim->setCount(0,MICROSEC_FORMAT);
- MyTim->refresh();
- MyTim->detachInterrupt();
- MyTim->attachInterrupt((void (*)(HardwareTimer *))lv_tick_handler);
- MyTim->detachInterrupt(0);
- MyTim->attachInterrupt(0,(void (*)(HardwareTimer *))lv_tick_handler);
- MyTim->resume();*/
+ /* static HardwareTimer * MyTim = new HardwareTimer(Instance);
+ MyTim->pause();
+ MyTim->setPrescaleFactor(1);
+ MyTim->setMode(0, TIMER_OUTPUT_COMPARE, NC);
+ MyTim->setOverflow(1000 * guiTickPeriod, MICROSEC_FORMAT); // MicroSec
+ MyTim->setCount(0,MICROSEC_FORMAT);
+ MyTim->refresh();
+ MyTim->detachInterrupt();
+ MyTim->attachInterrupt((void (*)(HardwareTimer *))lv_tick_handler);
+ MyTim->detachInterrupt(0);
+ MyTim->attachInterrupt(0,(void (*)(HardwareTimer *))lv_tick_handler);
+ MyTim->resume();*/
tick.start();
#endif
@@ -816,14 +821,13 @@ void IRAM_ATTR guiLoop()
tick.update();
#endif
- //lv_tick_handler();
+ // lv_tick_handler();
lv_task_handler(); /* let the GUI do its work */
guiCheckSleep();
#if TOUCH_DRIVER == 1
touch.loop();
#endif
-
}
void guiStop()
@@ -969,14 +973,15 @@ bool guiSetConfig(const JsonObject & settings)
}
if(calData[0] != 0 || calData[1] != 65535 || calData[2] != 0 || calData[3] != 65535) {
- Log.trace(F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3],calData[4]);
+ Log.trace(F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3],
+ calData[4]);
oobeSetAutoCalibrate(false);
} else {
Log.notice(F("First Touch Calibration enabled"));
oobeSetAutoCalibrate(true);
}
-
- if (status) tft.setTouch(calData);
+
+ if(status) tft.setTouch(calData);
changed |= status;
}
@@ -991,23 +996,15 @@ static void guiSetBmpHeader(uint8_t * buffer_p, int32_t data)
*buffer_p++ = (data >> 24) & 0xFF;
}
-#if defined(ARDUINO_ARCH_ESP8266)
static void guiSendBmpHeader();
-void guiTakeScreenshot(ESP8266WebServer & client)
-#endif
-#if defined(ARDUINO_ARCH_ESP32)
- static void guiSendBmpHeader();
-
-void guiTakeScreenshot(WebServer & client)
-#endif // ESP32{
-#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
+void guiTakeScreenshot()
{
- webClient = &client;
- lv_disp_t * disp = lv_disp_get_default();
+ // webClient = &client;
+ // lv_disp_t * disp = lv_disp_get_default();
- webClient->setContentLength(122 + disp->driver.hor_res * disp->driver.ver_res * sizeof(lv_color_t));
- webClient->send(200, PSTR("image/bmp"), "");
+ // webClient->setContentLength(122 + disp->driver.hor_res * disp->driver.ver_res * sizeof(lv_color_t));
+ // webClient->send(200, PSTR("image/bmp"), "");
guiSnapshot = 2;
guiSendBmpHeader();
@@ -1068,15 +1065,17 @@ static void guiSendBmpHeader()
buffer[70 + 0] = 0x20;
if(guiSnapshot == 1) {
+#if HASP_USE_SPIFFS > 0
size_t len = pFileOut.write(buffer, 122);
if(len != sizeof(buffer)) {
Log.warning(F("GUI: Data written does not match header size"));
} else {
Log.verbose(F("GUI: Bitmap header written"));
}
+#endif
} else if(guiSnapshot == 2) {
- if(webClient->client().write(buffer, 122) != 122) {
+ if(httpClientWrite(buffer, 122) != 122) {
Log.warning(F("GUI: Data sent does not match header size"));
} else {
Log.verbose(F("GUI: Bitmap header sent"));
@@ -1093,6 +1092,7 @@ static void guiSendBmpHeader()
* @param[in] pFileName Output binary file name.
*
**/
+#if HASP_USE_SPIFFS > 0
void guiTakeScreenshot(const char * pFileName)
{
pFileOut = SPIFFS.open(pFileName, "w");
diff --git a/src/hasp_gui.h b/src/hasp_gui.h
index f6f0618f..76166eae 100644
--- a/src/hasp_gui.h
+++ b/src/hasp_gui.h
@@ -6,15 +6,17 @@
#include "lvgl.h"
-#if defined(ARDUINO_ARCH_ESP8266)
-#include
-void guiTakeScreenshot(ESP8266WebServer & client);
-#endif
+// #if defined(ARDUINO_ARCH_ESP8266)
+// #include
+// void guiTakeScreenshot(ESP8266WebServer & client);
+// #endif
-#if defined(ARDUINO_ARCH_ESP32)
-#include
-void guiTakeScreenshot(WebServer & client);
-#endif // ESP32
+// #if defined(ARDUINO_ARCH_ESP32)
+// #include
+// void guiTakeScreenshot(WebServer & client);
+// #endif // ESP32
+
+void guiTakeScreenshot();
void guiSetup();
void guiLoop(void);
diff --git a/src/hasp_hal.cpp b/src/hasp_hal.cpp
index 672e7ba5..5a9536a6 100644
--- a/src/hasp_hal.cpp
+++ b/src/hasp_hal.cpp
@@ -1,10 +1,17 @@
-#if defined(ESP32) || defined(ESP8266)
-#include
+#if defined(STM32F4xx)
+#include
#endif
#include "hasp_hal.h"
-#if ESP32
+#if defined(ESP8266)
+#include
+#include
+#endif
+
+#if defined(ESP32)
+#include
+#include
#include "esp_system.h"
#endif
@@ -107,8 +114,6 @@ String halGetResetInfo()
#endif
}
-
-
String halGetCoreVersion()
{
#if defined(ARDUINO_ARCH_ESP32)
@@ -155,13 +160,12 @@ String halGetChipModel()
return model;
}
-
/*******************************/
/* Memory Management Functions */
#if defined(STM32F4xx)
-#include // for mallinfo()
-#include // for sbrk()
+#include // for mallinfo()
+#include // for sbrk()
int freeHighMemory()
{
@@ -177,29 +181,29 @@ int freeHighMemory()
#endif
/*
-extern char *fake_heap_end; // current heap start
-extern char *fake_heap_start; // current heap end
+extern char *fake_heap_end; // current heap start
+extern char *fake_heap_start; // current heap end
-char* getHeapStart() {
- return fake_heap_start;
-}
-
-char* getHeapEnd() {
- return (char*)sbrk(0);
-}
-
-char* getHeapLimit() {
- return fake_heap_end;
+char* getHeapStart() {
+ return fake_heap_start;
}
-int getMemUsed() { // returns the amount of used memory in bytes
- struct mallinfo mi = mallinfo();
- return mi.uordblks;
-}
+char* getHeapEnd() {
+ return (char*)sbrk(0);
+}
-int getMemFree() { // returns the amount of free memory in bytes
- struct mallinfo mi = mallinfo();
- return mi.fordblks + freeHighMemory();
+char* getHeapLimit() {
+ return fake_heap_end;
+}
+
+int getMemUsed() { // returns the amount of used memory in bytes
+ struct mallinfo mi = mallinfo();
+ return mi.uordblks;
+}
+
+int getMemFree() { // returns the amount of free memory in bytes
+ struct mallinfo mi = mallinfo();
+ return mi.fordblks + freeHighMemory();
} */
size_t halGetMaxFreeBlock()
@@ -239,3 +243,57 @@ uint8_t halGetHeapFragmentation()
return (int8_t)(100.00f - (float)freeHighMemory() * 100.00f / (float)halGetFreeHeap());
#endif
}
+
+String halGetMacAddress(int start, const char * seperator)
+{
+ byte mac[6];
+
+#if defined(STM32F4xx)
+ uint8_t * mac_p;
+ mac_p = Ethernet.MACAddress();
+ for(uint8_t i = 0; i < 6; i++) mac[i] = *(mac_p + i);
+#else
+ WiFi.macAddress(mac);
+#endif
+
+ String cMac((char *)0);
+ cMac.reserve(32);
+
+ for(int i = start; i < 6; ++i) {
+ if(mac[i] < 0x10) cMac += "0";
+ cMac += String(mac[i], HEX);
+ if(i < 5) cMac += seperator;
+ }
+ cMac.toUpperCase();
+ return cMac;
+}
+
+uint16_t halGetCpuFreqMHz()
+{
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_32)
+ return ESP.getCpuFreqMHz();
+#else
+ return (F_CPU / 1000 / 1000);
+#endif
+}
+
+String halFormatBytes(size_t bytes)
+{
+ String output((char *)0);
+ output.reserve(128);
+
+ if(bytes < 1024) {
+ output += bytes;
+ } else if(bytes < (1024 * 1024)) {
+ output += bytes / 1024.0;
+ output += "K";
+ } else if(bytes < (1024 * 1024 * 1024)) {
+ output += bytes / 1024.0 / 1024.0;
+ output += "M";
+ } else {
+ output += bytes / 1024.0 / 1024.0 / 1024.0;
+ output += "G";
+ }
+ output += "B";
+ return output;
+}
\ No newline at end of file
diff --git a/src/hasp_hal.h b/src/hasp_hal.h
index 97f85f0a..9cdbef18 100644
--- a/src/hasp_hal.h
+++ b/src/hasp_hal.h
@@ -10,5 +10,8 @@ size_t halGetMaxFreeBlock(void);
size_t halGetFreeHeap(void);
String halGetCoreVersion(void);
String halGetChipModel();
+String halGetMacAddress(int start, const char * seperator);
+uint16_t halGetCpuFreqMHz(void);
+String halFormatBytes(size_t bytes);
#endif
\ No newline at end of file
diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp
index 0b35fb4b..2d6b2dbd 100644
--- a/src/hasp_http.cpp
+++ b/src/hasp_http.cpp
@@ -1,430 +1,3 @@
-#if 0
-
-#include "Arduino.h"
-#include "ArduinoJson.h"
-#include "ArduinoLog.h"
-//#include "Update.h"
-#include "lvgl.h"
-
-#include "hasp_conf.h"
-
-#include "hasp_gui.h"
-#include "hasp_hal.h"
-#include "hasp_debug.h"
-#include "hasp_mqtt.h"
-#include "hasp_wifi.h"
-#include "hasp_spiffs.h"
-#include "hasp_config.h"
-#include "hasp_dispatch.h"
-#include "hasp.h"
-
-#ifdef ESP32
-#include
-#include
-#elif defined(ESP8266)
-#include
-#include
-#endif
-#include
-
-AsyncWebServer webServer(80);
-
-#if defined(ARDUINO_ARCH_ESP32)
-#include "SPIFFS.h"
-#endif
-#include
-#include
-
-bool httpEnable = true;
-bool webServerStarted = false;
-uint16_t httpPort = 80;
-FS * filesystem = &SPIFFS;
-File fsUploadFile;
-char httpUser[32] = "";
-char httpPassword[32] = "";
-// HTTPUpload * upload;
-#define HTTP_PAGE_SIZE (6 * 256)
-
-const char MAIN_MENU_BUTTON[] PROGMEM =
- "";
-const char MIT_LICENSE[] PROGMEM = "MIT License";
-
-const char HTTP_DOCTYPE[] PROGMEM =
- "";
-const char HTTP_META_GO_BACK[] PROGMEM = "";
-const char HTTP_HEADER[] PROGMEM = "%s";
-const char HTTP_STYLE[] PROGMEM =
- "";
-const char HTTP_SCRIPT[] PROGMEM = "";
-const char HTTP_HEADER_END[] PROGMEM =
- "";
-
-// Additional CSS style to match Hass theme
-const char HASP_STYLE[] PROGMEM =
- "";
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-
-// URL for auto-update "version.json"
-const char UPDATE_URL[] PROGMEM = "http://haswitchplate.com/update/version.json";
-// Default link to compiled Arduino firmware image
-String espFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.ino.d1_mini.bin";
-// Default link to compiled Nextion firmware images
-String lcdFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.tft";
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-
-String getOption(int value, String label, bool selected)
-{
- char buffer[128];
- snprintf_P(buffer, sizeof(buffer), PSTR("
"), value,
- (selected ? PSTR(" selected") : ""), label.c_str());
- return buffer;
-}
-String getOption(String value, String label, bool selected)
-{
- char buffer[128];
- snprintf_P(buffer, sizeof(buffer), PSTR("
"), value.c_str(),
- (selected ? PSTR(" selected") : ""), label.c_str());
- return buffer;
-}
-
-bool httpIsAuthenticated(AsyncWebServerRequest * request, const String & page)
-{
- if(httpPassword[0] != '\0') { // Request HTTP auth if httpPassword is set
- if(!request->authenticate(httpUser, httpPassword)) {
- request->requestAuthentication();
- return false;
- }
- }
-
- char buffer[128];
- snprintf(buffer, sizeof(buffer), PSTR("HTTP: Sending %s page to client connected from: %s"), page.c_str(),
- request->client()->remoteIP().toString().c_str());
- debugPrintln(buffer);
- return true;
-}
-
-void webSendFooter(AsyncResponseStream * response)
-{
- response->print(F("
"));
-}
-
-void webHandleRoot(AsyncWebServerRequest * request)
-{
- if(!httpIsAuthenticated(request, F("root"))) return;
- AsyncResponseStream * response = request->beginResponseStream("text/html");
-
- String nodename((char *)0);
- nodename.reserve(128);
- nodename = httpGetNodename();
-
- response->print(F("
"));
- response->print(nodename);
- response->print(F("
"));
-
- response->print(F("
"));
- response->print(
- F("
"));
- response->print(F("
"));
-
- response->print(
- F("
"));
-
- if(SPIFFS.exists(F("/edit.htm.gz"))) {
- response->print(F("
"));
- }
-
- response->print(
- F("
"));
-
- webSendFooter(response);
- request->send(response);
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-void webHandleHaspConfig(AsyncWebServerRequest * request)
-{ // http://plate01/config/http
- if(!httpIsAuthenticated(request, F("config/hasp"))) return;
- AsyncResponseStream * response = request->beginResponseStream("text/html");
-
- DynamicJsonDocument settings(256);
- haspGetConfig(settings.to
());
-
- String nodename((char *)0);
- nodename.reserve(128);
- nodename = httpGetNodename();
-
- response->print(F(""));
- response->print(nodename);
- response->print(F("
"));
-
- response->print(F("
"));
-
- response->print(F(""));
-
- response->print(
- F(""));
-
- webSendFooter(response);
- request->send(response);
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-void webHandleScreenshot(AsyncWebServerRequest * request)
-{ // http://plate01/screenshot
- if(!httpIsAuthenticated(request, F("screenshot"))) return;
-
- if(request->hasArg(F("q"))) {
- guiTakeScreenshot(request);
- } else {
- AsyncResponseStream * response = request->beginResponseStream("text/html");
-
- String nodename((char *)0);
- nodename.reserve(128);
- nodename = httpGetNodename();
-
- response->print(F(""));
- response->print(nodename);
- response->print(F("
"));
-
- response->print(F("
"));
- response->print(F(""));
- // response->print( FPSTR(MAIN_MENU_BUTTON);
-
- webSendFooter(response);
- request->send(response);
- }
-}
-////////////////////////////////////////////////////////////////////////////////////////////////////
-void httpHandleNotFound(AsyncWebServerRequest * request)
-{ // webServer 404
- // if(handleFileRead(webServer.uri())) return;
-
- debugPrintln(String(F("HTTP: Sending 404 to client connected from: ")) + request->client()->remoteIP().toString());
-
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
-
- httpMessage += F("File Not Found\n\nURI: ");
- httpMessage += request->url();
- httpMessage += F("\nMethod: ");
- httpMessage += (request->method() == HTTP_GET) ? F("GET") : F("POST");
- httpMessage += F("\nArguments: ");
- httpMessage += request->args();
- httpMessage += "\n";
- for(uint8_t i = 0; i < request->args(); i++) {
- httpMessage += " " + request->argName(i) + ": " + request->arg(i) + "\n";
- }
- request->send(404, F("text/plain"), httpMessage);
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-void webHandleSaveConfig()
-{
- // if(!httpIsAuthenticated(F("saveConfig"))) return;
-
- configWriteConfig();
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-void webHandleFirmware()
-{
- // if(!httpIsAuthenticated(F("firmware"))) return;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-void httpSetup()
-{
- if(WiFi.getMode() != WIFI_STA) {
- debugPrintln(F("HTTP: Wifi access point"));
- // webServer.on(F("/"), webHandleWifiConfig);
- } else {
-
- webServer.on(String(F("/")).c_str(), HTTP_GET, webHandleRoot);
- webServer.on(String(F("/config/hasp")).c_str(), webHandleHaspConfig);
- webServer.on(String(F("/screenshot")).c_str(), webHandleScreenshot);
-
- webServer.onNotFound(httpHandleNotFound);
-
- webServer.begin();
-
- httpReconnect();
- debugPrintln(F("HTTP: Setup Complete"));
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-void httpReconnect()
-{
- if(!httpEnable) return;
-
- if(webServerStarted) {
- webServer.end();
- webServerStarted = false;
- debugPrintln(F("HTTP: Server stoped"));
- } else if(WiFi.status() == WL_CONNECTED || WiFi.getMode() != WIFI_STA) {
-
- /*
- if(WiFi.getMode() != WIFI_STA) {
- webServer.on(F("/"), webHandleWifiConfig);
- webServer.on(F("/config"), webHandleConfig);
- webServer.onNotFound(httpHandleNotFound);
- } else {
- }
- */
- webServer.begin();
- webServerStarted = true;
-
- debugPrintln(String(F("HTTP: Server started @ http://")) +
- (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString() : WiFi.localIP().toString()));
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-void httpLoop()
-{
- // if(httpEnable) webServer.handleClient();
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-void httpEverySecond()
-{
- if(httpEnable && !webServerStarted) httpReconnect();
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-bool httpGetConfig(const JsonObject & settings)
-{
- settings[FPSTR(F_CONFIG_ENABLE)] = httpEnable;
- settings[FPSTR(F_CONFIG_PORT)] = httpPort;
- settings[FPSTR(F_CONFIG_USER)] = httpUser;
- settings[FPSTR(F_CONFIG_PASS)] = httpPassword;
-
- configOutput(settings);
- return true;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-bool httpSetConfig(const JsonObject & settings)
-{
- configOutput(settings);
- bool changed = false;
-
- changed |= configSet(httpPort, settings[FPSTR(F_CONFIG_PORT)], PSTR("httpPort"));
-
- if(!settings[FPSTR(F_CONFIG_USER)].isNull()) {
- changed |= strcmp(httpUser, settings[FPSTR(F_CONFIG_USER)]) != 0;
- strncpy(httpUser, settings[FPSTR(F_CONFIG_USER)], sizeof(httpUser));
- }
-
- if(!settings[FPSTR(F_CONFIG_PASS)].isNull()) {
- changed |= strcmp(httpPassword, settings[FPSTR(F_CONFIG_PASS)]) != 0;
- strncpy(httpPassword, settings[FPSTR(F_CONFIG_PASS)], sizeof(httpPassword));
- }
-
- return changed;
-}
-
-#else
-
//#include "webServer.h"
#include "Arduino.h"
#include "ArduinoJson.h"
@@ -432,7 +5,7 @@ bool httpSetConfig(const JsonObject & settings)
#include "lvgl.h"
#include "StringStream.h"
-#ifdef ESP32
+#if defined(ARDUINO_ARCH_ESP32)
#include "Update.h"
#endif
@@ -457,18 +30,26 @@ bool httpSetConfig(const JsonObject & settings)
#include
#endif
-#if HASP_USE_HTTP>0
+#if HASP_USE_HTTP > 0
bool httpEnable = true;
bool webServerStarted = false;
uint16_t httpPort = 80;
-FS * filesystem = &SPIFFS;
+
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
+FS * filesystem = &SPIFFS;
File fsUploadFile;
+#endif
+
char httpUser[32] = "";
char httpPassword[32] = "";
-HTTPUpload * upload;
#define HTTP_PAGE_SIZE (6 * 256)
+#if defined(STM32F4xx)
+#include
+EthernetWebServer webServer(80);
+#endif
+
#if defined(ARDUINO_ARCH_ESP8266)
#include
ESP8266WebServer webServer(80);
@@ -477,9 +58,10 @@ ESP8266WebServer webServer(80);
#if defined(ARDUINO_ARCH_ESP32)
#include
WebServer webServer(80);
-
#endif // ESP32
+HTTPUpload * upload;
+
const char MAIN_MENU_BUTTON[] PROGMEM =
"";
const char MIT_LICENSE[] PROGMEM = "MIT License";
@@ -551,10 +133,14 @@ bool httpIsAuthenticated(const __FlashStringHelper * page)
}
}
- {
- Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page,
- webServer.client().remoteIP().toString().c_str());
- }
+#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
+ Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page,
+ webServer.client().remoteIP().toString().c_str());
+#else
+ Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page,
+ String(webServer.client().remoteIP()).c_str());
+#endif
+
return true;
}
@@ -577,72 +163,100 @@ void webSendFooter()
char buffer[128];
snprintf_P(buffer, sizeof(buffer), PSTR("%u.%u.%u"), HASP_VERSION_MAJOR, HASP_VERSION_MINOR, HASP_VERSION_REVISION);
+#if defined(STM32F4xx)
+ webServer.sendContent(HTTP_END);
+ webServer.sendContent(buffer);
+ webServer.sendContent(HTTP_FOOTER);
+#else
webServer.sendContent_P(HTTP_END);
webServer.sendContent(buffer);
webServer.sendContent_P(HTTP_FOOTER);
+#endif
}
void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false)
{
- char buffer[64];
- snprintf_P(buffer, sizeof(buffer), PSTR("%u.%u.%u"), HASP_VERSION_MAJOR, HASP_VERSION_MINOR, HASP_VERSION_REVISION);
+ {
+ char buffer[64];
+ snprintf_P(buffer, sizeof(buffer), PSTR("%u.%u.%u"), HASP_VERSION_MAJOR, HASP_VERSION_MINOR,
+ HASP_VERSION_REVISION);
- /* Calculate Content Length upfront */
- uint16_t contentLength = strlen(buffer); // verion length
- contentLength += sizeof(HTTP_DOCTYPE) - 1;
- contentLength += sizeof(HTTP_HEADER) - 1 - 2 + strlen(nodename);
- contentLength += sizeof(HTTP_SCRIPT) - 1;
- contentLength += sizeof(HTTP_STYLE) - 1;
- contentLength += sizeof(HASP_STYLE) - 1;
- if(gohome) contentLength += sizeof(HTTP_META_GO_BACK) - 1;
- contentLength += sizeof(HTTP_HEADER_END) - 1;
- contentLength += sizeof(HTTP_END) - 1;
- contentLength += sizeof(HTTP_FOOTER) - 1;
+ /* Calculate Content Length upfront */
+ uint16_t contentLength = strlen(buffer); // verion length
+ contentLength += sizeof(HTTP_DOCTYPE) - 1;
+ contentLength += sizeof(HTTP_HEADER) - 1 - 2 + strlen(nodename);
+ contentLength += sizeof(HTTP_SCRIPT) - 1;
+ contentLength += sizeof(HTTP_STYLE) - 1;
+ contentLength += sizeof(HASP_STYLE) - 1;
+ if(gohome) contentLength += sizeof(HTTP_META_GO_BACK) - 1;
+ contentLength += sizeof(HTTP_HEADER_END) - 1;
+ contentLength += sizeof(HTTP_END) - 1;
+ contentLength += sizeof(HTTP_FOOTER) - 1;
- if(httpdatalength > HTTP_PAGE_SIZE) {
- Log.warning(F("HTTP: Sending page with %u static and %u dynamic bytes"), contentLength, httpdatalength);
+ if(httpdatalength > HTTP_PAGE_SIZE) {
+ Log.warning(F("HTTP: Sending page with %u static and %u dynamic bytes"), contentLength, httpdatalength);
+ }
+
+ webServer.setContentLength(contentLength + httpdatalength);
+#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
+ webServer.send_P(200, PSTR("text/html"), HTTP_DOCTYPE); // 122
+#else
+ webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122
+#endif
+
+ sprintf_P(buffer, HTTP_HEADER, nodename);
+ webServer.sendContent(buffer); // 17-2+len
}
- webServer.setContentLength(contentLength + httpdatalength);
- webServer.send_P(200, PSTR("text/html"), HTTP_DOCTYPE); // 122
- sprintf_P(buffer, HTTP_HEADER, nodename);
- webServer.sendContent(buffer); // 17-2+len
+#if defined(STM32F4xx)
+ webServer.sendContent(HTTP_SCRIPT); // 131
+ webServer.sendContent(HTTP_STYLE); // 487
+ webServer.sendContent(HASP_STYLE); // 145
+ if(gohome) webServer.sendContent(HTTP_META_GO_BACK); // 47
+ webServer.sendContent(HTTP_HEADER_END); // 80
+#else
webServer.sendContent_P(HTTP_SCRIPT); // 131
webServer.sendContent_P(HTTP_STYLE); // 487
webServer.sendContent_P(HASP_STYLE); // 145
if(gohome) webServer.sendContent_P(HTTP_META_GO_BACK); // 47
webServer.sendContent_P(HTTP_HEADER_END); // 80
+#endif
}
void webHandleRoot()
{
if(!httpIsAuthenticated(F("root"))) return;
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
- httpMessage += F("");
- httpMessage += httpGetNodename();
- httpMessage += F("
");
+ {
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("");
+ httpMessage += httpGetNodename();
+ httpMessage += F("
");
- httpMessage += F("");
- httpMessage += F("");
- httpMessage +=
- PSTR("");
+ httpMessage += F("");
+ httpMessage +=
+ F("");
+ httpMessage +=
+ PSTR("");
- httpMessage +=
- F("");
+ httpMessage +=
+ F("");
- if(SPIFFS.exists(F("/edit.htm.gz"))) {
- httpMessage += F(
- "");
+#if HASP_USE_SPIFFS > 0
+ if(SPIFFS.exists(F("/edit.htm.gz"))) {
+ httpMessage += F("");
+ }
+#endif
+
+ httpMessage +=
+ F("");
+
+ webSendPage(httpGetNodename(), httpMessage.length(), false);
+ webServer.sendContent(httpMessage);
}
-
- httpMessage +=
- F("");
-
- webSendPage(httpGetNodename(), httpMessage.length(), false);
- webServer.sendContent(httpMessage);
- httpMessage.clear();
+ // httpMessage.clear();
webSendFooter();
}
@@ -651,16 +265,18 @@ void httpHandleReboot()
{ // http://plate01/reboot
if(!httpIsAuthenticated(F("reboot"))) return;
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
- httpMessage += F("");
- httpMessage += httpGetNodename();
- httpMessage += F("
");
- httpMessage = F("Rebooting Device");
+ {
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("");
+ httpMessage += httpGetNodename();
+ httpMessage += F("
");
+ httpMessage = F("Rebooting Device");
- webSendPage(httpGetNodename(), httpMessage.length(), true);
- webServer.sendContent(httpMessage);
- httpMessage.clear();
+ webSendPage(httpGetNodename(), httpMessage.length(), true);
+ webServer.sendContent(httpMessage);
+ }
+ // httpMessage.clear();
webSendFooter();
delay(200);
@@ -692,30 +308,36 @@ void webHandleScreenshot()
}
if(webServer.hasArg(F("q"))) {
- guiTakeScreenshot(webServer);
+ lv_disp_t * disp = lv_disp_get_default();
+ webServer.setContentLength(122 + disp->driver.hor_res * disp->driver.ver_res * sizeof(lv_color_t));
+ webServer.send(200, PSTR("image/bmp"), "");
+ guiTakeScreenshot();
+ webServer.client().stop();
+
} else {
+ {
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("");
+ httpMessage += httpGetNodename();
+ httpMessage += F("
");
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
- httpMessage += F("");
- httpMessage += httpGetNodename();
- httpMessage += F("
");
+ httpMessage +=
+ F("");
+ httpMessage += F("
");
+ httpMessage += F(
+ "");
+ httpMessage += F("");
+ httpMessage += F("");
+ httpMessage += FPSTR(MAIN_MENU_BUTTON);
- httpMessage +=
- F("");
- httpMessage += F("
");
- httpMessage +=
- F("");
- httpMessage += F("");
- httpMessage += F("");
- httpMessage += FPSTR(MAIN_MENU_BUTTON);
-
- webSendPage(httpGetNodename(), httpMessage.length(), false);
- webServer.sendContent(httpMessage);
- httpMessage.clear();
+ webSendPage(httpGetNodename(), httpMessage.length(), false);
+ webServer.sendContent(httpMessage);
+ }
+ // httpMessage.clear();
webSendFooter();
}
}
@@ -726,44 +348,47 @@ void webHandleAbout()
{ // http://plate01/about
if(!httpIsAuthenticated(F("about"))) return;
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
+ {
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
- httpMessage += F("HASP OpenHardware edition
Copyright© 2020 Francis Van Roie ");
- httpMessage += FPSTR(MIT_LICENSE);
- httpMessage += F("Based on the previous work of the following open source developers.
");
- httpMessage += F("HASwitchPlate
Copyright© 2019 Allen Derusha allen@derusha.org");
- httpMessage += FPSTR(MIT_LICENSE);
- httpMessage +=
- F("LittlevGL
Copyright© 2016 Gábor Kiss-VámosiCopyright© 2019 "
- "LittlevGL");
- httpMessage += FPSTR(MIT_LICENSE);
- httpMessage += F("zi Font Engine
Copyright© 2020 Francis Van Roie");
- httpMessage += FPSTR(MIT_LICENSE);
- httpMessage += F("TFT_eSPI Library
Copyright© 2020 Bodmer (https://github.com/Bodmer) All "
- "rights reserved.FreeBSD License");
- httpMessage +=
- F("includes parts from the Adafruit_GFX libraryCopyright© 2012 Adafruit Industries. "
- "All rights reservedBSD License
");
- httpMessage += F("ArduinoJson
Copyright© 2014-2020 Benoit BLANCHON");
- httpMessage += FPSTR(MIT_LICENSE);
- httpMessage += F("PubSubClient
Copyright© 2008-2015 Nicholas O'Leary");
- httpMessage += FPSTR(MIT_LICENSE);
- httpMessage += F("ArduinoLog
Copyright© 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, "
- "dhylands, Josha blemasle, mfalkvidd");
- httpMessage += FPSTR(MIT_LICENSE);
- httpMessage += F("Syslog
Copyright© 2016 Martin Sloup");
- httpMessage += FPSTR(MIT_LICENSE);
- httpMessage += F("QR Code generator
Copyright© Project Nayuki");
- httpMessage += FPSTR(MIT_LICENSE);
- httpMessage += F("AceButton
Copyright© 2018 Brian T. Park");
- httpMessage += FPSTR(MIT_LICENSE);
+ httpMessage += F("HASP OpenHardware edition
Copyright© 2020 Francis Van Roie ");
+ httpMessage += FPSTR(MIT_LICENSE);
+ httpMessage += F("Based on the previous work of the following open source developers.
");
+ httpMessage += F("HASwitchPlate
Copyright© 2019 Allen Derusha allen@derusha.org");
+ httpMessage += FPSTR(MIT_LICENSE);
+ httpMessage +=
+ F("LittlevGL
Copyright© 2016 Gábor Kiss-VámosiCopyright© 2019 "
+ "LittlevGL");
+ httpMessage += FPSTR(MIT_LICENSE);
+ httpMessage += F("zi Font Engine
Copyright© 2020 Francis Van Roie");
+ httpMessage += FPSTR(MIT_LICENSE);
+ httpMessage += F("TFT_eSPI Library
Copyright© 2020 Bodmer (https://github.com/Bodmer) All "
+ "rights reserved.FreeBSD License");
+ httpMessage +=
+ F("includes parts from the Adafruit_GFX libraryCopyright© 2012 Adafruit Industries. "
+ "All rights reservedBSD License
");
+ httpMessage += F("ArduinoJson
Copyright© 2014-2020 Benoit BLANCHON");
+ httpMessage += FPSTR(MIT_LICENSE);
+ httpMessage += F("PubSubClient
Copyright© 2008-2015 Nicholas O'Leary");
+ httpMessage += FPSTR(MIT_LICENSE);
+ httpMessage +=
+ F("ArduinoLog
Copyright© 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, "
+ "dhylands, Josha blemasle, mfalkvidd");
+ httpMessage += FPSTR(MIT_LICENSE);
+ httpMessage += F("Syslog
Copyright© 2016 Martin Sloup");
+ httpMessage += FPSTR(MIT_LICENSE);
+ httpMessage += F("QR Code generator
Copyright© Project Nayuki");
+ httpMessage += FPSTR(MIT_LICENSE);
+ httpMessage += F("AceButton
Copyright© 2018 Brian T. Park");
+ httpMessage += FPSTR(MIT_LICENSE);
- httpMessage += FPSTR(MAIN_MENU_BUTTON);
+ httpMessage += FPSTR(MAIN_MENU_BUTTON);
- webSendPage(httpGetNodename(), httpMessage.length(), false);
- webServer.sendContent(httpMessage);
- httpMessage.clear();
+ webSendPage(httpGetNodename(), httpMessage.length(), false);
+ webServer.sendContent(httpMessage);
+ }
+ // httpMessage.clear();
webSendFooter();
}
@@ -772,144 +397,160 @@ void webHandleInfo()
{ // http://plate01/
if(!httpIsAuthenticated(F("info"))) return;
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
- httpMessage += F("");
- httpMessage += httpGetNodename();
- httpMessage += F("
");
+ {
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("");
+ httpMessage += httpGetNodename();
+ httpMessage += F("
");
- /* HASP Stats */
- httpMessage += F("HASP Version: ");
- httpMessage += String(haspGetVersion());
- httpMessage += F("
Build DateTime: ");
- httpMessage += __DATE__;
- httpMessage += F(" ");
- httpMessage += __TIME__;
- httpMessage += F(" CET
Uptime: ");
+ /* HASP Stats */
+ httpMessage += F("HASP Version: ");
+ httpMessage += String(haspGetVersion());
+ httpMessage += F("
Build DateTime: ");
+ httpMessage += __DATE__;
+ httpMessage += F(" ");
+ httpMessage += __TIME__;
+ httpMessage += F(" CET
Uptime: ");
- unsigned long time = millis() / 1000;
- uint16_t day = time / 86400;
- time = time % 86400;
- uint8_t hour = time / 3600;
- time = time % 3600;
- uint8_t min = time / 60;
- time = time % 60;
- uint8_t sec = time;
+ unsigned long time = millis() / 1000;
+ uint16_t day = time / 86400;
+ time = time % 86400;
+ uint8_t hour = time / 3600;
+ time = time % 3600;
+ uint8_t min = time / 60;
+ time = time % 60;
+ uint8_t sec = time;
- if(day > 0) {
- httpMessage += String(day);
- httpMessage += F("d ");
- }
- if(day > 0 || hour > 0) {
- httpMessage += String(hour);
- httpMessage += F("h ");
- }
- if(day > 0 || hour > 0 || min > 0) {
- httpMessage += String(min);
- httpMessage += F("m ");
- }
- httpMessage += String(sec);
- httpMessage += F("s");
+ if(day > 0) {
+ httpMessage += String(day);
+ httpMessage += F("d ");
+ }
+ if(day > 0 || hour > 0) {
+ httpMessage += String(hour);
+ httpMessage += F("h ");
+ }
+ if(day > 0 || hour > 0 || min > 0) {
+ httpMessage += String(min);
+ httpMessage += F("m ");
+ }
+ httpMessage += String(sec);
+ httpMessage += F("s");
- httpMessage += F("
Free Memory: ");
- httpMessage += spiffsFormatBytes(ESP.getFreeHeap());
- httpMessage += F("
Memory Fragmentation: ");
- httpMessage += String(halGetHeapFragmentation());
+ httpMessage += F("
Free Memory: ");
+ httpMessage += halFormatBytes(halGetFreeHeap());
+ httpMessage += F("
Memory Fragmentation: ");
+ httpMessage += String(halGetHeapFragmentation());
- /* LVGL Stats */
- lv_mem_monitor_t mem_mon;
- lv_mem_monitor(&mem_mon);
- httpMessage += F("LVGL Memory: ");
- httpMessage += spiffsFormatBytes(mem_mon.total_size);
- httpMessage += F("
LVGL Free: ");
- httpMessage += spiffsFormatBytes(mem_mon.free_size);
- httpMessage += F("
LVGL Fragmentation: ");
- httpMessage += mem_mon.frag_pct;
+ /* LVGL Stats */
+ lv_mem_monitor_t mem_mon;
+ lv_mem_monitor(&mem_mon);
+ httpMessage += F("
LVGL Memory: ");
+ httpMessage += halFormatBytes(mem_mon.total_size);
+ httpMessage += F("
LVGL Free: ");
+ httpMessage += halFormatBytes(mem_mon.free_size);
+ httpMessage += F("
LVGL Fragmentation: ");
+ httpMessage += mem_mon.frag_pct;
- // httpMessage += F("
LCD Model: ")) + String(LV_HASP_HOR_RES_MAX) + " x " +
- // String(LV_HASP_VER_RES_MAX); httpMessage += F("
LCD Version: ")) +
- // String(lcdVersion);
- httpMessage += F("
LCD Active Page: ");
- httpMessage += String(haspGetPage());
+ // httpMessage += F("
LCD Model: ")) + String(LV_HASP_HOR_RES_MAX) + " x " +
+ // String(LV_HASP_VER_RES_MAX); httpMessage += F("
LCD Version: ")) +
+ // String(lcdVersion);
+ httpMessage += F("
LCD Active Page: ");
+ httpMessage += String(haspGetPage());
- /* Wifi Stats */
- httpMessage += F("
SSID: ");
- httpMessage += String(WiFi.SSID());
- httpMessage += F("Signal Strength: ");
+ /* Wifi Stats */
+#if HASP_USE_WIFI > 0
+ httpMessage += F("
SSID: ");
+ httpMessage += String(WiFi.SSID());
+ httpMessage += F("Signal Strength: ");
- int8_t rssi = WiFi.RSSI();
- httpMessage += String(rssi);
- httpMessage += F("dBm (");
+ int8_t rssi = WiFi.RSSI();
+ httpMessage += String(rssi);
+ httpMessage += F("dBm (");
- if(rssi >= -50) {
- httpMessage += F("Excellent)");
- } else if(rssi >= -60) {
- httpMessage += F("Good)");
- } else if(rssi >= -70) {
- httpMessage += F("Fair)");
- } else if(rssi >= -80) {
- httpMessage += F("Weak)");
- } else {
- httpMessage += F("Very Bad)");
- }
+ if(rssi >= -50) {
+ httpMessage += F("Excellent)");
+ } else if(rssi >= -60) {
+ httpMessage += F("Good)");
+ } else if(rssi >= -70) {
+ httpMessage += F("Fair)");
+ } else if(rssi >= -80) {
+ httpMessage += F("Weak)");
+ } else {
+ httpMessage += F("Very Bad)");
+ }
- httpMessage += F("IP Address: ");
- httpMessage += String(WiFi.localIP().toString());
- httpMessage += F("Gateway: ");
- httpMessage += String(WiFi.gatewayIP().toString());
- httpMessage += F("DNS Server: ");
- httpMessage += String(WiFi.dnsIP().toString());
- httpMessage += F("MAC Address: ");
- httpMessage += String(WiFi.macAddress());
+ httpMessage += F("IP Address: ");
+ httpMessage += String(WiFi.localIP().toString());
+ httpMessage += F("Gateway: ");
+ httpMessage += String(WiFi.gatewayIP().toString());
+ httpMessage += F("DNS Server: ");
+ httpMessage += String(WiFi.dnsIP().toString());
+ httpMessage += F("MAC Address: ");
+ httpMessage += String(WiFi.macAddress());
+#endif
/* Mqtt Stats */
#if HASP_USE_MQTT > 0
- httpMessage += F("
MQTT Status: ");
- if(mqttIsConnected()) { // Check MQTT connection
- httpMessage += F("Connected");
- } else {
- httpMessage += F("Disconnected, return code: ");
- // +String(mqttClient.returnCode());
- }
- httpMessage += F("
MQTT ClientID: ");
+ httpMessage += F("
MQTT Status: ");
+ if(mqttIsConnected()) { // Check MQTT connection
+ httpMessage += F("Connected");
+ } else {
+ httpMessage += F("Disconnected, return code: ");
+ // +String(mqttClient.returnCode());
+ }
+ httpMessage += F("
MQTT ClientID: ");
- {
- char mqttClientId[64];
- byte mac[6];
- WiFi.macAddress(mac);
- snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%2x%2x%2x"), mqttNodeName, mac[3], mac[4], mac[5]);
- httpMessage += mqttClientId;
- }
+ {
+ char mqttClientId[64];
+#if HASP_USE_WIFI > 0
+ byte mac[6];
+ WiFi.macAddress(mac);
+ snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%02x%02x%02x"), mqttNodeName, mac[3], mac[4],
+ mac[5]);
+#endif
+#if HASP_USE_ETHERNET > 0
+ uint8_t * mac;
+ mac = Ethernet.MACAddress();
+ snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%02x%02x%02x"), mqttNodeName, *(mac + 3),
+ *(mac + 4), *(mac + 5));
+#endif
+ httpMessage += mqttClientId;
+ }
+#endif // MQTT
+
+ /* ESP Stats */
+ httpMessage += F("
MCU Model: ");
+ httpMessage += halGetChipModel();
+ httpMessage += F("
CPU Frequency: ");
+ httpMessage += String(halGetCpuFreqMHz());
+
+#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
+ httpMessage += F("MHz
Flash Chip Size: ");
+ httpMessage += halFormatBytes(ESP.getFlashChipSize());
+ httpMessage += F("Program Size: ");
+ httpMessage += halFormatBytes(ESP.getSketchSize());
+ httpMessage += F("
Free Program Space: ");
+ httpMessage += halFormatBytes(ESP.getFreeSketchSpace());
#endif
- /* ESP Stats */
- httpMessage += F("
MCU Model: ");
- httpMessage += halGetChipModel();
- httpMessage += F("
CPU Frequency: ");
- httpMessage += String(ESP.getCpuFreqMHz());
- httpMessage += F("MHz
Flash Chip Size: ");
- httpMessage += spiffsFormatBytes(ESP.getFlashChipSize());
- httpMessage += F("Program Size: ");
- httpMessage += spiffsFormatBytes(ESP.getSketchSize());
- httpMessage += F("
Free Program Space: ");
- httpMessage += spiffsFormatBytes(ESP.getFreeSketchSpace());
+ //#if defined(ARDUINO_ARCH_ESP32)
+ // httpMessage += F("
ESP SDK version: ");
+ // httpMessage += String(ESP.getSdkVersion());
+ //#else
+ httpMessage += F("
Core version: ");
+ httpMessage += String(halGetCoreVersion());
+ //#endif
+ httpMessage += F("
Last Reset: ");
+ httpMessage += halGetResetInfo();
-#if defined(ARDUINO_ARCH_ESP32)
- httpMessage += F("
ESP SDK version: ");
- httpMessage += String(ESP.getSdkVersion());
-#else
- httpMessage += F("
ESP Core version: ");
- httpMessage += String(ESP.getCoreVersion());
-#endif
- httpMessage += F("
Last Reset: ");
- httpMessage += halGetResetInfo();
+ httpMessage += FPSTR(MAIN_MENU_BUTTON);
- httpMessage += FPSTR(MAIN_MENU_BUTTON);
-
- webSendPage(httpGetNodename(), httpMessage.length(), false);
- webServer.sendContent(httpMessage);
- httpMessage.clear();
+ webSendPage(httpGetNodename(), httpMessage.length(), false);
+ webServer.sendContent(httpMessage);
+ }
+ // httpMessage.clear();
webSendFooter();
}
@@ -969,30 +610,6 @@ String getContentType(String filename)
return encodedString;
} */
-bool handleFileRead(String path)
-{
- if(!httpIsAuthenticated(F("fileread"))) return false;
-
- path = webServer.urlDecode(path).substring(0, 31);
- if(path.endsWith("/")) {
- path += F("index.htm");
- }
- String pathWithGz = path + F(".gz");
- if(filesystem->exists(pathWithGz) || filesystem->exists(path)) {
- if(filesystem->exists(pathWithGz)) path += F(".gz");
-
- File file = filesystem->open(path, "r");
- String contentType = getContentType(path);
- if(path == F("/edit.htm.gz")) {
- contentType = F("text/html");
- }
- webServer.streamFile(file, contentType);
- file.close();
- return true;
- }
- return false;
-}
-
static unsigned long htppLastLoopTime = 0;
void webUploadProgress()
{
@@ -1002,6 +619,7 @@ void webUploadProgress()
}
}
+#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
void webUpdatePrintError()
{
String output((char *)0);
@@ -1015,16 +633,18 @@ void webUpdateReboot()
{
Log.notice(F("Update Success: %u bytes received. Rebooting..."), upload->totalSize);
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
- httpMessage += F("
");
- httpMessage += httpGetNodename();
- httpMessage += F("
");
- httpMessage += F("Upload complete. Rebooting device, please wait...");
+ {
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("");
+ httpMessage += httpGetNodename();
+ httpMessage += F("
");
+ httpMessage += F("Upload complete. Rebooting device, please wait...");
- webSendPage(httpGetNodename(), httpMessage.length(), true);
- webServer.sendContent(httpMessage);
- httpMessage.clear();
+ webSendPage(httpGetNodename(), httpMessage.length(), true);
+ webServer.sendContent(httpMessage);
+ }
+ // httpMessage.clear();
webSendFooter();
delay(250);
@@ -1059,6 +679,32 @@ void webHandleFirmwareUpdate()
}
}
}
+#endif
+
+#if HASP_USE_SPIFFS > 0
+bool handleFileRead(String path)
+{
+ if(!httpIsAuthenticated(F("fileread"))) return false;
+
+ path = webServer.urlDecode(path).substring(0, 31);
+ if(path.endsWith("/")) {
+ path += F("index.htm");
+ }
+ String pathWithGz = path + F(".gz");
+ if(filesystem->exists(pathWithGz) || filesystem->exists(path)) {
+ if(filesystem->exists(pathWithGz)) path += F(".gz");
+
+ File file = filesystem->open(path, "r");
+ String contentType = getContentType(path);
+ if(path == F("/edit.htm.gz")) {
+ contentType = F("text/html");
+ }
+ webServer.streamFile(file, contentType);
+ file.close();
+ return true;
+ }
+ return false;
+}
void handleFileUpload()
{
@@ -1123,7 +769,7 @@ void handleFileDelete()
}
filesystem->remove(path);
webServer.send_P(200, mimetype, PSTR(""));
- path.clear();
+ // path.clear();
}
void handleFileCreate()
@@ -1188,7 +834,8 @@ void handleFileList()
file = root.openNextFile();
}
output += "]";
-#else
+ webServer.send(200, PSTR("text/json"), output);
+#elif defined(ARDUINO_ARCH_ESP8266)
Dir dir = filesystem->openDir(path);
String output = "[";
while(dir.next()) {
@@ -1209,9 +856,10 @@ void handleFileList()
entry.close();
}
output += "]";
-#endif
webServer.send(200, PSTR("text/json"), output);
+#endif
}
+#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleConfig()
@@ -1245,56 +893,65 @@ void webHandleConfig()
// Password might have changed
if(!httpIsAuthenticated(F("config"))) return;
+#if HASP_USE_WIFI > 0
} else if(save == String(PSTR("wifi"))) {
wifiSetConfig(settings.as());
+#endif
}
}
}
+// Reboot after saving wifi config in AP mode
+#if HASP_USE_WIFI > 0
if(WiFi.getMode() != WIFI_STA) {
httpHandleReboot();
}
+#endif
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
- httpMessage += F("");
- httpMessage += httpGetNodename();
- httpMessage += F("
");
+ {
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("");
+ httpMessage += httpGetNodename();
+ httpMessage += F("
");
- httpMessage +=
- F("");
+#if HASP_USE_WIFI > 0
+ httpMessage +=
+ F("");
+#endif
#if HASP_USE_MQTT > 0
- httpMessage +=
- F("");
+ httpMessage +=
+ F("");
#endif
- httpMessage +=
- F("");
+ httpMessage +=
+ F("");
- httpMessage +=
- F("");
+ httpMessage +=
+ F("");
- httpMessage +=
- F("");
+ httpMessage +=
+ F("");
#if HASP_USE_GPIO > 0
- httpMessage +=
- F("");
+ httpMessage +=
+ F("");
#endif
- httpMessage +=
- F("");
+ httpMessage +=
+ F("");
- httpMessage += F("");
+ httpMessage += F("");
- httpMessage += FPSTR(MAIN_MENU_BUTTON);
- ;
+ httpMessage += FPSTR(MAIN_MENU_BUTTON);
+ ;
- webSendPage(httpGetNodename(), httpMessage.length(), false);
- webServer.sendContent(httpMessage);
- httpMessage.clear();
+ webSendPage(httpGetNodename(), httpMessage.length(), false);
+ webServer.sendContent(httpMessage);
+ }
+ // httpMessage.clear();
webSendFooter();
}
@@ -1307,41 +964,43 @@ void webHandleMqttConfig()
DynamicJsonDocument settings(256);
mqttGetConfig(settings.to());
- // char buffer[128];
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
- httpMessage += F("");
- httpMessage += httpGetNodename();
- httpMessage += F("
");
+ {
+ // char buffer[128];
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("");
+ httpMessage += httpGetNodename();
+ httpMessage += F("
");
- httpMessage += F("");
- httpMessage +=
- PSTR("");
+ httpMessage += F("'>");
+ httpMessage +=
+ PSTR("");
- webSendPage(httpGetNodename(), httpMessage.length(), false);
- webServer.sendContent(httpMessage);
- httpMessage.clear();
+ webSendPage(httpGetNodename(), httpMessage.length(), false);
+ webServer.sendContent(httpMessage);
+ }
+ // httpMessage.clear();
webSendFooter();
}
#endif
@@ -1351,70 +1010,71 @@ void webHandleGuiConfig()
{ // http://plate01/config/wifi
if(!httpIsAuthenticated(F("config/gui"))) return;
- DynamicJsonDocument settings(256);
- guiGetConfig(settings.to());
+ {
+ DynamicJsonDocument settings(256);
+ guiGetConfig(settings.to());
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
- httpMessage += F("");
- httpMessage += httpGetNodename();
- httpMessage += F("
");
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("");
+ httpMessage += httpGetNodename();
+ httpMessage += F("
");
- httpMessage += F("");
+ httpMessage += F("");
- httpMessage += PSTR("");
+ httpMessage += PSTR("");
- httpMessage +=
- PSTR("");
+ httpMessage +=
+ PSTR("");
- webSendPage(httpGetNodename(), httpMessage.length(), false);
- webServer.sendContent(httpMessage);
- httpMessage.clear();
+ webSendPage(httpGetNodename(), httpMessage.length(), false);
+ webServer.sendContent(httpMessage);
+ }
webSendFooter();
if(webServer.hasArg(F("action"))) dispatchCommand(webServer.arg(F("action")));
@@ -1446,10 +1106,12 @@ void webHandleWifiConfig()
}
httpMessage += F("'>");
+#if HASP_USE_WIFI > 0
if(WiFi.getMode() == WIFI_STA) {
httpMessage +=
PSTR("");
}
+#endif
webSendPage(httpGetNodename(), httpMessage.length(), false);
webServer.sendContent(httpMessage);
@@ -1464,32 +1126,34 @@ void webHandleHttpConfig()
{ // http://plate01/config/http
if(!httpIsAuthenticated(F("config/http"))) return;
- DynamicJsonDocument settings(256);
- httpGetConfig(settings.to());
+ {
+ DynamicJsonDocument settings(256);
+ httpGetConfig(settings.to());
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
- httpMessage += F("");
- httpMessage += httpGetNodename();
- httpMessage += F("
");
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("");
+ httpMessage += httpGetNodename();
+ httpMessage += F("
");
- httpMessage += F("");
+
+ httpMessage +=
+ PSTR("");
+
+ webSendPage(httpGetNodename(), httpMessage.length(), false);
+ webServer.sendContent(httpMessage);
}
- httpMessage += F("'>");
-
- httpMessage +=
- PSTR("");
-
- webSendPage(httpGetNodename(), httpMessage.length(), false);
- webServer.sendContent(httpMessage);
- httpMessage.clear();
+ // httpMessage.clear();
webSendFooter();
}
#endif
@@ -1502,33 +1166,36 @@ void webHandleGpioConfig()
DynamicJsonDocument settings(256);
debugGetConfig(settings.to());
- String httpMessage((char *)0);
- httpMessage.reserve(HTTP_PAGE_SIZE);
- httpMessage += F("");
- httpMessage += httpGetNodename();
- httpMessage += F("
");
+ {
+ String httpMessage((char *)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("");
+ httpMessage += httpGetNodename();
+ httpMessage += F("
");
- httpMessage += F("