forked from norbert-walter/esp32-nmea2000-obp60
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GwIicSensors.h
117 lines (106 loc) · 3.42 KB
/
GwIicSensors.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef _GWIICSENSSORS_H
#define _GWIICSENSSORS_H
#include "GwApi.h"
#include "N2kMessages.h"
#include "GwXdrTypeMappings.h"
#include "GwHardware.h"
#include "GwSensor.h"
#ifdef _GWIIC
#include <Wire.h>
#else
class TwoWire;
#endif
using BusType=TwoWire;
using IICSensorList=SensorList<BusType>;
using IICSensorBase=SensorBase<BusType>;
template <class CFG>
bool addPressureXdr(GwApi *api, CFG &cfg)
{
if (! cfg.prAct) return false;
if (cfg.prNam.isEmpty()){
api->getLogger()->logDebug(GwLog::LOG, "pressure active for %s, no xdr mapping", cfg.prefix.c_str());
return true;
}
api->getLogger()->logDebug(GwLog::LOG, "adding pressure xdr mapping for %s", cfg.prefix.c_str());
GwXDRMappingDef xdr;
xdr.category = GwXDRCategory::XDRPRESSURE;
xdr.direction = GwXDRMappingDef::M_FROM2K;
xdr.selector = (int)cfg.prSrc;
xdr.instanceId = cfg.iid;
xdr.instanceMode = GwXDRMappingDef::IS_SINGLE;
xdr.xdrName = cfg.prNam;
api->addXdrMapping(xdr);
return true;
}
template <class CFG>
bool addTempXdr(GwApi *api, CFG &cfg)
{
if (!cfg.tmAct) return false;
if (cfg.tmNam.isEmpty()){
api->getLogger()->logDebug(GwLog::LOG, "temperature active for %s, no xdr mapping", cfg.prefix.c_str());
return true;
}
api->getLogger()->logDebug(GwLog::LOG, "adding temperature xdr mapping for %s", cfg.prefix.c_str());
GwXDRMappingDef xdr;
xdr.category = GwXDRCategory::XDRTEMP;
xdr.direction = GwXDRMappingDef::M_FROM2K;
xdr.field = GWXDRFIELD_TEMPERATURE_ACTUALTEMPERATURE;
xdr.selector = (int)cfg.tmSrc;
xdr.instanceMode = GwXDRMappingDef::IS_SINGLE;
xdr.instanceId = cfg.iid;
xdr.xdrName = cfg.tmNam;
api->addXdrMapping(xdr);
return true;
}
template <class CFG>
bool addHumidXdr(GwApi *api, CFG &cfg)
{
if (! cfg.huAct) return false;
if (cfg.huNam.isEmpty()){
api->getLogger()->logDebug(GwLog::LOG, "humidity active for %s, no xdr mapping", cfg.prefix.c_str());
return true;
}
api->getLogger()->logDebug(GwLog::LOG, "adding humidity xdr mapping for %s", cfg.prefix.c_str());
GwXDRMappingDef xdr;
xdr.category = GwXDRCategory::XDRHUMIDITY;
xdr.direction = GwXDRMappingDef::M_FROM2K;
xdr.field = GWXDRFIELD_HUMIDITY_ACTUALHUMIDITY;
xdr.selector = (int)cfg.huSrc;
xdr.instanceMode = GwXDRMappingDef::IS_SINGLE;
xdr.instanceId = cfg.iid;
xdr.xdrName = cfg.huNam;
api->addXdrMapping(xdr);
return true;
}
template <class CFG>
void sendN2kHumidity(GwApi *api,CFG &cfg,double value, int counterId){
tN2kMsg msg;
SetN2kHumidity(msg,1,cfg.iid,cfg.huSrc,value);
api->sendN2kMessage(msg);
api->increment(counterId,cfg.prefix+String("hum"));
}
template <class CFG>
void sendN2kPressure(GwApi *api,CFG &cfg,double value, int counterId){
tN2kMsg msg;
SetN2kPressure(msg,1,cfg.iid,cfg.prSrc,value);
api->sendN2kMessage(msg);
api->increment(counterId,cfg.prefix+String("press"));
}
template <class CFG>
void sendN2kTemperature(GwApi *api,CFG &cfg,double value, int counterId){
tN2kMsg msg;
SetN2kTemperature(msg,1,cfg.iid,cfg.tmSrc,value);
api->sendN2kMessage(msg);
api->increment(counterId,cfg.prefix+String("temp"));
}
#ifndef _GWI_IIC1
#define CHECK_IIC1() checkDef(GWIIC_SCL,GWIIC_SDA)
#else
#define CHECK_IIC1()
#endif
#ifndef _GWI_IIC2
#define CHECK_IIC2() checkDef(GWIIC_SCL2,GWIIC_SDA2)
#else
#define CHECK_IIC2()
#endif
#endif