EEPROMextent
Arduino EEPROM library
EEPROMextent.h
1 /*
2 EEPROMextent.h - EEPROMextent library
3 Copyright (c) 2015 Thierry Paris. All right reserved.
4 
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
39 #ifndef __EEPROMextent_h__
40 #define __EEPROMextent_h__
41 
42 #ifndef VISUALSTUDIO
43 #include <avr/eeprom.h>
44 #include <inttypes.h>
45 //#include <EEPROM.h>
46 #define INT64
47 #else
48 #include <EEPROM.h>
49 #define INT64 (__int64)
50 #endif
51 
52 #include "arduino.h"
53 
55 // Remove the '//' at the beginning of the line to be in
56 // debug mode.
57 //#define EEPROMEXTENT_DEBUG_MODE
58 
61 {
62 public:
70  inline uint8_t readByte(int address) { return eeprom_read_byte((uint8_t *)INT64 address); }
78  inline void writeByte(int address, uint8_t value) { eeprom_write_byte((uint8_t *)INT64 address, value); }
87  inline void updateByte(int address, uint8_t value) { eeprom_update_byte((uint8_t *)INT64 address, value); }
88 
89 #ifdef VISUALSTUDIO
91 #endif
92 
101  template <class T> int readAnything(int address, T& value)
102  {
103  eeprom_read_block((byte*)(void*)&value, (const uint8_t *)INT64 ee, sizeof(value));
104  return sizeof(value);
105  }
106 
115  template <class T> int writeAnything(int address, const T& value)
116  {
117  eeprom_write_block((const byte*)(const void*)&value, (uint8_t *)INT64 ee, sizeof(value));
118  return sizeof(value);
119  }
120 
133  template <class T> int updateAnything(int address, const T& value)
134  {
135  eeprom_update_block((const byte*)(const void*)&value, (uint8_t *)INT64 ee, sizeof(value));
136  return sizeof(value);
137  }
138 
148  char *readString(int address, char *outString, int inMaxLen);
157  int writeString(int address, const char *inString);
169  int updateString(int address, const char *inString);
170 
178  void clear(int address, int inSize, byte inFillCharacter = 0);
179 };
180 
181 extern EEPROMextentClass EEPROMextent;
182 
183 #include "EEPROM_ItemList.hpp"
184 #include "CircularBuffer.hpp"
185 
186 #endif
void clear(int address, int inSize, byte inFillCharacter = 0)
Definition: EEPROMextent.cpp:60
int updateString(int address, const char *inString)
Definition: EEPROMextent.cpp:43
int writeString(int address, const char *inString)
Definition: EEPROMextent.cpp:26
int updateAnything(int address, const T &value)
Definition: EEPROMextent.h:133
int writeAnything(int address, const T &value)
Definition: EEPROMextent.h:115
void updateByte(int address, uint8_t value)
Definition: EEPROMextent.h:87
char * readString(int address, char *outString, int inMaxLen)
Definition: EEPROMextent.cpp:11
int readAnything(int address, T &value)
Definition: EEPROMextent.h:101
void writeByte(int address, uint8_t value)
Definition: EEPROMextent.h:78
uint8_t readByte(int address)
Definition: EEPROMextent.h:70
Main class for basic functions.
Definition: EEPROMextent.h:60