From 51065acc8d7a4b0858e82562c69e1544f61036a9 Mon Sep 17 00:00:00 2001 From: andreas Date: Fri, 27 Oct 2023 21:32:16 +0200 Subject: [PATCH] allow to hide config values by calling setValue --- lib/config/GWConfig.cpp | 3 ++- lib/config/GWConfig.h | 2 +- lib/exampletask/GwExampleTask.cpp | 19 +++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/config/GWConfig.cpp b/lib/config/GWConfig.cpp index 8215872..99285cd 100644 --- a/lib/config/GWConfig.cpp +++ b/lib/config/GWConfig.cpp @@ -120,11 +120,12 @@ int GwConfigHandler::getInt(const String name,int defaultv) const{ void GwConfigHandler::stopChanges(){ allowChanges=false; } -bool GwConfigHandler::setValue(String name,String value){ +bool GwConfigHandler::setValue(String name,String value, bool hide){ if (! allowChanges) return false; GwConfigInterface *i=getConfigItem(name,false); if (!i) return false; i->value=value; + i->type=hide?GwConfigInterface::HIDDEN:GwConfigInterface::READONLY; return true; } diff --git a/lib/config/GWConfig.h b/lib/config/GWConfig.h index 8fdb77f..56fbee6 100644 --- a/lib/config/GWConfig.h +++ b/lib/config/GWConfig.h @@ -36,7 +36,7 @@ class GwConfigHandler: public GwConfigDefinitions{ * will become a noop after stopChanges has been called * !use with care! no checks of the value */ - bool setValue(String name, String value); + bool setValue(String name, String value, bool hide=false); static void toHex(unsigned long v,char *buffer,size_t bsize); unsigned long getSaltBase(){return saltBase;} ~GwConfigHandler(); diff --git a/lib/exampletask/GwExampleTask.cpp b/lib/exampletask/GwExampleTask.cpp index 3dd698a..72cdf09 100644 --- a/lib/exampletask/GwExampleTask.cpp +++ b/lib/exampletask/GwExampleTask.cpp @@ -39,8 +39,15 @@ void exampleInit(GwApi *api){ api->addCapability("testboard", "true"); api->addCapability("testboard2", "true"); // hide some config value - // just set HIDE + the name of the config item to true - api->addCapability("HIDEminXdrInterval", "true"); + // and force it's default value + auto current=api->getConfig()->getConfigItem(GwConfigDefinitions::minXdrInterval,false); + String defaultXdrInt="50"; + if (current){ + defaultXdrInt=current->getDefault(); + } + //with the true parameter this config value will be hidden + //if you would like the user to be able to see this item, omit the "false", the config value will be read only + api->getConfig()->setValue(GwConfigDefinitions::minXdrInterval,defaultXdrInt,true); // example for a user defined help url that will be shown when clicking the help button api->addCapability("HELP_URL", "https://www.wellenvogel.de"); @@ -51,14 +58,6 @@ void exampleInit(GwApi *api){ if (!api->taskInterfaces()->claim(taskName)){ api->getLogger()->logDebug(GwLog::ERROR,"unable to claim ExampleNotWorkingIf"); } - - //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"); //check if we should simulate some voltage measurements //add an XDR mapping in this case String voltageTransducer=api->getConfig()->getString(GwConfigDefinitions::exTransducer);