Added settings

This commit is contained in:
Gašper Dobrovoljc
2023-02-19 14:16:00 +01:00
parent af449d1a2b
commit 59252e81b0
7 changed files with 171 additions and 24 deletions

31
lib/settings/settings.cpp Normal file
View 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
View 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();
};