Config class as singleton with initializer in setup
This commit is contained in:
14
src/config.h
14
src/config.h
@@ -41,11 +41,21 @@ public:
|
||||
|
||||
class Config
|
||||
{
|
||||
|
||||
public:
|
||||
static Config &getInstance()
|
||||
{
|
||||
static Config instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private:
|
||||
Config() = default;
|
||||
Config(const Config &) = delete;
|
||||
Config &operator=(const Config &) = delete;
|
||||
|
||||
Config()
|
||||
public:
|
||||
void init()
|
||||
{
|
||||
FSmount mount; // scoped mount of the filesystem
|
||||
|
||||
@@ -102,7 +112,7 @@ public:
|
||||
LOG_ERROR("Unable to remove config.json");
|
||||
}
|
||||
LOG_WARN("Configuration reset, Restarting");
|
||||
}; //filesystem is unmounted here
|
||||
}; // filesystem is unmounted here
|
||||
delay(500);
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
10
src/main.cpp
10
src/main.cpp
@@ -18,6 +18,10 @@
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
/////////////// GLOBALS ///////////////
|
||||
Config& conf = Config::getInstance();
|
||||
/////////////// GLOBALS ///////////////
|
||||
|
||||
void callback(char *topic, uint8_t *payload, unsigned int length)
|
||||
{
|
||||
std::string pl;
|
||||
@@ -42,13 +46,11 @@ void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
LOG_ATTACH_SERIAL(Serial);
|
||||
conf.init();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/////////////// GLOBALS ///////////////
|
||||
Config conf = Config();
|
||||
/////////////// GLOBALS ///////////////
|
||||
const uint8_t baseRegister(0x00);
|
||||
uint16_t k(0);
|
||||
uint8_t sensors(0);
|
||||
@@ -83,7 +85,7 @@ void loop()
|
||||
//////////////// NETWORK ////////////////
|
||||
/////////////// CALLBACK ////////////////
|
||||
Network.onEvent(
|
||||
[&conf, ð, &rtc, &mqtt, &buzzer, &led](arduino_event_id_t event, arduino_event_info_t info) -> void
|
||||
[ð, &rtc, &mqtt, &buzzer, &led](arduino_event_id_t event, arduino_event_info_t info) -> void
|
||||
{
|
||||
eth.onEvent(event, info); // Arduino Ethernet event handler
|
||||
if (!eth.isConnected())
|
||||
|
||||
Reference in New Issue
Block a user