OmEspHelpers
OmEeprom.h
1 #include <vector>
2 #include <string>
3 #include <stdint.h>
4 
5 #ifndef OMEEPROM_H
6 #define OMEEPROM_H
7 
8 #if NOT_ARDUINO
9 #include <string>
10 #define String std::string
11 #else
12 #include "Arduino.h"
13 #endif
14 
15 typedef enum
16 {
17  OME_TYPE_STRING = 0,
18  OME_TYPE_INT = 1
19 } EOmEepromFieldType;
20 
22 {
23 public:
24  const char *name = 0;
25  EOmEepromFieldType type = OME_TYPE_STRING; // 0 string, 1 int.
26  uint8_t length = 0; // string container size (1 more than max length) or int size 1,2,4,8.
27  int offset = 0;
28 };
29 
31 class OmEeprom
32 {
33 public:
34  OmEeprom(const char *signature);
35  void addField(const char *fieldName, EOmEepromFieldType type, uint8_t length);
36 
37  void begin();
38 
39  bool get(const char *fieldName, void *valueOut);
40  bool put(const char *fieldName, const void *value);
41  bool commit();
42 
44  void dumpState();
45 
46  // And now, the friendlier API calls.
47  void addString(const char *fieldName, uint8_t length);
48  void addInt8(const char *fieldName);
49  void addInt16(const char *fieldName);
50  void addInt32(const char *fieldName);
51 
52  void set(const char *fieldName, String stringValue);
53  void set(const char *fieldName, int32_t intValue);
54  String getString(const char *fieldName);
55  int getInt(const char *fieldName);
56 
57 private:
58  int signatureSize;
59  const char *signature;
60 
61  std::vector<OmEepromField> fields;
62  bool didBegin = false;
63 
64  int dataSize = 0; // sum of signature & fields.
65  uint8_t *data = 0; // malloc'd by fields.
66  OmEepromField *findField(const char *fieldName);
67 };
68 
69 #endif // OMEEPROM_H
OmEeprom::dumpState
void dumpState()
Definition: OmEeprom.cpp:200
OmEeprom
Wrapper for eeprom, lets you structure fields and check signature.
Definition: OmEeprom.h:32
OmEepromField
Definition: OmEeprom.h:22