1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-14 06:23:07 +01:00

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

@@ -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++;
}