intermediate: move to ldf none mode

This commit is contained in:
andreas 2023-10-27 12:26:10 +02:00
parent 62124cb22d
commit 80017af0b4
17 changed files with 157 additions and 33 deletions

View File

@ -8,6 +8,10 @@ import json
import glob
from datetime import datetime
import re
import pprint
from platformio.project.config import ProjectConfig
Import("env")
#print(env.Dump())
OWN_FILE="extra_script.py"
@ -247,7 +251,7 @@ userTaskDirs=[]
def getUserTaskDirs():
rt=[]
taskdirs=glob.glob(os.path.join('lib','*task*'))
taskdirs=glob.glob(os.path.join( basePath(),'lib','*task*'))
for task in taskdirs:
rt.append(task)
return rt
@ -298,11 +302,59 @@ def getContentType(fn):
return "text/css"
return "application/octet-stream"
def addLibs(env,libs):
print("####Options:")
po=env.GetProjectOptions()
print("type po %s"%str(type(po)))
for k,v in po:
if k == 'lib_deps':
v+=libs
pprint.pprint(po)
def getLibs():
base=os.path.join(basePath(),"lib")
rt=[]
for sd in os.listdir(base):
if sd == '..':
continue
if sd == '.':
continue
fn=os.path.join(base,sd)
if os.path.isdir(fn):
rt.append(sd)
return rt
def prebuild(env):
global userTaskDirs
print("#prebuild running")
if not checkDir():
sys.exit(1)
allLibs=getLibs()
def GetProjectConfigX(env):
rt=ProjectConfig.get_instance(env["PROJECT_CONFIG"])
cenv="env:"+env['PIOENV']
libs=[]
for section,options in rt.as_tuple():
if section == cenv:
for key,values in options:
if key == 'lib_deps':
libs=values
mustUpdate=False
for lib in allLibs:
if not lib in libs:
libs.append(lib)
mustUpdate=True
if mustUpdate:
update=[(cenv,[('lib_deps',libs)])]
print("##update libdeps")
#pprint.pprint(update)
rt.update(update)
return rt
env.AddMethod(GetProjectConfigX,"GetProjectConfig")
addLibs(env,['appinfo'])
userTaskDirs=getUserTaskDirs()
mergedConfig=os.path.join(outPath(),os.path.basename(CFG_FILE))
generateMergedConfig(os.path.join(basePath(),CFG_FILE),mergedConfig,userTaskDirs)

View File

@ -155,7 +155,9 @@ class GwApi{
/**
* only allowed during init methods
*/
virtual bool addXdrMapping(const GwXDRMappingDef &);
virtual bool addXdrMapping(const GwXDRMappingDef &)=0;
virtual void addCapability(const String &name, const String &value)=0;
/**
* not thread safe methods

View File

@ -236,6 +236,15 @@
#define ESP32_CAN_RX_PIN GROOVE_PIN_1
#endif
#ifdef M5_ENV3
#ifndef M5_GROOVEIIC
#define M5_GROOVEIIC
#endif
#ifndef GWSHT3X
#define GWSHT3X -1
#endif
#endif
#ifdef M5_GROOVEIIC
#ifdef _GWM5_GROOVE
#error "can only have one M5 groove"
@ -253,12 +262,12 @@
#ifdef GWIIC_SDA
#ifndef GWIIC_SCL
#error "you must both define GWIIC_SDA and GWIIC_SCL
#error "you must both define GWIIC_SDA and GWIIC_SCL"
#endif
#endif
#ifdef GWIIC_SCL
#ifndef GWIIC_SDA
#error "you must both define GWIIC_SDA and GWIIC_SCL
#error "you must both define GWIIC_SDA and GWIIC_SCL"
#endif
#define _GWIIC
#endif

View File

@ -1,12 +1,19 @@
//#ifdef _GWIIC
#include "GwIicTask.h"
#include "GwHardware.h"
#include <Wire.h>
#include <SHT3X.h>
#include "GwTimer.h"
#include "N2kMessages.h"
#define GWSHT3X -1
#include "GwHardware.h"
#include "GwXdrTypeMappings.h"
//#define GWSHT3X -1
#ifndef GWIIC_SDA
#define GWIIC_SDA -1
#endif
#ifndef GWIIC_SCL
#define GWIIC_SCL -1
#endif
class SHT3XConfig{
public:
String tempTransducer;
@ -29,19 +36,49 @@ class SHT3XConfig{
tempSource=N2kts_InsideTemperature;
}
};
void runIicTask(GwApi *api){
void initIicTask(GwApi *api){
GwLog *logger=api->getLogger();
#ifndef _GWIIC
return;
#endif
#ifdef GWSHT3X
api->addCapability("SHT3X","true");
LOG_DEBUG(GwLog::LOG,"GWSHT3X configured, adding capability and xdr mappings");
SHT3XConfig sht3xConfig(api->getConfig());
if (sht3xConfig.humidActive && ! sht3xConfig.humidTransducer.isEmpty()){
//add XDR mapping for humidity
GwXDRMappingDef xdr;
xdr.category=GwXDRCategory::XDRHUMIDITY;
xdr.direction=GwXDRMappingDef::M_FROM2K;
xdr.field=GWXDRFIELD_HUMIDITY_ACTUALHUMIDITY;
xdr.selector=(int)sht3xConfig.humiditySource;
xdr.instanceMode=GwXDRMappingDef::IS_SINGLE;
xdr.instanceId=sht3xConfig.iid;
xdr.xdrName=sht3xConfig.humidTransducer;
api->addXdrMapping(xdr);
}
if (sht3xConfig.tempActive && ! sht3xConfig.tempTransducer.isEmpty()){
//add XDR mapping for humidity
GwXDRMappingDef xdr;
xdr.category=GwXDRCategory::XDRTEMP;
xdr.direction=GwXDRMappingDef::M_FROM2K;
xdr.field=GWXDRFIELD_TEMPERATURE_ACTUALTEMPERATURE;
xdr.selector=(int)sht3xConfig.tempSource;
xdr.instanceMode=GwXDRMappingDef::IS_SINGLE;
xdr.instanceId=sht3xConfig.iid;
xdr.xdrName=sht3xConfig.tempTransducer;
api->addXdrMapping(xdr);
}
#endif
}
void runIicTask(GwApi *api){
GwLog *logger=api->getLogger();
#ifndef _GWIIC
LOG_DEBUG(GwLog::LOG,"no iic defined, iic task stopped");
vTaskDelete(NULL);
return;
#endif
#ifndef GWIIC_SDA
#define GWIIC_SDA -1
#endif
#ifndef GWIIC_SCL
#define GWIIC_SCL -1
#endif
LOG_DEBUG(GwLog::LOG,"iic task started");
bool rt=Wire.begin(GWIIC_SDA,GWIIC_SCL);
if (! rt){
@ -60,7 +97,7 @@ void runIicTask(GwApi *api){
if (sht3xConfig.humidActive || sht3xConfig.tempActive){
sht3x=new SHT3X();
sht3x->init(addr,&Wire);
LOG_DEBUG(GwLog::LOG,"initialized SHT3X at address %d",(int)addr);
LOG_DEBUG(GwLog::LOG,"initialized SHT3X at address %d, interval %ld",(int)addr,sht3xConfig.interval);
runLoop=true;
timers.addAction(sht3xConfig.interval,[logger,api,sht3x,sht3xConfig](){
int rt=0;
@ -94,5 +131,5 @@ void runIicTask(GwApi *api){
delay(100);
timers.loop();
}
vTaskDelete(NULL);
}
//#endif

View File

@ -1,5 +1,8 @@
#ifndef _GWIICTASK
#define _GWIICTASK
#ifndef _GWIICTASK_H
#define _GWIICTASK_H
#include "GwApi.h"
DECLARE_USERTASK(runIicTask)
void runIicTask(GwApi *api);
void initIicTask(GwApi *api);
DECLARE_USERTASK_PARAM(runIicTask,3000);
DECLARE_INITFUNCTION(initIicTask);
#endif

View File

@ -1,6 +1,6 @@
#ifndef __SHT3X_H
#define __HT3X_H
//taken from https://github.com/m5stack/M5Unit-ENV/tree/0.0.8/src
#if ARDUINO >= 100
#include "Arduino.h"

View File

@ -1,9 +1,9 @@
[
{
"name": "iicSHT3XTemp",
"label": "SHT3X Temperature",
"type": "boolen",
"default": true,
"label": "SHT3X Temp",
"type": "boolean",
"default": "true",
"description": "Enable the I2C SHT3x temp sensor",
"category": "sensors",
"capabilities": {
@ -14,7 +14,7 @@
"name": "iicSHT3XHumid",
"label": "SHT3X Humidity",
"type": "boolean",
"default": true,
"default": "true",
"description": "Enable the I2C SHT3x humidity sensor",
"category": "sensors",
"capabilities": {
@ -23,7 +23,7 @@
},
{
"name": "SHT3XTempName",
"label": "SHT3X Temperature XDR",
"label": "SHT3X Temp XDR",
"type": "String",
"default": "Temp",
"description": "set the XDR transducer name for the SHT3X Temperature, leave empty to disable ",
@ -34,7 +34,7 @@
},
{
"name": "SHT3XHumidName",
"label": "SHT3X Humidity XDR",
"label": "SHT3X Humid XDR",
"type": "String",
"default": "Humidity",
"description": "set the XDR transducer name for the SHT3X Humidity, leave empty to disable ",
@ -45,7 +45,7 @@
},
{
"name": "SHT3Xiid",
"label": "SHT3X N2K instance id",
"label": "SHT3X N2K iid",
"type": "number",
"default": 99,
"description": "the N2K instance id the SHT3X Temperature and Humidity ",

View File

@ -166,12 +166,14 @@ class TaskApi : public GwApiInternal
bool counterUsed=false;
int counterIdx=0;
TaskInterfacesImpl *interfaces;
bool isInit=false;
public:
TaskApi(GwApiInternal *api,
int sourceId,
SemaphoreHandle_t *mainLock,
const String &name,
TaskInterfacesStorage *s)
TaskInterfacesStorage *s,
bool init=false)
{
this->sourceId = sourceId;
this->api = api;
@ -179,6 +181,7 @@ public:
this->name=name;
localLock=xSemaphoreCreateMutex();
interfaces=new TaskInterfacesImpl(name,s);
isInit=init;
}
virtual GwRequestQueue *getQueue()
{
@ -283,6 +286,10 @@ public:
virtual bool addXdrMapping(const GwXDRMappingDef &def){
return api->addXdrMapping(def);
}
virtual void addCapability(const String &name, const String &value){
if (! isInit) return;
userCapabilities[name]=value;
}
};
@ -322,7 +329,7 @@ void GwUserCode::startInitTasks(int baseId){
LOG_DEBUG(GwLog::DEBUG,"starting %d user init tasks",initTasks.size());
for (auto it=initTasks.begin();it != initTasks.end();it++){
LOG_DEBUG(GwLog::LOG,"starting user init task %s with id %d",it->name.c_str(),baseId);
it->api=new TaskApi(api,baseId,mainLock,it->name,taskData);
it->api=new TaskApi(api,baseId,mainLock,it->name,taskData,true);
userTaskStart(&(*it));
baseId++;
}

View File

@ -27,8 +27,11 @@ lib_deps =
ttlappalainen/NMEA0183 @ 1.9.1
ArduinoJson @ 6.18.5
ottowinter/ESPAsyncWebServer-esphome@2.0.1
#fastled/FastLED @ 3.4.0
fastled/FastLED @ 3.6.0
fastled/FastLED @ 3.6.0
FS
Preferences
ESPmDNS
WiFi
board_build.embed_files =
lib/generated/index.html.gz
lib/generated/index.js.gz
@ -40,7 +43,7 @@ board_build.partitions = partitions_custom.csv
extra_scripts =
pre:extra_script.py
post:post.py
lib_ldf_mode = chain+
lib_ldf_mode = off
monitor_speed = 115200
build_flags =
-D PIO_ENV_BUILD=$PIOENV

View File

@ -16,6 +16,7 @@
//#define FALLBACK_SERIAL
const unsigned long HEAP_REPORT_TIME=2000; //set to 0 to disable heap reporting
#include <Arduino.h>
#include "FS.h"
#include "GwApi.h"
#include "GwHardware.h"
@ -326,6 +327,7 @@ public:
}
return xdrMappings.addFixedMapping(mapping);
}
virtual void addCapability(const String &name, const String &value){}
};
bool delayedRestart(){

View File

@ -64,10 +64,19 @@ types:
resource: serial
- &m5groovei2c
type: multi
type: frame
key: m5groovei2c
label: "M5 I2C Groove Units"
values:
children:
- label: "M5 ENV3"
type: checkbox
key: m5env3
target: define
url: "https://docs.m5stack.com/en/unit/envIII"
description: "M5 sensor module temperature, humidity, pressure"
values:
- value: M5_ENV3
key: true
- &m5groovecan
type: select
key: m5groovecan