From f2d86115fb99d0dc7a868acfe4a87c454660e8a2 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Thu, 14 Nov 2024 15:12:25 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20Moves=20utilities=20to=20own=20f?= =?UTF-8?q?older?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp32/lib/ESP32-sveltekit/BatteryService.h | 4 +- esp32/lib/ESP32-sveltekit/MotionService.h | 2 +- esp32/lib/ESP32-sveltekit/Peripherals.h | 2 +- esp32/lib/ESP32-sveltekit/SettingValue.cpp | 58 ------------------- esp32/lib/ESP32-sveltekit/SettingValue.h | 24 -------- esp32/lib/ESP32-sveltekit/ap_service.h | 2 +- .../ESP32-sveltekit/settings/ap_settings.h | 6 +- .../ESP32-sveltekit/settings/wifi_settings.h | 6 +- .../{IPUtils.h => utils/ip_utils.h} | 0 .../{JsonUtils.h => utils/json_utils.h} | 2 +- .../string_utils.h} | 0 .../lib/ESP32-sveltekit/{ => utils}/timing.h | 10 ++++ esp32/lib/ESP32-sveltekit/wifi_service.h | 2 +- 13 files changed, 23 insertions(+), 95 deletions(-) delete mode 100644 esp32/lib/ESP32-sveltekit/SettingValue.cpp delete mode 100644 esp32/lib/ESP32-sveltekit/SettingValue.h rename esp32/lib/ESP32-sveltekit/{IPUtils.h => utils/ip_utils.h} (100%) rename esp32/lib/ESP32-sveltekit/{JsonUtils.h => utils/json_utils.h} (96%) rename esp32/lib/ESP32-sveltekit/{string_utilities.h => utils/string_utils.h} (100%) rename esp32/lib/ESP32-sveltekit/{ => utils}/timing.h (77%) diff --git a/esp32/lib/ESP32-sveltekit/BatteryService.h b/esp32/lib/ESP32-sveltekit/BatteryService.h index 32ef032..45c872b 100644 --- a/esp32/lib/ESP32-sveltekit/BatteryService.h +++ b/esp32/lib/ESP32-sveltekit/BatteryService.h @@ -15,9 +15,9 @@ **/ #include -#include +#include #include -#include +#include #define ADC_VOLTAGE 0 #define ADC_CURRENT 1 diff --git a/esp32/lib/ESP32-sveltekit/MotionService.h b/esp32/lib/ESP32-sveltekit/MotionService.h index 3183360..9a3e5a2 100644 --- a/esp32/lib/ESP32-sveltekit/MotionService.h +++ b/esp32/lib/ESP32-sveltekit/MotionService.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/esp32/lib/ESP32-sveltekit/Peripherals.h b/esp32/lib/ESP32-sveltekit/Peripherals.h index 00dae94..e7697fd 100644 --- a/esp32/lib/ESP32-sveltekit/Peripherals.h +++ b/esp32/lib/ESP32-sveltekit/Peripherals.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/esp32/lib/ESP32-sveltekit/SettingValue.cpp b/esp32/lib/ESP32-sveltekit/SettingValue.cpp deleted file mode 100644 index 122def2..0000000 --- a/esp32/lib/ESP32-sveltekit/SettingValue.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/** - * ESP32 SvelteKit - * - * A simple, secure and extensible framework for IoT projects for ESP32 platforms - * with responsive Sveltekit front-end built with TailwindCSS and DaisyUI. - * https://github.com/theelims/ESP32-sveltekit - * - * Copyright (C) 2018 - 2023 rjwats - * Copyright (C) 2023 theelims - * - * All Rights Reserved. This software may be modified and distributed under - * the terms of the LGPL v3 license. See the LICENSE file for details. - **/ - -#include - -namespace SettingValue { -const String PLATFORM = "esp32"; - -/** - * Returns a new string after replacing each instance of the pattern with a value generated by calling the provided - * callback. - */ -String replaceEach(String value, String pattern, String (*generateReplacement)()) { - while (true) { - int index = value.indexOf(pattern); - if (index == -1) { - break; - } - value = value.substring(0, index) + generateReplacement() + value.substring(index + pattern.length()); - } - return value; -} - -/** - * Generates a random number, encoded as a hex string. - */ -String getRandom() { return String(random(2147483647), HEX); } - -/** - * Uses the station's MAC address to create a unique id for each device. - */ -String getUniqueId() { - uint8_t mac[6]; - esp_read_mac(mac, ESP_MAC_WIFI_STA); - char macStr[13] = {0}; - sprintf(macStr, "%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - return String(macStr); -} - -String format(String value) { - value = replaceEach(value, "#{random}", getRandom); - value.replace("#{unique_id}", getUniqueId()); - value.replace("#{platform}", PLATFORM); - return value; -} - -}; // end namespace SettingValue diff --git a/esp32/lib/ESP32-sveltekit/SettingValue.h b/esp32/lib/ESP32-sveltekit/SettingValue.h deleted file mode 100644 index 93dc23a..0000000 --- a/esp32/lib/ESP32-sveltekit/SettingValue.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef SettingValue_h -#define SettingValue_h - -/** - * ESP32 SvelteKit - * - * A simple, secure and extensible framework for IoT projects for ESP32 platforms - * with responsive Sveltekit front-end built with TailwindCSS and DaisyUI. - * https://github.com/theelims/ESP32-sveltekit - * - * Copyright (C) 2018 - 2023 rjwats - * Copyright (C) 2023 theelims - * - * All Rights Reserved. This software may be modified and distributed under - * the terms of the LGPL v3 license. See the LICENSE file for details. - **/ - -#include - -namespace SettingValue { -String format(String value); -}; - -#endif // end SettingValue diff --git a/esp32/lib/ESP32-sveltekit/ap_service.h b/esp32/lib/ESP32-sveltekit/ap_service.h index ab42f0f..7038c79 100644 --- a/esp32/lib/ESP32-sveltekit/ap_service.h +++ b/esp32/lib/ESP32-sveltekit/ap_service.h @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include class APService : public StatefulService { diff --git a/esp32/lib/ESP32-sveltekit/settings/ap_settings.h b/esp32/lib/ESP32-sveltekit/settings/ap_settings.h index 8a98e3d..9273671 100644 --- a/esp32/lib/ESP32-sveltekit/settings/ap_settings.h +++ b/esp32/lib/ESP32-sveltekit/settings/ap_settings.h @@ -3,9 +3,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/esp32/lib/ESP32-sveltekit/settings/wifi_settings.h b/esp32/lib/ESP32-sveltekit/settings/wifi_settings.h index 2ea3661..338c241 100644 --- a/esp32/lib/ESP32-sveltekit/settings/wifi_settings.h +++ b/esp32/lib/ESP32-sveltekit/settings/wifi_settings.h @@ -3,9 +3,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #ifndef FACTORY_WIFI_SSID diff --git a/esp32/lib/ESP32-sveltekit/IPUtils.h b/esp32/lib/ESP32-sveltekit/utils/ip_utils.h similarity index 100% rename from esp32/lib/ESP32-sveltekit/IPUtils.h rename to esp32/lib/ESP32-sveltekit/utils/ip_utils.h diff --git a/esp32/lib/ESP32-sveltekit/JsonUtils.h b/esp32/lib/ESP32-sveltekit/utils/json_utils.h similarity index 96% rename from esp32/lib/ESP32-sveltekit/JsonUtils.h rename to esp32/lib/ESP32-sveltekit/utils/json_utils.h index b26d847..5298fdc 100644 --- a/esp32/lib/ESP32-sveltekit/JsonUtils.h +++ b/esp32/lib/ESP32-sveltekit/utils/json_utils.h @@ -2,7 +2,7 @@ #define JsonUtils_h #include -#include +#include #include class JsonUtils { diff --git a/esp32/lib/ESP32-sveltekit/string_utilities.h b/esp32/lib/ESP32-sveltekit/utils/string_utils.h similarity index 100% rename from esp32/lib/ESP32-sveltekit/string_utilities.h rename to esp32/lib/ESP32-sveltekit/utils/string_utils.h diff --git a/esp32/lib/ESP32-sveltekit/timing.h b/esp32/lib/ESP32-sveltekit/utils/timing.h similarity index 77% rename from esp32/lib/ESP32-sveltekit/timing.h rename to esp32/lib/ESP32-sveltekit/utils/timing.h index c993b0f..a773f2b 100644 --- a/esp32/lib/ESP32-sveltekit/timing.h +++ b/esp32/lib/ESP32-sveltekit/utils/timing.h @@ -29,4 +29,14 @@ } \ } +#define CALLS_PER_SECOND(name) \ + static unsigned long name##_count = 0; \ + static unsigned long last_time = 0; \ + name##_count++; \ + if (millis() - last_time >= 1000) { \ + Serial.printf("%s: %lu calls per second\n", #name, name##_count); \ + name##_count = 0; \ + last_time = millis(); \ + } + #endif \ No newline at end of file diff --git a/esp32/lib/ESP32-sveltekit/wifi_service.h b/esp32/lib/ESP32-sveltekit/wifi_service.h index 5996e26..431e70c 100644 --- a/esp32/lib/ESP32-sveltekit/wifi_service.h +++ b/esp32/lib/ESP32-sveltekit/wifi_service.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include