allow to set default and hide for cfg values in hardware defs

This commit is contained in:
andreas 2023-10-05 16:57:05 +02:00
parent 27de94b1ae
commit 9572b1e95e
6 changed files with 58 additions and 4 deletions

View File

@ -136,13 +136,27 @@ def generateCfg(inFile,outFile,addDirs=[]):
data+=' GwConfigInterface *configs[%d]={\n'%(l)
first=True
for item in config:
name=item.get('name')
if name is None:
continue
if not first:
data+=',\n'
first=False
secret="false";
if item.get('type') == 'password':
secret="true"
data+=" new GwConfigInterface(%s,\"%s\",%s)"%(item.get('name'),item.get('default'),secret)
secret="true"
data+=" #undef __CFGHIDDEN\n"
data+=" #ifdef CFGHIDE_%s\n"%(name)
data+=" #define __CFGHIDDEN true\n"
data+=" #else\n"
data+=" #define __CFGHIDDEN false\n"
data+=" #endif\n"
data+=" #ifdef CFGDEFAULT_%s\n"%(name)
data+=" new GwConfigInterface(%s,CFGDEFAULT_%s,%s,__CFGHIDDEN)\n"%(name,name,secret)
data+=" #else\n"
data+=" new GwConfigInterface(%s,\"%s\",%s,__CFGHIDDEN)\n"%(name,item.get('default'),secret)
data+=" #endif\n"
data+='};\n'
data+='};\n'
writeFileIfChanged(outFile,data)

View File

@ -159,6 +159,24 @@ void GwConfigHandler::toHex(unsigned long v, char *buffer, size_t bsize)
buffer[2 * i] = 0;
}
std::vector<String> GwConfigHandler::getHidden() const{
std::vector<String> rt;
rt.reserve(numHidden());
for (int i=0L;i<getNumConfig();i++){
if (configs[i]->isHidden()){
rt.push_back(configs[i]->getName());
};
}
return rt;
}
int GwConfigHandler::numHidden() const{
int rt=0;
for (int i=0L;i<getNumConfig();i++){
if (configs[i]->isHidden()) rt++;
}
return rt;
}
void GwNmeaFilter::handleToken(String token, int index){
switch(index){
case 0:

View File

@ -4,8 +4,10 @@
#include <Preferences.h>
#include "GwLog.h"
#include "GwConfigItem.h"
#include "GwHardware.h"
#include "GwConfigDefinitions.h"
#include <map>
#include <vector>
class GwConfigHandler: public GwConfigDefinitions{
@ -28,6 +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;
/**
* change the value of a config item
* will become a noop after stopChanges has been called

View File

@ -10,12 +10,14 @@ class GwConfigInterface{
const char * initialValue;
String value;
bool secret=false;
bool hidden=false;
public:
GwConfigInterface(const String &name, const char * initialValue, bool secret=false){
GwConfigInterface(const String &name, const char * initialValue, bool secret=false, bool hidden=false){
this->name=name;
this->initialValue=initialValue;
this->value=initialValue;
this->secret=secret;
this->hidden=hidden;
}
virtual String asString() const{
return value;
@ -41,6 +43,9 @@ class GwConfigInterface{
String getDefault() const {
return initialValue;
}
bool isHidden() const {
return hidden;
}
friend class GwConfigHandler;
};

View File

@ -144,6 +144,14 @@
#define GWSERIAL_TYPE GWSERIAL_TYPE_UNI
#endif
//M5 GPS (Atomic GPS Base)
#ifdef M5_GPS_KIT
#define GWSERIAL_RX BOARD_LEFT1
#define GWSERIAL_TYPE GWSERIAL_TYPE_RX
#define CFGGDEFAULT_serialBaud "9600"
#define CFGHIDE_serialBaud
#endif
//below we define the final device config based on the above
//boards and peripherals
//this allows us to easily also set them from outside

View File

@ -430,11 +430,16 @@ class CapabilitiesRequest : public GwRequestMessage{
protected:
virtual void processRequest(){
int numCapabilities=userCodeHandler.getCapabilities()->size();
GwJsonDocument json(JSON_OBJECT_SIZE(numCapabilities*3+8));
int numHidden=config.numHidden();
GwJsonDocument json(JSON_OBJECT_SIZE(numCapabilities*3+numHidden*2+8));
for (auto it=userCodeHandler.getCapabilities()->begin();
it != userCodeHandler.getCapabilities()->end();it++){
json[it->first]=it->second;
}
std::vector<String> hiddenCfg=config.getHidden();
for (auto it=hiddenCfg.begin();it != hiddenCfg.end();it++){
json["HIDE"+*it]=true;
}
json["serialmode"]=channels.getMode(SERIAL1_CHANNEL_ID);
json["serial2mode"]=channels.getMode(SERIAL2_CHANNEL_ID);
#ifdef GWBUTTON_PIN