Skip to content

Commit

Permalink
intermediate: allow for config array definitions, prepare multiple se…
Browse files Browse the repository at this point in the history
…nsors
  • Loading branch information
andreas committed Nov 3, 2023
1 parent f3c6824 commit 16b7652
Show file tree
Hide file tree
Showing 4 changed files with 523 additions and 400 deletions.
39 changes: 39 additions & 0 deletions extra_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,52 @@ def mergeConfig(base,other):
base=base+merge
return base

def replaceTexts(data,replacements):
if replacements is None:
return data
if isinstance(data,str):
for k,v in replacements.items():
data=data.replace("$"+k,str(v))
return data
if isinstance(data,list):
rt=[]
for e in data:
rt.append(replaceTexts(e,replacements))
return rt
if isinstance(data,dict):
rt={}
for k,v in data.items():
rt[replaceTexts(k,replacements)]=replaceTexts(v,replacements)
return rt
return data
def expandConfig(config):
rt=[]
for item in config:
type=item.get('type')
if type != 'array':
rt.append(item)
continue
replacements=item.get('replace')
children=item.get('children')
name=item.get('name')
if name is None:
name="#unknown#"
if not isinstance(replacements,list):
raise Exception("missing replacements at array %s"%name)
for replace in replacements:
if children is not None:
for c in children:
rt.append(replaceTexts(c,replace))
return rt

def generateMergedConfig(inFile,outFile,addDirs=[]):
if not os.path.exists(inFile):
raise Exception("unable to read cfg file %s"%inFile)
data=""
with open(inFile,'rb') as ch:
config=json.load(ch)
config=mergeConfig(config,addDirs)
config=expandConfig(config)
data=json.dumps(config,indent=2)
writeFileIfChanged(outFile,data)

Expand Down
20 changes: 12 additions & 8 deletions lib/iictask/GwIicTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
#ifdef _GWIIC
#include <Wire.h>
#endif
#ifdef GWSHT3X
#if defined(GWSHT3X) || defined(GWSHT3X1) || defined(GWSHT3X2) || defined(GWSHT3X2) || defined(GWSHT3X4)
#define _GWSHT3X
#else
#undef _GWSHT3X
#endif
#ifdef _GWSHT3X
#include "SHT3X.h"
#endif
#ifdef GWQMP6988
Expand All @@ -16,7 +21,6 @@
#ifdef GWBME280
#include <Adafruit_BME280.h>
#endif
//#define GWSHT3X -1

#ifndef GWIIC_SDA
#define GWIIC_SDA -1
Expand All @@ -29,14 +33,14 @@
cfg->getValue(name, GwConfigDefinitions::prefix ## name)

#define CSHT3X(name) \
CFG_GET(config,name,SHT3X)
CFG_GET(config,name,SHT3X1)
#define CQMP6988(name) \
CFG_GET(config,name,QMP6988)
CFG_GET(config,name,QMP69881)
#define CBME280(name) \
CFG_GET(config,name,BME280)
CFG_GET(config,name,BME2801)
class SHT3XConfig{
public:
const String prefix="SHT3X";
const String prefix="SHT3X1";
String tmNam;
String huNam;
int iid;
Expand All @@ -60,7 +64,7 @@ class SHT3XConfig{

class QMP6988Config{
public:
const String prefix="QMP6988";
const String prefix="QMP69881";
String prNam="Pressure";
int iid=99;
bool prAct=true;
Expand All @@ -79,7 +83,7 @@ class QMP6988Config{

class BME280Config{
public:
const String prefix="BME280";
const String prefix="BME2801";
bool prAct=true;
bool tmAct=true;
bool huAct=true;
Expand Down
Loading

0 comments on commit 16b7652

Please sign in to comment.