EEPROM_Class (community library)

Summary

Name Value
Name EEPROM_Class
Version 1.1.0
Installs 491
License MIT
Author Randy E. Rainwater
URL https://github.com/Randyrtx/EEPROM_Class
Repository https://github.com/Randyrtx/EEPROM_Class.git
Download .tar.gz
All Versions 1.1.0, 1.0.2, 1.0.1, 1.0.0

Class for managing configuration data stored in EEPROM for non-volatility.

Example Build Testing

Device OS Version:

This table is generated from an automated build. Success only indicates that the code compiled successfully.

Library Read Me

This content is provided by the library maintainer and has not been validated or approved.

EEPROM_Class Library for Particle Version 1.1.0

This library implements classes for managing data objects stored in the emulated EEPROM of Particle devices.

EEPROM_Class

template <class OBJ>
class EEPROM_Class {}

Implements the basic, low-level functions for storing and retrieving generic data objects in EEPROM. Integrity is maintained via a 16-bit checksum which is verifed before data is retrieved, and updated whenever the entries in the object are changed. May be used standalone for small data objects or used in derived classes for specialized data objects.

Implemented as a template class so that objects of any type may be used.

UserSettingsClass

class UserSettingsClass : public EEPROM_Class<SettingsObject> {}

Derives from the EEPROM_Class base class to implement a specialized data object containing clock settings and Wifi information not already provided by the system OS.

API Documentation

Simple Object use with EEPROM_Class

User-defined data object (example)
// Define structure of the object
struct UserCredentials
{
char userName[16];
char password[16];
};

// Declare the object
UserCredentials myCredentials = {"", ""};

// Instantiate the class object with the type
EEPROM_Class<UserCredentials> myEEPROM;

// Define the EEPROM address for the object,
//      where: 0 <= address <= EEPROM.length()  - (sizeof(object) + sizeof(uint16_t))
#define mySettingsAddress 0

// Initialize the data object with EEPROM image
if(myEEPROM.begin(myCredentialsAddress, myCredentials))
// Valid Image Loaded
else
// Checksum error, image not loaded
Updating the object
strcpy(myCredentials.userName, "NewUserName");
strcpy(myCredentials.password, "NewPassword");
myEEPROM.writeObject(myCredentials);

Refer to the API Documentation and Examples for further details.

UserSettingsClass User Configuration Object

Data Object
struct SettingsObject
{
float timeZone;
float dstOffset;
bool dstEnabled;
char hostName[32];
WLanSelectAntenna_TypeDef antennaType;
};
Class instantiation and startup
// User Settings Class Object
UserSettingsClass mySettings;

// Define the EEPROM address for the object,
//      where: 0 <= address <= EEPROM.length() - (sizeof(object) + sizeof(uint16_t))
#define mySettingsAddress 0

if (mySettings.begin(mySettingsAddress))
{
// Valid Image Loaded
}
else
{
// Checksum error, image not loaded
}
Typical use:
Time.zone(mySettings.getTimeZone()); // Set time zone
Time.setDSTOffset(mySettings.getDstOffset()); // Set DST offset
if (mySettings.isDSTEnabled())
{
Time.beginDST(); // Set Daylight Savings Time flag
}
else
{
Time.endDST(); // Note: this is not needed on startup, as the DST setting defaults to off.
}

WiFi.setHostname(mySettings.getHostName());
WiFi.selectAntenna(mySettings.getAntennaType());

Object Address Calculation for Multiple Data Objects

// Define desired start of used EEPROM for data objects
#define EEPROM_START_ADDRESS 0

// Create an address variable to set starting address for each object
size_t objectAddress = EEPROM_START_ADDRESS;

// Create first object
UserSettingsClass mySettingsObject;
mySettingsObject.begin(objectAddress);

// bump the address for next item
objectAddress += mySettingsObject.getSize();

// Create next object
struct UserObject { ... };
UserObject myObject;
EEPROM_Class<UserObject> myEEPROM;
myEEPROM.begin(objectAddress, myObject);

// bump the address for next item
objectAddress += myObject.getSize();

Refer to the provided examples for more details.

Examples:

Basic Usage Example: Demonstrates use of the UserSettingsClass for common system settings.

Advanced Usage Example: Demonstrates use of the EEPROM_Class for a small user-defined data object.

LICENSE

Copyright 2019 Randy E. Rainwater

Licensed under the MIT License

Browse Library Files