#include "./settings.h"
#include <EEPROM.h>


#define SettingsIdentifier 0x42
#define SettingsVersion1 1

SettingsContainer Settings;


struct SettingsHeader
{
  uint8_t identifier;
  uint8_t version;
};

#define SettingsHeightsAddress sizeof(SettingsHeader)


// Forward declarations
void readHeights();


bool readSettings()
{
  memset(&Settings, 0, sizeof(SettingsContainer));

  SettingsHeader header;
  EEPROM.get(0, header);

  if (header.identifier == SettingsIdentifier)
  {
    if (header.version >= 1)
        readHeights();

    return true;
  }

  return false;
}


void readHeights()
{
  EEPROM.get(SettingsHeightsAddress, Settings.Height);
}


void writeSettingsHeights()
{
  EEPROM.put(SettingsHeightsAddress, Settings.Height);
}
