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 import glob
from datetime import datetime from datetime import datetime
import re import re
import pprint
from platformio.project.config import ProjectConfig
Import("env") Import("env")
#print(env.Dump()) #print(env.Dump())
OWN_FILE="extra_script.py" OWN_FILE="extra_script.py"
@ -247,7 +251,7 @@ userTaskDirs=[]
def getUserTaskDirs(): def getUserTaskDirs():
rt=[] rt=[]
taskdirs=glob.glob(os.path.join('lib','*task*')) taskdirs=glob.glob(os.path.join( basePath(),'lib','*task*'))
for task in taskdirs: for task in taskdirs:
rt.append(task) rt.append(task)
return rt return rt
@ -298,11 +302,59 @@ def getContentType(fn):
return "text/css" return "text/css"
return "application/octet-stream" 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): def prebuild(env):
global userTaskDirs global userTaskDirs
print("#prebuild running") print("#prebuild running")
if not checkDir(): if not checkDir():
sys.exit(1) 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() userTaskDirs=getUserTaskDirs()
mergedConfig=os.path.join(outPath(),os.path.basename(CFG_FILE)) mergedConfig=os.path.join(outPath(),os.path.basename(CFG_FILE))
generateMergedConfig(os.path.join(basePath(),CFG_FILE),mergedConfig,userTaskDirs) generateMergedConfig(os.path.join(basePath(),CFG_FILE),mergedConfig,userTaskDirs)

View File

@ -155,7 +155,9 @@ class GwApi{
/** /**
* only allowed during init methods * 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 * not thread safe methods

View File

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

View File

@ -1,12 +1,19 @@
//#ifdef _GWIIC
#include "GwIicTask.h" #include "GwIicTask.h"
#include "GwHardware.h" #include "GwHardware.h"
#include <Wire.h> #include <Wire.h>
#include <SHT3X.h> #include <SHT3X.h>
#include "GwTimer.h" #include "GwTimer.h"
#include "N2kMessages.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{ class SHT3XConfig{
public: public:
String tempTransducer; String tempTransducer;
@ -29,19 +36,49 @@ class SHT3XConfig{
tempSource=N2kts_InsideTemperature; tempSource=N2kts_InsideTemperature;
} }
}; };
void runIicTask(GwApi *api){
void initIicTask(GwApi *api){
GwLog *logger=api->getLogger(); GwLog *logger=api->getLogger();
#ifndef _GWIIC #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"); LOG_DEBUG(GwLog::LOG,"no iic defined, iic task stopped");
vTaskDelete(NULL); vTaskDelete(NULL);
return; return;
#endif #endif
#ifndef GWIIC_SDA
#define GWIIC_SDA -1
#endif
#ifndef GWIIC_SCL
#define GWIIC_SCL -1
#endif
LOG_DEBUG(GwLog::LOG,"iic task started"); LOG_DEBUG(GwLog::LOG,"iic task started");
bool rt=Wire.begin(GWIIC_SDA,GWIIC_SCL); bool rt=Wire.begin(GWIIC_SDA,GWIIC_SCL);
if (! rt){ if (! rt){
@ -60,7 +97,7 @@ void runIicTask(GwApi *api){
if (sht3xConfig.humidActive || sht3xConfig.tempActive){ if (sht3xConfig.humidActive || sht3xConfig.tempActive){
sht3x=new SHT3X(); sht3x=new SHT3X();
sht3x->init(addr,&Wire); 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; runLoop=true;
timers.addAction(sht3xConfig.interval,[logger,api,sht3x,sht3xConfig](){ timers.addAction(sht3xConfig.interval,[logger,api,sht3x,sht3xConfig](){
int rt=0; int rt=0;
@ -94,5 +131,5 @@ void runIicTask(GwApi *api){
delay(100); delay(100);
timers.loop(); timers.loop();
} }
vTaskDelete(NULL);
} }
//#endif

View File

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

View File

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

View File

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

View File

@ -166,12 +166,14 @@ class TaskApi : public GwApiInternal
bool counterUsed=false; bool counterUsed=false;
int counterIdx=0; int counterIdx=0;
TaskInterfacesImpl *interfaces; TaskInterfacesImpl *interfaces;
bool isInit=false;
public: public:
TaskApi(GwApiInternal *api, TaskApi(GwApiInternal *api,
int sourceId, int sourceId,
SemaphoreHandle_t *mainLock, SemaphoreHandle_t *mainLock,
const String &name, const String &name,
TaskInterfacesStorage *s) TaskInterfacesStorage *s,
bool init=false)
{ {
this->sourceId = sourceId; this->sourceId = sourceId;
this->api = api; this->api = api;
@ -179,6 +181,7 @@ public:
this->name=name; this->name=name;
localLock=xSemaphoreCreateMutex(); localLock=xSemaphoreCreateMutex();
interfaces=new TaskInterfacesImpl(name,s); interfaces=new TaskInterfacesImpl(name,s);
isInit=init;
} }
virtual GwRequestQueue *getQueue() virtual GwRequestQueue *getQueue()
{ {
@ -283,6 +286,10 @@ public:
virtual bool addXdrMapping(const GwXDRMappingDef &def){ virtual bool addXdrMapping(const GwXDRMappingDef &def){
return api->addXdrMapping(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()); LOG_DEBUG(GwLog::DEBUG,"starting %d user init tasks",initTasks.size());
for (auto it=initTasks.begin();it != initTasks.end();it++){ 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); 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)); userTaskStart(&(*it));
baseId++; baseId++;
} }

View File

@ -27,8 +27,11 @@ lib_deps =
ttlappalainen/NMEA0183 @ 1.9.1 ttlappalainen/NMEA0183 @ 1.9.1
ArduinoJson @ 6.18.5 ArduinoJson @ 6.18.5
ottowinter/ESPAsyncWebServer-esphome@2.0.1 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 = board_build.embed_files =
lib/generated/index.html.gz lib/generated/index.html.gz
lib/generated/index.js.gz lib/generated/index.js.gz
@ -40,7 +43,7 @@ board_build.partitions = partitions_custom.csv
extra_scripts = extra_scripts =
pre:extra_script.py pre:extra_script.py
post:post.py post:post.py
lib_ldf_mode = chain+ lib_ldf_mode = off
monitor_speed = 115200 monitor_speed = 115200
build_flags = build_flags =
-D PIO_ENV_BUILD=$PIOENV -D PIO_ENV_BUILD=$PIOENV

View File

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

View File

@ -64,10 +64,19 @@ types:
resource: serial resource: serial
- &m5groovei2c - &m5groovei2c
type: multi type: frame
key: m5groovei2c key: m5groovei2c
label: "M5 I2C Groove Units" 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 - &m5groovecan
type: select type: select
key: m5groovecan key: m5groovecan