-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added persistent storage! Every KWH the counter is stored.
Will change to a regular interval later on to reduce flash memory wear.
- Loading branch information
Showing
3 changed files
with
56 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <EEPROM.h> | ||
#include <Arduino.h> // for type definitions | ||
|
||
template <class T> int EEPROM_writeAnything(int ee, const T& value) | ||
{ | ||
const byte* p = (const byte*)(const void*)&value; | ||
unsigned int i; | ||
EEPROM.begin(sizeof(value)); | ||
for (i = 0; i < sizeof(value); i++) | ||
EEPROM.write(ee++, *p++); | ||
EEPROM.end(); | ||
return i; | ||
} | ||
|
||
template <class T> int EEPROM_readAnything(int ee, T& value) | ||
{ | ||
byte* p = (byte*)(void*)&value; | ||
unsigned int i; | ||
EEPROM.begin(sizeof(value)); | ||
for (i = 0; i < sizeof(value); i++) | ||
*p++ = EEPROM.read(ee++); | ||
EEPROM.end(); | ||
return i; | ||
} |
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