Public Access
Drop the schedule converter for version 4
2.18.0 stored the schedule on the display in version 5, so only that version is read now. Version 2.18.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e9f3c16c78
commit
16b7856593
2 files changed
+3
-107
No files matched your search
+1
-1
@@ -118,7 +118,7 @@ const uint32_t SETUP_AP_DELAY = 20000; // open the AP when WiFi fails thi
|
|||||||
const uint32_t WIFI_CONNECT_TIMEOUT = 30000;
|
const uint32_t WIFI_CONNECT_TIMEOUT = 30000;
|
||||||
const uint32_t WIFI_RESTART_TIME = 10UL * 60 * 1000;
|
const uint32_t WIFI_RESTART_TIME = 10UL * 60 * 1000;
|
||||||
|
|
||||||
#define FIRMWARE_VERSION "2.18.0"
|
#define FIRMWARE_VERSION "2.18.1"
|
||||||
|
|
||||||
// Home Assistant device id (do not change: Home Assistant's entities are linked to it)
|
// Home Assistant device id (do not change: Home Assistant's entities are linked to it)
|
||||||
const uint8_t HA_DEVICE_ID[] = {0x34, 0x86, 0x5d, 0x3a, 0x08, 0x28};
|
const uint8_t HA_DEVICE_ID[] = {0x34, 0x86, 0x5d, 0x3a, 0x08, 0x28};
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
static const char *NAMESPACE = "flipdot";
|
static const char *NAMESPACE = "flipdot";
|
||||||
static const char *KEY = "schedule";
|
static const char *KEY = "schedule";
|
||||||
// Increase when PageSchedule changes; records of other versions are ignored (an empty
|
// Increase when PageSchedule changes; records of other versions are ignored (an empty
|
||||||
// schedule) unless converted below. To keep the schedule over a change, add a frozen copy
|
// schedule). 2.18.0 stored the schedule again in version 5. To keep the schedule over a
|
||||||
// of the old layout and convert it.
|
// change, add a frozen copy of the old layout and convert it (see git history).
|
||||||
static const uint16_t VERSION = 5;
|
static const uint16_t VERSION = 5;
|
||||||
|
|
||||||
struct StoredSchedule
|
struct StoredSchedule
|
||||||
@@ -17,96 +17,6 @@ struct StoredSchedule
|
|||||||
PageSchedule schedule;
|
PageSchedule schedule;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Version 4 (2.15.0 - 2.17.0): no skip_slow_mode. Frozen copy, converted when read; the
|
|
||||||
// converted schedule is only stored when it is saved again (a rollback can still read
|
|
||||||
// version 4). Drop this once the display has saved its schedule in version 5.
|
|
||||||
namespace v4
|
|
||||||
{
|
|
||||||
struct Item
|
|
||||||
{
|
|
||||||
char page[PAGE_NAME_SIZE];
|
|
||||||
uint16_t seconds;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Block
|
|
||||||
{
|
|
||||||
uint16_t start;
|
|
||||||
bool effect;
|
|
||||||
uint8_t item_count;
|
|
||||||
Item items[BLOCK_ITEMS];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Rule
|
|
||||||
{
|
|
||||||
char entity[ELEMENT_ENTITY_SIZE];
|
|
||||||
char attribute[ELEMENT_ATTRIBUTE_SIZE];
|
|
||||||
Compare compare;
|
|
||||||
char value[RULE_VALUE_SIZE];
|
|
||||||
char page[PAGE_NAME_SIZE];
|
|
||||||
TriggerMode mode;
|
|
||||||
uint16_t seconds;
|
|
||||||
uint16_t interval;
|
|
||||||
uint8_t blocks;
|
|
||||||
bool over_manual;
|
|
||||||
bool over_slow_mode;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Schedule
|
|
||||||
{
|
|
||||||
bool enabled;
|
|
||||||
uint8_t block_count;
|
|
||||||
Block blocks[SCHEDULE_BLOCKS];
|
|
||||||
uint8_t rule_count;
|
|
||||||
Rule rules[TRIGGER_RULES];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Stored
|
|
||||||
{
|
|
||||||
uint16_t version;
|
|
||||||
uint16_t size;
|
|
||||||
Schedule schedule;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void convert(const Schedule &old, PageSchedule &s)
|
|
||||||
{
|
|
||||||
s = PageSchedule(); // skip_slow_mode: false
|
|
||||||
s.enabled = old.enabled;
|
|
||||||
s.block_count = old.block_count;
|
|
||||||
for (int i = 0; i < SCHEDULE_BLOCKS; i++)
|
|
||||||
{
|
|
||||||
const Block &o = old.blocks[i];
|
|
||||||
ScheduleBlock &b = s.blocks[i];
|
|
||||||
b.start = o.start;
|
|
||||||
b.effect = o.effect;
|
|
||||||
b.item_count = o.item_count;
|
|
||||||
for (int j = 0; j < BLOCK_ITEMS; j++)
|
|
||||||
{
|
|
||||||
memcpy(b.items[j].page, o.items[j].page, sizeof(b.items[j].page));
|
|
||||||
b.items[j].seconds = o.items[j].seconds;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.rule_count = old.rule_count;
|
|
||||||
for (int i = 0; i < TRIGGER_RULES; i++)
|
|
||||||
{
|
|
||||||
const Rule &o = old.rules[i];
|
|
||||||
TriggerRule &r = s.rules[i];
|
|
||||||
memcpy(r.entity, o.entity, sizeof(r.entity));
|
|
||||||
memcpy(r.attribute, o.attribute, sizeof(r.attribute));
|
|
||||||
r.compare = o.compare;
|
|
||||||
memcpy(r.value, o.value, sizeof(r.value));
|
|
||||||
memcpy(r.page, o.page, sizeof(r.page));
|
|
||||||
r.mode = o.mode;
|
|
||||||
r.seconds = o.seconds;
|
|
||||||
r.interval = o.interval;
|
|
||||||
r.blocks = o.blocks;
|
|
||||||
r.over_manual = o.over_manual;
|
|
||||||
r.over_slow_mode = o.over_slow_mode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace v4
|
|
||||||
|
|
||||||
static_assert(sizeof(v4::Stored) != sizeof(StoredSchedule), "the record sizes tell the versions apart");
|
|
||||||
|
|
||||||
void loadSchedule(PageSchedule &schedule)
|
void loadSchedule(PageSchedule &schedule)
|
||||||
{
|
{
|
||||||
schedule = PageSchedule();
|
schedule = PageSchedule();
|
||||||
@@ -122,20 +32,6 @@ void loadSchedule(PageSchedule &schedule)
|
|||||||
schedule = stored->schedule;
|
schedule = stored->schedule;
|
||||||
delete stored;
|
delete stored;
|
||||||
}
|
}
|
||||||
else if (length == sizeof(v4::Stored))
|
|
||||||
{
|
|
||||||
v4::Stored *stored = new v4::Stored;
|
|
||||||
PageSchedule *converted = new PageSchedule;
|
|
||||||
if (prefs.getBytes(KEY, stored, sizeof(v4::Stored)) == sizeof(v4::Stored) && stored->version == 4 &&
|
|
||||||
stored->size == sizeof(v4::Schedule))
|
|
||||||
{
|
|
||||||
v4::convert(stored->schedule, *converted);
|
|
||||||
if (validateSchedule(*converted) == nullptr)
|
|
||||||
schedule = *converted;
|
|
||||||
}
|
|
||||||
delete converted;
|
|
||||||
delete stored;
|
|
||||||
}
|
|
||||||
prefs.end();
|
prefs.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user