allow to set default and hide for cfg values in hardware defs
This commit is contained in:
parent
27de94b1ae
commit
9572b1e95e
|
@ -136,13 +136,27 @@ def generateCfg(inFile,outFile,addDirs=[]):
|
||||||
data+=' GwConfigInterface *configs[%d]={\n'%(l)
|
data+=' GwConfigInterface *configs[%d]={\n'%(l)
|
||||||
first=True
|
first=True
|
||||||
for item in config:
|
for item in config:
|
||||||
|
name=item.get('name')
|
||||||
|
if name is None:
|
||||||
|
continue
|
||||||
if not first:
|
if not first:
|
||||||
data+=',\n'
|
data+=',\n'
|
||||||
first=False
|
first=False
|
||||||
secret="false";
|
secret="false";
|
||||||
if item.get('type') == 'password':
|
if item.get('type') == 'password':
|
||||||
secret="true"
|
secret="true"
|
||||||
data+=" new GwConfigInterface(%s,\"%s\",%s)"%(item.get('name'),item.get('default'),secret)
|
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'
|
||||||
data+='};\n'
|
data+='};\n'
|
||||||
writeFileIfChanged(outFile,data)
|
writeFileIfChanged(outFile,data)
|
||||||
|
|
|
@ -159,6 +159,24 @@ void GwConfigHandler::toHex(unsigned long v, char *buffer, size_t bsize)
|
||||||
buffer[2 * i] = 0;
|
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){
|
void GwNmeaFilter::handleToken(String token, int index){
|
||||||
switch(index){
|
switch(index){
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
@ -4,8 +4,10 @@
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
#include "GwLog.h"
|
#include "GwLog.h"
|
||||||
#include "GwConfigItem.h"
|
#include "GwConfigItem.h"
|
||||||
|
#include "GwHardware.h"
|
||||||
#include "GwConfigDefinitions.h"
|
#include "GwConfigDefinitions.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
class GwConfigHandler: public GwConfigDefinitions{
|
class GwConfigHandler: public GwConfigDefinitions{
|
||||||
|
@ -28,6 +30,8 @@ class GwConfigHandler: public GwConfigDefinitions{
|
||||||
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;
|
||||||
bool checkPass(String hash);
|
bool checkPass(String hash);
|
||||||
|
std::vector<String> getHidden() const;
|
||||||
|
int numHidden() const;
|
||||||
/**
|
/**
|
||||||
* change the value of a config item
|
* change the value of a config item
|
||||||
* will become a noop after stopChanges has been called
|
* will become a noop after stopChanges has been called
|
||||||
|
|
|
@ -10,12 +10,14 @@ class GwConfigInterface{
|
||||||
const char * initialValue;
|
const char * initialValue;
|
||||||
String value;
|
String value;
|
||||||
bool secret=false;
|
bool secret=false;
|
||||||
|
bool hidden=false;
|
||||||
public:
|
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->name=name;
|
||||||
this->initialValue=initialValue;
|
this->initialValue=initialValue;
|
||||||
this->value=initialValue;
|
this->value=initialValue;
|
||||||
this->secret=secret;
|
this->secret=secret;
|
||||||
|
this->hidden=hidden;
|
||||||
}
|
}
|
||||||
virtual String asString() const{
|
virtual String asString() const{
|
||||||
return value;
|
return value;
|
||||||
|
@ -41,6 +43,9 @@ class GwConfigInterface{
|
||||||
String getDefault() const {
|
String getDefault() const {
|
||||||
return initialValue;
|
return initialValue;
|
||||||
}
|
}
|
||||||
|
bool isHidden() const {
|
||||||
|
return hidden;
|
||||||
|
}
|
||||||
friend class GwConfigHandler;
|
friend class GwConfigHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,14 @@
|
||||||
#define GWSERIAL_TYPE GWSERIAL_TYPE_UNI
|
#define GWSERIAL_TYPE GWSERIAL_TYPE_UNI
|
||||||
#endif
|
#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
|
//below we define the final device config based on the above
|
||||||
//boards and peripherals
|
//boards and peripherals
|
||||||
//this allows us to easily also set them from outside
|
//this allows us to easily also set them from outside
|
||||||
|
|
|
@ -430,11 +430,16 @@ class CapabilitiesRequest : public GwRequestMessage{
|
||||||
protected:
|
protected:
|
||||||
virtual void processRequest(){
|
virtual void processRequest(){
|
||||||
int numCapabilities=userCodeHandler.getCapabilities()->size();
|
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();
|
for (auto it=userCodeHandler.getCapabilities()->begin();
|
||||||
it != userCodeHandler.getCapabilities()->end();it++){
|
it != userCodeHandler.getCapabilities()->end();it++){
|
||||||
json[it->first]=it->second;
|
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["serialmode"]=channels.getMode(SERIAL1_CHANNEL_ID);
|
||||||
json["serial2mode"]=channels.getMode(SERIAL2_CHANNEL_ID);
|
json["serial2mode"]=channels.getMode(SERIAL2_CHANNEL_ID);
|
||||||
#ifdef GWBUTTON_PIN
|
#ifdef GWBUTTON_PIN
|
||||||
|
|
Loading…
Reference in New Issue