ESP214/ESP212 and hooks (#999)

* Add expandString to ESP214

* Implement ESP212 for sending text to printer screen (M117)

* Implement hooks for got IP and got DateTime

* Allow finish processing  current stream before adding new one instead of reject

* Add parmeter to expandString to escape space

* Update notifications_service.cpp

* Add sanity check for hooks and autoscript
This commit is contained in:
Luc
2024-02-08 10:32:24 +01:00
committed by GitHub
parent ec7c422f7f
commit 2c1661007d
18 changed files with 228 additions and 39 deletions

View File

@@ -23,7 +23,7 @@
#include "../include/esp3d_config.h"
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
#include "../modules/network/netconfig.h"
#endif // WIFI_FEATURE || ETH_FEATURE
@@ -184,31 +184,32 @@ const char* esp3d_string::formatBytes(uint64_t bytes) {
return res.c_str();
}
bool esp3d_string::isPrintableChar(char ch){
int c = static_cast<int>(ch);
if (c==9 || (c >= 32 && c <= 126) || c>=128) {
bool esp3d_string::isPrintableChar(char ch) {
int c = static_cast<int>(ch);
if (c == 9 || (c >= 32 && c <= 126) || c >= 128) {
return true;
}
return false;
}
const char * esp3d_string::expandString(const char *s){
const char* esp3d_string::expandString(const char* s, bool formatspace) {
static String tmp;
tmp = s;
if (tmp.indexOf("%") != -1) {
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
tmp.replace("%ESP_IP%", NetConfig::localIP().c_str());
tmp.replace("%ESP_NAME%", NetConfig::hostname());
#if defined(WIFI_FEATURE) || defined(ETH_FEATURE)
tmp.replace("%ESP_IP%", NetConfig::localIP().c_str());
tmp.replace("%ESP_NAME%", NetConfig::hostname());
#else
tmp.replace("%ESP_IP%", "???");
tmp.replace("%ESP_NAME%", "???");
tmp.replace("%ESP_IP%", "???");
tmp.replace("%ESP_NAME%", "???");
#endif // WIFI_FEATURE || ETH_FEATURE
#if defined(TIMESTAMP_FEATURE)
tmp.replace("%ESP_DATETIME%", timeService.getCurrentTime());
String dt = timeService.getCurrentTime();
if (formatspace) dt.replace(" ", "\\ ");
tmp.replace("%ESP_DATETIME%", dt.c_str());
#else
tmp.replace("%ESP_DATETIME%", "???");
#endif // TIMESTAMP_FEATURE
}
return tmp.c_str();
}