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 
53 // Remove the '//' at the beginning of the line to be in
54 // debug mode.
55 //#define EEPROMEXTENT_DEBUG_MODE
56 
59 {
60 public:
68  inline uint8_t readByte(int address) { return eeprom_read_byte((uint8_t *)INT64 address); }
76  inline void writeByte(int address, uint8_t value) { eeprom_write_byte((uint8_t *)INT64 address, value); }
85  inline void updateByte(int address, uint8_t value) { eeprom_update_byte((uint8_t *)INT64 address, value); }
86 
87 #ifdef VISUALSTUDIO
89 #endif
90 
99  template <class T> int readAnything(int address, T& value)
100  {
101  eeprom_read_block((byte*)(void*)&value, (const uint8_t *)INT64 address, sizeof(value));
102  return sizeof(value);
103  }
104 
113  template <class T> int writeAnything(int address, const T& value)
114  {
115  eeprom_write_block((const byte*)(const void*)&value, (uint8_t *)INT64 address, sizeof(value));
116  return sizeof(value);
117  }
118 
131  template <class T> int updateAnything(int address, const T& value)
132  {
133  eeprom_update_block((const byte*)(const void*)&value, (uint8_t *)INT64 address, sizeof(value));
134  return sizeof(value);
135  }
136 
146  char *readString(int address, char *outString, int inMaxLen);
155  int writeString(int address, const char *inString);
167  int updateString(int address, const char *inString);
168 
176  void clear(int address, int inSize, byte inFillCharacter = 0);
177 };
178 
179 extern EEPROMextentClass EEPROMextent;
180 
181 #include "EEPROM_ItemList.hpp"
182 #include "CircularBuffer.hpp"
183 
184 #endif
void clear(int address, int inSize, byte inFillCharacter = 0)
int updateString(int address, const char *inString)
int writeString(int address, const char *inString)
int updateAnything(int address, const T &value)
Definition: EEPROMextent.h:131
int writeAnything(int address, const T &value)
Definition: EEPROMextent.h:113
void updateByte(int address, uint8_t value)
Definition: EEPROMextent.h:85
char * readString(int address, char *outString, int inMaxLen)
int readAnything(int address, T &value)
Definition: EEPROMextent.h:99
void writeByte(int address, uint8_t value)
Definition: EEPROMextent.h:76
uint8_t readByte(int address)
Definition: EEPROMextent.h:68
Main class for basic functions.
Definition: EEPROMextent.h:58