Public Access
Drop the converters for old data
2.15.0 stored all settings, schedules and pages on the display in the current formats (old_data_left 0), so only those are read now: settings version 7, schedule version 4, page format 7. The one-time migrations (icons from 2.10.0, data from 2.15.0) are removed too. About 9 KB less flash. CLAUDE.md says how to keep data over a future format change. Version 2.15.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
968492ca35
commit
9959c1aa74
14 files changed
+28
-996
No files matched your search
+2
-150
@@ -109,9 +109,6 @@ static void reloadPage()
|
||||
controller.pageChanged();
|
||||
}
|
||||
|
||||
static bool settings_converted = false;
|
||||
static bool schedule_converted = false;
|
||||
|
||||
const Settings &appSettings()
|
||||
{
|
||||
return settings;
|
||||
@@ -119,8 +116,8 @@ const Settings &appSettings()
|
||||
|
||||
void appLoadSettings()
|
||||
{
|
||||
settings_converted = loadSettings(settings);
|
||||
schedule_converted = loadSchedule(page_schedule);
|
||||
loadSettings(settings);
|
||||
loadSchedule(page_schedule);
|
||||
selector.setSchedule(&page_schedule);
|
||||
selector.setChosen(settings.page);
|
||||
haApiWatchRules(&page_schedule);
|
||||
@@ -470,151 +467,6 @@ const char *appIconToBitmap(const char *name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The one-time move, in steps over many loop() passes: LittleFS is slow (listing a
|
||||
// directory of 40 files takes about a second), and loop() must never get near the
|
||||
// watchdog. Each pass works for about MIGRATION_STEP_MS.
|
||||
enum class Migration
|
||||
{
|
||||
Start,
|
||||
Pages, // which candidates the pages use (one page after the other)
|
||||
Move,
|
||||
Done,
|
||||
};
|
||||
static const uint32_t MIGRATION_STEP_MS = 1000;
|
||||
static Migration migration = Migration::Start;
|
||||
static std::vector<String> migration_bitmaps; // uploaded bitmaps not shown on their own
|
||||
static std::vector<bool> migration_used;
|
||||
static std::vector<String> migration_pages;
|
||||
static size_t migration_next = 0;
|
||||
static int migration_moved = 0;
|
||||
static uint32_t migration_started = 0;
|
||||
|
||||
void appMigrateIcons()
|
||||
{
|
||||
if (migration == Migration::Done)
|
||||
return;
|
||||
uint32_t pass = millis();
|
||||
auto time_left = [pass]() { return millis() - pass < MIGRATION_STEP_MS; };
|
||||
|
||||
if (migration == Migration::Start)
|
||||
{
|
||||
if (iconMigrationDone())
|
||||
{
|
||||
migration = Migration::Done;
|
||||
return;
|
||||
}
|
||||
migration_started = pass;
|
||||
for (const BitmapInfo &b : listBitmaps())
|
||||
if (!b.builtin && !shownOnItsOwn(b.name.c_str()))
|
||||
migration_bitmaps.push_back(b.name);
|
||||
migration_used.assign(migration_bitmaps.size(), false);
|
||||
for (const PageInfo &p : listPages())
|
||||
migration_pages.push_back(p.name);
|
||||
migration_next = 0;
|
||||
migration = Migration::Pages;
|
||||
return;
|
||||
}
|
||||
|
||||
if (migration == Migration::Pages)
|
||||
{
|
||||
DynamicPage *page = new DynamicPage;
|
||||
while (migration_next < migration_pages.size() && time_left())
|
||||
if (loadPage(migration_pages[migration_next++].c_str(), *page))
|
||||
for (size_t i = 0; i < migration_bitmaps.size(); i++)
|
||||
if (pageUsesImage(*page, migration_bitmaps[i].c_str(), true))
|
||||
migration_used[i] = true;
|
||||
delete page;
|
||||
if (migration_next >= migration_pages.size())
|
||||
{
|
||||
migration_next = 0;
|
||||
migration = Migration::Move;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
while (migration_next < migration_bitmaps.size() && time_left())
|
||||
{
|
||||
size_t i = migration_next++;
|
||||
const char *name = migration_bitmaps[i].c_str();
|
||||
// Checked again: the web UI may have changed something in the meantime
|
||||
if (!migration_used[i] || shownOnItsOwn(name))
|
||||
continue;
|
||||
const char *error = moveToIcon(name);
|
||||
if (error)
|
||||
Serial.printf("Bitmap \"%s\" stays a bitmap: %s\n", name, error);
|
||||
else
|
||||
migration_moved++;
|
||||
}
|
||||
if (migration_next < migration_bitmaps.size())
|
||||
return;
|
||||
|
||||
setIconMigrationDone();
|
||||
Serial.printf("%d bitmaps that only pages use became icons (%lu ms)\n", migration_moved,
|
||||
(unsigned long)(millis() - migration_started));
|
||||
migration_bitmaps.clear();
|
||||
migration_used.clear();
|
||||
migration_pages.clear();
|
||||
migration = Migration::Done;
|
||||
if (migration_moved)
|
||||
reloadPage();
|
||||
}
|
||||
|
||||
// Same steps as the icon migration: one page per check, MIGRATION_STEP_MS per pass
|
||||
static bool data_listed = false;
|
||||
static bool data_done = false;
|
||||
static std::vector<String> data_pages;
|
||||
static size_t data_next = 0;
|
||||
static int data_left = -1;
|
||||
|
||||
void appMigrateData()
|
||||
{
|
||||
if (data_done || migration != Migration::Done)
|
||||
return;
|
||||
uint32_t pass = millis();
|
||||
if (settings_converted)
|
||||
{
|
||||
saveSettings(settings);
|
||||
settings_converted = false;
|
||||
Serial.println("Settings stored in the new layout");
|
||||
}
|
||||
if (schedule_converted)
|
||||
{
|
||||
saveSchedule(page_schedule);
|
||||
schedule_converted = false;
|
||||
Serial.println("Schedule stored in the new layout");
|
||||
}
|
||||
if (!data_listed)
|
||||
{
|
||||
data_pages = storedPageNames();
|
||||
data_listed = true;
|
||||
data_left = 0;
|
||||
return;
|
||||
}
|
||||
DynamicPage *page = new DynamicPage;
|
||||
while (data_next < data_pages.size() && millis() - pass < MIGRATION_STEP_MS)
|
||||
{
|
||||
const char *name = data_pages[data_next++].c_str();
|
||||
if (!pageInOldFormat(name))
|
||||
continue;
|
||||
const char *error = loadPage(name, *page) ? savePage(name, *page) : "unreadable";
|
||||
Serial.printf("Page \"%s\" in the new format: %s\n", name, error ? error : "ok");
|
||||
if (error)
|
||||
data_left++;
|
||||
}
|
||||
delete page;
|
||||
if (data_next < data_pages.size())
|
||||
return;
|
||||
data_pages.clear();
|
||||
data_done = true;
|
||||
}
|
||||
|
||||
int appOldDataLeft()
|
||||
{
|
||||
if (!data_done)
|
||||
return -1;
|
||||
return data_left + (settings_converted ? 1 : 0) + (schedule_converted ? 1 : 0);
|
||||
}
|
||||
|
||||
const char *appSaveFont(const char *name, const uint8_t *data, size_t size)
|
||||
{
|
||||
const char *error = saveFont(name, data, size);
|
||||
|
||||
Reference in new issue
Block a user