Added settings
This commit is contained in:
31
lib/settings/settings.cpp
Normal file
31
lib/settings/settings.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "settings.h"
|
||||
#include <EEPROM.h>
|
||||
|
||||
Settings::Settings() {
|
||||
refreshInterval = 1000;
|
||||
sensorPin = 26;
|
||||
}
|
||||
|
||||
void Settings::load() {
|
||||
EEPROM.begin(sizeof(Settings));
|
||||
EEPROM.get(0, *this);
|
||||
}
|
||||
|
||||
void Settings::save() {
|
||||
EEPROM.put(0, *this);
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
void Settings::setRefreshInterval(unsigned long refreshInterval) {
|
||||
this->refreshInterval = refreshInterval;
|
||||
save();
|
||||
}
|
||||
|
||||
long Settings::getRefreshInterval() { return refreshInterval; }
|
||||
|
||||
void Settings::setSensorPin(unsigned int sensorPin) {
|
||||
this->sensorPin = sensorPin;
|
||||
save();
|
||||
}
|
||||
|
||||
unsigned int Settings::getSensorPin() { return sensorPin; }
|
||||
19
lib/settings/settings.h
Normal file
19
lib/settings/settings.h
Normal file
@@ -0,0 +1,19 @@
|
||||
class Settings {
|
||||
|
||||
public:
|
||||
Settings();
|
||||
|
||||
void load();
|
||||
|
||||
void setRefreshInterval(unsigned long);
|
||||
long getRefreshInterval();
|
||||
|
||||
void setSensorPin(unsigned int);
|
||||
unsigned int getSensorPin();
|
||||
|
||||
private:
|
||||
unsigned long refreshInterval;
|
||||
unsigned int sensorPin;
|
||||
|
||||
void save();
|
||||
};
|
||||
Reference in New Issue
Block a user