mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 22:02:17 +01:00
Merge pull request #54 from cjkas/fix/restore-skip-rooms
fix: skip the room records too when a restore leaves the shades out
This commit is contained in:
commit
2b2a4f815d
4 changed files with 91 additions and 20 deletions
|
|
@ -574,10 +574,8 @@ bool ShadeConfigFile::restoreFile(SomfyShadeController *s, const char *filename,
|
|||
}
|
||||
else {
|
||||
ESP_LOGI(TAG, "Shade data ignored");
|
||||
// FF past the shades and groups.
|
||||
this->file.seek(this->file.position()
|
||||
+ (this->header.shadeRecords * this->header.shadeRecordSize)
|
||||
+ (this->header.groupRecords * this->header.groupRecordSize), SeekSet); // Start at the beginning of the file after the header.
|
||||
// FF past the rooms, shades and groups.
|
||||
this->file.seek(this->file.position() + shadeModelBytes(this->header), SeekSet);
|
||||
}
|
||||
if(opts.repeaters) {
|
||||
ESP_LOGI(TAG, "Restoring Repeaters...");
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <LittleFS.h>
|
||||
#include "Somfy.h"
|
||||
#include "ConfigSettings.h"
|
||||
#include "ConfigHeader.h"
|
||||
|
||||
#ifndef configfile_h
|
||||
#define configfile_h
|
||||
|
|
@ -12,22 +13,6 @@
|
|||
#define CFG_TOK_QUOTE '"'
|
||||
|
||||
|
||||
struct config_header_t {
|
||||
uint8_t version = 1;
|
||||
uint8_t repeaterRecords = 0;
|
||||
uint8_t repeaterRecordSize = 0;
|
||||
uint8_t roomRecords = 0;
|
||||
uint16_t roomRecordSize = 0;
|
||||
uint16_t shadeRecordSize = 0;
|
||||
uint8_t shadeRecords = 0;
|
||||
uint16_t groupRecordSize = 0;
|
||||
uint8_t groupRecords = 0;
|
||||
uint16_t settingsRecordSize = 0;
|
||||
uint16_t netRecordSize = 0;
|
||||
uint16_t transRecordSize = 0;
|
||||
char serverId[10] = ""; // This must match the server id size in the ConfigSettings.
|
||||
int8_t length = 0;
|
||||
};
|
||||
class ConfigFile {
|
||||
protected:
|
||||
File file;
|
||||
|
|
|
|||
33
src/ConfigHeader.h
Normal file
33
src/ConfigHeader.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef CONFIG_HEADER_H
|
||||
#define CONFIG_HEADER_H
|
||||
#include <stdint.h>
|
||||
|
||||
// The header of a shades.cfg file: its version and how many records of each
|
||||
// kind follow, and their sizes. Kept free of the file system so it can be
|
||||
// unit tested on the PC (pio test -e native).
|
||||
struct config_header_t {
|
||||
uint8_t version = 1;
|
||||
uint8_t repeaterRecords = 0;
|
||||
uint8_t repeaterRecordSize = 0;
|
||||
uint8_t roomRecords = 0;
|
||||
uint16_t roomRecordSize = 0;
|
||||
uint16_t shadeRecordSize = 0;
|
||||
uint8_t shadeRecords = 0;
|
||||
uint16_t groupRecordSize = 0;
|
||||
uint8_t groupRecords = 0;
|
||||
uint16_t settingsRecordSize = 0;
|
||||
uint16_t netRecordSize = 0;
|
||||
uint16_t transRecordSize = 0;
|
||||
char serverId[10] = ""; // This must match the server id size in the ConfigSettings.
|
||||
int8_t length = 0;
|
||||
};
|
||||
|
||||
// The bytes of the shade model's records, which follow the header in this
|
||||
// order: rooms, shades, groups. A restore that leaves the shades out skips
|
||||
// this many bytes.
|
||||
inline uint32_t shadeModelBytes(const config_header_t &header) {
|
||||
return static_cast<uint32_t>(header.roomRecords) * header.roomRecordSize
|
||||
+ static_cast<uint32_t>(header.shadeRecords) * header.shadeRecordSize
|
||||
+ static_cast<uint32_t>(header.groupRecords) * header.groupRecordSize;
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue