Skip to content

Commit

Permalink
Merge pull request letscontrolit#4764 from tonhuisman/feature/Core-ex…
Browse files Browse the repository at this point in the history
…tend-custom-task-settings

[Core] Add extra storage space for Custom TaskSettings
  • Loading branch information
TD-er authored Apr 28, 2024
2 parents c428918 + 0232929 commit 3cc3dd1
Show file tree
Hide file tree
Showing 12 changed files with 616 additions and 366 deletions.
2 changes: 1 addition & 1 deletion src/_P095_ILI9341.ino
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ boolean Plugin_095(uint8_t function, struct EventStruct *event, String& string)
F("pbgcolor"),
P095_CONFIG_GET_COLOR_BACKGROUND);

uint16_t remain = DAT_TASKS_CUSTOM_SIZE;
uint16_t remain = DAT_TASKS_CUSTOM_SIZE + DAT_TASKS_CUSTOM_EXTENSION_SIZE;
{
String strings[P095_Nlines];
LoadCustomTaskSettings(event->TaskIndex, strings, P095_Nlines, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/_P096_eInk.ino
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ boolean Plugin_096(uint8_t function, struct EventStruct *event, String& string)
String strings[P096_Nlines];
LoadCustomTaskSettings(event->TaskIndex, strings, P096_Nlines, 0);

uint16_t remain = DAT_TASKS_CUSTOM_SIZE;
uint16_t remain = DAT_TASKS_CUSTOM_SIZE + DAT_TASKS_CUSTOM_EXTENSION_SIZE;

for (uint8_t varNr = 0; varNr < P096_Nlines; varNr++) {
addFormTextBox(concat(F("Line "), (varNr + 1)), getPluginCustomArgName(varNr), strings[varNr], P096_Nchars);
Expand Down
3 changes: 1 addition & 2 deletions src/_P116_ST77xx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,12 @@ boolean Plugin_116(uint8_t function, struct EventStruct *event, String& string)
String strings[P116_Nlines];
LoadCustomTaskSettings(event->TaskIndex, strings, P116_Nlines, 0);

uint16_t remain = DAT_TASKS_CUSTOM_SIZE;
uint16_t remain = DAT_TASKS_CUSTOM_SIZE + DAT_TASKS_CUSTOM_EXTENSION_SIZE;

for (uint8_t varNr = 0; varNr < P116_Nlines; varNr++) {
addFormTextBox(concat(F("Line "), varNr + 1), getPluginCustomArgName(varNr), strings[varNr], P116_Nchars);
remain -= (strings[varNr].length() + 1);
}
addUnit(concat(F("Remaining: "), remain));
}

success = true;
Expand Down
2 changes: 1 addition & 1 deletion src/_P131_NeoPixelMatrix.ino
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ boolean Plugin_131(uint8_t function, struct EventStruct *event, String& string)
String strings[P131_Nlines];
LoadCustomTaskSettings(event->TaskIndex, strings, P131_Nlines, 0);

uint16_t remain = DAT_TASKS_CUSTOM_SIZE;
uint16_t remain = DAT_TASKS_CUSTOM_SIZE + DAT_TASKS_CUSTOM_EXTENSION_SIZE;

addFormSubHeader(F("Lines"));
addRowLabel(F("Lines"));
Expand Down
55 changes: 39 additions & 16 deletions src/src/CustomBuild/StorageLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@


/*
The settings files have some reserved space for each struct stored in there.
The settings files have some reserved space for each struct stored in there.
CONFIG_FILE_SIZE File size of config.dat
Settings struct is positioned at the start of the settings file Config.dat
Settings struct is positioned at the start of the settings file Config.dat
DAT_BASIC_SETTINGS_SIZE Reserved size for Settings struct
Parameters used for locating the task data:
Parameters used for locating the task data:
DAT_OFFSET_TASKS Position of first TaskSettings in the Settings file
DAT_TASKS_SIZE Reserved size for TaskSettings
Expand All @@ -36,8 +36,8 @@
DAT_TASKS_DISTANCE = DAT_TASKS_SIZE + DAT_TASKS_CUSTOM_SIZE
Parameters used for locating the controller data:
Parameters used for locating the controller data:
DAT_OFFSET_CONTROLLER Position of first ControllerSettings in the Settings file
DAT_CONTROLLER_SIZE Reserved size for ControllerSettings
Expand All @@ -47,12 +47,12 @@
ControllerSettings and CustomControllerSettings are not located interleaved in the settings file.
So there is no distance value for controller settings. (equal to the controller size)
Notification settings are located in a different file.
Notification settings are located in a different file.
DAT_NOTIFICATION_SIZE Reserved size for NotificationSettings
DAT_NOTIFICATION_SIZE Reserved size for NotificationSettings
*/
*/

#ifndef DAT_BASIC_SETTINGS_SIZE
// For size of SettingsStruct stored at this area in config.dat
Expand All @@ -79,6 +79,25 @@
#ifndef DAT_TASKS_CUSTOM_SIZE
# define DAT_TASKS_CUSTOM_SIZE 1024
#endif // ifndef DAT_TASKS_CUSTOM_SIZE
// FEATURE_EXTENDED_CUSTOM_SETTINGS: Default will be determined in define_plugin_sets.h, based on used plugins
#ifndef FEATURE_EXTENDED_CUSTOM_SETTINGS
# ifdef BUILD_MINIMAL_OTA
# define FEATURE_EXTENDED_CUSTOM_SETTINGS 0 // Never on minimal builds?
# else // ifdef BUILD_MINIMAL_OTA
# define FEATURE_EXTENDED_CUSTOM_SETTINGS 1
# endif // ifdef BUILD_MINIMAL_OTA
#endif // if FEATURE_EXTENDED_CUSTOM_SETTINGS
#ifndef DAT_TASKS_CUSTOM_EXTENSION_SIZE
# if FEATURE_EXTENDED_CUSTOM_SETTINGS
# define DAT_TASKS_CUSTOM_EXTENSION_SIZE 4096 // 4kB extension with external file extcfg<tasknr>.dat
# else // if FEATURE_EXTENDED_CUSTOM_SETTINGS
# define DAT_TASKS_CUSTOM_EXTENSION_SIZE 0 // No extension, but defined to avoid #if checks all over the code
# endif // if FEATURE_EXTENDED_CUSTOM_SETTINGS
#endif // ifndef DAT_TASKS_CUSTOM_EXTENSION_SIZE
// Filename _must_ include the task number (1-based, as shown in the UI) and the % is also used elsewhere, so keep the %02d !
#ifndef DAT_TASKS_CUSTOM_EXTENSION_FILEMASK
# define DAT_TASKS_CUSTOM_EXTENSION_FILEMASK "extcfg%02d.dat"
#endif // ifndef DAT_TASKS_CUSTOM_EXTENSION_FILEMASK
#ifndef DAT_TASKS_DISTANCE
# define DAT_TASKS_DISTANCE 2048 // DAT_TASKS_SIZE + DAT_TASKS_CUSTOM_SIZE
#endif // ifndef DAT_TASKS_DISTANCE
Expand Down Expand Up @@ -119,7 +138,8 @@
#define TASKS_MAX 24
#define DAT_OFFSET_CONTROLLER (DAT_OFFSET_TASKS + (DAT_TASKS_DISTANCE * TASKS_MAX)) // each controller =
1k, 4 max
#define DAT_OFFSET_CUSTOM_CONTROLLER (DAT_OFFSET_CONTROLLER + (DAT_CUSTOM_CONTROLLER_SIZE * CONTROLLER_MAX)) // each custom controller config =
#define DAT_OFFSET_CUSTOM_CONTROLLER (DAT_OFFSET_CONTROLLER + (DAT_CUSTOM_CONTROLLER_SIZE * CONTROLLER_MAX)) // each custom controller
config =
1k, 4 max
Expand All @@ -136,7 +156,9 @@
#if defined(ESP8266)
# if FEATURE_NON_STANDARD_24_TASKS
# ifndef DAT_OFFSET_TASKS
# define DAT_OFFSET_TASKS 4096 // 0x1000 each task = 2k, (1024 basic + 1024 bytes custom)
# define DAT_OFFSET_TASKS 4096 // 0x1000 each task = 2k,
// (1024 basic + 1024 bytes
// custom)
# endif // ifndef DAT_OFFSET_TASKS
# ifndef DAT_OFFSET_CONTROLLER
# define DAT_OFFSET_CONTROLLER (DAT_OFFSET_TASKS + (DAT_TASKS_DISTANCE * TASKS_MAX)) // each controller = 1k, 3 max, DAT_OFFSET_CDN is at position of any 4th controller.
Expand Down Expand Up @@ -167,24 +189,25 @@
# define DAT_OFFSET_CDN (DAT_OFFSET_TASKS - DAT_CDN_SIZE) // single CDN settings block of 1k
# endif
# ifdef LIMIT_BUILD_SIZE
// Limit the config size for 1M builds, since their file system is also quite small

// Limit the config size for 1M builds, since their file system is also quite small
# ifndef CONFIG_FILE_SIZE
# define CONFIG_FILE_SIZE 36864 // DAT_OFFSET_CUSTOM_CONTROLLER + 4x DAT_CUSTOM_CONTROLLER_SIZE
# endif // ifndef CONFIG_FILE_SIZE
# else
# else // ifdef LIMIT_BUILD_SIZE
# ifndef CONFIG_FILE_SIZE
# define CONFIG_FILE_SIZE 65536
# endif // ifndef CONFIG_FILE_SIZE
# endif
# endif // ifdef LIMIT_BUILD_SIZE
# endif // if FEATURE_NON_STANDARD_24_TASKS
#endif // if defined(ESP8266)

#if defined(ESP32)
# ifndef DAT_OFFSET_TASKS
# define DAT_OFFSET_TASKS 32768 // each task = 2k, (1024 basic + 1024 bytes custom), 32 max
# define DAT_OFFSET_TASKS 32768 // each task = 2k, (1024 basic + 1024 bytes custom), 32 max
# endif // ifndef DAT_OFFSET_TASKS
# ifndef DAT_OFFSET_CONTROLLER
# define DAT_OFFSET_CONTROLLER 8192 // each controller = 1k, 4 max
# define DAT_OFFSET_CONTROLLER 8192 // each controller = 1k, 4 max
# endif // ifndef DAT_OFFSET_CONTROLLER
# ifndef DAT_OFFSET_CUSTOM_CONTROLLER
# define DAT_OFFSET_CUSTOM_CONTROLLER 12288 // each custom controller config = 1k, 4 max.
Expand Down
10 changes: 10 additions & 0 deletions src/src/CustomBuild/define_plugin_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -3245,6 +3245,16 @@ To create/register a plugin, you have to :
#endif
#endif

// Check for plugins that will use Extended Custom Settings storage when available
#ifndef FEATURE_EXTENDED_CUSTOM_SETTINGS
#if defined(USES_P094) || defined(USES_P095) || defined(USES_P096) || defined(USES_P099) || defined(USES_P104) || defined(USES_P116) || defined(USES_P123) || defined(USES_P131)
#define FEATURE_EXTENDED_CUSTOM_SETTINGS 1
#else
#define FEATURE_EXTENDED_CUSTOM_SETTINGS 0
#endif
#endif // ifndef FEATURE_EXTENDED_CUSTOM_SETTINGS



#ifndef FEATURE_CLEAR_I2C_STUCK
#ifdef ESP8266
Expand Down
29 changes: 25 additions & 4 deletions src/src/DataTypes/ESPEasyFileType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

#include "../../ESPEasy_common.h"

#include "../CustomBuild/StorageLayout.h"

#include "../Globals/ResetFactoryDefaultPref.h"

#include "../Helpers/StringConverter.h"

bool matchFileType(const String& filename, FileType::Enum filetype)
{
if (filename.startsWith(F("/"))) {
Expand All @@ -14,10 +18,27 @@ bool matchFileType(const String& filename, FileType::Enum filetype)

bool isProtectedFileType(const String& filename)
{
return matchFileType(filename, FileType::CONFIG_DAT) ||
matchFileType(filename, FileType::SECURITY_DAT) ||
matchFileType(filename, FileType::NOTIFICATION_DAT) ||
matchFileType(filename, FileType::PROVISIONING_DAT);
#if FEATURE_EXTENDED_CUSTOM_SETTINGS
bool isTaskSpecificConfig = false;
const String fname = filename.substring(filename.startsWith(F("/")) ? 1 : 0);
const String mask = F(DAT_TASKS_CUSTOM_EXTENSION_FILEMASK);
const int8_t mPerc = mask.indexOf('%');

if ((mPerc > -1) && fname.startsWith(mask.substring(0, mPerc))) {
for (uint8_t n = 0; n < TASKS_MAX && !isTaskSpecificConfig; ++n) {
isTaskSpecificConfig |= (fname.equalsIgnoreCase(strformat(mask, n + 1)));
}
}
#endif // if FEATURE_EXTENDED_CUSTOM_SETTINGS

return
#if FEATURE_EXTENDED_CUSTOM_SETTINGS
isTaskSpecificConfig || // Support for extcfgNN.dat
#endif // if FEATURE_EXTENDED_CUSTOM_SETTINGS
matchFileType(filename, FileType::CONFIG_DAT) ||
matchFileType(filename, FileType::SECURITY_DAT) ||
matchFileType(filename, FileType::NOTIFICATION_DAT) ||
matchFileType(filename, FileType::PROVISIONING_DAT);
}

const __FlashStringHelper* getFileName(FileType::Enum filetype) {
Expand Down
10 changes: 8 additions & 2 deletions src/src/DataTypes/SettingsType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../DataStructs/SecurityStruct.h"
#include "../DataTypes/ESPEasyFileType.h"
#include "../Globals/Settings.h"
#include "../Helpers/StringConverter.h"

const __FlashStringHelper * SettingsType::getSettingsTypeString(Enum settingsType) {
switch (settingsType) {
Expand Down Expand Up @@ -63,7 +64,7 @@ bool SettingsType::getSettingsParameters(Enum settingsType, int index, int& max_
if (!getSettingsParameters(Enum::TaskSettings_Type, index, max_index, offset, max_size, struct_size))
return false;
offset += (DAT_TASKS_CUSTOM_OFFSET);
max_size = DAT_TASKS_CUSTOM_SIZE;
max_size = (DAT_TASKS_CUSTOM_SIZE + DAT_TASKS_CUSTOM_EXTENSION_SIZE);

// struct_size may differ.
struct_size = 0;
Expand Down Expand Up @@ -235,7 +236,12 @@ SettingsType::SettingsFileEnum SettingsType::getSettingsFile(Enum settingsType)
return SettingsFileEnum::FILE_UNKNOWN_type;
}

String SettingsType::getSettingsFileName(Enum settingsType) {
String SettingsType::getSettingsFileName(Enum settingsType, int index) {
#if FEATURE_EXTENDED_CUSTOM_SETTINGS
if ((Enum::CustomTaskSettings_Type == settingsType) && validTaskIndex(index)) {
return strformat(F(DAT_TASKS_CUSTOM_EXTENSION_FILEMASK), index + 1); // Add 0/1 offset to match displayed task ID
}
#endif // if FEATURE_EXTENDED_CUSTOM_SETTINGS
return getSettingsFileName(getSettingsFile(settingsType));
}

Expand Down
5 changes: 3 additions & 2 deletions src/src/DataTypes/SettingsType.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define DATATYPES_SETTINGSTYPE_H

#include "../../ESPEasy_common.h"

#include "../DataTypes/TaskIndex.h"

class SettingsType {
public:
Expand Down Expand Up @@ -50,7 +50,8 @@ class SettingsType {
#endif // ifndef BUILD_MINIMAL_OTA

static SettingsFileEnum getSettingsFile(Enum settingsType);
static String getSettingsFileName(Enum settingsType);
static String getSettingsFileName(Enum settingsType,
int index = INVALID_TASK_INDEX);
static const __FlashStringHelper * getSettingsFileName(SettingsType::SettingsFileEnum file_type);
static size_t getInitFileSize(SettingsType::SettingsFileEnum file_type);
};
Expand Down
Loading

0 comments on commit 3cc3dd1

Please sign in to comment.