207 lines
4.5 KiB
C++
207 lines
4.5 KiB
C++
#include <ESP8266WiFi.h>
|
|
#include <EEPROM.h>
|
|
#include "h1602_eeprom.h"
|
|
|
|
eepromStruct_t eepromStruct;
|
|
|
|
//Read eeprom check for empty eeprom
|
|
void checkEeprom()
|
|
{
|
|
EEPROM.get(EEPROMSTRUCT_OFFSET, eepromStruct);
|
|
bool writeCheck = false;
|
|
|
|
//volatile stops optimization
|
|
volatile uint8_t boolvalue = (uint8_t)eepromStruct.apMode;
|
|
if (boolvalue >= 3)
|
|
{
|
|
eepromStruct.apMode = false;
|
|
writeCheck = true;
|
|
}
|
|
|
|
if (eepromStruct.password[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.ssid, "SDNmtr\0");
|
|
strcpy(eepromStruct.password, "LockedSDN\0");
|
|
writeCheck = true;
|
|
}
|
|
if (eepromStruct.noderedHost[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.noderedHost, "http://nodered.sdnsupport.nl:1880\0");
|
|
writeCheck = true;
|
|
}
|
|
if (eepromStruct.noderedUrl[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.noderedUrl, "Default\0");
|
|
writeCheck = true;
|
|
}
|
|
if (eepromStruct.device[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.device, "WSEN0000\0");
|
|
writeCheck = true;
|
|
}
|
|
|
|
boolvalue = (uint8_t)eepromStruct.use_ssdp;
|
|
if (boolvalue >= 3)
|
|
{
|
|
eepromStruct.use_ssdp = true;
|
|
writeCheck = true;
|
|
}
|
|
|
|
if (eepromStruct.updateTime == UINT_MAX)
|
|
{
|
|
eepromStruct.updateTime = 900;
|
|
writeCheck = true;
|
|
}
|
|
|
|
if (eepromStruct.channel[1].channel[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.channel[1].channel, "channel1\0");
|
|
eepromStruct.channel[1].enable = false;
|
|
writeCheck = true;
|
|
}
|
|
if (eepromStruct.channel[2].channel[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.channel[2].channel, "channel2\0");
|
|
eepromStruct.channel[2].enable = false;
|
|
writeCheck = true;
|
|
}
|
|
if (eepromStruct.channel[3].channel[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.channel[3].channel, "channel3\0");
|
|
eepromStruct.channel[3].enable = false;
|
|
writeCheck = true;
|
|
}
|
|
if (eepromStruct.channel[4].channel[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.channel[4].channel, "channel4\0");
|
|
eepromStruct.channel[4].enable = false;
|
|
writeCheck = true;
|
|
}
|
|
|
|
if (eepromStruct.www_username[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.www_username, "admin\0");
|
|
writeCheck = true;
|
|
}
|
|
if (eepromStruct.www_password[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.www_password, "password\0");
|
|
writeCheck = true;
|
|
}
|
|
|
|
boolvalue = (uint8_t)eepromStruct.use_prtg;
|
|
if (boolvalue >= 3)
|
|
{
|
|
eepromStruct.use_prtg = false;
|
|
writeCheck = true;
|
|
}
|
|
|
|
boolvalue = (uint8_t)eepromStruct.use_nodered;
|
|
if (boolvalue >= 3)
|
|
{
|
|
eepromStruct.use_nodered = false;
|
|
writeCheck = true;
|
|
}
|
|
|
|
if (eepromStruct.prtgHost[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.prtgHost, "prtg.sdnsupport.nl\0");
|
|
writeCheck = true;
|
|
}
|
|
if (eepromStruct.prtgHttpPort == 0xffffffff)
|
|
{
|
|
eepromStruct.prtgHttpPort = 5050;
|
|
writeCheck = true;
|
|
}
|
|
if (eepromStruct.serialnumber[0] == UCHAR_MAX)
|
|
{
|
|
strcpy(eepromStruct.serialnumber, "XXXXXXX\0");
|
|
writeCheck = true;
|
|
}
|
|
boolvalue = (uint8_t)eepromStruct.isSerialSet;
|
|
if (boolvalue >= 3)
|
|
{
|
|
eepromStruct.isSerialSet = false;
|
|
writeCheck = true;
|
|
}
|
|
|
|
boolvalue = (uint8_t)eepromStruct.use_mdns;
|
|
if (boolvalue >= 3)
|
|
{
|
|
eepromStruct.use_mdns = true;
|
|
writeCheck = true;
|
|
}
|
|
|
|
boolvalue = (uint8_t)eepromStruct.use_llmnr;
|
|
if (boolvalue >= 3)
|
|
{
|
|
eepromStruct.use_llmnr = true;
|
|
writeCheck = true;
|
|
}
|
|
|
|
boolvalue = (uint8_t)eepromStruct.use_netbios;
|
|
if (boolvalue >= 3)
|
|
{
|
|
eepromStruct.use_netbios = true;
|
|
writeCheck = true;
|
|
}
|
|
|
|
yield();
|
|
|
|
if (writeCheck)
|
|
{
|
|
EEPROM.put(EEPROMSTRUCT_OFFSET, eepromStruct);
|
|
EEPROM.commit();
|
|
}
|
|
}
|
|
|
|
void startEeprom()
|
|
{
|
|
EEPROM.begin(EEPROM_SIZE);
|
|
checkEeprom();
|
|
}
|
|
|
|
void storeApMode(bool state)
|
|
{
|
|
//AP mode activation
|
|
eepromStruct.apMode = state;
|
|
EEPROM.put(EEPROMSTRUCT_OFFSET, eepromStruct);
|
|
EEPROM.commit();
|
|
}
|
|
|
|
eepromStruct_t *getEeprom()
|
|
{
|
|
return &eepromStruct;
|
|
}
|
|
|
|
channel_t *getEepromChannel(int channel)
|
|
{
|
|
return &eepromStruct.channel[channel];
|
|
}
|
|
|
|
bool anyChannelEnabled()
|
|
{
|
|
return (eepromStruct.channel[1].enable || eepromStruct.channel[2].enable || eepromStruct.channel[3].enable || eepromStruct.channel[4].enable);
|
|
// if (eepromStruct.channel[1].enable == true || eepromStruct.channel[2].enable == true || eepromStruct.channel[3].enable == true || eepromStruct.channel[4].enable == true)
|
|
// {
|
|
// return true;
|
|
// }
|
|
// return false;
|
|
}
|
|
|
|
bool saveEeprom()
|
|
{
|
|
EEPROM.put(EEPROMSTRUCT_OFFSET, eepromStruct);
|
|
return EEPROM.commit();
|
|
}
|
|
|
|
void clearEeprom()
|
|
{
|
|
// write a 0 to all 512 bytes of the EEPROM
|
|
for (int i = 0; i < EEPROM_SIZE; i++)
|
|
{
|
|
EEPROM.write(i, 0xFF);
|
|
yield();
|
|
}
|
|
EEPROM.commit();
|
|
} |