Fix eeprom on esp32

This commit is contained in:
GHOSCHT 2022-04-10 10:10:56 +02:00
parent 57850dd0d9
commit 6c2f39a4ea
No known key found for this signature in database
GPG key ID: A35BD466B8871994

View file

@ -9,6 +9,7 @@ LightController::LightController(const int bjtPins[], __SIZE_TYPE__ bjtCount)
this->bjtCount = bjtCount;
this->bjtPins = bjtPins;
this->bjtState = new int[bjtCount];
EEPROM.begin(64);
initializePins();
initializeState();
}
@ -31,7 +32,7 @@ void LightController::initializeStateDefaultValues()
{
for (__SIZE_TYPE__ i = 0; i < bjtCount; i++)
{
bjtState[i] = 0;
bjtState[i] = 20;
}
}
@ -39,7 +40,7 @@ void LightController::restoreState()
{
for (__SIZE_TYPE__ i = 0; i < bjtCount; i++)
{
bjtState[i] = EEPROM.read(i);
bjtState[i] = EEPROM.readInt(i * sizeof(bjtState[i]));
commitPinState(i);
}
}
@ -113,7 +114,8 @@ int LightController::clampState(int stateValue)
void LightController::commitState(int index)
{
commitPinState(index);
EEPROM.write(index, bjtState[index]);
EEPROM.writeInt(index * sizeof(bjtState[index]), bjtState[index]);
EEPROM.commit();
}
void LightController::commitPinState(int index)