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
|
#ifdef ESP32
|
||||||
if (this->mount_spiffs() == ERROR)
|
if (this->mount_spiffs() == ERROR)
|
||||||
endless_loop();
|
endless_loop();
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
this->setup_eeprom();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,23 +28,36 @@ namespace fw
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
#elif defined(ESP8266)
|
#endif
|
||||||
return NO_ACTION;
|
}
|
||||||
|
|
||||||
|
ok_t Storage::setup_eeprom()
|
||||||
|
{
|
||||||
|
#ifdef ESP8266
|
||||||
|
EEPROM.begin(this->eeprom_size);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Storage::retrieve_settings_value(const char *key)
|
uint8_t Storage::retrieve_settings_value(const char *key)
|
||||||
{
|
{
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
uint8_t amount_of_rules;
|
uint8_t value;
|
||||||
|
|
||||||
this->memory.begin("settings", true);
|
this->memory.begin("settings", true);
|
||||||
amount_of_rules = memory.getUChar(key, 0);
|
value = memory.getUChar(key, 0);
|
||||||
this->memory.end();
|
this->memory.end();
|
||||||
|
|
||||||
return amount_of_rules;
|
return value;
|
||||||
#elif defined(ESP8266)
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +67,13 @@ namespace fw
|
||||||
this->memory.begin("settings", false);
|
this->memory.begin("settings", false);
|
||||||
this->memory.putUChar(key, new_amount);
|
this->memory.putUChar(key, new_amount);
|
||||||
this->memory.end();
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#include "Preferences.h"
|
#include "Preferences.h"
|
||||||
#include "SPIFFS.h"
|
#include "SPIFFS.h"
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
#include "EEPROM.h"
|
||||||
|
#include "spiffs_api.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
@ -15,8 +18,14 @@ namespace fw
|
||||||
private:
|
private:
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
Preferences memory;
|
Preferences memory;
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
uint16_t eeprom_size = 1000;
|
||||||
|
uint8_t security_number = 93;
|
||||||
|
uint16_t eeprom_settings_head = 0;
|
||||||
|
uint16_t eeprom_rules_head = 10;
|
||||||
#endif
|
#endif
|
||||||
ok_t mount_spiffs();
|
ok_t mount_spiffs();
|
||||||
|
ok_t setup_eeprom();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t retrieve_settings_value(const char *);
|
uint8_t retrieve_settings_value(const char *);
|
||||||
|
|
Reference in a new issue