diff --git a/Network.cpp b/Network.cpp index 5d96618..5c9d5db 100644 --- a/Network.cpp +++ b/Network.cpp @@ -32,6 +32,9 @@ void Network::setupDevice() int hardwareDetect = _preferences->getInt(preference_network_hardware); int hardwareDetectGpio = _preferences->getInt(preference_network_hardware_gpio); + Log->print("Hardware detect : "); Log->println(hardwareDetect); + Log->print("Hardware detect GPIO: "); Log->println(hardwareDetectGpio); + if(strcmp(WiFi_fallbackDetect, "wifi_fallback") == 0) { Log->println(F("Switching to WiFi device as fallback.")); @@ -56,14 +59,19 @@ void Network::setupDevice() Log->print(hardwareDetectGpio); Log->println(F(" for network device selection")); - pinMode(hardwareDetect, INPUT_PULLUP); - _networkDeviceType = digitalRead(hardwareDetect) == HIGH ? NetworkDeviceType::WiFi : NetworkDeviceType::W5500; + pinMode(hardwareDetectGpio, INPUT_PULLUP); + _networkDeviceType = digitalRead(hardwareDetectGpio) == HIGH ? NetworkDeviceType::WiFi : NetworkDeviceType::W5500; } else if(hardwareDetect == 2) { Log->print(F("W5500 on M5Sack Atom POE")); _networkDeviceType = NetworkDeviceType::W5500; } + else + { + Log->println(F("Unknown hardware selected, falling back to Wifi.")); + _networkDeviceType = NetworkDeviceType::WiFi; + } } switch(_networkDeviceType) diff --git a/Pins.h b/Pins.h index e7f9d90..e29cf79 100644 --- a/Pins.h +++ b/Pins.h @@ -1,7 +1,5 @@ #pragma once -#define ETHERNET_CS_PIN 19 -#define ETHERNET_RESET_PIN -1 #define TRIGGER_LOCK_PIN 32 #define TRIGGER_UNLOCK_PIN 33 #define TRIGGER_UNLATCH_PIN 27 diff --git a/networkDevices/W5500Device.cpp b/networkDevices/W5500Device.cpp index 6a84af4..0822237 100644 --- a/networkDevices/W5500Device.cpp +++ b/networkDevices/W5500Device.cpp @@ -41,10 +41,12 @@ void W5500Device::initialize() switch(_variant) { case W5500Variant::M5StackAtomPoe: - Ethernet.init(ETHERNET_CS_PIN, 22, 23, 33); + _resetPin = -1; + Ethernet.init(19, 22, 23, 33); break; default: - Ethernet.init(ETHERNET_CS_PIN); + _resetPin = -1; + Ethernet.init(5); break; } @@ -132,14 +134,15 @@ void W5500Device::reconfigure() void W5500Device::resetDevice() { - if(ETHERNET_RESET_PIN == -1) return; + if(_resetPin == -1) return; + Log->println(F("Resetting network hardware.")); - pinMode(ETHERNET_RESET_PIN, OUTPUT); - digitalWrite(ETHERNET_RESET_PIN, HIGH); + pinMode(_resetPin, OUTPUT); + digitalWrite(_resetPin, HIGH); delay(250); - digitalWrite(ETHERNET_RESET_PIN, LOW); + digitalWrite(_resetPin, LOW); delay(50); - digitalWrite(ETHERNET_RESET_PIN, HIGH); + digitalWrite(_resetPin, HIGH); delay(1500); } diff --git a/networkDevices/W5500Device.h b/networkDevices/W5500Device.h index 4272760..98dddb8 100644 --- a/networkDevices/W5500Device.h +++ b/networkDevices/W5500Device.h @@ -65,6 +65,7 @@ private: Preferences* _preferences = nullptr; int _maintainResult = 0; + int _resetPin = -1; bool _hasDHCPAddress = false; char* _path; W5500Variant _variant;