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-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-06-29 08:08:37 +00:00
|
|
|
class CTempSense {
|
|
|
|
|
|
|
|
OneWireBus * _owb;
|
|
|
|
owb_rmt_driver_info _rmt_driver_info;
|
2019-09-21 23:03:42 +00:00
|
|
|
DS18B20_Info * _Sensors[MAX_DS18B20_DEVICES];
|
|
|
|
OneWireBus_ROMCode _device_rom_codes[MAX_DS18B20_DEVICES];
|
|
|
|
int _nNumSensors;
|
|
|
|
|
|
|
|
float _Readings[MAX_DS18B20_DEVICES];
|
|
|
|
DS18B20_ERROR _Errors[MAX_DS18B20_DEVICES];
|
2019-06-29 08:08:37 +00:00
|
|
|
|
|
|
|
bool _discover();
|
2019-09-21 23:03:42 +00:00
|
|
|
int _sensorMap[3];
|
2019-06-29 08:08:37 +00:00
|
|
|
public:
|
|
|
|
CTempSense();
|
|
|
|
void begin(int pin);
|
|
|
|
bool find();
|
2019-09-21 23:03:42 +00:00
|
|
|
#ifdef SINGLE_DS18B20_SENSOR
|
2019-06-29 08:08:37 +00:00
|
|
|
bool readROMcode();
|
|
|
|
bool attach();
|
2019-09-21 23:03:42 +00:00
|
|
|
#endif
|
|
|
|
bool readSensors();
|
2019-06-29 08:08:37 +00:00
|
|
|
void startConvert();
|
|
|
|
void waitConvertDone();
|
2019-09-22 04:46:39 +00:00
|
|
|
bool getTemperature(int mapIdx, float& tempReading); // indexed as mapped by user
|
|
|
|
bool getTemperatureIdx(int sensIdx, float& tempReading); // index is sensor discovery order on one-wire bus
|
|
|
|
bool getRomCodeIdx(int sensIdx, OneWireBus_ROMCode& romCode); // index is sensor discovery order on one-wire bus
|
2019-09-21 23:03:42 +00:00
|
|
|
int checkNumSensors() const;
|
|
|
|
int getNumSensors() const { return _nNumSensors; };
|
|
|
|
bool mapSensor(int idx, OneWireBus_ROMCode romCode = { 0 } );
|
2019-06-29 08:08:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|