allow to hide config items from the ui and allow to change config values in the init function
This commit is contained in:
parent
e70591eb4f
commit
966ef0c4fb
|
@ -114,6 +114,16 @@ int GwConfigHandler::getInt(const String name,int defaultv) const{
|
||||||
if (!i) return defaultv;
|
if (!i) return defaultv;
|
||||||
return i->asInt();
|
return i->asInt();
|
||||||
}
|
}
|
||||||
|
void GwConfigHandler::stopChanges(){
|
||||||
|
allowChanges=false;
|
||||||
|
}
|
||||||
|
bool GwConfigHandler::setValue(String name,String value){
|
||||||
|
if (! allowChanges) return false;
|
||||||
|
GwConfigInterface *i=getConfigItem(name,false);
|
||||||
|
if (!i) return false;
|
||||||
|
i->value=value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void GwNmeaFilter::handleToken(String token, int index){
|
void GwNmeaFilter::handleToken(String token, int index){
|
||||||
switch(index){
|
switch(index){
|
||||||
|
|
|
@ -14,11 +14,13 @@ class GwConfigHandler: public GwConfigDefinitions{
|
||||||
GwLog *logger;
|
GwLog *logger;
|
||||||
typedef std::map<String,String> StringMap;
|
typedef std::map<String,String> StringMap;
|
||||||
StringMap changedValues;
|
StringMap changedValues;
|
||||||
|
boolean allowChanges=true;
|
||||||
public:
|
public:
|
||||||
public:
|
public:
|
||||||
GwConfigHandler(GwLog *logger);
|
GwConfigHandler(GwLog *logger);
|
||||||
bool loadConfig();
|
bool loadConfig();
|
||||||
bool saveConfig();
|
bool saveConfig();
|
||||||
|
void stopChanges();
|
||||||
bool updateValue(String name, String value);
|
bool updateValue(String name, String value);
|
||||||
bool reset(bool save);
|
bool reset(bool save);
|
||||||
String toString() const;
|
String toString() const;
|
||||||
|
@ -27,6 +29,12 @@ class GwConfigHandler: public GwConfigDefinitions{
|
||||||
bool getBool(const String name,bool defaultv=false) const ;
|
bool getBool(const String name,bool defaultv=false) const ;
|
||||||
int getInt(const String name,int defaultv=0) const;
|
int getInt(const String name,int defaultv=0) const;
|
||||||
GwConfigInterface * getConfigItem(const String name, bool dummy=false) const;
|
GwConfigInterface * getConfigItem(const String name, bool dummy=false) const;
|
||||||
|
/**
|
||||||
|
* change the value of a config item
|
||||||
|
* will become a noop after stopChanges has been called
|
||||||
|
* !use with care! no checks of the value
|
||||||
|
*/
|
||||||
|
bool setValue(String name, String value);
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -10,6 +10,13 @@
|
||||||
*/
|
*/
|
||||||
void exampleInit(GwApi *api){
|
void exampleInit(GwApi *api){
|
||||||
api->getLogger()->logDebug(GwLog::LOG,"example init running");
|
api->getLogger()->logDebug(GwLog::LOG,"example init running");
|
||||||
|
//this example is a more or less useless example how you could set some
|
||||||
|
//config value to a fixed value
|
||||||
|
//you can only set config values within the init function
|
||||||
|
//you could also compute this value from some own configuration
|
||||||
|
//for this example it would make a lot of sense to declare a capability
|
||||||
|
//to hide this config item from the UI - see header file
|
||||||
|
api->getConfig()->setValue(api->getConfig()->minXdrInterval,"50");
|
||||||
}
|
}
|
||||||
#define INVALID_COORD -99999
|
#define INVALID_COORD -99999
|
||||||
class GetBoatDataRequest: public GwMessage{
|
class GetBoatDataRequest: public GwMessage{
|
||||||
|
@ -84,6 +91,7 @@ void exampleTask(GwApi *api){
|
||||||
bool hasPosition=false;
|
bool hasPosition=false;
|
||||||
bool hasPosition2=false;
|
bool hasPosition2=false;
|
||||||
LOG_DEBUG(GwLog::DEBUG,"example switch ist %s",exampleSwitch?"true":"false");
|
LOG_DEBUG(GwLog::DEBUG,"example switch ist %s",exampleSwitch?"true":"false");
|
||||||
|
LOG_DEBUG(GwLog::DEBUG,"minXdrInterval=%d",api->getConfig()->getInt(api->getConfig()->minXdrInterval));
|
||||||
GwApi::BoatValue *longitude=new GwApi::BoatValue(F("Longitude"));
|
GwApi::BoatValue *longitude=new GwApi::BoatValue(F("Longitude"));
|
||||||
GwApi::BoatValue *latitude=new GwApi::BoatValue(F("Latitude"));
|
GwApi::BoatValue *latitude=new GwApi::BoatValue(F("Latitude"));
|
||||||
GwApi::BoatValue *testValue=new GwApi::BoatValue(boatItemName);
|
GwApi::BoatValue *testValue=new GwApi::BoatValue(boatItemName);
|
||||||
|
|
|
@ -43,4 +43,7 @@ DECLARE_INITFUNCTION(exampleInit);
|
||||||
//elements when this capability is set correctly
|
//elements when this capability is set correctly
|
||||||
DECLARE_CAPABILITY(testboard,true);
|
DECLARE_CAPABILITY(testboard,true);
|
||||||
DECLARE_CAPABILITY(testboard2,true);
|
DECLARE_CAPABILITY(testboard2,true);
|
||||||
|
//hide some config value
|
||||||
|
//just set HIDE + the name of the config item to true
|
||||||
|
DECLARE_CAPABILITY(HIDEminXdrInterval,true);
|
||||||
#endif
|
#endif
|
|
@ -599,6 +599,10 @@ void setup() {
|
||||||
logger.prefix="FALLBACK:";
|
logger.prefix="FALLBACK:";
|
||||||
#endif
|
#endif
|
||||||
userCodeHandler.startInitTasks(MIN_USER_TASK);
|
userCodeHandler.startInitTasks(MIN_USER_TASK);
|
||||||
|
config.stopChanges();
|
||||||
|
//maybe the user code changed the level
|
||||||
|
level=config.getInt(config.logLevel,LOGLEVEL);
|
||||||
|
logger.setLevel(level);
|
||||||
gwWifi.setup();
|
gwWifi.setup();
|
||||||
MDNS.begin(config.getConfigItem(config.systemName)->asCString());
|
MDNS.begin(config.getConfigItem(config.systemName)->asCString());
|
||||||
channels.begin(fallbackSerial);
|
channels.begin(fallbackSerial);
|
||||||
|
@ -682,7 +686,7 @@ void setup() {
|
||||||
NMEA2000.SetProductInformation("1", // Manufacturer's Model serial code
|
NMEA2000.SetProductInformation("1", // Manufacturer's Model serial code
|
||||||
100, // Manufacturer's product code
|
100, // Manufacturer's product code
|
||||||
systemName->asCString(), // Manufacturer's Model ID
|
systemName->asCString(), // Manufacturer's Model ID
|
||||||
VERSION, // Manufacturer's Software version code
|
FIRMWARE_TYPE, // Manufacturer's Software version code
|
||||||
VERSION, // Manufacturer's Model version,
|
VERSION, // Manufacturer's Model version,
|
||||||
N2K_LOAD_LEVEL,
|
N2K_LOAD_LEVEL,
|
||||||
0xffff, //Version
|
0xffff, //Version
|
||||||
|
|
24
web/index.js
24
web/index.js
|
@ -953,17 +953,23 @@ function createConfigDefinitions(parent, capabilities, defs,includeXdr) {
|
||||||
category = item.category;
|
category = item.category;
|
||||||
}
|
}
|
||||||
let showItem=true;
|
let showItem=true;
|
||||||
if (item.capabilities !== undefined) {
|
let itemCapabilities=item.capabilities||{};
|
||||||
for (let capability in item.capabilities) {
|
itemCapabilities['HIDE'+item.name]=null;
|
||||||
let values = item.capabilities[capability];
|
for (let capability in itemCapabilities) {
|
||||||
let found = false;
|
let values = itemCapabilities[capability];
|
||||||
if (! (values instanceof Array)) values=[values];
|
let found = false;
|
||||||
values.forEach(function (v) {
|
if (! (values instanceof Array)) values=[values];
|
||||||
|
values.forEach(function (v) {
|
||||||
|
if ( v === null){
|
||||||
|
if (capabilities[capability] === undefined) found=true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
if (capabilities[capability] == v) found = true;
|
if (capabilities[capability] == v) found = true;
|
||||||
});
|
}
|
||||||
if (!found) showItem=false;
|
});
|
||||||
}
|
if (!found) showItem=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showItem) {
|
if (showItem) {
|
||||||
currentCategoryPopulated=true;
|
currentCategoryPopulated=true;
|
||||||
let row = addEl('div', 'row', categoryEl);
|
let row = addEl('div', 'row', categoryEl);
|
||||||
|
|
Loading…
Reference in New Issue