1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-14 06:23:07 +01:00

allow to set a read only mode for config items, output compiler messages for overwritten configs, add m5 gps unit defs

This commit is contained in:
andreas
2023-10-05 18:52:30 +02:00
parent 9572b1e95e
commit 4fa40b98b3
7 changed files with 114 additions and 45 deletions

View File

@@ -1,3 +1,4 @@
#define CFG_MESSAGES
#include "GWConfig.h"
#include <ArduinoJson.h>
#include <string.h>
@@ -159,20 +160,20 @@ void GwConfigHandler::toHex(unsigned long v, char *buffer, size_t bsize)
buffer[2 * i] = 0;
}
std::vector<String> GwConfigHandler::getHidden() const{
std::vector<String> GwConfigHandler::getSpecial() const{
std::vector<String> rt;
rt.reserve(numHidden());
rt.reserve(numSpecial());
for (int i=0L;i<getNumConfig();i++){
if (configs[i]->isHidden()){
if (configs[i]->getType() != GwConfigInterface::NORMAL){
rt.push_back(configs[i]->getName());
};
}
return rt;
}
int GwConfigHandler::numHidden() const{
int GwConfigHandler::numSpecial() const{
int rt=0;
for (int i=0L;i<getNumConfig();i++){
if (configs[i]->isHidden()) rt++;
if (configs[i]->getType() != GwConfigInterface::NORMAL) rt++;
}
return rt;
}

View File

@@ -30,8 +30,8 @@ class GwConfigHandler: public GwConfigDefinitions{
int getInt(const String name,int defaultv=0) const;
GwConfigInterface * getConfigItem(const String name, bool dummy=false) const;
bool checkPass(String hash);
std::vector<String> getHidden() const;
int numHidden() const;
std::vector<String> getSpecial() const;
int numSpecial() const;
/**
* change the value of a config item
* will become a noop after stopChanges has been called

View File

@@ -5,19 +5,25 @@
class GwConfigHandler;
class GwConfigInterface{
public:
typedef enum {
NORMAL=0,
HIDDEN=1,
READONLY=2
} ConfigType;
private:
String name;
const char * initialValue;
String value;
bool secret=false;
bool hidden=false;
ConfigType type=NORMAL;
public:
GwConfigInterface(const String &name, const char * initialValue, bool secret=false, bool hidden=false){
GwConfigInterface(const String &name, const char * initialValue, bool secret=false,ConfigType type=NORMAL){
this->name=name;
this->initialValue=initialValue;
this->value=initialValue;
this->secret=secret;
this->hidden=hidden;
this->type=type;
}
virtual String asString() const{
return value;
@@ -43,8 +49,8 @@ class GwConfigInterface{
String getDefault() const {
return initialValue;
}
bool isHidden() const {
return hidden;
ConfigType getType() const {
return type;
}
friend class GwConfigHandler;
};
@@ -67,5 +73,7 @@ class GwNmeaFilter{
String toString();
};
#define __XSTR(x) __STR(x)
#define __STR(x) #x
#define __MSG(x) _Pragma (__STR(message (x)))
#endif