Skip to content

Commit

Permalink
Refactor to TimeReacged()
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Aug 18, 2024
1 parent e741427 commit 4f62a0d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 36 deletions.
4 changes: 2 additions & 2 deletions tasmota/tasmota_xdrv_driver/xdrv_07_domoticz.ino
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void MqttPublishDomoticzFanState(void) {
Response_P(DOMOTICZ_MESSAGE, (int)DomoticzRelayIdx(1), (0 == fan_speed) ? 0 : 2, svalue, DomoticzBatteryQuality(), DomoticzRssiQuality());
MqttPublish(domoticz_in_topic);

Domoticz->fan_debounce = millis();
Domoticz->fan_debounce = millis() + 1000; // 1 second
}
}

Expand Down Expand Up @@ -321,7 +321,7 @@ bool DomoticzMqttData(void) {
if (GetFanspeed() == svalue) {
return true; // Stop as already set
}
if (TimePassedSince(Domoticz->fan_debounce) < 1000) {
if (!TimeReached(Domoticz->fan_debounce)) {
return true; // Stop if device in limbo
}
snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_FANSPEED));
Expand Down
14 changes: 1 addition & 13 deletions tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,7 @@ void ShutterAllowPreStartProcedure(uint8_t i) {
#ifdef USE_RULES
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Delay Start? var%d <99>=<%s>, max10s?"),i + 1, rules_vars[i]);
// wait for response from rules
/*
uint32_t start_time = millis();
while (TimePassedSince(start_time) < 10000 && (String)rules_vars[i] == "99") {
delay(1);
}
*/
uint32_t end_time = millis() + 10000;
uint32_t end_time = millis() + 10000; // 10 seconds
while (!TimeReached(end_time) && (String)rules_vars[i] == "99") {
delay(1);
}
Expand Down Expand Up @@ -1389,12 +1383,6 @@ void ShutterUpdateVelocity(uint8_t i)

void ShutterWaitForMotorStart(uint8_t i)
{
/*
uint32_t start_time = Shutter[i].last_stop_time;
while (TimePassedSince(start_time) < ShutterSettings.shutter_motorstop && TimePassedSince(start_time) > 0) {
loop();
}
*/
uint32_t end_time = Shutter[i].last_stop_time + ShutterSettings.shutter_motorstop;
while (!TimeReached(end_time)) {
loop();
Expand Down
12 changes: 0 additions & 12 deletions tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,6 @@ void ShutterWaitForMotorStop(uint8_t i)

void ShutterWaitForMotorStart(uint8_t i)
{
/*
uint32_t start_time = Shutter[i].last_stop_time;
while (TimePassedSince(start_time) < Settings->shutter_motorstop && TimePassedSince(start_time) > 0) {
loop();
}
*/
uint32_t end_time = Shutter[i].last_stop_time + Settings->shutter_motorstop;
while (!TimeReached(end_time)) {
loop();
Expand Down Expand Up @@ -740,12 +734,6 @@ void ShutterAllowPreStartProcedure(uint8_t i) {
#ifdef USE_RULES
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Delay Start? var%d <99>=<%s>, max10s?"),i + 1, rules_vars[i]);
// wait for response from rules
/*
uint32_t start_time = millis();
while (TimePassedSince(start_time) < 10000 && (String)rules_vars[i] == "99") {
delay(1);
}
*/
uint32_t end_time = millis() + 10000;
while (!TimeReached(end_time) && (String)rules_vars[i] == "99") {
delay(1);
Expand Down
8 changes: 4 additions & 4 deletions tasmota/tasmota_xdrv_driver/xdrv_30_exs_dimmer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ void ExsSerialSend(const uint8_t data[] = nullptr, uint16_t len = 0)
ExsSerial->flush();

// wait for any response
uint32_t snd_time = millis();
while ((TimePassedSince(snd_time) < EXS_ACK_TIMEOUT) &&
uint32_t snd_time = millis() + EXS_ACK_TIMEOUT;
while ((!TimeReached(snd_time)) &&
(!ExsSerial->available()))
;

Expand Down Expand Up @@ -550,8 +550,8 @@ void CmndExsState(void)
ExsSendCmd(EXS_GET_VALUES, 0);

// wait for data
uint32_t snd_time = millis();
while ((TimePassedSince(snd_time) < EXS_ACK_TIMEOUT) &&
uint32_t snd_time = millis() + EXS_ACK_TIMEOUT;
while ((!TimeReached(snd_time)) &&
(!ExsSerial->available()))
;
ExsSerialInput();
Expand Down
4 changes: 2 additions & 2 deletions tasmota/tasmota_xdrv_driver/xdrv_45_shelly_dimmer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ bool ShdSerialSend(const uint8_t data[] = nullptr, uint16_t len = 0)
ShdSerial->flush();

// wait for any response
uint32_t snd_time = millis();
while (TimePassedSince(snd_time) < SHD_ACK_TIMEOUT)
uint32_t snd_time = millis() + SHD_ACK_TIMEOUT;
while (!TimeReached(snd_time))
{
if (ShdSerialInput())
return true;
Expand Down
6 changes: 3 additions & 3 deletions tasmota/tasmota_xsns_sensor/xsns_20_novasds.ino
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ bool NovaSdsCommand(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint16_t sensor
NovaSdsSerial->flush();

// wait for any response
unsigned long cmndtime = millis();
while ( (TimePassedSince(cmndtime) < NOVA_SDS_RECDATA_TIMEOUT) && ( ! NovaSdsSerial->available() ) );
unsigned long cmndtime = millis() + NOVA_SDS_RECDATA_TIMEOUT;
while ( (!TimeReached(cmndtime)) && ( ! NovaSdsSerial->available() ) );
if ( ! NovaSdsSerial->available() ) {
// timeout
return false;
}
uint8_t recbuf[10];
memset(recbuf, 0, sizeof(recbuf));
// sync to 0xAA header
while ( (TimePassedSince(cmndtime) < NOVA_SDS_RECDATA_TIMEOUT) && ( NovaSdsSerial->available() > 0) && (0xAA != (recbuf[0] = NovaSdsSerial->read())) );
while ( (!TimeReached(cmndtime)) && ( NovaSdsSerial->available() > 0) && (0xAA != (recbuf[0] = NovaSdsSerial->read())) );
if ( 0xAA != recbuf[0] ) {
// no head found
return false;
Expand Down

0 comments on commit 4f62a0d

Please sign in to comment.