From 515b75160c1f9aad55b865e85ad25d67524aa2a9 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Mon, 8 Dec 2025 12:42:11 +0100 Subject: [PATCH] stub to remove #ifndef EMSESP_STANDALONE --- lib/esp32-psram/src/esp32-psram.h | 2 ++ lib_standalone/esp32-psram.h | 4 ++++ src/core/analogsensor.cpp | 26 +++++++++++++------------- src/core/analogsensor.h | 12 +----------- src/core/emsdevice.h | 11 ----------- src/core/emsesp.h | 11 +---------- src/core/system.h | 8 +------- src/core/telegram.h | 19 +------------------ src/core/temperaturesensor.h | 15 ++++++++------- src/web/WebCustomEntityService.h | 11 +---------- src/web/WebCustomizationService.h | 9 +-------- src/web/WebLogService.h | 21 +++++---------------- src/web/WebSchedulerService.h | 7 ------- 13 files changed, 38 insertions(+), 118 deletions(-) create mode 100644 lib_standalone/esp32-psram.h diff --git a/lib/esp32-psram/src/esp32-psram.h b/lib/esp32-psram/src/esp32-psram.h index d3e04502f..a69d9f4cd 100644 --- a/lib/esp32-psram/src/esp32-psram.h +++ b/lib/esp32-psram/src/esp32-psram.h @@ -19,6 +19,8 @@ #include "esp32-psram/RingBufferStream.h" // Stream-based ring buffer #include "esp32-psram/TypedRingBuffer.h" // Typed ring buffer for structured data +#define stringPSRAM std::basic_string, AllocatorPSRAM> + #ifndef ESP32_PSRAM_NO_NAMESPACE using namespace esp32_psram; #endif diff --git a/lib_standalone/esp32-psram.h b/lib_standalone/esp32-psram.h new file mode 100644 index 000000000..76c02826f --- /dev/null +++ b/lib_standalone/esp32-psram.h @@ -0,0 +1,4 @@ +#pragma once + +#define stringPSRAM std::string +#define AllocatorPSRAM std::allocator diff --git a/src/core/analogsensor.cpp b/src/core/analogsensor.cpp index 2c83b919a..1bd662929 100644 --- a/src/core/analogsensor.cpp +++ b/src/core/analogsensor.cpp @@ -130,7 +130,7 @@ void AnalogSensor::reload(bool get_nvs) { for (const auto & sensor : settings.analogCustomizations) { // search customlist if (sensor_.gpio() == sensor.gpio) { // for output sensors set value to new start-value - if (sensor.type >= AnalogType::DIGITAL_OUT && sensor.type <= AnalogType::PWM_2 + if (((sensor.type >= AnalogType::DIGITAL_OUT && sensor.type <= AnalogType::PWM_2) || sensor.type >= AnalogType::RGB) && (sensor_.type() != sensor.type || sensor_.offset() != sensor.offset || sensor_.factor() != sensor.factor)) { sensor_.set_value(sensor.offset); } @@ -164,12 +164,11 @@ void AnalogSensor::reload(bool get_nvs) { } if (!found) { // it's new, we assume it's valid - AnalogType type = static_cast(sensor.type); - sensors_.emplace_back(sensor.gpio, sensor.name, sensor.offset, sensor.factor, sensor.uom, type, sensor.is_system); + sensors_.emplace_back(sensor.gpio, sensor.name, sensor.offset, sensor.factor, sensor.uom, sensor.type, sensor.is_system); sensors_.back().ha_registered = false; // this will trigger recreate of the HA config - if (sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT - || (sensor.type >= AnalogType::CNT_0 && sensor.type <= AnalogType::CNT_2)) { + if (sensor.type == AnalogType::COUNTER || (sensor.type >= AnalogType::DIGITAL_OUT && sensor.type <= AnalogType::PWM_2) + || sensor.type == AnalogType::RGB || (sensor.type >= AnalogType::CNT_0 && sensor.type <= AnalogType::CNT_2)) { sensors_.back().set_value(sensor.offset); } else { sensors_.back().set_value(0); // reset value only for new sensors @@ -374,10 +373,10 @@ void AnalogSensor::measure() { uint16_t a = analogReadMilliVolts(sensor.gpio()); // e.g. ADC1_CHANNEL_0_GPIO_NUM if (!sensor.analog_) { // init first time sensor.analog_ = a; - sensor.sum_ = a * 512; + sensor.sum_ = a * 128; } else { // simple moving average filter - sensor.sum_ = (sensor.sum_ * 511) / 512 + a; - sensor.analog_ = sensor.sum_ / 512; + sensor.sum_ = (sensor.sum_ * 127) / 128 + a; + sensor.analog_ = sensor.sum_ / 128; } // detect change with little hysteresis on raw mV value @@ -427,7 +426,7 @@ void AnalogSensor::measure() { auto index = sensor.type() - AnalogType::CNT_0; auto oldval = sensor.value(); portENTER_CRITICAL_ISR(&mux); - auto c = edgecnt[index]; + auto c = edgecnt[index]; edgecnt[index] = 0; portEXIT_CRITICAL_ISR(&mux); sensor.set_value(oldval + sensor.factor() * c); @@ -709,7 +708,7 @@ void AnalogSensor::publish_values(const bool force) { LOG_DEBUG("Recreating HA config for analog sensor GPIO %02d", sensor.gpio()); JsonDocument config; - config["~"] = Mqtt::base(); + config["~"] = Mqtt::base(); char stat_t[50]; snprintf(stat_t, sizeof(stat_t), "~/%s_data", F_(analogsensor)); // use base path @@ -742,7 +741,7 @@ void AnalogSensor::publish_values(const bool force) { snprintf(uniq_s, sizeof(uniq_s), "%s_%02d", F_(analogsensor), sensor.gpio()); } - config["~"] = Mqtt::base(); + config["~"] = Mqtt::base(); config["uniq_id"] = uniq_s; char name[50]; @@ -877,10 +876,11 @@ void AnalogSensor::get_value_json(JsonObject output, const Sensor & sensor) { output["value"] = sensor.value(); output["readable"] = true; output["writeable"] = sensor.type() == AnalogType::COUNTER || sensor.type() == AnalogType::RGB || sensor.type() == AnalogType::PULSE - || (sensor.type() >= AnalogType::DIGITAL_OUT && sensor.type() <= AnalogType::PWM_2)|| (sensor.type() >= AnalogType::CNT_0 && sensor.type() <= AnalogType::CNT_2); + || (sensor.type() >= AnalogType::DIGITAL_OUT && sensor.type() <= AnalogType::PWM_2) + || (sensor.type() >= AnalogType::CNT_0 && sensor.type() <= AnalogType::CNT_2); output["visible"] = true; output["is_system"] = sensor.is_system(); - if (sensor.type() == AnalogType::COUNTER|| (sensor.type() >= AnalogType::CNT_0 && sensor.type() <= AnalogType::CNT_2)) { + if (sensor.type() == AnalogType::COUNTER || (sensor.type() >= AnalogType::CNT_0 && sensor.type() <= AnalogType::CNT_2)) { output["min"] = 0; output["max"] = 4000000; output["start_value"] = sensor.offset(); diff --git a/src/core/analogsensor.h b/src/core/analogsensor.h index 47c75e272..bc077c9d9 100644 --- a/src/core/analogsensor.h +++ b/src/core/analogsensor.h @@ -25,9 +25,7 @@ #include -#ifndef EMSESP_STANDALONE #include -#endif namespace emsesp { @@ -150,11 +148,7 @@ class AnalogSensor { bool updated_values(); // return back reference to the sensor list, used by other classes -#ifndef EMSESP_STANDALONE std::vector> sensors() const { -#else - std::vector sensors() const { -#endif return sensors_; } @@ -205,12 +199,8 @@ class AnalogSensor { void addSensorJson(JsonObject output, const Sensor & sensor); void get_value_json(JsonObject output, const Sensor & sensor); -#ifndef EMSESP_STANDALONE std::vector> sensors_; // our list of sensors -#else - std::vector sensors_; // our list of sensors -#endif - static std::vector exclude_types_; + static std::vector exclude_types_; bool analog_enabled_; bool changed_ = true; // this will force a publish of all sensors when initialising diff --git a/src/core/emsdevice.h b/src/core/emsdevice.h index b05997a1a..c74604d2b 100644 --- a/src/core/emsdevice.h +++ b/src/core/emsdevice.h @@ -25,9 +25,7 @@ #include "helpers.h" #include "emsdevicevalue.h" -#ifndef EMSESP_STANDALONE #include -#endif #include namespace emsesp { @@ -552,21 +550,12 @@ class EMSdevice { } }; -#ifndef EMSESP_STANDALONE std::vector> handlers_ignored_, handlers_broadcasted_, handlers_config_; -#else - std::vector handlers_ignored_, handlers_broadcasted_, handlers_config_; -#endif #if defined(EMSESP_STANDALONE) || defined(EMSESP_TEST) public: // so we can call it from WebCustomizationService::load_test_data() and EMSESP::dump_all_entities() #endif -#ifndef EMSESP_STANDALONE std::vector> telegram_functions_; // each EMS device has its own set of registered telegram types std::vector> devicevalues_; // all the device values -#else - std::vector telegram_functions_; // each EMS device has its own set of registered telegram types - std::vector devicevalues_; // all the device values -#endif }; } // namespace emsesp diff --git a/src/core/emsesp.h b/src/core/emsesp.h index 97fff50d6..5fe7cfb99 100644 --- a/src/core/emsesp.h +++ b/src/core/emsesp.h @@ -72,9 +72,7 @@ #include "command.h" #include "../emsesp_version.h" -#ifndef EMSESP_STANDALONE #include -#endif // Load external modules class Module {}; // forward declaration @@ -223,11 +221,7 @@ class EMSESP { static void scan_devices(); static void clear_all_devices(); -#ifndef EMSESP_STANDALONE static std::vector, AllocatorPSRAM>> emsdevices; -#else - static std::vector> emsdevices; -#endif // services static Mqtt mqtt_; static Modbus * modbus_; @@ -272,11 +266,8 @@ class EMSESP { const char * default_name; uint8_t flags; }; -#ifndef EMSESP_STANDALONE static std::vector> device_library_; -#else - static std::vector device_library_; -#endif + static uint16_t watch_id_; static uint8_t watch_; static uint16_t read_id_; diff --git a/src/core/system.h b/src/core/system.h index 7312ca466..6a0ceb4e1 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -31,9 +31,9 @@ #include #include #include -#include #endif +#include #include #include @@ -395,17 +395,11 @@ class System { void led_monitor(); void system_check(); -#ifndef EMSESP_STANDALONE static std::vector> string_range_to_vector(const std::string & range); static std::vector> valid_system_gpios_; // list of valid GPIOs for the ESP32 board that can be used static std::vector> used_gpios_; // list of GPIOs used by the application -#else - static std::vector string_range_to_vector(const std::string & range); - static std::vector valid_system_gpios_; // list of valid GPIOs for the ESP32 board that can be used - static std::vector used_gpios_; // list of GPIOs used by the application -#endif int8_t wifi_quality(int8_t dBm); uint8_t healthcheck_ = HEALTHCHECK_NO_NETWORK | HEALTHCHECK_NO_BUS; // start with all flags set, no wifi and no ems bus connection diff --git a/src/core/telegram.h b/src/core/telegram.h index f93e9838a..b6baeae71 100644 --- a/src/core/telegram.h +++ b/src/core/telegram.h @@ -31,9 +31,7 @@ #endif #include "helpers.h" -#ifndef EMSESP_STANDALONE #include -#endif #define MAX_RX_TELEGRAMS 100 // size of Rx queue #define MAX_TX_TELEGRAMS 160 // size of Tx queue @@ -290,11 +288,7 @@ class RxService : public EMSbus { } }; -#ifndef EMSESP_STANDALONE std::deque> queue() const { -#else - std::deque queue() const { -#endif return rx_telegrams_; } @@ -305,11 +299,8 @@ class RxService : public EMSbus { uint32_t telegram_count_ = 0; // # Rx received uint32_t telegram_error_count_ = 0; // # Rx CRC errors std::shared_ptr rx_telegram; // the incoming Rx telegram -#ifndef EMSESP_STANDALONE + std::deque> rx_telegrams_; // the Rx Queue -#else - std::deque rx_telegrams_; // the Rx Queue -#endif }; class TxService : public EMSbus { @@ -430,11 +421,7 @@ class TxService : public EMSbus { } }; -#ifndef EMSESP_STANDALONE std::deque> queue() const { -#else - std::deque queue() const { -#endif return tx_telegrams_; } @@ -446,11 +433,7 @@ class TxService : public EMSbus { static constexpr uint32_t POST_SEND_DELAY = 2000; private: -#ifndef EMSESP_STANDALONE std::deque> tx_telegrams_; // the Tx queue -#else - std::deque tx_telegrams_; // the Tx queue -#endif uint32_t telegram_read_count_ = 0; // # Tx successful reads uint32_t telegram_write_count_ = 0; // # Tx successful writes diff --git a/src/core/temperaturesensor.h b/src/core/temperaturesensor.h index bcb048595..36906c026 100644 --- a/src/core/temperaturesensor.h +++ b/src/core/temperaturesensor.h @@ -27,9 +27,10 @@ #include +#include + #ifndef EMSESP_STANDALONE #include -#include #endif namespace emsesp { @@ -172,12 +173,12 @@ class TemperatureSensor { #ifndef EMSESP_STANDALONE std::vector> sensors_; // our list of active sensors - OneWire bus_; - uint32_t last_activity_ = uuid::get_uptime(); - State state_ = State::IDLE; - int8_t scancnt_ = SCAN_START; - uint8_t firstscan_ = 0; - int8_t scanretry_ = 0; + OneWire bus_; + uint32_t last_activity_ = uuid::get_uptime(); + State state_ = State::IDLE; + int8_t scancnt_ = SCAN_START; + uint8_t firstscan_ = 0; + int8_t scanretry_ = 0; #else std::vector sensors_; // our list of active sensors #endif diff --git a/src/web/WebCustomEntityService.h b/src/web/WebCustomEntityService.h index 99f8dde45..f474d8200 100644 --- a/src/web/WebCustomEntityService.h +++ b/src/web/WebCustomEntityService.h @@ -16,9 +16,7 @@ * along with this program. If not, see . */ #include "../core/telegram.h" -#ifndef EMSESP_STANDALONE #include -#endif #ifndef WebCustomEntityService_h #define WebCustomEntityService_h @@ -48,11 +46,7 @@ class CustomEntityItem { class WebCustomEntity { public: -#ifndef EMSESP_STANDALONE std::list> customEntityItems; -#else - std::list customEntityItems; -#endif static void read(WebCustomEntity & webEntity, JsonObject root); static StateUpdateResult update(JsonObject root, WebCustomEntity & webEntity); @@ -89,11 +83,8 @@ class WebCustomEntityService : public StatefulService { void getEntities(AsyncWebServerRequest * request); -#ifndef EMSESP_STANDALONE std::list> * customEntityItems_; // pointer to the list of entity items -#else - std::list * customEntityItems_; // pointer to the list of entity items -#endif + bool ha_registered_ = false; }; diff --git a/src/web/WebCustomizationService.h b/src/web/WebCustomizationService.h index 4f12807d1..58bee0bd6 100644 --- a/src/web/WebCustomizationService.h +++ b/src/web/WebCustomizationService.h @@ -18,9 +18,7 @@ #ifndef WebCustomizationService_h #define WebCustomizationService_h -#ifndef EMSESP_STANDALONE #include -#endif #define EMSESP_CUSTOMIZATION_FILE "/config/emsespCustomization.json" @@ -73,15 +71,10 @@ class EntityCustomization { class WebCustomization { public: -#ifndef EMSESP_STANDALONE std::list> sensorCustomizations; // for sensor names and offsets std::list> analogCustomizations; // for analog sensors std::list> entityCustomizations; // for a list of entities that have a special mask set -#else - std::list sensorCustomizations; // for sensor names and offsets - std::list analogCustomizations; // for analog sensors - std::list entityCustomizations; // for a list of entities that have a special mask set -#endif + static void read(WebCustomization & customizations, JsonObject root); static StateUpdateResult update(JsonObject root, WebCustomization & customizations); diff --git a/src/web/WebLogService.h b/src/web/WebLogService.h index 1d4c7bfed..5e5c328c1 100644 --- a/src/web/WebLogService.h +++ b/src/web/WebLogService.h @@ -21,10 +21,7 @@ #define EMSESP_EVENT_SOURCE_LOG_PATH "/es/log" #define EMSESP_LOG_SETTINGS_PATH "/rest/logSettings" -#ifndef EMSESP_STANDALONE #include -using stringPSRAM = std::basic_string, AllocatorPSRAM>; -#endif using ::uuid::console::Shell; @@ -59,11 +56,7 @@ class WebLogService : public uuid::log::Handler { uint64_t uptime_; uuid::log::Level level_; const char * name_; -#ifndef EMSESP_STANDALONE - stringPSRAM text_; -#else - std::string text_; -#endif + stringPSRAM text_; }; void transmit(const QueuedLogMessage & message); @@ -71,15 +64,11 @@ class WebLogService : public uuid::log::Handler { char * messagetime(char * out, const uint64_t t, const size_t bufsize); -#ifndef EMSESP_STANDALONE std::deque> log_messages_; // Queued log messages, in the order they were received -#else - std::deque log_messages_; // Queued log messages, in the order they were received -#endif - size_t maximum_log_messages_ = MAX_LOG_MESSAGES; // Maximum number of log messages to buffer before they are output - size_t limit_log_messages_ = 1; // dynamic limit - unsigned long log_message_id_ = 0; // The next identifier to use for queued log messages - unsigned long log_message_id_tail_ = 0; // last event shown on the screen after fetch + size_t maximum_log_messages_ = MAX_LOG_MESSAGES; // Maximum number of log messages to buffer before they are output + size_t limit_log_messages_ = 1; // dynamic limit + unsigned long log_message_id_ = 0; // The next identifier to use for queued log messages + unsigned long log_message_id_tail_ = 0; // last event shown on the screen after fetch bool compact_ = true; uuid::log::Level level_ = uuid::log::Level::INFO; }; diff --git a/src/web/WebSchedulerService.h b/src/web/WebSchedulerService.h index a09e015e6..445a0d938 100644 --- a/src/web/WebSchedulerService.h +++ b/src/web/WebSchedulerService.h @@ -16,9 +16,7 @@ * along with this program. If not, see . */ -#ifndef EMSESP_STANDALONE #include -#endif #ifndef WebSchedulerService_h #define WebSchedulerService_h @@ -113,13 +111,8 @@ class WebSchedulerService : public StatefulService { FSPersistence _fsPersistence; bool ha_registered_ = false; -#ifndef EMSESP_STANDALONE std::list> * scheduleItems_; // pointer to the list of schedule events std::list> cmd_changed_; // pointer to commands in list that are triggert by change -#else - std::list * scheduleItems_; // pointer to the list of schedule events - std::list cmd_changed_; // pointer to commands in list that are triggert by change -#endif }; } // namespace emsesp