Output.cycle FIX
This commit is contained in:
parent
ae1c6f5cda
commit
b88df843ad
19
src/Output.h
19
src/Output.h
@ -27,14 +27,15 @@ protected:
|
|||||||
|
|
||||||
unsigned long stateMillis = 0;
|
unsigned long stateMillis = 0;
|
||||||
|
|
||||||
void _write(const bool state) {
|
void _write(const bool wanted) {
|
||||||
if (state != get()) {
|
const auto current = get();
|
||||||
|
if (wanted != current) {
|
||||||
if (logState) {
|
if (logState) {
|
||||||
Serial.printf("[RELAY] \"%s\" = %s\n", name.c_str(), state ? "ON" : "OFF");
|
Serial.printf("[RELAY] \"%s\" = %s\n", name.c_str(), wanted ? "ON" : "OFF");
|
||||||
}
|
}
|
||||||
stateMillis = millis();
|
stateMillis = millis();
|
||||||
}
|
}
|
||||||
digitalWrite(pin, state ^ inverted ? HIGH : LOW);
|
digitalWrite(pin, wanted ^ inverted ? HIGH : LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _applyInitial() {
|
void _applyInitial() {
|
||||||
@ -73,19 +74,21 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cycle(const unsigned long onMillis_, const unsigned long offMillis_, const unsigned long onCount_ = -1) {
|
void cycle(const unsigned long onMillis_, const unsigned long offMillis_, const unsigned long onCount_ = -1) {
|
||||||
|
set(false); // this sets onCount=0, so do this first
|
||||||
this->onMillis = onMillis_;
|
this->onMillis = onMillis_;
|
||||||
this->offMillis = offMillis_;
|
this->offMillis = offMillis_;
|
||||||
this->onCount = onCount_;
|
this->onCount = onCount_;
|
||||||
set(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (get()) {
|
const auto status = get();
|
||||||
if (onMillis > 0 && millis() - stateMillis > onMillis) {
|
const auto ageMillis = millis() - stateMillis;
|
||||||
|
if (status) {
|
||||||
|
if (onMillis > 0 && ageMillis >= onMillis) {
|
||||||
_write(false);
|
_write(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (offMillis > 0 && millis() - stateMillis > offMillis && onCount != 0) {
|
if (offMillis > 0 && ageMillis >= offMillis && onCount != 0) {
|
||||||
_write(true);
|
_write(true);
|
||||||
if (onCount > 0) {
|
if (onCount > 0) {
|
||||||
onCount--;
|
onCount--;
|
||||||
|
|||||||
@ -30,6 +30,7 @@ void wifiConnect() {
|
|||||||
const auto wifiSSID = configRead(CONFIG_WIFI_SSID, DEFAULT_WIFI_SSID);
|
const auto wifiSSID = configRead(CONFIG_WIFI_SSID, DEFAULT_WIFI_SSID);
|
||||||
const auto wifiPass = configRead(CONFIG_WIFI_PASSWORD, DEFAULT_WIFI_PASSWORD, true, true);
|
const auto wifiPass = configRead(CONFIG_WIFI_PASSWORD, DEFAULT_WIFI_PASSWORD, true, true);
|
||||||
|
|
||||||
|
Serial.printf("[WiFi] Connecting: \"%s\"\n", wifiSSID.c_str());
|
||||||
WiFi.hostname(hostname);
|
WiFi.hostname(hostname);
|
||||||
WiFi.begin(wifiSSID.c_str(), wifiPass.c_str());
|
WiFi.begin(wifiSSID.c_str(), wifiPass.c_str());
|
||||||
wifiLast = max(1UL, millis());
|
wifiLast = max(1UL, millis());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user