Config class as singleton with initializer in setup
This commit is contained in:
12
src/config.h
12
src/config.h
@@ -41,11 +41,21 @@ public:
|
|||||||
|
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static Config &getInstance()
|
||||||
|
{
|
||||||
|
static Config instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Config() = default;
|
||||||
Config(const Config &) = delete;
|
Config(const Config &) = delete;
|
||||||
Config &operator=(const Config &) = delete;
|
Config &operator=(const Config &) = delete;
|
||||||
|
|
||||||
Config()
|
public:
|
||||||
|
void init()
|
||||||
{
|
{
|
||||||
FSmount mount; // scoped mount of the filesystem
|
FSmount mount; // scoped mount of the filesystem
|
||||||
|
|
||||||
|
|||||||
10
src/main.cpp
10
src/main.cpp
@@ -18,6 +18,10 @@
|
|||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
/////////////// GLOBALS ///////////////
|
||||||
|
Config& conf = Config::getInstance();
|
||||||
|
/////////////// GLOBALS ///////////////
|
||||||
|
|
||||||
void callback(char *topic, uint8_t *payload, unsigned int length)
|
void callback(char *topic, uint8_t *payload, unsigned int length)
|
||||||
{
|
{
|
||||||
std::string pl;
|
std::string pl;
|
||||||
@@ -42,13 +46,11 @@ void setup()
|
|||||||
{
|
{
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
LOG_ATTACH_SERIAL(Serial);
|
LOG_ATTACH_SERIAL(Serial);
|
||||||
|
conf.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
/////////////// GLOBALS ///////////////
|
|
||||||
Config conf = Config();
|
|
||||||
/////////////// GLOBALS ///////////////
|
|
||||||
const uint8_t baseRegister(0x00);
|
const uint8_t baseRegister(0x00);
|
||||||
uint16_t k(0);
|
uint16_t k(0);
|
||||||
uint8_t sensors(0);
|
uint8_t sensors(0);
|
||||||
@@ -83,7 +85,7 @@ void loop()
|
|||||||
//////////////// NETWORK ////////////////
|
//////////////// NETWORK ////////////////
|
||||||
/////////////// CALLBACK ////////////////
|
/////////////// CALLBACK ////////////////
|
||||||
Network.onEvent(
|
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
|
eth.onEvent(event, info); // Arduino Ethernet event handler
|
||||||
if (!eth.isConnected())
|
if (!eth.isConnected())
|
||||||
|
|||||||
Reference in New Issue
Block a user