#pragma once
#ifndef RZMEEPROMMAP_H
#define RZMEEPROMMAP_H

#include <Arduino.h>
#include <EEPROM.h>

class RzmEepromMap
{
    enum class EepromMapAddr
    {
        FW_VERSION_MAJOR = 0x00,
        FW_VERSION_MINOR = 0x01,
        HARDWARE_ID      = 0x02
    };

public:

    uint16_t firmwareVersion(uint8_t major = 0xFF, uint8_t minor = 0xFF)
    {
        if ((major == 0xFF) && (minor == 0xFF))
        {
            Serial.print((EEPROM.read((uint16_t)EepromMapAddr::FW_VERSION_MAJOR)));
            Serial.print(".");
            Serial.print((EEPROM.read((uint16_t)EepromMapAddr::FW_VERSION_MINOR)));
            Serial.println();
            return (uint16_t)((EEPROM.read((uint16_t)EepromMapAddr::FW_VERSION_MAJOR) << 8) | (EEPROM.read((uint16_t)EepromMapAddr::FW_VERSION_MINOR) << 0));
        }
        else
        {
            EEPROM.write((uint16_t)EepromMapAddr::FW_VERSION_MAJOR, major);
            EEPROM.write((uint16_t)EepromMapAddr::FW_VERSION_MINOR, minor);
            return 0;
        }
    }

    uint8_t hardwareID(uint8_t i = 0xFF)
    {
        if (i == 0xFF)
        {
            return EEPROM.read((uint16_t)EepromMapAddr::HARDWARE_ID);
        }
        else
        {
            EEPROM.write((uint16_t)EepromMapAddr::HARDWARE_ID, i);
            return 0;
        }
    }

    bool checkHardwareID(uint8_t i)
    {
        return (hardwareID() == i);
    }

private:
};

#endif // RZMEEPROMMAP_H
