mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-13 05:53:06 +01:00
intermediate: externalize config definitions
This commit is contained in:
@@ -54,7 +54,7 @@ GwConfigInterface * GwConfigHandler::getConfigItem(const String name, bool dummy
|
||||
return &dummyConfig;
|
||||
}
|
||||
#define PREF_NAME "gwprefs"
|
||||
GwConfigHandler::GwConfigHandler(GwLog *logger){
|
||||
GwConfigHandler::GwConfigHandler(GwLog *logger): GwConfigDefinitions(){
|
||||
this->logger=logger;
|
||||
}
|
||||
bool GwConfigHandler::loadConfig(){
|
||||
|
||||
@@ -3,74 +3,16 @@
|
||||
#include <Arduino.h>
|
||||
#include <Preferences.h>
|
||||
#include "GwLog.h"
|
||||
|
||||
class GwConfigInterface{
|
||||
public:
|
||||
virtual String asString() const=0;
|
||||
virtual const char * asCString() const =0;
|
||||
virtual bool asBoolean() const = 0;
|
||||
virtual int asInt() const = 0;
|
||||
};
|
||||
class GwConfigItem: public GwConfigInterface{
|
||||
private:
|
||||
String name;
|
||||
String initialValue;
|
||||
String value;
|
||||
public:
|
||||
GwConfigItem(const String &name, const String initialValue){
|
||||
this->name=name;
|
||||
this->initialValue=initialValue;
|
||||
this->value=initialValue;
|
||||
}
|
||||
virtual String asString() const{
|
||||
return value;
|
||||
}
|
||||
virtual const char * asCString() const{
|
||||
return value.c_str();
|
||||
};
|
||||
virtual void fromString(const String v){
|
||||
value=v;
|
||||
};
|
||||
virtual bool asBoolean() const{
|
||||
return strcasecmp(value.c_str(),"true") == 0;
|
||||
}
|
||||
virtual int asInt() const{
|
||||
return (int)value.toInt();
|
||||
}
|
||||
String getName() const{
|
||||
return name;
|
||||
}
|
||||
virtual void reset(){
|
||||
value=initialValue;
|
||||
}
|
||||
bool changed() const{
|
||||
return value != initialValue;
|
||||
}
|
||||
String getDefault() const {
|
||||
return initialValue;
|
||||
}
|
||||
};
|
||||
#include "GwConfigItem.h"
|
||||
#include "GwConfigDefinitions.h"
|
||||
|
||||
|
||||
class GwConfigHandler{
|
||||
class GwConfigHandler: public GwConfigDefinitions{
|
||||
private:
|
||||
Preferences prefs;
|
||||
GwLog *logger;
|
||||
public:
|
||||
public:
|
||||
const String sendUsb=F("sendUsb");
|
||||
const String receiveUsb=F("receiveUsb");
|
||||
const String wifiClient=F("wifiClient");
|
||||
const String wifiPass=F("wifiPass");
|
||||
const String wifiSSID=F("wifiSSID");
|
||||
const String serverPort=F("serverPort");
|
||||
const String maxClients=F("maxClients");
|
||||
const String sendTCP=F("sendTCP");
|
||||
const String readTCP=F("receiveTCP");
|
||||
const String sendSeasmart=F("sendSeasmart");
|
||||
const String usbBaud=F("usbBaud");
|
||||
const String systemName=F("systemName");
|
||||
const String stopApTime=F("stopApTime");
|
||||
GwConfigHandler(GwLog *logger);
|
||||
bool loadConfig();
|
||||
bool saveConfig();
|
||||
@@ -85,23 +27,5 @@ class GwConfigHandler{
|
||||
GwConfigItem * findConfig(const String name, bool dummy=false);
|
||||
GwConfigInterface * getConfigItem(const String name, bool dummy=false) const;
|
||||
private:
|
||||
GwConfigItem* configs[13]={
|
||||
new GwConfigItem(sendUsb,"true"),
|
||||
new GwConfigItem (receiveUsb,"false"),
|
||||
new GwConfigItem (wifiClient,"false"),
|
||||
new GwConfigItem (wifiSSID,""),
|
||||
new GwConfigItem (wifiPass,""),
|
||||
new GwConfigItem (serverPort,"2222"),
|
||||
new GwConfigItem (maxClients, "10"),
|
||||
new GwConfigItem (sendTCP,"true"),
|
||||
new GwConfigItem (readTCP,"true"),
|
||||
new GwConfigItem (sendSeasmart,"false"),
|
||||
new GwConfigItem (usbBaud,"115200"),
|
||||
new GwConfigItem (systemName,"ESP32NMEA2K"),
|
||||
new GwConfigItem (stopApTime,"0")
|
||||
};
|
||||
int getNumConfig() const{
|
||||
return 13;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
52
lib/config/GwConfigItem.h
Normal file
52
lib/config/GwConfigItem.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef _GWCONFIGITEM_H
|
||||
#define _GWCONFIGITEM_H
|
||||
#include "WString.h"
|
||||
class GwConfigInterface{
|
||||
public:
|
||||
virtual String asString() const=0;
|
||||
virtual const char * asCString() const =0;
|
||||
virtual bool asBoolean() const = 0;
|
||||
virtual int asInt() const = 0;
|
||||
};
|
||||
class GwConfigItem: public GwConfigInterface{
|
||||
private:
|
||||
String name;
|
||||
String initialValue;
|
||||
String value;
|
||||
public:
|
||||
GwConfigItem(const String &name, const String initialValue){
|
||||
this->name=name;
|
||||
this->initialValue=initialValue;
|
||||
this->value=initialValue;
|
||||
}
|
||||
virtual String asString() const{
|
||||
return value;
|
||||
}
|
||||
virtual const char * asCString() const{
|
||||
return value.c_str();
|
||||
};
|
||||
virtual void fromString(const String v){
|
||||
value=v;
|
||||
};
|
||||
virtual bool asBoolean() const{
|
||||
return strcasecmp(value.c_str(),"true") == 0;
|
||||
}
|
||||
virtual int asInt() const{
|
||||
return (int)value.toInt();
|
||||
}
|
||||
String getName() const{
|
||||
return name;
|
||||
}
|
||||
virtual void reset(){
|
||||
value=initialValue;
|
||||
}
|
||||
bool changed() const{
|
||||
return value != initialValue;
|
||||
}
|
||||
String getDefault() const {
|
||||
return initialValue;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user