From 80017af0b4af89613ac3cdf09f897da331a77b45 Mon Sep 17 00:00:00 2001 From: andreas Date: Fri, 27 Oct 2023 12:26:10 +0200 Subject: [PATCH] intermediate: move to ldf none mode --- extra_script.py | 54 ++++++++++++++++- lib/api/GwApi.h | 4 +- lib/{update => gwupdate}/GwUpdate.cpp | 0 lib/{update => gwupdate}/GwUpdate.h | 0 .../GwWebServer.cpp | 0 lib/{webserver => gwwebserver}/GwWebServer.h | 0 lib/{wifi => gwwifi}/GWWifi.h | 0 lib/{wifi => gwwifi}/GwWifi.cpp | 0 lib/hardware/GwHardware.h | 13 +++- lib/iictask/GwIicTask.cpp | 59 +++++++++++++++---- lib/iictask/GwIicTask.h | 9 ++- lib/iictask/SHT3X.h | 2 +- lib/iictask/config.json | 14 ++--- lib/usercode/GwUserCode.cpp | 11 +++- platformio.ini | 9 ++- src/main.cpp | 2 + webinstall/build.yaml | 13 +++- 17 files changed, 157 insertions(+), 33 deletions(-) rename lib/{update => gwupdate}/GwUpdate.cpp (100%) rename lib/{update => gwupdate}/GwUpdate.h (100%) rename lib/{webserver => gwwebserver}/GwWebServer.cpp (100%) rename lib/{webserver => gwwebserver}/GwWebServer.h (100%) rename lib/{wifi => gwwifi}/GWWifi.h (100%) rename lib/{wifi => gwwifi}/GwWifi.cpp (100%) diff --git a/extra_script.py b/extra_script.py index 969935f..1ec3bd1 100644 --- a/extra_script.py +++ b/extra_script.py @@ -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) diff --git a/lib/api/GwApi.h b/lib/api/GwApi.h index 6d42011..6b99390 100644 --- a/lib/api/GwApi.h +++ b/lib/api/GwApi.h @@ -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 diff --git a/lib/update/GwUpdate.cpp b/lib/gwupdate/GwUpdate.cpp similarity index 100% rename from lib/update/GwUpdate.cpp rename to lib/gwupdate/GwUpdate.cpp diff --git a/lib/update/GwUpdate.h b/lib/gwupdate/GwUpdate.h similarity index 100% rename from lib/update/GwUpdate.h rename to lib/gwupdate/GwUpdate.h diff --git a/lib/webserver/GwWebServer.cpp b/lib/gwwebserver/GwWebServer.cpp similarity index 100% rename from lib/webserver/GwWebServer.cpp rename to lib/gwwebserver/GwWebServer.cpp diff --git a/lib/webserver/GwWebServer.h b/lib/gwwebserver/GwWebServer.h similarity index 100% rename from lib/webserver/GwWebServer.h rename to lib/gwwebserver/GwWebServer.h diff --git a/lib/wifi/GWWifi.h b/lib/gwwifi/GWWifi.h similarity index 100% rename from lib/wifi/GWWifi.h rename to lib/gwwifi/GWWifi.h diff --git a/lib/wifi/GwWifi.cpp b/lib/gwwifi/GwWifi.cpp similarity index 100% rename from lib/wifi/GwWifi.cpp rename to lib/gwwifi/GwWifi.cpp diff --git a/lib/hardware/GwHardware.h b/lib/hardware/GwHardware.h index 9ef1b92..eedad5b 100644 --- a/lib/hardware/GwHardware.h +++ b/lib/hardware/GwHardware.h @@ -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 diff --git a/lib/iictask/GwIicTask.cpp b/lib/iictask/GwIicTask.cpp index 9801e1e..1639973 100644 --- a/lib/iictask/GwIicTask.cpp +++ b/lib/iictask/GwIicTask.cpp @@ -1,12 +1,19 @@ -//#ifdef _GWIIC #include "GwIicTask.h" #include "GwHardware.h" #include #include #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 diff --git a/lib/iictask/GwIicTask.h b/lib/iictask/GwIicTask.h index e2af38f..728f7ab 100644 --- a/lib/iictask/GwIicTask.h +++ b/lib/iictask/GwIicTask.h @@ -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 \ No newline at end of file diff --git a/lib/iictask/SHT3X.h b/lib/iictask/SHT3X.h index bee5812..48a33f1 100644 --- a/lib/iictask/SHT3X.h +++ b/lib/iictask/SHT3X.h @@ -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" diff --git a/lib/iictask/config.json b/lib/iictask/config.json index b1d3037..bf29dc5 100644 --- a/lib/iictask/config.json +++ b/lib/iictask/config.json @@ -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 ", diff --git a/lib/usercode/GwUserCode.cpp b/lib/usercode/GwUserCode.cpp index a30ca2b..7eb13c7 100644 --- a/lib/usercode/GwUserCode.cpp +++ b/lib/usercode/GwUserCode.cpp @@ -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++; } diff --git a/platformio.ini b/platformio.ini index 3dabab3..99632cd 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 diff --git a/src/main.cpp b/src/main.cpp index 3eb8136..0d99b0c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ //#define FALLBACK_SERIAL const unsigned long HEAP_REPORT_TIME=2000; //set to 0 to disable heap reporting #include +#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(){ diff --git a/webinstall/build.yaml b/webinstall/build.yaml index 7ec1712..c970bd8 100644 --- a/webinstall/build.yaml +++ b/webinstall/build.yaml @@ -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