Added external thermostat via GPIO in 2. Want to change how GPIO pins are defined.

Modded code to only allow single DS18B20 - getting funny ROM SEARCH lock ups...
Set mini temp sample interval to 750ms, as per data sheet for 12bit DS18B20
This commit is contained in:
Ray Jones 2019-08-07 18:59:30 +10:00
parent e205119b24
commit 10db95733f
21 changed files with 223 additions and 69 deletions

View file

@ -11,15 +11,14 @@
[env:esp32dev]
platform = espressif32
lib_extra_dirs = ~/Documents/Arduino/libraries
;lib_dir = src/Afterburner/src
board = esp32dev
framework = arduino
board_build.partitions = min_spiffs.csv
upload_speed = 921600
upload_port = 192.168.20.40
upload_protocol = espota
;upload_port = COM16
;upload_protocol = esptool
;upload_port = 192.168.20.40
;upload_protocol = espota
upload_port = COM16
upload_protocol = esptool
upload_flags =
--port=3232
monitor_speed = 115200

View file

@ -123,8 +123,8 @@
#define RX_DATA_TIMOUT 50
const int FirmwareRevision = 30;
const int FirmwareSubRevision = 2;
const char* FirmwareDate = "3 Aug 2019";
const int FirmwareSubRevision = 3;
const char* FirmwareDate = "7 Aug 2019";
#ifdef ESP32
@ -326,7 +326,7 @@ void setup() {
digitalWrite(GPIOout2_pin, LOW);
nvs_stats_t nvs_stats;
esp_err_t err = nvs_get_stats(NULL, &nvs_stats);
nvs_get_stats(NULL, &nvs_stats);
// initialise TelnetSpy (port 23) as well as Serial to 115200
// Serial is the usual USB connection to a PC
@ -1033,6 +1033,17 @@ bool getThermostatModeActive()
}
}
bool getExternalThermostatModeActive()
{
return GPIOin.usesExternalThermostat();
}
bool getExternalThermostatOn()
{
return GPIOin.getState(1);
}
void checkDisplayUpdate()
{
// only update OLED when not processing blue wire
@ -1086,10 +1097,10 @@ float getTemperatureDesired()
return getHeaterInfo().getHeaterDemand();
}
else {
if(getThermostatModeActive())
// if(getThermostatModeActive())
return RTC_Store.getDesiredTemp();
else
return RTC_Store.getDesiredPump();
// else
// return RTC_Store.getDesiredPump();
}
}
@ -1390,7 +1401,13 @@ void setupGPIO()
}
else {
// unknown board or forced no GPIO by grounding pin26 - deny all GPIO operation
GPIOin.begin(0, 0, GPIOinNone, LOW);
// set all pins as inputs with pull ups
pinMode(GPIOin2_pin, INPUT_PULLUP);
pinMode(GPIOin1_pinV21V10, INPUT_PULLUP);
pinMode(GPIOin1_pinV20, INPUT_PULLUP);
pinMode(GPIOout1_pin, INPUT_PULLUP);
pinMode(GPIOout2_pin, INPUT_PULLUP);
GPIOin.begin(0, 0, GPIOinNone, LOW); // ensure modes disabled (should already be by constructors)
GPIOout.begin(0, 0, GPIOoutNone);
GPIOalg.begin(ADC1_CHANNEL_5, GPIOalgNone);
}

View file

@ -116,7 +116,7 @@ CBasicScreen::show()
case 0:
// Show current heat demand setting
if(getThermostatModeActive()) {
if(getThermostatModeActive() && !getExternalThermostatModeActive()) {
float fTemp = getTemperatureDesired();
if(NVstore.getUserSettings().degF) {
fTemp = fTemp * 9 / 5 + 32;

View file

@ -98,8 +98,9 @@ CDetailedScreen::show()
float desiredT = 0;
float fPump = 0;
if((runstate && (runstate <= 5)) || (runstate == 9) || _showTarget) { // state 9 = manufactured "heating glow plug"
if(getThermostatModeActive())
if(getThermostatModeActive() && !getExternalThermostatModeActive()) {
desiredT = getTemperatureDesired();
}
else {
fPump = getHeaterInfo().getPump_Fixed();
if(NVstore.getUserSettings().cyclic.isEnabled())
@ -328,7 +329,16 @@ CDetailedScreen::showThermometer(float fDesired, float fActual, float fPump)
// draw target setting
// may be suppressed if not in normal start or run state
if((fDesired != 0) || (fPump != 0)) {
_drawBitmap(X_TARGET_ICON, Y_TARGET_ICON, TargetIconInfo); // draw target icon
if(getThermostatModeActive() && getExternalThermostatModeActive()) {
_drawBitmap(X_TARGET_ICON-2, Y_TARGET_ICON+1, ExtThermoIconInfo); // draw external input #2 icon
if(getExternalThermostatOn())
_drawBitmap(X_TARGET_ICON-2, Y_TARGET_ICON+9, CloseIconInfo); // draw external input #2 icon
else
_drawBitmap(X_TARGET_ICON-2, Y_TARGET_ICON+9, OpenIconInfo); // draw external input #2 icon
}
else {
_drawBitmap(X_TARGET_ICON, Y_TARGET_ICON, TargetIconInfo); // draw target icon
}
char msg[16];
if(fPump == 0) {
int yPos = Y_BULB + TEMP_YPOS(fDesired) - 2; // 2 offsets mid height of icon

View file

@ -25,6 +25,7 @@
#include "../Utility/NVStorage.h"
#include "../Utility/BTC_GPIO.h"
#include "fonts/Icons.h"
#include "../Utility/BoardDetect.h"
extern CGPIOout GPIOout;
extern CGPIOin GPIOin;
@ -79,14 +80,15 @@ CGPIOScreen::show()
}
else {
_showTitle("GPIO Settings");
_drawBitmap(10, 14, GPIOIconInfo);
_drawBitmap(10, 14, (getBoardRevision() != BRD_V2_GPIO_NOALG) ? GPIOIconInfo : GPIOIconNoAlgInfo);
{
const char* msgText = NULL;
switch(_GPIOparams.inMode) {
case GPIOinNone: msgText = "Disabled"; break;
case GPIOinOn1Off2: msgText = "1-On 2-Off"; break;
case GPIOinOnHold1: msgText = "1-On 2-\352T"; break;
case GPIOinOn1Off1: msgText = "1-On/Off"; break;
case GPIOinOn1Off2: msgText = "1:On 2:Off"; break;
case GPIOinOnHold1: msgText = "1:On 2:\352T"; break;
case GPIOinOn1Off1: msgText = "1:On/Off"; break;
case GPIOinExtThermostat2: msgText = "2:\352T"; break;
}
if(msgText)
_printMenuText(Column, Line3, msgText, _rowSel == 3);
@ -103,7 +105,7 @@ CGPIOScreen::show()
_printMenuText(Column, Line2, msgText, _rowSel == 2);
}
{
if(getBoardRevision() != BRD_V2_GPIO_NOALG) { // Not No Analog support
const char* msgText = NULL;
switch(_GPIOparams.algMode) {
case GPIOalgNone: msgText = "Disabled"; break;
@ -157,9 +159,10 @@ CGPIOScreen::animate()
_display.drawFastHLine(0, 52, 128, WHITE);
switch(_GPIOparams.inMode) {
case GPIOinNone: pMsg = " Digital inputs are disabled. "; break;
case GPIOinOn1Off2: pMsg = " Input 1: Starts upon closure. Input 2: Stops upon closure. "; break;
case GPIOinOnHold1: pMsg = " Input 1: Starts when held closed, stops when opened. Input2: Max fuel when closed, min fuel when open. "; break;
case GPIOinOn1Off2: pMsg = " Input 1: Starts upon closure. Input 2: Stops upon closure. "; break;
case GPIOinOnHold1: pMsg = " Input 1: Starts when held closed, stops when opened. Input2: Max fuel when closed, min fuel when open. "; break;
case GPIOinOn1Off1: pMsg = " Input 1: Starts or Stops upon closure. "; break;
case GPIOinExtThermostat2: pMsg = " Input 1: not used. Input 2: Max fuel when closed, min fuel when open. "; break;
}
if(pMsg)
_scrollMessage(56, pMsg, _scrollChar);
@ -213,12 +216,16 @@ CGPIOScreen::keyHandler(uint8_t event)
if(event & key_Down) {
_scrollChar = 0;
_rowSel--;
if((_rowSel == 1) && (getBoardRevision() == BRD_V2_GPIO_NOALG)) // GPIO but NO analog support
_rowSel--; // force skip if analog input is not supported by PCB
LOWERLIMIT(_rowSel, 0);
}
// UP press
if(event & key_Up) {
switch(_rowSel) {
case 0:
if(getBoardRevision() == BRD_V2_GPIO_NOALG) // GPIO but NO Analog support
_rowSel++; // force skip if analog input is not supported by PCB
case 1:
case 2:
case 3:
@ -279,7 +286,7 @@ CGPIOScreen::_adjust(int dir)
case 3:
tVal = _GPIOparams.inMode;
tVal += dir;
WRAPLIMITS(tVal, 0, 3);
WRAPLIMITS(tVal, 0, 4);
_GPIOparams.inMode = (GPIOinModes)tVal;
break;
}

View file

@ -53,6 +53,7 @@
#include "../Protocol/Protocol.h"
#include "fonts/Arial.h"
#include <SPIFFS.h>
#include "../Utility/BoardDetect.h"
#pragma pack ( push, 1)
struct sBMPhdr {
@ -395,7 +396,7 @@ CScreenManager::begin(bool bNoClock)
if(!bNoClock)
menuloop.push_back(new CClockScreen(*_pDisplay, *this)); // clock
menuloop.push_back(new CPrimingScreen(*_pDisplay, *this)); // mode / priming
if(getBoardRevision() != 0 && getBoardRevision() != 22)
if(getBoardRevision() != 0 && getBoardRevision() != BRD_V2_NOGPIO) // has GPIO support
menuloop.push_back(new CGPIOInfoScreen(*_pDisplay, *this)); // GPIO info
menuloop.push_back(new CMenuTrunkScreen(*_pDisplay, *this));
_Screens.push_back(menuloop);
@ -431,7 +432,7 @@ CScreenManager::begin(bool bNoClock)
menuloop.push_back(new CThermostatModeScreen(*_pDisplay, *this)); // thermostat settings screen
menuloop.push_back(new CHomeMenuSelScreen(*_pDisplay, *this)); // Home menu settings screen
menuloop.push_back(new COtherOptionsScreen(*_pDisplay, *this)); // Other options screen
if(getBoardRevision() != 0 && getBoardRevision() != 22)
if(getBoardRevision() != 0 && getBoardRevision() != BRD_V2_NOGPIO) // has GPIO support ?
menuloop.push_back(new CGPIOScreen(*_pDisplay, *this)); // GPIO settings screen
_Screens.push_back(menuloop);

View file

@ -79,7 +79,6 @@ CThermostatModeScreen::show()
}
else {
_showTitle("Thermostat Mode");
// _printInverted(_display.xCentre(), 0, " Thermostat Mode ", true, eCentreJustify);
_drawBitmap(3, 14, ThermostatIconInfo);
float fTemp = _window;
if(NVstore.getUserSettings().degF) {
@ -90,17 +89,15 @@ CThermostatModeScreen::show()
sprintf(msg, "%.1f\367C", fTemp);
}
_printMenuText(Column, Line2, msg, _rowSel == 3);
const char* modeStr = NULL;
switch(_thermoMode) {
case 1:
_printMenuText(Column, Line3, "Deadband", _rowSel == 4);
break;
case 2:
_printMenuText(Column, Line3, "Linear Hz", _rowSel == 4);
break;
default:
_printMenuText(Column, Line3, "Standard", _rowSel == 4);
break;
case 0: modeStr = "Standard"; break;
case 1: modeStr = "Deadband"; break;
case 2: modeStr = "Linear Hz"; break;
case 3: modeStr = "Ext thermostat"; break;
}
if(modeStr)
_printMenuText(Column, Line3, modeStr, _rowSel == 4);
if(_cyclicMode.isEnabled()) {
float fTemp = _cyclicMode.Stop+1;
if(NVstore.getUserSettings().degF) {
@ -117,7 +114,6 @@ CThermostatModeScreen::show()
_printMenuText(Column, Line1, msg, _rowSel == 1);
if(_cyclicMode.isEnabled()) {
float fTemp = _cyclicMode.Start;
// if(NVstore.getDegFMode()) {
if(NVstore.getUserSettings().degF) {
fTemp = fTemp * 9 / 5;
sprintf(msg, "\352<%.0f\367F", fTemp);
@ -166,14 +162,17 @@ CThermostatModeScreen::animate()
case 4:
_display.drawFastHLine(0, 52, 128, WHITE);
switch(_thermoMode) {
case 0:
pMsg = " Use heater's standard thermostat control. ";
break;
case 1:
pMsg = " The user defined window sets the thermostat's hysteresis. ";
break;
case 2:
pMsg = " The pump rate is adjusted linearly across the set point window. ";
break;
default:
pMsg = " Use heater's standard thermostat control. ";
case 3:
pMsg = " The heater runs according to GPIO input #2: Open:minimum, Closed:maximum. ";
break;
}
if(pMsg)
@ -311,6 +310,7 @@ CThermostatModeScreen::keyHandler(uint8_t event)
void
CThermostatModeScreen::_adjust(int dir)
{
int wrap;
switch(_rowSel) {
case 1:
_cyclicMode.Stop += dir;
@ -326,7 +326,8 @@ CThermostatModeScreen::_adjust(int dir)
break;
case 4: // thermostat mode
_thermoMode += dir;
WRAPLIMITS(_thermoMode, 0, 2);
wrap = getExternalThermostatModeActive() ? 3 : 2;
WRAPLIMITS(_thermoMode, 0, wrap);
break;
}
}

View file

@ -96,13 +96,12 @@ CVersionInfoScreen::show()
// }
_drawBitmap(18, 34, HardwareIconInfo);
int PCB = getBoardRevision();
sprintf(msg, "V%.1f", float(PCB)*0.1f);
_printMenuText(41, 38, msg);
if(PCB == 20) {
_printMenuText(41, 38, getBoardRevisionString(PCB));
if(PCB == BRD_V2_GPIO_NOALG) {
_display.fillRect(70, 36, 57, 11, WHITE);
_printInverted(99, 38, "No Analog", true, eCentreJustify);
}
if(PCB == 22) {
if(PCB == BRD_V2_NOGPIO) {
_display.fillRect(82, 36, 45, 11, WHITE);
_printInverted(105, 38, "No GPIO", true, eCentreJustify);
}

View file

@ -868,6 +868,7 @@ const uint8_t PROGMEM GPIOIcon[] =
0x01, 0x80, 0x00, // ##
};
const BITMAP_INFO GPIOIconInfo(20, 33, GPIOIcon);
const BITMAP_INFO GPIOIconNoAlgInfo(20, 20, GPIOIcon);
const uint8_t PROGMEM firmwareIcon[] =
@ -1153,3 +1154,18 @@ const uint8_t PROGMEM miniThermoIcon[] =
};
const BITMAP_INFO miniThermoIconInfo(6, 13, miniThermoIcon);
//
// Image data for externalThermostat
//
const uint8_t PROGMEM ExtThermoIcon[] =
{
0x00, 0x80, // #
0x04, 0x80, // # #
0x02, 0x9c, // # # ###
0xFF, 0x84, // ######### #
0x02, 0x9c, // # # ###
0x04, 0x90, // # # #
0x00, 0x9c, // # ###
};
const BITMAP_INFO ExtThermoIconInfo(14, 7, ExtThermoIcon);

View file

@ -116,8 +116,9 @@ extern const BITMAP_INFO RefreshIconInfo;
// Bitmap for thermostat modes
extern const BITMAP_INFO ThermostatIconInfo;
// Bitmap for gPIO
// Bitmap for GPIO
extern const BITMAP_INFO GPIOIconInfo;
extern const BITMAP_INFO GPIOIconNoAlgInfo;
// Bitmap for firmware
extern const BITMAP_INFO FirmwareIconInfo;
@ -142,3 +143,4 @@ extern const BITMAP_INFO ThermostatDegFIconInfo;
extern const BITMAP_INFO ThermostatHzIconInfo;
extern const BITMAP_INFO resetIconInfo;
extern const BITMAP_INFO miniThermoIconInfo;
extern const BITMAP_INFO ExtThermoIconInfo;

View file

@ -148,8 +148,23 @@ CTxManage::PrepareFrame(const CProtocol& basisFrame, bool isBTCmaster)
Window /= 2;
switch(ThermoMode) {
case 3: // GPIO controlled thermostat mode
if(getExternalThermostatModeActive()) {
if(getExternalThermostatOn()) {
u8Temp = m_TxFrame.getTemperature_Max(); // input active (contact closure) - max burn
}
else {
u8Temp = m_TxFrame.getTemperature_Min(); // input not active (contact open) - min burn
}
m_TxFrame.setHeaterDemand(u8Temp);
m_TxFrame.setThermostatModeProtocol(0); // direct heater to use Hz Mode
m_TxFrame.setTemperature_Actual(0); // must force actual to 0 for Hz mode
break;
}
// deliberately fall through if not enabled for GPIO control to standard thermostat
// |
// V
case 0: // conventional heater controlled thermostat mode
case 3: // conventional heater controlled thermostat mode
m_TxFrame.setThermostatModeProtocol(1); // using heater thermostat control
u8Temp = (uint8_t)(tActual + 0.5);
m_TxFrame.setTemperature_Actual(u8Temp);

View file

@ -30,20 +30,21 @@ const int FADEAMOUNT = 3;
const int FLASHPERIOD = 2000;
const int ONFLASHINTERVAL = 50;
const char* GPIOinNames[4] = {
const char* GPIOinNames[] = {
"Disabled",
"On1Off2",
"Hold1",
"On1Off1"
"On1Off1",
"ExtThermostat"
};
const char* GPIOoutNames[3] = {
const char* GPIOoutNames[] = {
"Disabled",
"Status",
"User"
};
const char* GPIOalgNames[2] = {
const char* GPIOalgNames[] = {
"Disabled",
"HeatDemand"
};
@ -127,6 +128,8 @@ CGPIOin::simulateKey(uint8_t newKey)
case GPIOinOn1Off1:
_doOn1Off1(newKey);
break;
case GPIOinExtThermostat2:
break; // handling actually performed at Tx Manage for setting the fuel rate
}
}

View file

@ -27,15 +27,16 @@
#include "Debounce.h"
#include <list>
extern const char* GPIOinNames[4];
extern const char* GPIOoutNames[3];
extern const char* GPIOalgNames[2];
extern const char* GPIOinNames[];
extern const char* GPIOoutNames[];
extern const char* GPIOalgNames[];
enum GPIOinModes {
GPIOinNone,
GPIOinOn1Off2, // input 1 closure, heater starts; input2 closure, heater stops
GPIOinOnHold1, // hold input 1 closure, heater runs; input 1 open, heater stops
GPIOinOn1Off1 // alternate input 1 closures start or stop the heater
GPIOinOn1Off1, // alternate input 1 closures start or stop the heater
GPIOinExtThermostat2 // input 2 used to max/min heater if closed/open
};
@ -75,6 +76,9 @@ public:
uint8_t getState(int channel);
GPIOinModes getMode() const;
void simulateKey(uint8_t newKey);
bool usesExternalThermostat() const {
return (_Mode == GPIOinOnHold1) || (_Mode == GPIOinExtThermostat2);
};
};
class CGPIOout {

View file

@ -123,7 +123,7 @@ void interpretJsonCommand(char* pLine)
else if(strcmp("ThermostatMethod", it->key) == 0) {
sUserSettings settings = NVstore.getUserSettings();
uint8_t val = it->value.as<uint8_t>();
if(INBOUNDS(val, 0, 2))
if(INBOUNDS(val, 0, 3))
settings.ThermostatMethod = val;
NVstore.setUserSettings(settings);
}

View file

@ -105,20 +105,20 @@ int BoardDetect()
int pin26 = digitalRead(26);
if((pin33 == HIGH) && (pin26 == HIGH) && (pin25 == HIGH)) {
revision = 10;
revision = BRD_V2_FULLGPIO;
DebugPort.println("Board detect: digital input test reveals V1.x PCB");
}
else if((pin33 == LOW) && (pin26 == HIGH) && (pin25 == LOW)) {
revision = 20;
DebugPort.println("Board detect: digital input test reveals V2.0 PCB");
}
else if((pin33 == HIGH) && (pin26 == LOW) && (pin25 == LOW)) {
revision = 21;
DebugPort.println("Board detect: digital input test reveals V2.1 PCB");
revision = BRD_V2_NOGPIO;
DebugPort.println("Board detect: digital input test reveals V2.2 PCB - no GPIO (V2.0 userID) ");
}
else if((pin33 == HIGH) && (pin26 == LOW) && (pin25 == HIGH)) {
revision = 22;
DebugPort.println("Board detect: digital input test reveals V2.0 PCB - no GPIO");
revision = BRD_V2_GPIO_NOALG;
DebugPort.println("Board detect: digital input test reveals V2.0 PCB - Digital only GPIO (V2.1 userID)");
}
else if((pin33 == HIGH) && (pin26 == LOW) && (pin25 == LOW)) {
revision = BRD_V2_FULLGPIO;
DebugPort.println("Board detect: digital input test reveals V2.1 PCB - Full GPIO (V2.2 userID)");
}
else {
DebugPort.println("Board detect: digital input test failed to detect a valid combination!!!");
@ -135,4 +135,15 @@ int BoardDetect()
DebugPort.printf("Board detect: Result = V%.1f\r\n", float(revision)*0.1f);
return revision;
}
}
const char* getBoardRevisionString(int ID)
{
switch(ID) {
case BRD_V1_FULLGPIO: return "V1.0";
case BRD_V2_FULLGPIO: return "V2.2";
case BRD_V2_NOGPIO: return "V2.0";
case BRD_V2_GPIO_NOALG: return "V2.1";
default: return "???";
}
}

View file

@ -21,5 +21,19 @@
#include <stdint.h>
// **** NOTE: internal codes do not match user codes ****
// internal codes follow the evoloution of discovering that the intial analog input
// could not be used and had to be swapped with GPIOin1 :-(
// the the easier to build PCB with no GPIO!
// The User IDs make more logical sense:
// V2.0 base no GPIO
// V2.1 only digital IO
// V2.2 full GPIO
#define BRD_V1_FULLGPIO 10
#define BRD_V2_GPIO_NOALG 20 // original V20 board - no cut traces - analog on wrong pin :-(
#define BRD_V2_FULLGPIO 21 // V2 board cut traces tranposed GPIO1 & Analog
#define BRD_V2_NOGPIO 22 // V2 board forced short on analog input - NO GPIO mode
int BoardDetect();
void BoardRevisionReset();
const char* getBoardRevisionString(int ID);

View file

@ -345,7 +345,7 @@ sUserSettings::load()
validatedLoad("cyclicStop", cyclic.Stop, 0, s8inBounds, 0, 10);
validatedLoad("cyclicStart", cyclic.Start, -1, s8inBounds, -20, 0);
uint8_t tVal;
validatedLoad("GPIOinMode", tVal, 0, u8inBounds, 0, 3); GPIO.inMode = (GPIOinModes)tVal;
validatedLoad("GPIOinMode", tVal, 0, u8inBounds, 0, 4); GPIO.inMode = (GPIOinModes)tVal;
validatedLoad("GPIOoutMode", tVal, 0, u8inBounds, 0, 2); GPIO.outMode = (GPIOoutModes)tVal;
validatedLoad("GPIOalgMode", tVal, 0, u8inBounds, 0, 2); GPIO.algMode = (GPIOalgModes)tVal;
validatedLoad("MenuOnTimeout", HomeMenu.onTimeout, 0, u8inBounds, 0, 3);

View file

@ -262,7 +262,7 @@ struct sUserSettings : public CESP32_NVStorage {
retval &= INBOUNDS(dimTime, -600000, 600000); // +/- 10 mins
retval &= INBOUNDS(menuTimeout, 0, 300000); // 5 mins
retval &= (degF == 0) || (degF == 1);
retval &= (ThermostatMethod & 0x03) < 3; // only modes 0, 1 or 2
retval &= ThermostatMethod <= 3; // only modes 0, 1 or 2, 3
retval &= INBOUNDS(ThermostatWindow, 0.2f, 10.f);
retval &= useThermostat < 2;
retval &= (enableWifi == 0) || (enableWifi == 1);

View file

@ -31,6 +31,24 @@ CTempSense::CTempSense()
}
void CTempSense::begin(int pin)
{
// initialise DS18B20 sensor interface
// create one wire bus interface, using RMT peripheral
pinMode(pin, INPUT_PULLUP);
_owb = owb_rmt_initialize(&_rmt_driver_info, pin, RMT_CHANNEL_1, RMT_CHANNEL_0);
owb_use_crc(_owb, true); // enable CRC check for ROM code
// bool found = find();
delay(10); // couple of glitches take place during pin setup - give a bit of space to avoid no sensor issues?
bool found = readROMcode();
// Create DS18B20 device on the 1-Wire bus
if(found) {
attach();
}
}
/*void CTempSense::begin(int pin)
{
// initialise DS18B20 sensor interface
// create one wire bus interface, using RMT peripheral
@ -46,9 +64,44 @@ void CTempSense::begin(int pin)
attach();
}
}
*/
bool
CTempSense::readTemperature(float& tempReading)
{
if(_TempSensor == NULL) {
// bool found = find();
bool found = readROMcode();
if(found) {
DebugPort.println("Found DS18B20 device");
// readROMcode();
attach();
startConvert(); // request a new conversion,
waitConvertDone();
}
}
if(_TempSensor != NULL) {
DS18B20_ERROR error = ds18b20_read_temp(_TempSensor, &tempReading);
// DebugPort.printf(">>>> DS18B20 = %f, error=%d\r\n", fTemperature, error);
if(error == DS18B20_OK) {
return true;
}
else {
DebugPort.println("\007DS18B20 sensor removed?");
ds18b20_free(&_TempSensor);
}
}
return false;
}
/*bool
CTempSense::readTemperature(float& tempReading)
{
if(_TempSensor == NULL) {
@ -81,7 +134,7 @@ CTempSense::readTemperature(float& tempReading)
return false;
}
*/
bool
CTempSense::find()
{

View file

@ -36,6 +36,8 @@ extern bool reqDemand(uint8_t newTemp, bool save=true);
extern bool reqThermoToggle();
extern bool setThermostatMode(uint8_t);
extern bool getThermostatModeActive(); // OEM: actual mode from blue wire, BTC: or our NV
extern bool getExternalThermostatModeActive();
extern bool getExternalThermostatOn();
extern void reqPumpPrime(bool on);
extern float getTemperatureDesired(); // OEM: the advertised value, BTC our setpoint
extern uint8_t getDemandDegC();

View file

@ -73,7 +73,7 @@
///////////////////////////////////////////////////////////////////////////////
// DS18B20 temperature sensing
//
#define MIN_TEMPERATURE_INTERVAL 500
#define MIN_TEMPERATURE_INTERVAL 750 // max conversion time for 12 bit DS18B20
///////////////////////////////////////////////////////////////////////////////
// Real Time Clock support