From ae1c6f5cda3b3029b09d839eb4aeb78643afa3a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Sat, 30 Aug 2025 08:15:26 +0200 Subject: [PATCH] GosundSP111 --- platformio.ini | 49 ++++++++++++++++++++++++++++++++++++++++--------- src/config.cpp | 2 +- src/http.cpp | 6 ++++++ src/io.cpp | 43 ++++++++++++++++++++++++++++++++----------- src/io.h | 38 +++++++++++++++++++++----------------- upload.sh | 7 +++++-- 6 files changed, 105 insertions(+), 40 deletions(-) diff --git a/platformio.ini b/platformio.ini index 19c650e..5e41645 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,19 +1,50 @@ -[env:Sonoff4ChPro] +[common] platform = espressif8266 board = esp8285 framework = arduino upload_speed = 921600 -upload_port = 10.0.0.178 monitor_speed = 115200 build.filesystem = littlefs lib_deps = bblanchon/ArduinoJson @ 7.4.2 -[env:ESP32Test] +[env:Sonoff4ChPro] +platform = ${common.platform} +board = ${common.board} +framework = ${common.framework} +upload_speed = ${common.upload_speed} +monitor_speed = ${common.monitor_speed} +build.filesystem = ${common.build.filesystem} +lib_deps = ${common.lib_deps} +upload_port = 10.0.0.178 +build_flags = -D Sonoff4ChPro + +[env:Sonoff4ChPro_ESP32] platform = espressif32 board = esp32dev -framework = arduino -upload_speed = 921600 -monitor_speed = 115200 -build.filesystem = littlefs -lib_deps = bblanchon/ArduinoJson @ 7.4.2 -build_flags = -D STATUS_PIN=2 -D STATUS_INVERT=false -D CORE_DEBUG_LEVEL=0 \ No newline at end of file +framework = ${common.framework} +upload_speed = ${common.upload_speed} +monitor_speed = ${common.monitor_speed} +build.filesystem = ${common.build.filesystem} +lib_deps = ${common.lib_deps} +build_flags = -D Sonoff4ChPro -D ESP32_TESTBOARD -D CORE_DEBUG_LEVEL=0 + +[env:GosundSP111] +platform = ${common.platform} +board = ${common.board} +framework = ${common.framework} +upload_speed = ${common.upload_speed} +monitor_speed = ${common.monitor_speed} +build.filesystem = ${common.build.filesystem} +lib_deps = ${common.lib_deps} +upload_port = 10.0.0.179 +build_flags = -D GosundSP111 + +[env:GosundSP111_ESP32] +platform = espressif32 +board = esp32dev +framework = ${common.framework} +upload_speed = ${common.upload_speed} +monitor_speed = ${common.monitor_speed} +build.filesystem = ${common.build.filesystem} +lib_deps = ${common.lib_deps} +build_flags = -D GosundSP111 -D ESP32_TESTBOARD -D CORE_DEBUG_LEVEL=0 \ No newline at end of file diff --git a/src/config.cpp b/src/config.cpp index 928d8c7..b70a1ea 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -46,7 +46,7 @@ void listDir(const String &path, const String &indent) { void configSetup() { #ifdef ESP32 - LittleFS.begin(true) + LittleFS.begin(true); #endif #ifdef ESP8266 if (!LittleFS.begin()) { diff --git a/src/http.cpp b/src/http.cpp index fef9206..73588a3 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -82,9 +82,11 @@ void httpStatus() { const auto relays = json["relays"].to(); httpRelayJson(relay0, relays.add()); +#ifdef Sonoff4ChPro httpRelayJson(relay1, relays.add()); httpRelayJson(relay2, relays.add()); httpRelayJson(relay3, relays.add()); +#endif String response; serializeJson(json, response); @@ -93,17 +95,21 @@ void httpStatus() { void httpSet() { httpRelay(0, relay0); +#ifdef Sonoff4ChPro httpRelay(1, relay1); httpRelay(2, relay2); httpRelay(3, relay3); +#endif httpStatus(); } void httpOff() { relay0.set(false); +#ifdef Sonoff4ChPro relay1.set(false); relay2.set(false); relay3.set(false); +#endif httpStatus(); } diff --git a/src/io.cpp b/src/io.cpp index 25ca44b..ccf054f 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -1,22 +1,26 @@ #include "io.h" -#ifndef STATUS_PIN -#define STATUS_PIN 13 +#ifdef GosundSP111 + +#ifndef ESP32_TESTBOARD +#define STATUS_PIN 0 +#define STATUS_INVERT true #endif -#ifndef STATUS_INVERT -#define STATUS_INVERT true +Button button0(13, true, true, [](const ButtonEvent event) { buttonCallback(relay0, event); }); + +Relay relay0(0, "RELAY #0", 15, false, true); + #endif -Relay relay0(0, "RELAY #0", 12, false, true); +#ifdef Sonoff4ChPro -Relay relay1(1, "RELAY #1", 5, false, true); +#ifndef ESP32_TESTBOARD +#define STATUS_PIN 13 +#define STATUS_INVERT true +#endif -Relay relay2(2, "RELAY #2", 4, false, true); - -Relay relay3(3, "RELAY #3", 15, false, true); - -Output status("Status", STATUS_PIN, STATUS_INVERT, false); +Output status("Status", 13, true, false); Button button0(0, true, true, [](const ButtonEvent event) { buttonCallback(relay0, event); }); @@ -26,6 +30,23 @@ Button button2(10, true, true, [](const ButtonEvent event) { buttonCallback(rela Button button3(14, true, true, [](const ButtonEvent event) { buttonCallback(relay3, event); }); +Relay relay0(0, "RELAY #0", 12, false, true); + +Relay relay1(1, "RELAY #1", 5, false, true); + +Relay relay2(2, "RELAY #2", 4, false, true); + +Relay relay3(3, "RELAY #3", 15, false, true); + +#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) { if (event == BUTTON_PRESSED) { output.toggle(); diff --git a/src/io.h b/src/io.h index b3add7c..ff6ace4 100644 --- a/src/io.h +++ b/src/io.h @@ -6,50 +6,54 @@ void buttonCallback(Output &output, ButtonEvent event); -extern Relay relay0; - -extern Relay relay1; - -extern Relay relay2; - -extern Relay relay3; - extern Output status; extern Button button0; +extern Relay relay0; + +#ifdef Sonoff4ChPro + extern Button button1; extern Button button2; extern Button button3; +extern Relay relay1; + +extern Relay relay2; + +extern Relay relay3; + +#endif + inline void ioSetup() { + status.setup(); button0.setup(); + relay0.setup(); +#ifdef Sonoff4ChPro button1.setup(); button2.setup(); button3.setup(); - - status.setup(); - - relay0.setup(); relay1.setup(); relay2.setup(); relay3.setup(); +#endif } inline void ioLoop() { + status.loop(); button0.loop(); + relay0.loop(); +#ifdef Sonoff4ChPro button1.loop(); button2.loop(); button3.loop(); - - status.loop(); - - relay0.loop(); - relay0.loop(); + relay1.loop(); relay2.loop(); relay3.loop(); +#endif } #endif diff --git a/upload.sh b/upload.sh index fa41583..63d2314 100644 --- a/upload.sh +++ b/upload.sh @@ -7,5 +7,8 @@ minify index.html | sed 's|http://10.42.0.204||g' > index.html.min || exit 2 #curl -s 'http://10.42.0.204/upload/index' -F "file=@index.html.min" #curl -s 'http://10.42.0.204/upload/icon' -F "file=@icon.svg" -curl -s 'http://10.0.0.178/upload/index' -F "file=@index.html.min" -curl -s 'http://10.0.0.178/upload/icon' -F "file=@icon.svg" +#curl -s 'http://10.0.0.178/upload/index' -F "file=@index.html.min" +#curl -s 'http://10.0.0.178/upload/icon' -F "file=@icon.svg" + +curl -s 'http://10.0.0.174/upload/index' -F "file=@index.html.min" +curl -s 'http://10.0.0.174/upload/icon' -F "file=@icon.svg"