mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-13 05:53:06 +01:00
CFG_INIT for initial cfg values
This commit is contained in:
@@ -4,6 +4,19 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <string.h>
|
||||
#include <MD5Builder.h>
|
||||
using CfgInit=std::function<void(GwConfigHandler *)>;
|
||||
static std::vector<CfgInit> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <HardwareSerial.h>
|
||||
#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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user