diff --git a/extra_script.py b/extra_script.py index ea5a8f7..51c484a 100644 --- a/extra_script.py +++ b/extra_script.py @@ -185,34 +185,13 @@ def generateCfg(inFile,outFile,impl): name=item.get('name') if name is None: continue - data+=' configs[%d]=\n'%(idx) + data+=' configs[%d]='%(idx) idx+=1 secret="false"; if item.get('type') == 'password': secret="true" - data+=" #undef __CFGMODE\n" - data+=" #ifdef CFGMODE_%s\n"%(name) - data+=" #define __CFGMODE CFGMODE_%s\n"%(name) - data+=" #else\n" - data+=" #define __CFGMODE GwConfigInterface::NORMAL\n" - data+=" #endif\n" - data+=" #ifdef CFGDEFAULT_%s\n"%(name) - data+=" new GwConfigInterface(%s,CFGDEFAULT_%s,%s,__CFGMODE)\n"%(name,name,secret) - data+=" #else\n" - data+=" new GwConfigInterface(%s,\"%s\",%s,__CFGMODE)\n"%(name,item.get('default'),secret) - data+=" #endif\n" - data+=";\n" + data+=" new GwConfigInterface(%s,\"%s\",%s);\n"%(name,item.get('default'),secret) data+='}\n' - for item in config: - name=item.get('name') - if name is None: - continue - data+="#ifdef CFGMODE_%s\n"%(name) - data+=" __MSG(\"CFGMODE_%s=\" __XSTR(CFGMODE_%s))\n"%(name,name) - data+="#endif\n" - data+="#ifdef CFGDEFAULT_%s\n"%(name) - data+=" __MSG(\"CFGDEFAULT_%s=\" CFGDEFAULT_%s)\n"%(name,name) - data+="#endif\n" writeFileIfChanged(outFile,data) def labelFilter(label): diff --git a/lib/config/GWConfig.cpp b/lib/config/GWConfig.cpp index 28528c4..fbe1862 100644 --- a/lib/config/GWConfig.cpp +++ b/lib/config/GWConfig.cpp @@ -4,6 +4,19 @@ #include #include #include +using CfgInit=std::function; +static std::vector cfgInits; +class CfgInitializer{ + public: + CfgInitializer(CfgInit f){ + cfgInits.push_back(f); + } +}; +#define CFG_INIT(name,value,mode) \ + __MSG("config set " #name " " #value " " #mode); \ + static CfgInitializer _ ## name ## _init([](GwConfigHandler *cfg){ \ + cfg->setValue(GwConfigDefinitions::name,value,GwConfigInterface::mode); \ + }); #include "GwHardware.h" #include "GwConfigDefImpl.h" @@ -61,6 +74,9 @@ GwConfigHandler::GwConfigHandler(GwLog *logger): GwConfigDefinitions(){ saltBase=esp_random(); configs=new GwConfigInterface*[getNumConfig()]; populateConfigs(configs); + for (auto &&init:cfgInits){ + init(this); + } prefs=new Preferences(); } GwConfigHandler::~GwConfigHandler(){ @@ -126,11 +142,16 @@ void GwConfigHandler::stopChanges(){ allowChanges=false; } bool GwConfigHandler::setValue(String name,String value, bool hide){ + return setValue(name,value,hide?GwConfigInterface::HIDDEN:GwConfigInterface::READONLY); +} +bool GwConfigHandler::setValue(String name, String value, GwConfigInterface::ConfigType type){ if (! allowChanges) return false; + LOG_DEBUG(GwLog::LOG,"setValue for %s to %s, mode %d", + name.c_str(),value.c_str(),(int)type); GwConfigInterface *i=getConfigItem(name,false); if (!i) return false; i->value=value; - i->type=hide?GwConfigInterface::HIDDEN:GwConfigInterface::READONLY; + i->type=type; return true; } diff --git a/lib/config/GWConfig.h b/lib/config/GWConfig.h index 6264506..eb2a095 100644 --- a/lib/config/GWConfig.h +++ b/lib/config/GWConfig.h @@ -38,6 +38,7 @@ class GwConfigHandler: public GwConfigDefinitions{ * !use with care! no checks of the value */ bool setValue(String name, String value, bool hide=false); + bool setValue(String name, String value, GwConfigInterface::ConfigType type); static void toHex(unsigned long v,char *buffer,size_t bsize); unsigned long getSaltBase(){return saltBase;} ~GwConfigHandler(); diff --git a/lib/hardware/GwHardware.h b/lib/hardware/GwHardware.h index 6680e3c..2227cd2 100644 --- a/lib/hardware/GwHardware.h +++ b/lib/hardware/GwHardware.h @@ -24,6 +24,9 @@ #include #include "GwAppInfo.h" #include "GwUserTasks.h" +#ifndef CFG_INIT + #define CFG_INIT(name,value,mode) +#endif //general definitions for M5AtomLite //hint for groove pins: @@ -162,7 +165,7 @@ #define GWSERIAL_RX BOARD_LEFT1 #define GWSERIAL_TYPE GWSERIAL_TYPE_UNI #endif - +CFG_INIT(serialBaud,"9600",READONLY) //M5 GPS (Atomic GPS Base) #ifdef M5_GPS_KIT #ifdef _GWM5_BOARD @@ -171,12 +174,15 @@ #define _GWM5_BOARD #define GWSERIAL_RX BOARD_LEFT1 #define GWSERIAL_TYPE GWSERIAL_TYPE_RX - #define CFGDEFAULT_serialBaud "9600" - #define CFGMODE_serialBaud GwConfigInterface::READONLY + CFG_INIT(serialBaud,"9600",READONLY) #endif //M5 ProtoHub #ifdef M5_PROTO_HUB + #ifdef _GWM5_BOARD + #error "can only define one M5 base" + #endif + #define _GWM5_BOARD #define PPIN22 BOARD_LEFT1 #define PPIN19 BOARD_LEFT2 #define PPIN23 BOARD_LEFT3 @@ -185,6 +191,20 @@ #define PPIN25 BOARD_RIGHT2 #endif +//M5 PortABC extension +#ifdef M5_PORTABC + #ifdef _GWM5_BOARD + #error "can only define one M5 base" + #endif + #define _GWM5_BOARD + #define ABC_PAYELLOW BOARD_RIGHT2 + #define ABC_PAWHITE BOARD_RIGHT1 + #define ABC_PBYELLOW BOARD_LEFT3 + #define ABC_PBWHITE BOARD_LEFT4 + #define ABC_PCYELLOW BOARD_LEFT1 + #define ABC_PCWHITE BOARD_LEFT2 +#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 @@ -228,13 +248,11 @@ #ifdef GWSERIAL_TYPE #define GWSERIAL2_RX GROOVE_PIN_1 #define GWSERIAL2_TYPE GWSERIAL_TYPE_RX - #define CFGDEFAULT_serialBaud "9600" - #define CFGMODE_serialBaud GwConfigInterface::READONLY + CFG_INIT(serialBaud,"9600",READONLY) #else #define GWSERIAL_RX GROOVE_PIN_1 #define GWSERIAL_TYPE GWSERIAL_TYPE_RX - #define CFGDEFAULT_serial2Baud "9600" - #define CFGMODE_serial2Baud GwConfigInterface::READONLY + CFG_INIT(serial2Baud,"9600",READONLY) #endif #endif @@ -332,12 +350,13 @@ #endif #ifdef GWLED_FASTLED - #define CFGMODE_ledBrightness GwConfigInterface::NORMAL #ifdef GWLED_BRIGHTNESS - #define CFGDEFAULT_ledBrightness GWSTRINGIFY(GWLED_BRIGHTNESS) + CFG_INIT(ledBrightness,GWSTRINGIFY(GWLED_BRIGHTNESS),NORMAL) + #else + CFG_INIT(ledBrightness,"64",NORMAL) #endif #else - #define CFGMODE_ledBrightness GwConfigInterface::HIDDEN + CFG_INIT(ledBrightness,"64",HIDDEN) #endif