working spi task, measure with dms22b
This commit is contained in:
parent
5356b783c3
commit
0c94293ccb
|
@ -70,6 +70,15 @@ class GwConfigHandler: public GwConfigDefinitions{
|
||||||
target=i->asInt();
|
target=i->asInt();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
bool getValue(float &target, const String &name, float defaultv=0){
|
||||||
|
GwConfigInterface *i=getConfigItem(name);
|
||||||
|
if (!i){
|
||||||
|
target=defaultv;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
target=i->asFloat();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
bool getValue(bool &target, const String name, bool defaultv=false){
|
bool getValue(bool &target, const String name, bool defaultv=false){
|
||||||
GwConfigInterface *i=getConfigItem(name);
|
GwConfigInterface *i=getConfigItem(name);
|
||||||
if (!i){
|
if (!i){
|
||||||
|
|
|
@ -37,6 +37,9 @@ class GwConfigInterface{
|
||||||
virtual int asInt() const{
|
virtual int asInt() const{
|
||||||
return (int)value.toInt();
|
return (int)value.toInt();
|
||||||
}
|
}
|
||||||
|
virtual float asFloat() const{
|
||||||
|
return value.toFloat();
|
||||||
|
}
|
||||||
String getName() const{
|
String getName() const{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,86 @@
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
#include "GWDMS22B.h"
|
#include "GWDMS22B.h"
|
||||||
#define PREFIX1 "DMS22B11"
|
#include "GwApi.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define CHECK_BUS(BUS) \
|
||||||
|
checkDef("missing config for " #BUS,GW ## BUS ## _CLK ,GW ## BUS ## _MISO);
|
||||||
|
|
||||||
|
#define ADD22B(PRFX,BUS) \
|
||||||
|
CHECK_BUS(BUS); \
|
||||||
|
GWDMS22B *dms=new GWDMS22B(api,#PRFX,GW ## BUS ## _HOST);\
|
||||||
|
sensors.add(api,dms);
|
||||||
|
|
||||||
|
#ifdef GWDMS22B11
|
||||||
|
#define ADD22B11 ADD22B(DMS22B11,SPI0)
|
||||||
|
#ifndef GWDMS22B11_CS
|
||||||
|
#define GWDMS22B11_CS -1
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define GWDMS22B11_CS -1
|
||||||
|
#define ADD22B11
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GWDMS22B12
|
||||||
|
#define ADD22B12 ADD22B(DMS22B12,SPI0)
|
||||||
|
#ifndef GWDMS22B12_CS
|
||||||
|
#define GWDMS22B12_CS -1
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define GWDMS22B12_CS -1
|
||||||
|
#define ADD22B12
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GWDMS22B13
|
||||||
|
#define ADD22B13 ADD22B(DMS22B13,SPI0)
|
||||||
|
#ifndef GWDMS22B13_CS
|
||||||
|
#define GWDMS22B13_CS -1
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define GWDMS22B13_CS -1
|
||||||
|
#define ADD22B13
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GWDMS22B21
|
||||||
|
#define ADD22B21 ADD22B(DMS22B21,SPI1)
|
||||||
|
#ifndef GWDMS22B21_CS
|
||||||
|
#define GWDMS22B21_CS -1
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define GWDMS22B21_CS -1
|
||||||
|
#define ADD22B21
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GWDMS22B22
|
||||||
|
#define ADD22B22 ADD22B(DMS22B22,SPI1)
|
||||||
|
#ifndef GWDMS22B22_CS
|
||||||
|
#define GWDMS22B22_CS -1
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define GWDMS22B22_CS -1
|
||||||
|
#define ADD22B22
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GWDMS22B23
|
||||||
|
#define ADD22B23 ADD22B(DMS22B23,SPI1)
|
||||||
|
#ifndef GWDMS22B23_CS
|
||||||
|
#define GWDMS22B23_CS -1
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define GWDMS22B23_CS -1
|
||||||
|
#define ADD22B23
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GWDMS22B : public SSISensor{
|
class GWDMS22B : public SSISensor{
|
||||||
uint32_t zero=2047;
|
uint32_t zero=2047;
|
||||||
public:
|
public:
|
||||||
using SSISensor::SSISensor;
|
using SSISensor::SSISensor;
|
||||||
virtual bool preinit(GwApi * api){
|
virtual bool preinit(GwApi * api){
|
||||||
GwLog *logger=api->getLogger();
|
GwLog *logger=api->getLogger();
|
||||||
LOG_DEBUG(GwLog::LOG,"DMS22B configured, prefix=%s",prefix.c_str());
|
LOG_DEBUG(GwLog::LOG,"DMS22B configured, prefix=%s, intv=%f",prefix.c_str());
|
||||||
api->addCapability(prefix,"true");
|
api->addCapability(prefix,"true");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -33,30 +105,36 @@ class GWDMS22B : public SSISensor{
|
||||||
}
|
}
|
||||||
LOG_DEBUG(GwLog::LOG,"measure %s : %d",prefix.c_str(),value);
|
LOG_DEBUG(GwLog::LOG,"measure %s : %d",prefix.c_str(),value);
|
||||||
}
|
}
|
||||||
#define DMS22B(prefix)\
|
#define DMS22B(PRFX,...) \
|
||||||
CFG_GET(act,prefix); \
|
if (prefix == #PRFX) {\
|
||||||
CFG_GET(iid,prefix); \
|
CFG_GET(act,PRFX); \
|
||||||
CFG_GET(intv,prefix); \
|
CFG_GET(iid,PRFX); \
|
||||||
CFG_GET(zero,prefix);
|
CFG_GET(fintv,PRFX); \
|
||||||
virtual void readConfig(GwConfigHandler *cfg){
|
CFG_GET(zero,PRFX); \
|
||||||
if (prefix == PREFIX1){
|
bits=12; \
|
||||||
DMS22B(DMS22B11);
|
clock=500000; \
|
||||||
busId=GWSPIHOST1;
|
cs=GW ## PRFX ## _CS; \
|
||||||
bits=12;
|
__VA_ARGS__ \
|
||||||
clock=500000;
|
|
||||||
#ifdef GWDMS22B11_CS
|
|
||||||
cs=GWDMS22B11_CS;
|
|
||||||
#else
|
|
||||||
cs=-1;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
//TODO: other
|
|
||||||
|
|
||||||
|
virtual void readConfig(GwConfigHandler *cfg){
|
||||||
|
DMS22B(DMS22B11);
|
||||||
|
DMS22B(DMS22B12);
|
||||||
|
DMS22B(DMS22B13);
|
||||||
|
DMS22B(DMS22B21);
|
||||||
|
DMS22B(DMS22B22);
|
||||||
|
DMS22B(DMS22B23);
|
||||||
|
intv=1000*fintv;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void registerDMS22B(GwApi *api,SpiSensorList &sensors){
|
void registerDMS22B(GwApi *api,SpiSensorList &sensors){
|
||||||
#ifdef GWDMS22B11
|
ADD22B11
|
||||||
GWDMS22B *dms=new GWDMS22B(api,PREFIX1);
|
ADD22B12
|
||||||
sensors.add(dms);
|
ADD22B13
|
||||||
#endif
|
ADD22B21
|
||||||
|
ADD22B22
|
||||||
|
ADD22B23
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,7 @@ class SSISensor : public SensorBase<BusType>{
|
||||||
int cs=-1;
|
int cs=-1;
|
||||||
int clock=0;
|
int clock=0;
|
||||||
bool act=false;
|
bool act=false;
|
||||||
|
float fintv=0;
|
||||||
virtual bool initSSI(GwLog*logger,const SPIBus *bus,
|
virtual bool initSSI(GwLog*logger,const SPIBus *bus,
|
||||||
int clock,int cs, int bits){
|
int clock,int cs, int bits){
|
||||||
mask= (1 << bits)-1;
|
mask= (1 << bits)-1;
|
||||||
|
@ -123,7 +124,10 @@ class SSISensor : public SensorBase<BusType>{
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using SensorBase<BusType>::SensorBase;
|
SSISensor(GwApi *api,const String &prfx, int host):SensorBase(api,prfx)
|
||||||
|
{
|
||||||
|
busId=host;
|
||||||
|
}
|
||||||
virtual bool isActive(){return act;};
|
virtual bool isActive(){return act;};
|
||||||
virtual bool initDevice(GwApi *api,BusType *bus){
|
virtual bool initDevice(GwApi *api,BusType *bus){
|
||||||
return initSSI(api->getLogger(),bus, clock,cs,bits);
|
return initSSI(api->getLogger(),bus, clock,cs,bits);
|
||||||
|
@ -131,6 +135,6 @@ class SSISensor : public SensorBase<BusType>{
|
||||||
|
|
||||||
};
|
};
|
||||||
using SpiSensorList=SensorList<BusType>;
|
using SpiSensorList=SensorList<BusType>;
|
||||||
#define GWSPIHOST1 SPI2_HOST
|
#define GWSPI0_HOST SPI2_HOST
|
||||||
#define GWSPIHOST2 SPI3_HOST
|
#define GWSPI1_HOST SPI3_HOST
|
||||||
#endif
|
#endif
|
|
@ -17,11 +17,27 @@
|
||||||
#include "GWDMS22B.h"
|
#include "GWDMS22B.h"
|
||||||
#include "GwTimer.h"
|
#include "GwTimer.h"
|
||||||
|
|
||||||
static SPIBus bus1(GWSPIHOST1);
|
static SPIBus bus1(GWSPI0_HOST);
|
||||||
static SPIBus bus2(GWSPIHOST2);
|
static SPIBus bus2(GWSPI1_HOST);
|
||||||
|
|
||||||
static SpiSensorList sensors;
|
static SpiSensorList sensors;
|
||||||
|
|
||||||
|
#ifdef GWSPI0_CLK
|
||||||
|
static const int spi0clk=GWSPI0_CLK;
|
||||||
|
#else
|
||||||
|
static const int spi0clk=-1;
|
||||||
|
#endif
|
||||||
|
#ifdef GWSPI0_MISO
|
||||||
|
static const int spi0miso=GWSPI0_MISO;
|
||||||
|
#else
|
||||||
|
static const int spi0miso=-1;
|
||||||
|
#endif
|
||||||
|
#ifdef GWSPI0_MOSI
|
||||||
|
static const int spi0mosi=GWSPI0_MOSI;
|
||||||
|
#else
|
||||||
|
static const int spi0mosi=-1;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef GWSPI1_CLK
|
#ifdef GWSPI1_CLK
|
||||||
static const int spi1clk=GWSPI1_CLK;
|
static const int spi1clk=GWSPI1_CLK;
|
||||||
#else
|
#else
|
||||||
|
@ -38,22 +54,6 @@ static const int spi1mosi=GWSPI1_MOSI;
|
||||||
static const int spi1mosi=-1;
|
static const int spi1mosi=-1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GWSPI2_CLK
|
|
||||||
static const int spi2clk=GWSPI2_CLK;
|
|
||||||
#else
|
|
||||||
static const int spi2clk=-1;
|
|
||||||
#endif
|
|
||||||
#ifdef GWSPI2_MISO
|
|
||||||
static const int spi2miso=GWSPI2_MISO;
|
|
||||||
#else
|
|
||||||
static const int spi2miso=-1;
|
|
||||||
#endif
|
|
||||||
#ifdef GWSPI2_MOSI
|
|
||||||
static const int spi2mosi=GWSPI2_MOSI;
|
|
||||||
#else
|
|
||||||
static const int spi2mosi=-1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define _GWSPI
|
#define _GWSPI
|
||||||
void runSpiTask(GwApi *api){
|
void runSpiTask(GwApi *api){
|
||||||
GwLog *logger=api->getLogger();
|
GwLog *logger=api->getLogger();
|
||||||
|
@ -64,22 +64,22 @@ void runSpiTask(GwApi *api){
|
||||||
if (bus == buses.end()){
|
if (bus == buses.end()){
|
||||||
switch (busId)
|
switch (busId)
|
||||||
{
|
{
|
||||||
case 1:
|
case GWSPI0_HOST:
|
||||||
if (spi1clk < 0){
|
if (spi0clk < 0){
|
||||||
LOG_DEBUG(GwLog::ERROR,"SPI bus 1 not configured, cannot create %s",sensor->prefix.c_str());
|
LOG_DEBUG(GwLog::ERROR,"SPI bus 1 not configured, cannot create %s",sensor->prefix.c_str());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (bus1.init(logger,spi1miso,spi1mosi,spi1clk)){
|
if (bus1.init(logger,spi0mosi,spi0miso,spi0clk)){
|
||||||
buses[busId]=&bus1;
|
buses[busId]=&bus1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case GWSPI1_HOST:
|
||||||
if (spi2clk < 0){
|
if (spi1clk < 0){
|
||||||
LOG_DEBUG(GwLog::ERROR,"SPI bus 2 not configured, cannot create %s",sensor->prefix.c_str());
|
LOG_DEBUG(GwLog::ERROR,"SPI bus 2 not configured, cannot create %s",sensor->prefix.c_str());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (bus2.init(logger,spi2miso,spi2mosi,spi2clk)){
|
if (bus2.init(logger,spi1mosi,spi1miso,spi1clk)){
|
||||||
buses[busId]=&bus2;
|
buses[busId]=&bus2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "DMS22B$iintv",
|
"name": "DMS22B$ifintv",
|
||||||
"label": "DMS22B$i Interval",
|
"label": "DMS22B$i Interval",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": 2,
|
"default": 2,
|
||||||
|
|
|
@ -7,8 +7,8 @@ lib_deps =
|
||||||
${env.lib_deps}
|
${env.lib_deps}
|
||||||
${sensors.lib_deps}
|
${sensors.lib_deps}
|
||||||
build_flags=
|
build_flags=
|
||||||
-D GWSPI1_CLK=21
|
-D GWSPI0_CLK=21
|
||||||
-D GWSPI1_MISO=25
|
-D GWSPI0_MISO=25
|
||||||
-D GWDMS22B11
|
-D GWDMS22B11
|
||||||
-D GWDMS22B11_CS=22
|
-D GWDMS22B11_CS=22
|
||||||
${env.build_flags}
|
${env.build_flags}
|
||||||
|
|
Loading…
Reference in New Issue