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

intermediate: restructure for sensors via API

This commit is contained in:
andreas
2024-11-16 20:15:09 +01:00
parent 56518d9309
commit f75f8033d1
15 changed files with 173 additions and 77 deletions

20
lib/sensors/GwSensor.cpp Normal file
View File

@@ -0,0 +1,20 @@
/*
(C) Andreas Vogel andreas@wellenvogel.de
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "GwSensor.h"
#include "GwApi.h"
void SensorList::add(SensorBase::Ptr sensor){
this->push_back(sensor);
}

View File

@@ -14,9 +14,11 @@
*/
#ifndef _GWSENSORS_H
#define _GWSENSORS_H
#include "GwApi.h"
#include "GwLog.h"
#include <Arduino.h>
#include <memory>
#include <vector>
class GwApi;
class GwConfigHandler;
class SensorBase{
public:
using BusType=enum{
@@ -63,16 +65,13 @@ class SensorTemplate : public SensorBase{
class SensorList : public std::vector<SensorBase::Ptr>{
public:
void add(GwApi *api, SensorBase::Ptr sensor){
sensor->readConfig(api->getConfig());
api->getLogger()->logDebug(GwLog::LOG,"configured sensor %s, status %d",sensor->prefix.c_str(),(int)sensor->ok);
this->push_back(sensor);
}
void add(SensorBase::Ptr sensor);
using std::vector<SensorBase::Ptr>::vector;
};
#define CFG_GET(name,prefix) \
cfg->getValue(name, GwConfigDefinitions::prefix ## name)
#endif