feat: board profiles (#11)

This commit is contained in:
proddy
2021-03-22 21:12:19 +01:00
parent 273efbcb65
commit b996c4dcf6
13 changed files with 415 additions and 363 deletions

View File

@@ -50,6 +50,7 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
root["api_enabled"] = settings.api_enabled;
root["analog_enabled"] = settings.analog_enabled;
root["pbutton_gpio"] = settings.pbutton_gpio;
root["board_profile"] = settings.board_profile;
}
StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) {
@@ -132,6 +133,9 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
// doesn't need any follow-up actions
settings.api_enabled = root["api_enabled"] | EMSESP_DEFAULT_API_ENABLED;
// board profiles
settings.board_profile = root["board_profile"] | EMSESP_DEFAULT_BOARD_PROFILE;
return StateUpdateResult::CHANGED;
}

View File

@@ -42,6 +42,7 @@
#define EMSESP_DEFAULT_API_ENABLED false // turn off, because its insecure
#define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off
#define EMSESP_DEFAULT_ANALOG_ENABLED false
#define EMSESP_DEFAULT_BOARD_PROFILE 0 // default ESP32
// Default GPIO PIN definitions
#if defined(ESP32)
@@ -84,6 +85,7 @@ class WebSettings {
bool api_enabled;
bool analog_enabled;
uint8_t pbutton_gpio;
uint8_t board_profile;
static void read(WebSettings & settings, JsonObject & root);
static StateUpdateResult update(JsonObject & root, WebSettings & settings);

View File

@@ -169,12 +169,14 @@ void System::get_settings() {
// LED
hide_led_ = settings.hide_led;
led_gpio_ = settings.led_gpio;
// BOARD profile
board_profile_ = settings.board_profile;
});
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
hostname(networkSettings.hostname.c_str());
LOG_INFO(F("System %s booted (EMS-ESP version %s)"), networkSettings.hostname.c_str(), EMSESP_APP_VERSION); // print boot message
ethernet_profile_ = networkSettings.ethernet_profile;
});
}
@@ -284,7 +286,6 @@ void System::button_init(bool refresh) {
}
// Allow 0 for Boot-button on NodeMCU-32s?
// if (pbutton_gpio_) {
if (!myPButton_.init(pbutton_gpio_, HIGH)) {
LOG_INFO(F("External multi-functional button not detected"));
} else {
@@ -295,7 +296,6 @@ void System::button_init(bool refresh) {
myPButton_.onDblClick(BUTTON_DblClickDelay, button_OnDblClick);
myPButton_.onLongPress(BUTTON_LongPressDelay, button_OnLongPress);
myPButton_.onVLongPress(BUTTON_VLongPressDelay, button_OnVLongPress);
// }
}
// set the LED to on or off when in normal operating mode
@@ -454,7 +454,7 @@ void System::network_init(bool refresh) {
// check ethernet profile
// ethernet uses lots of additional memory so we only start it when it's explicitly set in the config
if (ethernet_profile_ == 0) {
if (board_profile_ == 0) {
return;
}
@@ -465,7 +465,7 @@ void System::network_init(bool refresh) {
eth_phy_type_t type; // Type of the Ethernet PHY (LAN8720 or TLK110)
eth_clock_mode_t clock_mode; // ETH_CLOCK_GPIO0_IN or ETH_CLOCK_GPIO0_OUT, ETH_CLOCK_GPIO16_OUT, ETH_CLOCK_GPIO17_OUT for 50Hz inverted clock
if (ethernet_profile_ == 1) {
if (board_profile_ == 1) {
// LAN8720
phy_addr = 0;
power = -1;
@@ -473,7 +473,7 @@ void System::network_init(bool refresh) {
mdio = 18;
type = ETH_PHY_LAN8720;
clock_mode = ETH_CLOCK_GPIO0_IN;
} else if (ethernet_profile_ == 2) {
} else if (board_profile_ == 2) {
// TLK110
phy_addr = 31;
power = -1;
@@ -803,10 +803,10 @@ void System::console_commands(Shell & shell, unsigned int context) {
[](Shell & shell, const std::vector<std::string> & arguments) {
uint8_t n = Helpers::hextoint(arguments.front().c_str());
if (n <= 2) {
EMSESP::esp8266React.getNetworkSettingsService()->update(
[&](NetworkSettings & networkSettings) {
networkSettings.ethernet_profile = n;
shell.printfln(F_(ethernet_option_fmt), networkSettings.ethernet_profile);
EMSESP::webSettingsService.update(
[&](WebSettings & settings) {
settings.board_profile = n;
shell.printfln(F_(ethernet_option_fmt), n);
return StateUpdateResult::CHANGED;
},
"local");
@@ -827,8 +827,6 @@ void System::console_commands(Shell & shell, unsigned int context) {
shell.printfln(F_(wifi_ssid_fmt), networkSettings.ssid.isEmpty() ? uuid::read_flash_string(F_(unset)).c_str() : networkSettings.ssid.c_str());
shell.print(F(" "));
shell.printfln(F_(wifi_password_fmt), networkSettings.ssid.isEmpty() ? F_(unset) : F_(asterisks));
shell.print(F(" "));
shell.printfln(F_(ethernet_option_fmt), networkSettings.ethernet_profile);
});
});

View File

@@ -143,7 +143,7 @@ class System {
uint8_t led_gpio_;
bool syslog_enabled_;
bool analog_enabled_;
uint8_t ethernet_profile_;
uint8_t board_profile_;
uint8_t pbutton_gpio_;
int8_t syslog_level_;
uint32_t syslog_mark_interval_;

View File

@@ -1,2 +1,2 @@
#define EMSESP_APP_VERSION "3.0.1b1"
#define EMSESP_APP_VERSION "3.0.1b2"
#define EMSESP_PLATFORM "ESP32"