Compare commits
4 Commits
71490427f2
...
801b99a3a7
| Author | SHA1 | Date | |
|---|---|---|---|
| 801b99a3a7 | |||
| 4e5fff2498 | |||
| b88df843ad | |||
| ae1c6f5cda |
@ -26,7 +26,7 @@ upload_speed = ${common.upload_speed}
|
|||||||
monitor_speed = ${common.monitor_speed}
|
monitor_speed = ${common.monitor_speed}
|
||||||
build.filesystem = ${common.build.filesystem}
|
build.filesystem = ${common.build.filesystem}
|
||||||
lib_deps = ${common.lib_deps}
|
lib_deps = ${common.lib_deps}
|
||||||
build_flags = -D Sonoff4ChPro -D CORE_DEBUG_LEVEL=0
|
build_flags = -D Sonoff4ChPro -D ESP32_TESTBOARD -D CORE_DEBUG_LEVEL=0
|
||||||
|
|
||||||
[env:GosundSP111]
|
[env:GosundSP111]
|
||||||
platform = ${common.platform}
|
platform = ${common.platform}
|
||||||
@ -47,4 +47,4 @@ upload_speed = ${common.upload_speed}
|
|||||||
monitor_speed = ${common.monitor_speed}
|
monitor_speed = ${common.monitor_speed}
|
||||||
build.filesystem = ${common.build.filesystem}
|
build.filesystem = ${common.build.filesystem}
|
||||||
lib_deps = ${common.lib_deps}
|
lib_deps = ${common.lib_deps}
|
||||||
build_flags = -D GosundSP111 -D CORE_DEBUG_LEVEL=0
|
build_flags = -D GosundSP111 -D ESP32_TESTBOARD -D CORE_DEBUG_LEVEL=0
|
||||||
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--;
|
||||||
|
|||||||
17
src/io.cpp
17
src/io.cpp
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
#ifdef GosundSP111
|
#ifdef GosundSP111
|
||||||
|
|
||||||
Output status("Status", 0, true, false);
|
#ifndef ESP32_TESTBOARD
|
||||||
|
#define STATUS_PIN 0
|
||||||
|
#define STATUS_INVERT true
|
||||||
|
#endif
|
||||||
|
|
||||||
Button button0(13, true, true, [](const ButtonEvent event) { buttonCallback(relay0, event); });
|
Button button0(13, true, true, [](const ButtonEvent event) { buttonCallback(relay0, event); });
|
||||||
|
|
||||||
@ -12,6 +15,11 @@ Relay relay0(0, "RELAY #0", 15, false, true);
|
|||||||
|
|
||||||
#ifdef Sonoff4ChPro
|
#ifdef Sonoff4ChPro
|
||||||
|
|
||||||
|
#ifndef ESP32_TESTBOARD
|
||||||
|
#define STATUS_PIN 13
|
||||||
|
#define STATUS_INVERT true
|
||||||
|
#endif
|
||||||
|
|
||||||
Output status("Status", 13, true, false);
|
Output status("Status", 13, true, false);
|
||||||
|
|
||||||
Button button0(0, true, true, [](const ButtonEvent event) { buttonCallback(relay0, event); });
|
Button button0(0, true, true, [](const ButtonEvent event) { buttonCallback(relay0, event); });
|
||||||
@ -32,6 +40,13 @@ Relay relay3(3, "RELAY #3", 15, false, true);
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ESP32_TESTBOARD
|
||||||
|
#define STATUS_PIN 2
|
||||||
|
#define STATUS_INVERT false
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Output status("Status", STATUS_PIN, STATUS_INVERT, true);
|
||||||
|
|
||||||
void buttonCallback(Output &output, const ButtonEvent event) {
|
void buttonCallback(Output &output, const ButtonEvent event) {
|
||||||
if (event == BUTTON_PRESSED) {
|
if (event == BUTTON_PRESSED) {
|
||||||
output.toggle();
|
output.toggle();
|
||||||
|
|||||||
@ -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());
|
||||||
@ -50,7 +51,7 @@ void wifiLoop() {
|
|||||||
} else {
|
} else {
|
||||||
if (connected) {
|
if (connected) {
|
||||||
status.set(false);
|
status.set(false);
|
||||||
Serial.printf("[WiFi] Connected as \"%s\" (%s)\n", WiFi.getHostname(), WiFi.localIP().toString().c_str());
|
Serial.printf("[WiFi] Connected \"%s\" as \"%s\" (%s)\n", WiFi.SSID().c_str(), WiFi.getHostname(), WiFi.localIP().toString().c_str());
|
||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
httpSetup();
|
httpSetup();
|
||||||
} else if (wifiLast == 0 || millis() - wifiLast >= 10000) {
|
} else if (wifiLast == 0 || millis() - wifiLast >= 10000) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user