On/Off requests now repeat.

Using Minimal SPIFFS, can now fit internal Bluetooth code BUT internal Bluetooth and WiFi
bang radio heads - refusing to co-operate :-(
This commit is contained in:
rljonesau 2018-11-07 21:31:00 +11:00
parent dc8e1940f2
commit a7b6399c30
7 changed files with 35 additions and 10 deletions

View file

@ -3,5 +3,5 @@
"port": "192.168.0.108",
"sketch": "BTCDieselHeater.ino",
"output": "..\\build",
"configuration": "PSRAM=disabled,PartitionScheme=default,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,DebugLevel=none"
"configuration": "PSRAM=disabled,PartitionScheme=min_spiffs,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,DebugLevel=none"
}

View file

@ -11,6 +11,8 @@
#define USE_BLE_BLUETOOTH 0
#define USE_CLASSIC_BLUETOOTH 0
#define USE_WIFI 1
///////////////////////////////////////////////////////////////////////////////
// limit rate of Bluetooth delivery from enthusiastic OEM controllers

View file

@ -170,10 +170,12 @@ void setup() {
// this is the usual USB connection to a PC
// DO THIS BEFORE WE TRY AND SEND DEBUG INFO!
DebugPort.begin(115200);
#if USE_WIFI == 1
initWifi(WiFi_TriggerPin, FAILEDSSID, FAILEDPASSWORD);
initOTA();
initWebServer();
#endif
pinMode(ListenOnlyPin, INPUT_PULLUP); // pin to enable passive mode
pinMode(LED_Pin, OUTPUT); // On board LED indicator
@ -225,9 +227,12 @@ void setup() {
void loop()
{
unsigned long timenow = millis();
#if USE_WIFI == 1
doWiFiManager();
DoOTA();
doWebServer();
#endif
// check for test commands received from PC Over USB
if(DebugPort.available()) {
@ -430,6 +435,7 @@ void loop()
// do some monitoring of the heater state variable
// if abnormal transitions, introduce a smart error!
// This will also cancel ON/OFF requests if runstate in startup/shutdown
SmartError.monitor(HeaterFrame1);
// echo heater reponse data to Bluetooth client

View file

@ -56,6 +56,7 @@ void
CBluetoothESP32Classic::init()
{
_rxLine.clear();
DebugPort.println("Initialising ESP32 Classic Bluetooth");
if(!SerialBT.begin("ESPHEATER")) {
DebugPort.println("An error occurred initialising Bluetooth");

View file

@ -1,4 +1,5 @@
#include "SmartError.h"
#include "TxManage.h"
CSmartError::CSmartError()
{
@ -80,6 +81,19 @@ CSmartError::monitor(unsigned char newRunState)
}
}
if(m_prevRunState != newRunState) {
// check for transition to startup
// - force cancellation of an on request if we generated it
if(newRunState == 2) {
TxManage.queueOnRequest(false); // ensure ON request is cancelled
}
// check for transition to shutdown
// - force cancellation of an off request if we generated it
if(newRunState == 7) {
TxManage.queueOffRequest(false); // ensure OFF request is cancelled
}
}
m_prevRunState = newRunState;
}

View file

@ -42,15 +42,17 @@ void CTxManage::begin()
}
void
CTxManage::queueOnRequest()
CTxManage::queueOnRequest(bool set)
{
m_bOnReq = true;
m_bOnReq = set; // allow cancel via heater frame decode
m_bOffReq = false;
}
void
CTxManage::queueOffRequest()
CTxManage::queueOffRequest(bool set)
{
m_bOffReq = true;
m_bOffReq = set; // allow cancel via heater frame decode
m_bOnReq = false;
}
void
@ -77,11 +79,11 @@ CTxManage::PrepareFrame(const CProtocol& basisFrame, bool isBTCmaster)
}
else {
if(m_bOnReq) {
m_bOnReq = false;
// m_bOnReq = false; // requires cancel via queueOnRequest(false)
m_TxFrame.onCommand();
}
if(m_bOffReq) {
m_bOffReq = false;
// m_bOffReq = false; // requires cancel via queueOffRequest(false)
m_TxFrame.offCommand();
}
}

View file

@ -9,8 +9,8 @@ class CTxManage
public:
CTxManage(int TxGatePin, HardwareSerial& serial);
void queueOnRequest();
void queueOffRequest();
void queueOnRequest(bool set = true); // use false to remove repeating command
void queueOffRequest(bool set = true); // use false to remove repeating command
void queueRawCommand(unsigned char val);
void PrepareFrame(const CProtocol& Frame, bool isBTCmaster);
void Start(unsigned long timenow);