move preference converter switch cases to NetworkUtil

This commit is contained in:
technyon
2024-08-18 08:21:28 +02:00
parent 7138802462
commit 0b423ee29d
3 changed files with 78 additions and 51 deletions

View File

@@ -218,59 +218,12 @@ void NukiNetwork::setupDevice()
#if defined(CONFIG_IDF_TARGET_ESP32)
else if(custPHY >= 4 && custPHY <= 9)
{
std::string custName;
eth_phy_type_t custEthtype;
eth_clock_mode_t custCLK;
switch(custPHY)
{
case 4:
custName = "Custom (LAN8720)";
custEthtype = ETH_PHY_TYPE_LAN8720;
break;
case 5:
custName = "Custom (RTL8201)";
custEthtype = ETH_PHY_RTL8201;
break;
case 6:
custName = "Custom (TLK110)";
custEthtype = ETH_PHY_TLK110;
break;
case 7:
custName = "Custom (DP83848)";
custEthtype = ETH_PHY_DP83848;
break;
case 8:
custName = "Custom (KSZ8041)";
custEthtype = ETH_PHY_KSZ8041;
break;
case 9:
custName = "Custom (KSZ8081)";
custEthtype = ETH_PHY_KSZ8081;
break;
default:
custName = "Custom (LAN8720)";
custEthtype = ETH_PHY_TYPE_LAN8720;
break;
}
int custCLKpref = _preferences->getInt(preference_network_custom_clk, 0);
switch(custCLKpref)
{
case 0:
custCLK = ETH_CLOCK_GPIO0_IN;
break;
case 2:
custCLK = ETH_CLOCK_GPIO16_OUT;
break;
case 3:
custCLK = ETH_CLOCK_GPIO17_OUT;
break;
default:
custCLK = ETH_CLOCK_GPIO17_OUT;
break;
}
std::string custName = NetworkUtil::GetCustomEthernetDeviceName(custPHY);
eth_phy_type_t custEthtype = NetworkUtil::GetCustomEthernetType(custPHY);
eth_clock_mode_t custCLK = NetworkUtil::GetCustomClock(custCLKpref);
_device = new EthernetDevice(_hostname, _preferences, _ipConfiguration, custName, _preferences->getInt(preference_network_custom_addr, -1), _preferences->getInt(preference_network_custom_pwr, -1), _preferences->getInt(preference_network_custom_mdc, -1), _preferences->getInt(preference_network_custom_mdio, -1), custEthtype, custCLK);
}
#endif

View File

@@ -1,5 +1,6 @@
#include "NetworkUtil.h"
#include "../Logger.h"
#include "../networkDevices/LAN8720Definitions.h"
NetworkDeviceType NetworkUtil::GetDeviceTypeFromPreference(int hardwareDetect, int customPhy)
{
@@ -51,3 +52,71 @@ NetworkDeviceType NetworkUtil::GetDeviceTypeFromPreference(int hardwareDetect, i
break;
}
}
std::string NetworkUtil::GetCustomEthernetDeviceName(int custPHY)
{
switch(custPHY)
{
case 4:
return "Custom (LAN8720)";
case 5:
return"Custom (RTL8201)";
case 6:
return "Custom (TLK110)";
case 7:
return "Custom (DP83848)";
case 8:
return "Custom (KSZ8041)";
case 9:
return "Custom (KSZ8081)";
default:
return"Custom (LAN8720)";
}
}
eth_phy_type_t NetworkUtil::GetCustomEthernetType(int custPHY)
{
switch(custPHY)
{
case 4:
return ETH_PHY_TYPE_LAN8720;
break;
case 5:
return ETH_PHY_RTL8201;
break;
case 6:
return ETH_PHY_TLK110;
break;
case 7:
return ETH_PHY_DP83848;
break;
case 8:
return ETH_PHY_KSZ8041;
break;
case 9:
return ETH_PHY_KSZ8081;
break;
default:
return ETH_PHY_TYPE_LAN8720;
break;
}
}
eth_clock_mode_t NetworkUtil::GetCustomClock(int custCLKpref)
{
switch(custCLKpref)
{
case 0:
return ETH_CLOCK_GPIO0_IN;
break;
case 2:
return ETH_CLOCK_GPIO16_OUT;
break;
case 3:
return ETH_CLOCK_GPIO17_OUT;
break;
default:
return ETH_CLOCK_GPIO17_OUT;
break;
}
}

View File

@@ -1,9 +1,14 @@
#pragma once
#include <string>
#include <ETH.h>
#include "../enums/NetworkDeviceType.h"
class NetworkUtil
{
public:
static NetworkDeviceType GetDeviceTypeFromPreference(int hardwareDetect, int customPhy);
static std::string GetCustomEthernetDeviceName(int custPHY);
static eth_phy_type_t GetCustomEthernetType(int custPHY);
static eth_clock_mode_t GetCustomClock(int custCLKpref);
};