2019-06-29 08:08:37 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the "bluetoothheater" distribution
|
|
|
|
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Ray Jones <ray@mrjones.id.au>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __BTC_TEMPSENSE_H__
|
|
|
|
#define __BTC_TEMPSENSE_H__
|
|
|
|
|
2019-07-25 07:40:23 +00:00
|
|
|
#include "../../lib/esp32-ds18b20/ds18b20.h"
|
2019-10-18 01:55:16 +00:00
|
|
|
#include "../../lib/Adafruit_BME280_Library/Adafruit_BME280.h"
|
|
|
|
#include "DataFilter.h"
|
2019-06-29 08:08:37 +00:00
|
|
|
|
2019-09-21 23:03:42 +00:00
|
|
|
//#define SINGLE_DS18B20_SENSOR
|
|
|
|
|
|
|
|
const int MAX_DS18B20_DEVICES = 3;
|
|
|
|
|
2019-10-18 01:55:16 +00:00
|
|
|
class CSensor {
|
2019-10-18 22:58:19 +00:00
|
|
|
float _reading;
|
|
|
|
CExpMean _filter;
|
|
|
|
int _holdoff;
|
|
|
|
protected:
|
|
|
|
bool update(float val);
|
|
|
|
void reset();
|
2019-10-18 01:55:16 +00:00
|
|
|
public:
|
2019-10-18 22:58:19 +00:00
|
|
|
CSensor();
|
2019-10-18 01:55:16 +00:00
|
|
|
bool getTemperature(float& tempReading, bool filtered);
|
|
|
|
const char* getID();
|
|
|
|
};
|
2019-06-29 08:08:37 +00:00
|
|
|
|
2019-10-18 22:58:19 +00:00
|
|
|
class CDS18B20probe : public CSensor {
|
2019-10-18 01:55:16 +00:00
|
|
|
DS18B20_Info * pSensorInfo;
|
|
|
|
DS18B20_ERROR error;
|
|
|
|
public:
|
|
|
|
CDS18B20probe();
|
|
|
|
void init();
|
|
|
|
void assign(DS18B20_Info *pInfo) { pSensorInfo = pInfo; };
|
|
|
|
void release();
|
|
|
|
bool readSensor();
|
|
|
|
void setError(DS18B20_ERROR err) { error = err; };
|
|
|
|
bool OK() { return error == DS18B20_OK; };
|
|
|
|
OneWireBus_ROMCode getROMcode() const;
|
|
|
|
DS18B20_Info* getSensorInfo() { return pSensorInfo; };
|
|
|
|
float getReading(bool filtered);
|
|
|
|
bool matchROMcode(uint8_t test[8]);
|
|
|
|
};
|
2019-06-29 08:08:37 +00:00
|
|
|
|
2019-10-18 22:58:19 +00:00
|
|
|
class CDS18B20SensorSet {
|
2019-06-29 08:08:37 +00:00
|
|
|
OneWireBus * _owb;
|
|
|
|
owb_rmt_driver_info _rmt_driver_info;
|
2019-09-21 23:03:42 +00:00
|
|
|
|
2019-10-18 01:55:16 +00:00
|
|
|
CDS18B20probe _Sensors[MAX_DS18B20_DEVICES];
|
|
|
|
int _nNumSensors;
|
2019-10-27 03:25:40 +00:00
|
|
|
bool _bReportFind;
|
2019-10-18 01:55:16 +00:00
|
|
|
int _sensorMap[MAX_DS18B20_DEVICES];
|
2019-06-29 08:08:37 +00:00
|
|
|
bool _discover();
|
2019-10-18 01:55:16 +00:00
|
|
|
|
2019-06-29 08:08:37 +00:00
|
|
|
public:
|
2019-10-18 22:58:19 +00:00
|
|
|
CDS18B20SensorSet();
|
2019-06-29 08:08:37 +00:00
|
|
|
void begin(int pin);
|
|
|
|
bool find();
|
2019-09-21 23:03:42 +00:00
|
|
|
bool readSensors();
|
2019-06-29 08:08:37 +00:00
|
|
|
void startConvert();
|
|
|
|
void waitConvertDone();
|
2019-09-21 23:03:42 +00:00
|
|
|
int checkNumSensors() const;
|
2019-10-18 01:55:16 +00:00
|
|
|
bool getTemperature(int mapIdx, float& tempReading, bool filtered);
|
|
|
|
bool getTemperatureIdx(int sensIdx, float& tempReading, bool filtered) ; // index is sensor discovery order on one-wire bus
|
|
|
|
bool getRomCodeIdx(int sensIdx, OneWireBus_ROMCode& romCode) const; // index is sensor discovery order on one-wire bus
|
2019-09-21 23:03:42 +00:00
|
|
|
bool mapSensor(int idx, OneWireBus_ROMCode romCode = { 0 } );
|
2019-10-18 01:55:16 +00:00
|
|
|
int getNumSensors() const { return _nNumSensors; };
|
|
|
|
const char* getID();
|
|
|
|
};
|
|
|
|
|
|
|
|
class CBME280Sensor : public CSensor {
|
|
|
|
Adafruit_BME280 _bme; // I2C
|
|
|
|
long _lastSampleTime;
|
|
|
|
int _count;
|
|
|
|
public:
|
|
|
|
CBME280Sensor();
|
|
|
|
bool begin(int ID);
|
|
|
|
bool getTemperature(float& tempReading, bool filtered) ;
|
2020-01-13 08:48:32 +00:00
|
|
|
bool getAltitude(float& reading);
|
|
|
|
bool getHumidity(float& reading);
|
2019-10-18 01:55:16 +00:00
|
|
|
const char* getID();
|
|
|
|
int getCount() const { return _count; };
|
|
|
|
};
|
|
|
|
|
|
|
|
class CTempSense {
|
|
|
|
|
2019-10-18 22:58:19 +00:00
|
|
|
CDS18B20SensorSet DS18B20;
|
2019-10-18 01:55:16 +00:00
|
|
|
CBME280Sensor BME280;
|
|
|
|
|
|
|
|
bool _discover();
|
|
|
|
public:
|
|
|
|
CTempSense();
|
|
|
|
void begin(int oneWirePin, int I2CID);
|
|
|
|
bool readSensors();
|
|
|
|
void startConvert();
|
2019-10-18 22:58:19 +00:00
|
|
|
int getSensorType(int usrIdx);
|
|
|
|
const char* getID(int usrIdx);
|
2019-10-18 01:55:16 +00:00
|
|
|
bool getTemperature(int usrIdx, float& tempReading, bool filtered=true) ; // indexed as mapped by user
|
|
|
|
float getOffset(int usrIdx);
|
|
|
|
void setOffset(int usrIdx, float offset);
|
|
|
|
bool getTemperatureBME280(float& tempReading) ; // index is sensor discovery order on one-wire bus
|
|
|
|
bool getTemperatureDS18B20Idx(int sensIdx, float& tempReading) ; // index is sensor discovery order on one-wire bus
|
|
|
|
int getNumSensors() const;
|
2020-01-13 08:48:32 +00:00
|
|
|
bool getAltitude(float& reading);
|
|
|
|
bool getHumidity(float& reading);
|
2019-10-18 01:55:16 +00:00
|
|
|
CBME280Sensor& getBME280() { return BME280; };
|
2019-10-18 22:58:19 +00:00
|
|
|
CDS18B20SensorSet& getDS18B20() { return DS18B20; };
|
|
|
|
static void format(char* msg, float fTemp);
|
2019-06-29 08:08:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|