retrieving/storing amount on eeprom esp8266
This commit is contained in:
parent
85c41b6530
commit
b356054121
2 changed files with 37 additions and 6 deletions
|
@ -7,6 +7,8 @@ namespace fw
|
|||
#ifdef ESP32
|
||||
if (this->mount_spiffs() == ERROR)
|
||||
endless_loop();
|
||||
#elif defined(ESP8266)
|
||||
this->setup_eeprom();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -26,23 +28,36 @@ namespace fw
|
|||
};
|
||||
}
|
||||
return SUCCESS;
|
||||
#elif defined(ESP8266)
|
||||
return NO_ACTION;
|
||||
#endif
|
||||
}
|
||||
|
||||
ok_t Storage::setup_eeprom()
|
||||
{
|
||||
#ifdef ESP8266
|
||||
EEPROM.begin(this->eeprom_size);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t Storage::retrieve_settings_value(const char *key)
|
||||
{
|
||||
#ifdef ESP32
|
||||
uint8_t amount_of_rules;
|
||||
uint8_t value;
|
||||
|
||||
this->memory.begin("settings", true);
|
||||
amount_of_rules = memory.getUChar(key, 0);
|
||||
value = memory.getUChar(key, 0);
|
||||
this->memory.end();
|
||||
|
||||
return amount_of_rules;
|
||||
return value;
|
||||
#elif defined(ESP8266)
|
||||
return 0;
|
||||
if (strncmp("amount_of_rules", key, 16))
|
||||
{
|
||||
uint8_t security_number = EEPROM.read(this->eeprom_settings_head);
|
||||
uint8_t amount_of_rules = EEPROM.read(this->eeprom_settings_head + 1);
|
||||
|
||||
if (amount_of_rules > 50 || security_number != this->security_number)
|
||||
return amount_of_rules;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -52,6 +67,13 @@ namespace fw
|
|||
this->memory.begin("settings", false);
|
||||
this->memory.putUChar(key, new_amount);
|
||||
this->memory.end();
|
||||
#elif defined(ESP8266)
|
||||
if (strncmp("amount_of_rules", key, 16))
|
||||
{
|
||||
EEPROM.write(this->eeprom_settings_head, this->security_number);
|
||||
EEPROM.write(this->eeprom_settings_head + 1, new_amount);
|
||||
EEPROM.commit();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue