-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hector Oliveros
committed
Jan 6, 2018
1 parent
80f949b
commit 894a0ef
Showing
1 changed file
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,82 @@ | ||
# ConfigDB | ||
A fast way to store configurations in the "EEPROM" memory (NodeMCU / esp8266 12e) | ||
<p align="center"> | ||
<h3 align="center">ConfigDB</h3> | ||
|
||
<p align="center"> | ||
A fast way to store configurations data in the "EEPROM" memory (NodeMCU / esp8266 12e) | ||
</p> | ||
</p> | ||
|
||
<br> | ||
|
||
##### Problem | ||
Saving data structures in the EEPROM can be complicated. | ||
This library was created with the purpose of facilitating the saving of configurations in the EEPROM memory | ||
|
||
##### Steps to use: | ||
To use this library should jump define your own configuration class (in the example i made MyConfiguration class) | ||
|
||
##### Simple example | ||
|
||
This code shows examples of saving and obtaining the configuration data. | ||
|
||
```c++ | ||
#include <math.h> | ||
#include <configdb.h> | ||
|
||
/** The custom MyConfiguration class **/ | ||
class MyConfiguration | ||
{ | ||
public: | ||
int intValue; | ||
float floatValue; | ||
}; | ||
|
||
ConfigDB<MyConfiguration> configDB; | ||
|
||
bool printCfg(MyConfiguration cfg) | ||
{ | ||
Serial.printf("cfg.intValue:%d\n", cfg.intValue); | ||
Serial.printf("cfg.floatValue:%f\n", cfg.floatValue); | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
|
||
// intValue | floatValue | ||
MyConfiguration defaultCfg = {0, 9876.543}; | ||
|
||
// If the MyConfiguration is not saved then save it with a default value | ||
bool isPreviusConfigStored = configDB.storeDefaultIfNotLoad(defaultCfg); | ||
|
||
Serial.printf("\nisPreviusConfigStored=%d\n", isPreviusConfigStored); // False | ||
|
||
// Get the Configuration from the eeprom | ||
MyConfiguration newCfg = configDB.load(); | ||
printCfg(newCfg); | ||
|
||
// Make new config and save | ||
newCfg.intValue = 1234; | ||
newCfg.floatValue = EULER; | ||
configDB.save(newCfg); | ||
|
||
// Get the new MyConfiguration recently saved in the eeprom | ||
newCfg = configDB.load(); | ||
printCfg(newCfg); | ||
|
||
configDB.clear(); | ||
} | ||
|
||
void loop() | ||
{ | ||
// put your main code here, to run repeatedly: | ||
} | ||
``` | ||
<br><br> | ||
This diagram shows a diagram of the hash table used to associate the commands to the functions. | ||
![](media/serial_output.png) | ||
<br><br> | ||
###### Command message format: | ||
![](media/format.png) | ||