Skip to content

Commit

Permalink
improved reliablity of setting desired water temperatur
Browse files Browse the repository at this point in the history
- PureSpaIO::setDesiredWaterTempCelsius: repeat intial change on failure (more robust)
- PureSpaIO::setDesiredWaterTempCelsius: skip getting acutal setpoint when change has failed (speedup)
- PureSpaIO::setDesiredWaterTempCelsius: increase inital wait after change to catch double trigger (more robust)
- PureSpaIO::setDesiredWaterTempCelsius: increase changeTries by one fore ever 10 degrees (more robust)
- PureSpaIO::decodeButton: incease reply pulse length to 3 µs (more robust)
  • Loading branch information
jnsbyr committed Aug 4, 2023
1 parent 389dace commit 1143e8b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
59 changes: 38 additions & 21 deletions PureSpaIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,23 +481,38 @@ void PureSpaIO::setDesiredWaterTempCelsius(int temp)
delay(1);
#else
// trigger temp modification
changeWaterTemp(-1);
if (!changeWaterTemp(-1))
{
changeWaterTemp(+1);
}

int sleep = 100; // ms
int sleep = 5*CYCLE::PERIOD; // ms
int changeTries = 3;
int setTemp = UNDEF::INT;
bool getActualSetpoint = true;
do
{
// wait for temp readback (will take 2-3 blink durations)
int readTries = 5*BLINK::PERIOD/sleep;
int newSetTemp = UNDEF::INT;
// get actual temperature setpoint (will take 2-3 blink durations, especially inital) but skip when change has failed
int readTries = 4*BLINK::PERIOD/sleep;
int newSetTemp = getActualSetpoint? UNDEF::INT : setTemp;
ESP.wdtFeed();
do
if (getActualSetpoint)
{
// always wait after change, especially to catch double trigger
waitBuzzerOff();
delay(BLINK::PERIOD);
}
while (getActualSetpoint)
{
delay(sleep);
newSetTemp = getDesiredWaterTempCelsius();
readTries--;
} while (newSetTemp == setTemp && readTries);
getActualSetpoint = newSetTemp == setTemp && readTries;
if (getActualSetpoint)
{
// only wait when not done
delay(sleep);
}
}
DEBUG_MSG("\nst:%d (rt:%d)", newSetTemp, readTries);

// check success
Expand All @@ -513,18 +528,19 @@ void PureSpaIO::setDesiredWaterTempCelsius(int temp)
if (setTemp == UNDEF::INT)
{
changeTries += abs(newSetTemp - temp);
changeTries += changeTries/10;
}

// change temperature by 1 degree
setTemp = newSetTemp;
if (temp > setTemp)
{
changeWaterTemp(+1);
getActualSetpoint = changeWaterTemp(+1);
changeTries--;
}
else if (temp < setTemp)
{
changeWaterTemp(-1);
getActualSetpoint = changeWaterTemp(-1);
changeTries--;
}
}
Expand Down Expand Up @@ -599,18 +615,19 @@ void PureSpaIO::setDisinfectionTime(int hours)
*/
bool PureSpaIO::pressButton(volatile unsigned int& buttonPressCount)
{
WiFi.setSleepMode(WIFI_LIGHT_SLEEP);
waitBuzzerOff();
unsigned int tries = BUTTON::ACK_TIMEOUT/BUTTON::ACK_CHECK_PERIOD;
WiFi.setSleepMode(WIFI_LIGHT_SLEEP);
buttonPressCount = BUTTON::PRESS_COUNT;
while (buttonPressCount && tries)
{
delay(BUTTON::ACK_CHECK_PERIOD);
tries--;
}
bool success = state.buzzer;
WiFi.setSleepMode(WIFI_NONE_SLEEP);

return tries;
return success;
}

void PureSpaIO::setBubbleOn(bool on)
Expand Down Expand Up @@ -693,10 +710,12 @@ bool PureSpaIO::waitBuzzerOff() const
*/
bool PureSpaIO::changeWaterTemp(int up)
{
bool success = false;

if (isPowerOn() && state.error == ERROR_NONE)
{
waitBuzzerOff();
//DEBUG_MSG("\nP ");
waitBuzzerOff();

#ifndef FORCE_WIFI_SLEEP
WiFi.setSleepMode(WIFI_LIGHT_SLEEP);
Expand Down Expand Up @@ -725,29 +744,27 @@ bool PureSpaIO::changeWaterTemp(int up)
buttons.toggleTempDown = 0;
}

// wait for buzzer
// wait for buzzer on
tries = (BUTTON::PRESS_COUNT - BUTTON::PRESS_SHORT_COUNT)*CYCLE::PERIOD/BUTTON::ACK_CHECK_PERIOD;
while (!state.buzzer && tries)
{
delay(BUTTON::ACK_CHECK_PERIOD);
tries--;
}

success = state.buzzer;

#ifndef FORCE_WIFI_SLEEP
WiFi.setSleepMode(WIFI_NONE_SLEEP);
#endif

if (state.buzzer)
{
return true;
}
else
if (!success)
{
DEBUG_MSG("\ncWT fail");
}
}

return false;
return success;
}

int PureSpaIO::convertDisplayToCelsius(uint32 value) const
Expand Down Expand Up @@ -1210,7 +1227,7 @@ ICACHE_RAM_ATTR inline void PureSpaIO::decodeButton()
#if F_CPU == 160000000L
delayMicroseconds(1);
pinMode(PIN::DATA, OUTPUT);
delayMicroseconds(2);
delayMicroseconds(3);
pinMode(PIN::DATA, INPUT);
#else
#error 160 MHz CPU frequency required! Pulse timing not possible at 80 MHz, because the code above takes too long to reach this point.
Expand Down
2 changes: 1 addition & 1 deletion PureSpaIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class PureSpaIO
{
public:
static const unsigned int PRESS_COUNT = BLINK::PERIOD/CYCLE::PERIOD; // cycles, must be long enough to activate buzzer
static const unsigned int PRESS_SHORT_COUNT = 340/CYCLE::PERIOD; // cycles, must be long enough to trigger, but short enough to avoid double trigger
static const unsigned int PRESS_SHORT_COUNT = 380/CYCLE::PERIOD; // cycles, must be long enough to trigger, but short enough to avoid double trigger
static const unsigned int ACK_CHECK_PERIOD = 10; // ms
static const unsigned int ACK_TIMEOUT = 2*PRESS_COUNT*CYCLE::PERIOD; // ms
};
Expand Down
2 changes: 1 addition & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

namespace CONFIG
{
const char WIFI_VERSION[] = "1.0.6.1"; // 24.07.2023
const char WIFI_VERSION[] = "1.0.6.2"; // 30.07.2023

// WiFi parameters
const unsigned long WIFI_MAX_DISCONNECT_DURATION = 900000; // [ms] 5 min until reboot
Expand Down

0 comments on commit 1143e8b

Please sign in to comment.