intermediate: prepare for multiple grove configs

This commit is contained in:
andreas 2024-03-18 20:20:38 +01:00
parent 8641f0efd9
commit 59a80fcc9a
7 changed files with 107 additions and 70 deletions

View File

@ -1,5 +1,19 @@
#include "GwChannelList.h"
#include "GwApi.h"
using SerInitFunction=std::function<void(GwChannelList *)>;
std::vector<SerInitFunction> initFunctions;
#define CFG_EXP(ser) GwChannelList::ser
#define CFG_SERIAL(ser,rx,tx,mode) \
__MSG("serial config " __STR(ser) " rx=" __STR(rx) ", tx=" __STR(tx) ",mode=" __STR(mode)); \
static GwInitializer<SerInitFunction> _ ## name ## _init( \
initFunctions,[](GwChannelList *cl){cl->addSerial(CFG_EXP(ser),rx,tx,mode);});
//check for duplicate groove usages
#define __GR_EXP(GROOVE) __groveuse_ ## GROOVE
#define GROVE_USE(USER) \
__MSG("grove " __STR(USER) " used by " #USER) \
static int __GR_EXP(USER) =1;
#include "GwHardware.h"
#include "GwSocketServer.h"
#include "GwSerial.h"
@ -101,8 +115,18 @@ static SerialParam *getSerialParam(int id){
}
return nullptr;
}
void GwChannelList:: addSerial(HardwareSerial *stream,int id,int type,int rx,int tx){
void GwChannelList::addSerial(const String &name, int rx, int tx, int type){
if (name == serial){
addSerial(&Serial1,SERIAL1_CHANNEL_ID,type,rx,tx);
return;
}
if (name == serial2){
addSerial(&Serial2,SERIAL2_CHANNEL_ID,type,rx,tx);
return;
}
LOG_DEBUG(GwLog::ERROR,"invalid serial config")
}
void GwChannelList::addSerial(HardwareSerial *stream,int id,int type,int rx,int tx){
const char *mode=nullptr;
switch (type)
{
@ -126,6 +150,12 @@ void GwChannelList:: addSerial(HardwareSerial *stream,int id,int type,int rx,int
addSerial(stream,id,mode,rx,tx);
}
void GwChannelList::addSerial(HardwareSerial *serialStream,int id,const String &mode,int rx,int tx){
for (auto &&it:theChannels){
if (it->isOwnSource(id)){
LOG_DEBUG(GwLog::ERROR,"trying to re-add serial id=%d, ignoring",id);
return;
}
}
SerialParam *param=getSerialParam(id);
if (param == nullptr){
logger->logDebug(GwLog::ERROR,"trying to set up an unknown serial channel: %d",id);
@ -223,6 +253,11 @@ void GwChannelList::begin(bool fallbackSerial){
LOG_DEBUG(GwLog::LOG,"%s",channel->toString().c_str());
theChannels.push_back(channel);
//new serial config handling
for (auto &&init:initFunctions){
init(this);
}
//handle separate defines
//serial 1
#ifndef GWSERIAL_TX
#define GWSERIAL_TX -1

View File

@ -33,6 +33,9 @@ class GwChannelList{
void addSerial(HardwareSerial *stream,int id,const String &mode,int rx,int tx);
void addSerial(HardwareSerial *stream,int id,int type,int rx,int tx);
public:
static constexpr const char* serial="serial";
static constexpr const char* serial2="serial2";
void addSerial(const String &name, int rx, int tx, int type);
GwChannelList(GwLog *logger, GwConfigHandler *config);
typedef std::function<void(GwChannel *)> ChannelAction;
void allChannels(ChannelAction action);

View File

@ -6,15 +6,9 @@
#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){ \
static GwInitializer<CfgInit> _ ## name ## _init(cfgInits,[](GwConfigHandler *cfg){ \
cfg->setValue(GwConfigDefinitions::name,value,GwConfigInterface::mode); \
});
#include "GwHardware.h"

View File

@ -2,7 +2,6 @@
#define _GWCONFIGITEM_H
#include "WString.h"
#include <vector>
class GwConfigHandler;
class GwConfigInterface{
public:
@ -79,4 +78,14 @@ class GwNmeaFilter{
#define __XSTR(x) __STR(x)
#define __STR(x) #x
#define __MSG(x) _Pragma (__STR(message (x)))
template<typename F>
class GwInitializer{
public:
using List=std::vector<F>;
GwInitializer(List &l,F f){
l.push_back(f);
}
};
#endif

View File

@ -25,9 +25,16 @@
#include "GwAppInfo.h"
#include "GwUserTasks.h"
#ifndef CFG_INIT
#define CFG_INIT(name,value,mode)
#define CFG_INIT(...)
#endif
#define CFG_INITP(prefix,suffix,value,mode) CFG_INIT(prefix ## suffix,value,mode)
#ifndef CFG_SERIAL
#define CFG_SERIAL(...)
#endif
#ifndef GROVE_USE
#define GROVE_USE(...)
#endif
#define _GW_GROOVE_SERIAL serial
//general definitions for M5AtomLite
//hint for groove pins:
//according to some schematics the numbering is 1,2,3(VCC),4(GND)
@ -71,7 +78,6 @@
#define BOARD_RIGHT1 GPIO_NUM_39
#define BOARD_RIGHT2 GPIO_NUM_38
#endif
//M5Stick C
#ifdef PLATFORM_BOARD_M5STICK_C
#define GROOVE_PIN_2 GPIO_NUM_32
@ -150,9 +156,9 @@
//M5 Serial (Atomic RS232 Base)
#ifdef M5_SERIAL_KIT_232
#define _GWM5_BOARD
#define GWSERIAL_TX BOARD_LEFT2
#define GWSERIAL_RX BOARD_LEFT1
#define GWSERIAL_TYPE GWSERIAL_TYPE_BI
CFG_SERIAL(serial,BOARD_LEFT1,BOARD_LEFT2,GWSERIAL_TYPE_BI)
#undef _GW_GROOVE_SERIAL
#define _GW_GROOVE_SERIAL serial2
#endif
//M5 Serial (Atomic RS485 Base)
@ -161,19 +167,19 @@
#error "can only define one M5 base"
#endif
#define _GWM5_BOARD
#define GWSERIAL_TX BOARD_LEFT2
#define GWSERIAL_RX BOARD_LEFT1
#define GWSERIAL_TYPE GWSERIAL_TYPE_UNI
CFG_SERIAL(serial,BOARD_LEFT1,BOARD_LEFT2,GWSERIAL_TYPE_UNI)
#undef _GW_GROOVE_SERIAL
#define _GW_GROOVE_SERIAL serial2
#endif
CFG_INIT(serialBaud,"9600",READONLY)
//M5 GPS (Atomic GPS Base)
#ifdef M5_GPS_KIT
#ifdef _GWM5_BOARD
#error "can only define one M5 base"
#endif
#define _GWM5_BOARD
#define GWSERIAL_RX BOARD_LEFT1
#define GWSERIAL_TYPE GWSERIAL_TYPE_RX
CFG_SERIAL(serial,BOARD_LEFT1,-1,GWSERIAL_TYPE_UNI)
#undef _GW_GROOVE_SERIAL
#define _GW_GROOVE_SERIAL serial2
CFG_INIT(serialBaud,"9600",READONLY)
#endif
@ -212,48 +218,19 @@ CFG_INIT(serialBaud,"9600",READONLY)
//we use serial2 for groove serial if serial1 is already defined
//before (e.g. by serial kit)
#ifdef SERIAL_GROOVE_485
#define _GWM5_GROOVE
#ifdef GWSERIAL_TYPE
#define GWSERIAL2_TX GROOVE_PIN_2
#define GWSERIAL2_RX GROOVE_PIN_1
#define GWSERIAL2_TYPE GWSERIAL_TYPE_UNI
#else
#define GWSERIAL_TX GROOVE_PIN_2
#define GWSERIAL_RX GROOVE_PIN_1
#define GWSERIAL_TYPE GWSERIAL_TYPE_UNI
#endif
GROVE_USE(SERIAL_GROOVE_485)
CFG_SERIAL(_GW_GROOVE_SERIAL,GROOVE_PIN_1,GROOVE_PIN_2,GWSERIAL_TYPE_UNI)
#endif
#ifdef SERIAL_GROOVE_232
#ifdef _GWM5_GROOVE
#error "can only have one groove device"
#endif
#define _GWM5_GROOVE
#ifdef GWSERIAL_TYPE
#define GWSERIAL2_TX GROOVE_PIN_2
#define GWSERIAL2_RX GROOVE_PIN_1
#define GWSERIAL2_TYPE GWSERIAL_TYPE_BI
#else
#define GWSERIAL_TX GROOVE_PIN_2
#define GWSERIAL_RX GROOVE_PIN_1
#define GWSERIAL_TYPE GWSERIAL_TYPE_BI
#endif
GROVE_USE(SERIAL_GROOVE_232)
CFG_SERIAL(_GW_GROOVE_SERIAL,GROOVE_PIN_1,GROOVE_PIN_2,GWSERIAL_TYPE_BI)
#endif
//http://docs.m5stack.com/en/unit/gps
#ifdef M5_GPS_UNIT
#ifdef _GWM5_GROOVE
#error "can only have one M5 groove"
#endif
#define _GWM5_GROOVE
#ifdef GWSERIAL_TYPE
#define GWSERIAL2_RX GROOVE_PIN_1
#define GWSERIAL2_TYPE GWSERIAL_TYPE_RX
CFG_INIT(serialBaud,"9600",READONLY)
#else
#define GWSERIAL_RX GROOVE_PIN_1
#define GWSERIAL_TYPE GWSERIAL_TYPE_RX
CFG_INIT(serial2Baud,"9600",READONLY)
#endif
GROVE_USE(M5_GPS_UNIT)
CFG_SERIAL(_GW_GROOVE_SERIAL,GROOVE_PIN_1,-1,GWSERIAL_TYPE_RX)
CFG_INITP(_GW_GROOVE_SERIAL,Baud,"9600",READONLY)
#endif
//can kit for M5 Atom
@ -267,17 +244,14 @@ CFG_INIT(serialBaud,"9600",READONLY)
#endif
//CAN via groove
#ifdef M5_CANUNIT
#ifdef _GWM5_GROOVE
#error "can only have one M5 groove"
#endif
#define _GWM5_GROOVE
GROVE_USE(M5_CANUNIT)
#define ESP32_CAN_TX_PIN GROOVE_PIN_2
#define ESP32_CAN_RX_PIN GROOVE_PIN_1
#endif
#ifdef M5_ENV3
#ifndef M5_GROOVEIIC
#define M5_GROOVEIIC
#define M5_GROOVEIIC M5_ENV3
#endif
#ifndef GWSHT3X
#define GWSHT3X -1
@ -288,10 +262,7 @@ CFG_INIT(serialBaud,"9600",READONLY)
#endif
#ifdef M5_GROOVEIIC
#ifdef _GWM5_GROOVE
#error "can only have one M5 groove"
#endif
#define _GWM5_GROOVE
GROVE_USE(M5_GROOVEIIC)
#ifdef GWIIC_SCL
#error "you cannot define both GWIIC_SCL and M5_GROOVEIIC"
#endif

View File

@ -101,7 +101,7 @@ types:
children:
- *m5grooveserial
- &gpiopin
type: dropdown
type: "#gpiotype#"
resource: "gpio:"
help: 'Select the number of the GPIO pin for this function'
values: "#gpiopinv#"
@ -136,7 +136,7 @@ types:
- 38
- &gpioinput
type: dropdown
type: "#gpiotype#"
resource: "gpio:"
help: 'Select the number of the GPIO pin for this function'
values: "#gpiopinv#"
@ -183,6 +183,16 @@ types:
- PPIN25
- PPIN33
- &abcgpio
- {label:unset, value:}
- ABC_PAYELLOW
- ABC_PAYWHITE
- ABC_PBYELLOW
- ABC_PBYWHITE
- ABC_PBYELLOW
- ABC_PBYWHITE
- &serialRX
<<: *gpioinput
key: RX
@ -235,6 +245,7 @@ types:
type: checkbox
label: 'Serial 1'
key: serial1
resource: serial1
base:
serial: GWSERIAL_
values: *serialValues
@ -243,6 +254,7 @@ types:
type: checkbox
label: 'Serial 2'
key: serial2
resource: serial2
base:
serial: GWSERIAL2_
values: *serialValues
@ -360,6 +372,7 @@ types:
type: checkbox
label: "I2C #busname#"
key: "i2c#busname#"
resource: "i2c#busname#"
description: "I2C Bus #busname#"
values:
- key: true
@ -433,6 +446,7 @@ types:
type: checkbox
label: "SPI/SSI #busname#"
key: "spi#busname#"
resource: "spi#busname#"
description: "SPI(SSI) Bus #busname#"
values:
- key: true
@ -541,6 +555,11 @@ types:
gpiopinv: *protogpio
children:
*m5protochildren
- value: M5_PORTABC
description: "M5 Stack Port ABC extension base"
url: "https://docs.m5stack.com/en/unit/AtomPortABC"
label: "ABC Ext"
base:
resources:
default: &esp32default
@ -558,6 +577,7 @@ config:
base:
gpiopinv: *gpiopinv
gpioinputv: *gpioinputv
gpiotype: dropdown
values:
- value: m5stack-atom-generic
label: m5stack-atom

View File

@ -119,7 +119,7 @@ class PipelineInfo{
.then((st)=>{
if (queryPipeline !== currentPipeline.id) return;
let stid=st.pipeline_id||st.id;
if (currentPipeline.id !== stid) return;
if (stid !== undefined && currentPipeline.id !== stid) return;
if (st.status === undefined) st.status=st.state;
currentPipeline.update(st);
updateStatus();
@ -516,6 +516,11 @@ class PipelineInfo{
});
}
}
if (expandedValues.length > 0 && config.type === 'display'){
let cb=addEl('div','t'+config.type,inputFrame);
addDescription(config,inputFrame);
initialConfig=expandedValues[0];
}
let childFrame=addEl('div','childFrame',frame);
if (initialConfig !== undefined){
callback(initialConfig,true,childFrame);