-
Notifications
You must be signed in to change notification settings - Fork 123
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
Showing
59 changed files
with
2,142 additions
and
1,896 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
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
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
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <EEPROM.h> | ||
#include "EPROMStore.hpp" | ||
#include "Utility.hpp" | ||
|
||
// The global instance of the platform-independant EEPROM class | ||
EPROMStore *EPROMStore::_eepromStore = NULL; | ||
|
||
// Initialize the EEPROM storage in a platform-independent abstraction | ||
void EPROMStore::initialize() | ||
{ | ||
LOGV2(DEBUG_VERBOSE, "EEPROM: Initialize. Instance is %s", _eepromStore == NULL ? "NULL" : "VALID"); | ||
if (_eepromStore == NULL) | ||
{ | ||
LOGV1(DEBUG_VERBOSE, "EEPROM: Creating single instance"); | ||
_eepromStore = new EPROMStore(); | ||
} | ||
} | ||
|
||
// Get the instance of the EEPROM storage | ||
EPROMStore *EPROMStore::Storage() | ||
{ | ||
return _eepromStore; | ||
} | ||
|
||
#ifdef ESPBOARD | ||
|
||
// Construct the EEPROM object for ESP boards, settign aside 32 bytes for storage | ||
EPROMStore::EPROMStore() | ||
{ | ||
LOGV1(DEBUG_VERBOSE, "EEPROM[ESP]: Startup with 32 bytes"); | ||
EEPROM.begin(32); | ||
} | ||
|
||
// Update the given location with the given value | ||
void EPROMStore::update(int location, uint8_t value) | ||
{ | ||
LOGV3(DEBUG_VERBOSE, "EEPROM[ESP]: Writing %x to %d", value, location); | ||
EEPROM.write(location, value); | ||
LOGV1(DEBUG_VERBOSE, "EEPROM[ESP]: Committing"); | ||
EEPROM.commit(); | ||
} | ||
|
||
// Read the value at the given location | ||
uint8_t EPROMStore::read(int location) | ||
{ | ||
uint8_t value; | ||
value = EEPROM.read(location); | ||
LOGV3(DEBUG_VERBOSE, "EEPROM[ESP]: Read %x from %d", value, location); | ||
return value; | ||
} | ||
|
||
#else | ||
|
||
// Construct the EEPROM object for non-ESP boards | ||
EPROMStore::EPROMStore() | ||
{ | ||
LOGV1(DEBUG_VERBOSE, "EEPROM[UNO]: Startup "); | ||
} | ||
|
||
// Update the given location with the given value | ||
void EPROMStore::update(int location, uint8_t value) | ||
{ | ||
LOGV3(DEBUG_VERBOSE, "EEPROM[UNO]: Writing %x to %d", value, location); | ||
EEPROM.write(location, value); | ||
} | ||
|
||
// Read the value at the given location | ||
uint8_t EPROMStore::read(int location) | ||
{ | ||
uint8_t value = EEPROM.read(location); | ||
LOGV3(DEBUG_VERBOSE, "EEPROM[UNO]: Read %x from %d", value, location); | ||
return value; | ||
} | ||
|
||
#endif |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
#include <Arduino.h> | ||
|
||
// Platform independant abstraction of the EEPROM storage capability of the boards. | ||
// This is needed because the ESP boards require two things that the Arduino boards don't: | ||
// 1) It wants to know how many bytes you want to use (at most) | ||
// 2) It wants you to call a commit() function after a write() to actual persist the data. | ||
class EPROMStore { | ||
static EPROMStore *_eepromStore; | ||
public: | ||
EPROMStore(); | ||
static void initialize(); | ||
|
||
void update(int location, uint8_t value); | ||
uint8_t read(int location); | ||
static EPROMStore* Storage(); | ||
}; | ||
|
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,10 +1,2 @@ | ||
#include "Globals.hpp" | ||
#include <EEPROM.h> | ||
|
||
void EEPROMupdate(int loc, byte val) | ||
{ | ||
if (EEPROM.read(loc)!=val) | ||
{ | ||
EEPROM.write(loc,val); | ||
} | ||
} | ||
#include "Utility.hpp" |
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
Oops, something went wrong.